Changeset 513 for OCO/branches/DAZ/drv16/waudio.cpp
- Timestamp:
- Jul 12, 2010, 12:57:31 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OCO/branches/DAZ/drv16/waudio.cpp
r496 r513 2 2 /* SCCSID = %W% %E% */ 3 3 /**************************************************************************** 4 * 5 * Copyright (c) IBM Corporation 1994 - 1997. 6 * 7 * The following IBM OS/2 source code is provided to you solely for the 4 * * 5 * Copyright (c) IBM Corporation 1994 - 1997. * 6 * * 7 * The following IBM OS/2 source code is provided to you solely for the * 8 8 * the purpose of assisting you in your development of OS/2 device drivers. * 9 * You may use this code in accordance with the IBM License Agreement 10 * provided in the IBM Device Driver Source Kit for OS/2. 11 * 9 * You may use this code in accordance with the IBM License Agreement * 10 * provided in the IBM Device Driver Source Kit for OS/2. * 11 * * 12 12 ****************************************************************************/ 13 13 /**@internal %W% 14 14 * @notes 15 * 16 * 17 * 15 * The default for 8 bps is unsigned and signed for > 8 bps 16 * The default byte order for > 8 bps is little endian 17 * (important for devices that support both formats) 18 18 * 19 19 * @version %I% 20 20 * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit, 21 * 21 * <stack context>. 22 22 * @history 23 23 * … … 86 86 // 87 87 ULONG aaulWave[NUMFREQS][BPSTYPES][MONOSTEREO] = { 88 WAVE_FORMAT_1M08, /* 11.025kHz, 8-bitMono */89 WAVE_FORMAT_1S08, /* 11.025kHz, 8-bitStereo */90 91 92 93 94 95 96 WAVE_FORMAT_2M08, /* 22.05kHz , 8-bitMono */97 WAVE_FORMAT_2S08, /* 22.05kHz , 8-bitStereo */98 99 100 101 102 103 104 WAVE_FORMAT_4M08, /* 44.1kHz , 8-bitMono */105 WAVE_FORMAT_4S08, /* 44.1kHz , 8-bitStereo */106 107 108 109 110 111 112 WAVE_FORMAT_8M08, /* 8.0kHz , 8-bitMono */113 WAVE_FORMAT_8S08, /* 8.0kHz , 8-bitStereo */114 115 116 117 118 119 WAVE_FORMAT_8S16/* 8.0kHz , 32-bit Stereo */ //TODO: what else can we fill in?120 88 WAVE_FORMAT_1M08, /* 11.025kHz, 8-bit Mono */ 89 WAVE_FORMAT_1S08, /* 11.025kHz, 8-bit Stereo */ 90 WAVE_FORMAT_1M16, /* 11.025kHz, 16-bit Mono */ 91 WAVE_FORMAT_1S16, /* 11.025kHz, 16-bit Stereo */ 92 WAVE_FORMAT_1M16, /* 11.025kHz, 24-bit Mono */ //TODO: what else can we fill in? 93 WAVE_FORMAT_1S16, /* 11.025kHz, 24-bit Stereo */ //TODO: what else can we fill in? 94 WAVE_FORMAT_1M16, /* 11.025kHz, 32-bit Mono */ //TODO: what else can we fill in? 95 WAVE_FORMAT_1S16, /* 11.025kHz, 32-bit Stereo */ //TODO: what else can we fill in? 96 WAVE_FORMAT_2M08, /* 22.05kHz , 8-bit Mono */ 97 WAVE_FORMAT_2S08, /* 22.05kHz , 8-bit Stereo */ 98 WAVE_FORMAT_2M16, /* 22.05kHz , 16-bit Mono */ 99 WAVE_FORMAT_2S16, /* 22.05kHz , 16-bit Stereo */ 100 WAVE_FORMAT_2M16, /* 22.05kHz , 24-bit Mono */ //TODO: what else can we fill in? 101 WAVE_FORMAT_2S16, /* 22.05kHz , 24-bit Stereo */ //TODO: what else can we fill in? 102 WAVE_FORMAT_2M16, /* 22.05kHz , 32-bit Mono */ //TODO: what else can we fill in? 103 WAVE_FORMAT_2S16, /* 22.05kHz , 32-bit Stereo */ //TODO: what else can we fill in? 104 WAVE_FORMAT_4M08, /* 44.1kHz , 8-bit Mono */ 105 WAVE_FORMAT_4S08, /* 44.1kHz , 8-bit Stereo */ 106 WAVE_FORMAT_4M16, /* 44.1kHz , 16-bit Mono */ 107 WAVE_FORMAT_4S16, /* 44.1kHz , 16-bit Stereo */ 108 WAVE_FORMAT_4M16, /* 44.1kHz , 24-bit Mono */ //TODO: what else can we fill in? 109 WAVE_FORMAT_4S16, /* 44.1kHz , 24-bit Stereo */ //TODO: what else can we fill in? 110 WAVE_FORMAT_4M16, /* 44.1kHz , 32-bit Mono */ //TODO: what else can we fill in? 111 WAVE_FORMAT_4S16, /* 44.1kHz , 32-bit Stereo */ //TODO: what else can we fill in? 112 WAVE_FORMAT_8M08, /* 8.0kHz , 8-bit Mono */ 113 WAVE_FORMAT_8S08, /* 8.0kHz , 8-bit Stereo */ 114 WAVE_FORMAT_8M16, /* 8.0kHz , 16-bit Mono */ 115 WAVE_FORMAT_8S16, /* 8.0kHz , 16-bit Stereo */ 116 WAVE_FORMAT_8M16, /* 8.0kHz , 24-bit Mono */ //TODO: what else can we fill in? 117 WAVE_FORMAT_8S16, /* 8.0kHz , 24-bit Stereo */ //TODO: what else can we fill in? 118 WAVE_FORMAT_8M16, /* 8.0kHz , 32-bit Mono */ //TODO: what else can we fill in? 119 WAVE_FORMAT_8S16 /* 8.0kHz , 32-bit Stereo */ //TODO: what else can we fill in? 120 }; 121 121 122 122 // … … 125 125 // _usfind_matching_sample_rate) and the number of channels 126 126 ULONG aaulAlaw[NUMFREQS][MONOSTEREO] = { 127 ALAW_8B11KM,/* 8bit 11kHz mono*/128 ALAW_8B11KS,/* 8bit 11kHz stereo*/129 ALAW_8B22KM,/* 8bit 22kHz mono*/130 ALAW_8B22KS,/* 8bit 22kHz stereo*/131 ALAW_8B44KM,/* 8bit 44kHz mono*/132 ALAW_8B44KS,/* 8bit 44kHz stereo*/133 ALAW_8B8KM ,/* 8bit 8kHz mono*/134 ALAW_8B8KS/* 8bit 8kHz stereo*/135 127 ALAW_8B11KM, /* 8bit 11kHz mono*/ 128 ALAW_8B11KS, /* 8bit 11kHz stereo*/ 129 ALAW_8B22KM, /* 8bit 22kHz mono*/ 130 ALAW_8B22KS, /* 8bit 22kHz stereo*/ 131 ALAW_8B44KM, /* 8bit 44kHz mono*/ 132 ALAW_8B44KS, /* 8bit 44kHz stereo*/ 133 ALAW_8B8KM , /* 8bit 8kHz mono*/ 134 ALAW_8B8KS /* 8bit 8kHz stereo*/ 135 }; 136 136 // 137 137 // the following 2-D array defines the subtypes for DATATYPE_MULAW … … 139 139 // _usfind_matching_sample_rate) and the number of channels 140 140 ULONG aaulMulaw[NUMFREQS][MONOSTEREO] = { 141 MULAW_8B11KM,/* 8bit 11kHz mono*/142 MULAW_8B11KS,/* 8bit 11kHz stereo*/143 MULAW_8B22KM,/* 8bit 22kHz mono*/144 MULAW_8B22KS,/* 8bit 22kHz stereo*/145 MULAW_8B44KM,/* 8bit 44kHz mono*/146 MULAW_8B44KS,/* 8bit 44kHz stereo*/147 MULAW_8B8KM ,/* 8bit 8kHz mono*/148 MULAW_8B8KS/* 8bit 8kHz stereo*/149 141 MULAW_8B11KM, /* 8bit 11kHz mono*/ 142 MULAW_8B11KS, /* 8bit 11kHz stereo*/ 143 MULAW_8B22KM, /* 8bit 22kHz mono*/ 144 MULAW_8B22KS, /* 8bit 22kHz stereo*/ 145 MULAW_8B44KM, /* 8bit 44kHz mono*/ 146 MULAW_8B44KS, /* 8bit 44kHz stereo*/ 147 MULAW_8B8KM , /* 8bit 8kHz mono*/ 148 MULAW_8B8KS /* 8bit 8kHz stereo*/ 149 }; 150 150 151 151 // … … 161 161 162 162 WAVEAUDIO::WAVEAUDIO(ULONG devicetype, ULONG ulDeviceNr) : 163 164 { 165 166 167 163 AUDIOHW(devicetype) 164 { 165 this->ulDeviceNr = ulDeviceNr; 166 167 StreamId = 0; 168 168 } 169 169 170 170 /**@internal _usfind_matching_sample_rate 171 * @param 172 * @param 171 * @param PULONG pulSampleRate 172 * @param PULONG pSampleRates 173 173 * @return 174 174 * @notes … … 182 182 USHORT WAVEAUDIO::_usfind_matching_sample_rate(PULONG pulSampleRate, int nrSampleRates, PULONG pSampleRates) 183 183 { 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 184 ULONG ulMinDistance = 0x7fffffff; 185 USHORT usMatching; 186 USHORT us; 187 188 if(nrSampleRates == 0) { 189 nrSampleRates = 4; 190 pSampleRates = aulSuppSampleRates; 191 } 192 for ( us = 0; us < nrSampleRates; us++ ) { 193 ULONG ulDistance = distance( *pulSampleRate, pSampleRates[us] ); 194 if (ulDistance < ulMinDistance) { 195 ulMinDistance = ulDistance; 196 usMatching = us; 197 } 198 } 199 *pulSampleRate = pSampleRates[usMatching]; 200 return usMatching; 201 201 } 202 202 //****************************************************************************** … … 208 208 ULONG WAVEAUDIO::QueryDataFlags(ULONG ulOperation, ULONG ulDataType, ULONG ulBitsPerSample) 209 209 { 210 ULONG 210 ULONG ulFlags; 211 211 PWAVE_CAPS pWaveCaps; 212 212 213 ulFlags = FIXED 214 213 ulFlags = FIXED | // Fixed length data 214 LEFT_ALIGNED; // Left align bits on byte bndry (for samples < 8 bits; TODO) 215 215 216 216 if(ulOperation == OPERATION_PLAY) { 217 217 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 218 218 } 219 219 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; … … 223 223 case DATATYPE_WAVEFORM: 224 224 case PCM: 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 225 //NOTE1: The default for 8 bps is unsigned and signed for > 8 bps !!! 226 //NOTE2: The default byte order for > 8 bps is little endian 227 228 switch(ulBitsPerSample) 229 { 230 case 8: 231 //default = unsigned 232 break; 233 case 16: 234 //default = signed 235 ulFlags |= TWOS_COMPLEMENT; 236 237 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_LE)) 238 { 239 ulFlags |= BIG_ENDIAN; 240 } 241 //else little endian 242 break; 243 case 24: 244 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS_SIGNED) 245 { 246 ulFlags |= TWOS_COMPLEMENT; 247 } 248 //else unsigned 249 250 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS_LE)) 251 { 252 ulFlags |= BIG_ENDIAN; 253 } 254 //else little endian 255 break; 256 case 32: 257 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS_SIGNED) 258 { 259 ulFlags |= TWOS_COMPLEMENT; 260 } 261 //else unsigned 262 263 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS_LE)) 264 { 265 ulFlags |= BIG_ENDIAN; 266 } 267 //else little endian 268 break; 269 }//switch BPS 270 break; 271 271 272 272 case DATATYPE_ALAW: 273 273 case DATATYPE_RIFF_ALAW: 274 274 case A_LAW: 275 275 break; 276 276 277 277 case DATATYPE_MULAW: 278 278 case DATATYPE_RIFF_MULAW: 279 279 case MU_LAW: 280 280 break; 281 281 282 282 case DATATYPE_ADPCM_AVC: 283 283 case DATATYPE_CT_ADPCM: 284 284 break; 285 285 286 286 default: 287 288 287 DebugInt3(); 288 return 0; 289 289 } 290 290 return ulFlags; … … 294 294 //****************************************************************************** 295 295 ULONG WAVEAUDIO::QueryOSSDataFormat(ULONG ulOperation, ULONG ulDataType, 296 296 ULONG ulBitsPerSample) 297 297 { 298 298 ULONG ulDataFormat; … … 300 300 301 301 if(ulOperation == OPERATION_PLAY) { 302 302 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 303 303 } 304 304 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; … … 308 308 case DATATYPE_WAVEFORM: 309 309 case PCM: 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 310 //NOTE1: The default for 8 bps is unsigned and signed for > 8 bps !!! 311 //NOTE2: The default byte order for > 8 bps is little endian 312 switch(ulBitsPerSample) 313 { 314 case 8: 315 //Default is unsigned, so check that first 316 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_U8) 317 { 318 ulDataFormat = OSS32_PCM_FORMAT_U8; 319 } 320 else ulDataFormat = OSS32_PCM_FORMAT_S8; 321 break; 322 323 case 16: 324 //Default is signed, so check that first 325 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_SIGNED) 326 {//signed LE or BE 327 //Default is LE, so check that first 328 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_LE) 329 { 330 ulDataFormat = OSS32_PCM_FORMAT_S16_LE; 331 } 332 else ulDataFormat = OSS32_PCM_FORMAT_S16_BE; 333 } 334 else 335 {//unsigned LE or BE 336 //Default is LE, so check that first 337 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_LE) 338 { 339 ulDataFormat = OSS32_PCM_FORMAT_U16_LE; 340 } 341 else ulDataFormat = OSS32_PCM_FORMAT_U16_BE; 342 } 343 break; 344 345 case 24: 346 //Default is signed, so check that first 347 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS_SIGNED) 348 {//signed LE or BE 349 //Default is LE, so check that first 350 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS_LE) 351 { 352 ulDataFormat = OSS32_PCM_FORMAT_S24_LE; 353 } 354 else ulDataFormat = OSS32_PCM_FORMAT_S24_BE; 355 } 356 else 357 {//unsigned LE or BE 358 //Default is LE, so check that first 359 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS_LE) 360 { 361 ulDataFormat = OSS32_PCM_FORMAT_U24_LE; 362 } 363 else ulDataFormat = OSS32_PCM_FORMAT_U24_BE; 364 } 365 break; 366 367 case 32: 368 //Default is signed, so check that first 369 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS_SIGNED) 370 {//signed LE or BE 371 //Default is LE, so check that first 372 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS_LE) 373 { 374 ulDataFormat = OSS32_PCM_FORMAT_S32_LE; 375 } 376 else ulDataFormat = OSS32_PCM_FORMAT_S32_BE; 377 } 378 else 379 {//unsigned LE or BE 380 //Default is LE, so check that first 381 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS_LE) 382 { 383 ulDataFormat = OSS32_PCM_FORMAT_U32_LE; 384 } 385 else ulDataFormat = OSS32_PCM_FORMAT_U32_BE; 386 } 387 break; 388 }//switch BPS 389 break; 390 390 391 391 case DATATYPE_ALAW: 392 392 case DATATYPE_RIFF_ALAW: 393 393 case A_LAW: 394 395 394 ulDataFormat = OSS32_PCM_FORMAT_ALAW; 395 break; 396 396 397 397 case DATATYPE_MULAW: 398 398 case DATATYPE_RIFF_MULAW: 399 399 case MU_LAW: 400 401 400 ulDataFormat = OSS32_PCM_FORMAT_MULAW; 401 break; 402 402 403 403 case DATATYPE_ADPCM_AVC: 404 404 case DATATYPE_CT_ADPCM: 405 406 405 ulDataFormat = OSS32_PCM_FORMAT_ADPCM; 406 break; 407 407 408 408 default: 409 410 411 409 dprintf(("DataFormat wrong:%x",ulBitsPerSample)); 410 DebugInt3(); 411 return 0; 412 412 } 413 413 return ulDataFormat; //flag to format type … … 417 417 //****************************************************************************** 418 418 BOOL WAVEAUDIO::SetupConversion(PWAVECONFIGINFO pConfigInfo, 419 420 421 { 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 else usConversion |= CONVERT_UNSIGNED;//unsigned to unsigned488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1560 561 // 562 563 564 565 566 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1567 568 // 569 570 571 572 573 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2574 575 // 576 577 578 579 580 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2581 582 // 583 584 585 586 587 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2588 589 // 590 591 592 593 594 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2595 596 597 598 599 600 601 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(2,0);//factor 4602 603 604 605 606 607 608 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(2,0);//factor 4609 610 611 612 613 614 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5615 616 617 618 619 620 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5621 622 623 624 625 626 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5627 628 629 630 631 632 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5633 634 635 636 637 638 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1639 640 641 642 643 644 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1645 646 647 648 649 650 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1651 652 653 654 655 656 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1657 658 659 660 661 662 663 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1664 665 666 667 668 669 670 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5671 672 673 674 675 676 677 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5678 679 680 681 682 683 684 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2685 686 687 688 689 690 691 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0);//factor 2692 693 694 695 696 697 698 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1699 700 701 702 703 704 705 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1706 707 708 709 710 711 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5712 713 714 715 716 717 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5718 719 720 721 722 723 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5724 725 726 727 728 729 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1);//factor 0.5730 731 732 733 734 735 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2);//factor 0.25736 737 738 739 740 741 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2);//factor 0.25742 743 744 745 746 747 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2);//factor 0.25748 749 750 751 752 753 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2);//factor 0.25754 755 756 757 758 759 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0);//factor 1760 761 762 763 764 765 766 767 768 769 //sample rate...770 771 772 773 774 775 pConfigInfo->ulFixedSampleRate= pWaveStream->GetProperty(PROPERTY_FREQUENCY);776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 419 ULONG ulOperation, ULONG ulDataType, 420 ULONG ulNumChannels, ULONG ulBitsPerSample) 421 { 422 USHORT usConversion; 423 PWAVE_CAPS pWaveCaps; 424 ULONG ulNrSampleRates; 425 426 usConversion = CONVERT_NONE; 427 428 if(ulOperation == OPERATION_PLAY) { 429 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 430 } 431 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; 432 433 //Check if hardware only supports one sample rate; if true, then we perform 434 //manual sample rate conversion before sending buffers to the ALSA driver 435 FindMatchingSampleRate(pConfigInfo->ulSampleRate, pWaveCaps->ulRateFlags, &ulNrSampleRates, &pConfigInfo->ulFixedSampleRate); 436 if(ulNrSampleRates <= 2 && pConfigInfo->ulSampleRate != pConfigInfo->ulFixedSampleRate) { 437 pConfigInfo->fSampleRateConversion = TRUE; 438 } 439 else { 440 pConfigInfo->fSampleRateConversion = FALSE; 441 } 442 443 //check if mono/stereo conversion is necessary 444 if(ulNumChannels < pWaveCaps->ulMinChannels) { 445 if(ulNumChannels == 1) { 446 if(ulOperation == OPERATION_PLAY) 447 usConversion |= CONVERT_MONO_STEREO; 448 else usConversion |= CONVERT_STEREO_MONO; 449 } 450 else DebugInt3(); 451 } 452 else 453 if(ulNumChannels > pWaveCaps->ulMaxChannels) { 454 if(ulNumChannels == 2) { 455 if(ulOperation == OPERATION_PLAY) 456 usConversion |= CONVERT_STEREO_MONO; 457 else usConversion |= CONVERT_MONO_STEREO; 458 } 459 else DebugInt3(); 460 } 461 462 //check for sample bit conversion 463 switch(ulDataType) { 464 case DATATYPE_NULL: //Warp 3 buggy data type 465 case DATATYPE_WAVEFORM: 466 case PCM: 467 switch(ulBitsPerSample) 468 { 469 case 8: 470 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_8BPS)) 471 { 472 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS)) { 473 DebugInt3(); 474 return FALSE; 475 } 476 if(ulOperation == OPERATION_PLAY) 477 usConversion |= CONVERT_8_16; 478 else usConversion |= CONVERT_16_8; 479 480 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_SIGNED) 481 { 482 if(ulOperation == OPERATION_PLAY) { 483 usConversion |= CONVERT_UNSIGNED_TO_SIGNED; 484 } 485 else usConversion |= CONVERT_SIGNED_TO_UNSIGNED; 486 } 487 else usConversion |= CONVERT_UNSIGNED; //unsigned to unsigned 488 } 489 else 490 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_U8) && 491 (pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_S8)) 492 { 493 if(ulOperation == OPERATION_PLAY) 494 usConversion |= (CONVERT_UNSIGNED_TO_SIGNED | CONVERT_8BPS); 495 else usConversion |= (CONVERT_SIGNED_TO_UNSIGNED | CONVERT_8BPS); 496 } 497 else { 498 if(usConversion != CONVERT_NONE) { 499 usConversion |= (CONVERT_8BPS | CONVERT_UNSIGNED); 500 } 501 } 502 break; 503 504 case 16: 505 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS)) 506 { 507 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_8BPS)) { 508 DebugInt3(); 509 return FALSE; 510 } 511 if(ulOperation == OPERATION_PLAY) 512 usConversion |= CONVERT_16_8; 513 else usConversion |= CONVERT_8_16; 514 515 if(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_U8) 516 { 517 if(ulOperation == OPERATION_PLAY) { 518 usConversion |= CONVERT_SIGNED_TO_UNSIGNED; 519 } 520 else usConversion |= CONVERT_UNSIGNED_TO_SIGNED; 521 } 522 else usConversion |= CONVERT_SIGNED; //signed to signed 523 } 524 else 525 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_SIGNED) && 526 (pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_16BPS_UNSIGNED)) 527 { 528 if(ulOperation == OPERATION_PLAY) 529 usConversion |= (CONVERT_SIGNED_TO_UNSIGNED | CONVERT_16BPS); 530 else usConversion |= (CONVERT_UNSIGNED_TO_SIGNED | CONVERT_16BPS); 531 } 532 else { 533 if(usConversion != CONVERT_NONE) { 534 usConversion |= (CONVERT_16BPS | CONVERT_SIGNED); 535 } 536 } 537 break; 538 } 539 break; 540 541 case DATATYPE_ALAW: 542 case DATATYPE_RIFF_ALAW: 543 case A_LAW: 544 case DATATYPE_MULAW: 545 case DATATYPE_RIFF_MULAW: 546 case MU_LAW: 547 case DATATYPE_ADPCM_AVC: 548 case DATATYPE_CT_ADPCM: 549 default: 550 DebugInt3(); 551 return FALSE; 552 } 553 554 pConfigInfo->usConversion = usConversion; 555 556 switch(usConversion) { 557 case CONVERT_NONE: 558 pConfigInfo->usConversion = CONVERT_NONE; 559 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 560 pConfigInfo->pfnConvert = ConvertNone; 561 // dprintf(("CNV_NONE")); 562 break; 563 564 case CONVERT_8_UNSIGNED_TO_8_SIGNED: 565 case CONVERT_8_SIGNED_TO_8_UNSIGNED: 566 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 567 pConfigInfo->pfnConvert = Convert8To8SignChange; 568 // dprintf(("CNV_8_U_TO_8_S/CNV_8_S_TO_8_U")); 569 break; 570 571 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 572 case CONVERT_8_SIGNED_TO_8_SIGNED_MONO_STEREO: 573 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 574 pConfigInfo->pfnConvert = Convert8MonoTo8Stereo; 575 // dprintf(("CNV_8_U_TO_8_U_MN_ST/CNV_8_S_TO_8_S_MN_ST")); 576 break; 577 578 case CONVERT_8_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 579 case CONVERT_8_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 580 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 581 pConfigInfo->pfnConvert = Convert8MonoTo8StereoSignChange; 582 // dprintf(("CNV_8_S_TO_8_U_MN_ST/CNV_8_U_TO_8_S_MN_ST")); 583 break; 584 585 case CONVERT_8_SIGNED_TO_16_SIGNED: 586 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED: 587 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 588 pConfigInfo->pfnConvert = Convert8To16; 589 // dprintf(("CNV_8_S_TO_16_S/CNV_8_U_TO_16_U")); 590 break; 591 592 case CONVERT_8_SIGNED_TO_16_UNSIGNED: 593 case CONVERT_8_UNSIGNED_TO_16_SIGNED: 594 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 595 pConfigInfo->pfnConvert = Convert8To16SignChange; 596 //dprintf(("CNV_8_S_TO_16_U/CNV_8_U_TO_16_S")); 597 break; 598 599 case CONVERT_8_SIGNED_TO_16_SIGNED_MONO_STEREO: 600 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 601 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(2,0); //factor 4 602 pConfigInfo->pfnConvert = Convert8MonoTo16Stereo; 603 //dprintf(("CNV_8_S_TO_16_S_MN_ST/CNV_8_U_TO_16_U_MN_ST")); 604 break; 605 606 case CONVERT_8_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 607 case CONVERT_8_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 608 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(2,0); //factor 4 609 pConfigInfo->pfnConvert = Convert8MonoTo16StereoSignChange; 610 //dprintf(("CNV_8_S_TO_16_U_MN_ST/CNV_8_U_TO_16_S_MN_ST")); 611 break; 612 613 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 614 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 615 pConfigInfo->pfnConvert = Convert8UnsignedTo8UnsignedStereoMono; 616 //dprintf(("CNV_8_U_TO_8_U_ST_MN")); 617 break; 618 619 case CONVERT_8_SIGNED_TO_8_SIGNED_STEREO_MONO: 620 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 621 pConfigInfo->pfnConvert = Convert8SignedTo8SignedStereoMono; 622 //dprintf(("CNV_8_S_TO_8_S_ST_MN")); 623 break; 624 625 case CONVERT_8_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 626 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 627 pConfigInfo->pfnConvert = Convert8UnsignedTo8SignedStereoMono; 628 //dprintf(("CNV_8_U_TO_8_S_ST_MN")); 629 break; 630 631 case CONVERT_8_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 632 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 633 pConfigInfo->pfnConvert = Convert8SignedTo8UnsignedStereoMono; 634 //dprintf(("CNV_8_S_TO_8_U_ST_MN")); 635 break; 636 637 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 638 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 639 pConfigInfo->pfnConvert = Convert8UnsignedTo16UnsignedStereoMono; 640 //dprintf(("CNV_8_U_TO_16_U_ST_MN")); 641 break; 642 643 case CONVERT_8_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 644 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 645 pConfigInfo->pfnConvert = Convert8UnsignedTo16SignedStereoMono; 646 //dprintf(("CNV_8_U_TO_16_S_ST_MN")); 647 break; 648 649 case CONVERT_8_SIGNED_TO_16_SIGNED_STEREO_MONO: 650 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 651 pConfigInfo->pfnConvert = Convert8SignedTo16SignedStereoMono; 652 //dprintf(("CNV_8_S_TO_16_S_ST_MN")); 653 break; 654 655 case CONVERT_8_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 656 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 657 pConfigInfo->pfnConvert = Convert8SignedTo16UnsignedStereoMono; 658 //dprintf(("CNV_8_S_TO_16_U_ST_MN")); 659 break; 660 661 case CONVERT_16_UNSIGNED_TO_16_SIGNED: 662 case CONVERT_16_SIGNED_TO_16_UNSIGNED: 663 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 664 pConfigInfo->pfnConvert = Convert16To16SignChange; 665 //dprintf(("CNV_16_U_TO_16_S/CNV_16_S_TO_16_U")); 666 break; 667 668 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED: 669 case CONVERT_16_SIGNED_TO_8_SIGNED: 670 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 671 pConfigInfo->pfnConvert = Convert16To8; 672 //dprintf(("CNV_16_U_TO_8_U/CNV_16_S_TO_8_S")); 673 break; 674 675 case CONVERT_16_UNSIGNED_TO_8_SIGNED: 676 case CONVERT_16_SIGNED_TO_8_UNSIGNED: 677 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 678 pConfigInfo->pfnConvert = Convert16To8SignChange; 679 //dprintf(("CNV_16_U_TO_8_S/CNV_16_S_TO_8_U")); 680 break; 681 682 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 683 case CONVERT_16_SIGNED_TO_16_SIGNED_MONO_STEREO: 684 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 685 pConfigInfo->pfnConvert = Convert16MonoTo16Stereo; 686 //dprintf(("CNV_16_U_TO_16_U_MN_ST/CNV_16_S_TO_16_S_MN_ST")); 687 break; 688 689 case CONVERT_16_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 690 case CONVERT_16_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 691 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(1,0); //factor 2 692 pConfigInfo->pfnConvert = Convert16MonoTo16StereoSignChange; 693 //dprintf(("CNV_16_U_TO_16_S_MN_ST/CNV_16_S_TO_16_U_MN_ST")); 694 break; 695 696 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 697 case CONVERT_16_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 698 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 699 pConfigInfo->pfnConvert = Convert16MonoTo8Stereo; 700 //dprintf(("CNV_16_U_TO_8_U_MONO_ST/CNV_16_S_TO_8_U_MN_ST")); 701 break; 702 703 case CONVERT_16_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 704 case CONVERT_16_SIGNED_TO_8_SIGNED_MONO_STEREO: 705 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 706 pConfigInfo->pfnConvert = Convert16MonoTo8StereoSignChange; 707 //dprintf(("CNV_16_U_TO_8_S_MN_ST/CNV_16_S_TO_8_S_MN_ST")); 708 break; 709 710 case CONVERT_16_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 711 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 712 pConfigInfo->pfnConvert = Convert16UnsignedTo16SignedStereoMono; 713 //dprintf(("CNV_16_U_TO_16_S_ST_MN")); 714 break; 715 716 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 717 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 718 pConfigInfo->pfnConvert = Convert16UnsignedTo16UnsignedStereoMono; 719 //dprintf(("CNV_16_U_TO_16_U_ST_MN")); 720 break; 721 722 case CONVERT_16_SIGNED_TO_16_SIGNED_STEREO_MONO: 723 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 724 pConfigInfo->pfnConvert = Convert16SignedTo16SignedStereoMono; 725 //dprintf(("CNV_16_S_TO_16_S_ST_MN")); 726 break; 727 728 case CONVERT_16_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 729 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,1); //factor 0.5 730 pConfigInfo->pfnConvert = Convert16SignedTo16UnsignedStereoMono; 731 //dprintf(("CNV_16_S_TO_16_U_ST_MN")); 732 break; 733 734 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 735 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2); //factor 0.25 736 pConfigInfo->pfnConvert = Convert16UnsignedTo8UnsignedStereoMono; 737 //dprintf(("CNV_16_U_TO_8_U_ST_MN")); 738 break; 739 740 case CONVERT_16_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 741 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2); //factor 0.25 742 pConfigInfo->pfnConvert = Convert16UnsignedTo8SignedStereoMono; 743 //dprintf(("CNV_16_U_TO_8_S_ST_MN")); 744 break; 745 746 case CONVERT_16_SIGNED_TO_8_SIGNED_STEREO_MONO: 747 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2); //factor 0.25 748 pConfigInfo->pfnConvert = Convert16SignedTo8SignedStereoMono; 749 //dprintf(("CNV_16_S_TO_8_S_ST_MN")); 750 break; 751 752 case CONVERT_16_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 753 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,2); //factor 0.25 754 pConfigInfo->pfnConvert = Convert16SignedTo8UnsignedStereoMono; 755 //dprintf(("CNV_16_S_TO_8_U_ST_MN")); 756 break; 757 758 default: 759 pConfigInfo->ulConversionFactor = CONVERSION_FACTOR(0,0); //factor 1 760 pConfigInfo->pfnConvert = NULL; 761 DebugInt3(); 762 return FALSE; 763 } 764 765 dprintf(("Cnv factor %lx", pConfigInfo->ulConversionFactor)); 766 767 //Some hardware can't do full duplex with different sample rates (e.g. ALS4000) 768 //NOTE: This isn't going to be pretty if the other active stream has a much lower 769 // sample rate... 770 if(pWaveCaps->ulRateFlags & OSS32_CAPS_PCM_RATE_HALFDUPLEX) { 771 WAVESTREAM *pWaveStream; 772 773 pWaveStream = (WAVESTREAM *)FindActiveStream((ulOperation == OPERATION_PLAY) ? STREAM_WAVE_CAPTURE : STREAM_WAVE_PLAY); 774 if(pWaveStream != NULL) { 775 pConfigInfo->ulFixedSampleRate = pWaveStream->GetProperty(PROPERTY_FREQUENCY); 776 pConfigInfo->fSampleRateConversion = TRUE; 777 dprintf(("Force sample rate cnv for legacy hardware -> %d", pConfigInfo->ulFixedSampleRate)); 778 } 779 } 780 781 if(pConfigInfo->fSampleRateConversion) 782 { 783 if(QuerySampleFormat(ulOperation, pConfigInfo) == TRUE) 784 { 785 if(pConfigInfo->ulHwBitsPerSample == 8) { 786 if(pConfigInfo->ulHwNumChannels == 2) { 787 pConfigInfo->pfnSRateConv = SRateConvert8Stereo; 788 } 789 else pConfigInfo->pfnSRateConv = SRateConvert8Mono; 790 } 791 else 792 if(pConfigInfo->ulHwBitsPerSample == 16) { 793 if(pConfigInfo->ulHwNumChannels == 2) { 794 pConfigInfo->pfnSRateConv = SRateConvert16Stereo; 795 } 796 else pConfigInfo->pfnSRateConv = SRateConvert16Mono; 797 } 798 else { 799 pConfigInfo->pfnSRateConv = NULL; 800 DebugInt3(); 801 } 802 pConfigInfo->ulSRatePosition = 0; 803 if(ulOperation == OPERATION_PLAY) { 804 pConfigInfo->ulSRateIncrement = SRATE_CALC_INCREMENT(pConfigInfo->ulFixedSampleRate, pConfigInfo->ulSampleRate); 805 } 806 else pConfigInfo->ulSRateIncrement = SRATE_CALC_INCREMENT_INVERT(pConfigInfo->ulFixedSampleRate, pConfigInfo->ulSampleRate); 807 808 dprintf(("Sample rate cnv: increment %ld", pConfigInfo->ulSRateIncrement)); 809 } 810 else { 811 pConfigInfo->pfnSRateConv = NULL; 812 DebugInt3(); 813 return FALSE; 814 } 815 } 816 return TRUE; 817 817 } 818 818 //****************************************************************************** … … 822 822 BOOL WAVEAUDIO::QuerySampleFormat(ULONG ulOperation, PWAVECONFIGINFO pConfigInfo) 823 823 { 824 825 826 827 828 829 830 824 if(pConfigInfo->ulHwBitsPerSample) { 825 //already determined; 826 return TRUE; 827 } 828 if(pConfigInfo->fSampleRateConversion) 829 { 830 pConfigInfo->ulHwSampleRate = pConfigInfo->ulFixedSampleRate; 831 831 #ifdef DEBUG 832 832 dprintf(("WA::QuerySampleFormat: SampleRate1 %d", pConfigInfo->ulHwSampleRate)); 833 833 #endif 834 835 836 837 834 } 835 else 836 { 837 pConfigInfo->ulHwSampleRate = pConfigInfo->ulSampleRate; 838 838 #ifdef DEBUG 839 839 dprintf(("WA::QuerySampleFormat: SampleRate2 %d", pConfigInfo->ulHwSampleRate)); 840 840 #endif 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 841 } 842 843 pConfigInfo->ulHwBitsPerSample = pConfigInfo->ulBitsPerSample; 844 pConfigInfo->ulHwNumChannels = pConfigInfo->ulNumChannels; 845 846 switch(pConfigInfo->usConversion) { 847 case CONVERT_NONE: 848 case CONVERT_8_UNSIGNED_TO_8_SIGNED: 849 case CONVERT_8_SIGNED_TO_8_UNSIGNED: 850 case CONVERT_16_UNSIGNED_TO_16_SIGNED: 851 case CONVERT_16_SIGNED_TO_16_UNSIGNED: 852 //no change 853 break; 854 855 case CONVERT_8_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 856 case CONVERT_8_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 857 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 858 case CONVERT_8_SIGNED_TO_8_SIGNED_MONO_STEREO: 859 case CONVERT_16_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 860 case CONVERT_16_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 861 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 862 case CONVERT_16_SIGNED_TO_16_SIGNED_MONO_STEREO: 863 if(ulOperation == OPERATION_PLAY) { 864 pConfigInfo->ulHwNumChannels = 2; 865 } 866 else pConfigInfo->ulHwNumChannels = 1; 867 break; 868 869 case CONVERT_8_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 870 case CONVERT_8_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 871 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 872 case CONVERT_8_SIGNED_TO_8_SIGNED_STEREO_MONO: 873 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 874 case CONVERT_16_SIGNED_TO_16_SIGNED_STEREO_MONO: 875 case CONVERT_16_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 876 case CONVERT_16_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 877 if(ulOperation == OPERATION_PLAY) { 878 pConfigInfo->ulHwNumChannels = 1; 879 } 880 else pConfigInfo->ulHwNumChannels = 2; 881 break; 882 883 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED: 884 case CONVERT_8_UNSIGNED_TO_16_SIGNED: 885 case CONVERT_8_SIGNED_TO_16_SIGNED: 886 case CONVERT_8_SIGNED_TO_16_UNSIGNED: 887 if(ulOperation == OPERATION_PLAY) { 888 pConfigInfo->ulHwBitsPerSample = 16; 889 } 890 else pConfigInfo->ulHwBitsPerSample = 8; 891 break; 892 893 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 894 case CONVERT_8_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 895 case CONVERT_8_SIGNED_TO_16_SIGNED_STEREO_MONO: 896 case CONVERT_8_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 897 if(ulOperation == OPERATION_PLAY) { 898 pConfigInfo->ulHwBitsPerSample = 16; 899 pConfigInfo->ulHwNumChannels = 1; 900 } 901 else { 902 pConfigInfo->ulHwBitsPerSample = 8; 903 pConfigInfo->ulHwNumChannels = 2; 904 } 905 break; 906 907 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 908 case CONVERT_8_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 909 case CONVERT_8_SIGNED_TO_16_SIGNED_MONO_STEREO: 910 case CONVERT_8_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 911 if(ulOperation == OPERATION_PLAY) { 912 pConfigInfo->ulHwBitsPerSample = 16; 913 pConfigInfo->ulHwNumChannels = 2; 914 } 915 else { 916 pConfigInfo->ulHwBitsPerSample = 8; 917 pConfigInfo->ulHwNumChannels = 1; 918 } 919 break; 920 921 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED: 922 case CONVERT_16_UNSIGNED_TO_8_SIGNED: 923 case CONVERT_16_SIGNED_TO_8_SIGNED: 924 case CONVERT_16_SIGNED_TO_8_UNSIGNED: 925 if(ulOperation == OPERATION_PLAY) { 926 pConfigInfo->ulHwBitsPerSample = 8; 927 } 928 else pConfigInfo->ulHwBitsPerSample = 16; 929 break; 930 931 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 932 case CONVERT_16_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 933 case CONVERT_16_SIGNED_TO_8_SIGNED_MONO_STEREO: 934 case CONVERT_16_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 935 if(ulOperation == OPERATION_PLAY) { 936 pConfigInfo->ulHwBitsPerSample = 8; 937 pConfigInfo->ulHwNumChannels = 2; 938 } 939 else { 940 pConfigInfo->ulHwBitsPerSample = 16; 941 pConfigInfo->ulHwNumChannels = 1; 942 } 943 break; 944 945 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 946 case CONVERT_16_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 947 case CONVERT_16_SIGNED_TO_8_SIGNED_STEREO_MONO: 948 case CONVERT_16_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 949 if(ulOperation == OPERATION_PLAY) { 950 pConfigInfo->ulHwBitsPerSample = 8; 951 pConfigInfo->ulHwNumChannels = 1; 952 } 953 else { 954 pConfigInfo->ulHwBitsPerSample = 16; 955 pConfigInfo->ulHwNumChannels = 2; 956 } 957 break; 958 959 default: 960 DebugInt3(); 961 return FALSE; 962 } 963 964 pConfigInfo->ulHwSampleSize = (pConfigInfo->ulHwBitsPerSample * pConfigInfo->ulHwNumChannels) / 8; 965 return TRUE; 966 966 } 967 967 //****************************************************************************** … … 969 969 //****************************************************************************** 970 970 ULONG WAVEAUDIO::FindMatchingSampleRate(ULONG ulSampleRate, ULONG ulOSSSRateFlags, 971 972 { 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 971 ULONG FAR *pulNrSampleRates, ULONG FAR *pulFixedSampleRate) 972 { 973 ULONG sampleRates[31]; 974 int nrSampleRates = 0; 975 976 if(pulFixedSampleRate) { 977 *pulFixedSampleRate = -1; 978 } 979 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_5512) { 980 sampleRates[nrSampleRates++] = 5512; 981 } 982 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_8000) { 983 sampleRates[nrSampleRates++] = 8000; 984 } 985 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_11025) { 986 sampleRates[nrSampleRates++] = 11025; 987 } 988 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_16000) { 989 sampleRates[nrSampleRates++] = 16000; 990 } 991 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_22050) { 992 sampleRates[nrSampleRates++] = 22050; 993 } 994 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_32000) { 995 sampleRates[nrSampleRates++] = 32000; 996 } 997 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_44100) { 998 sampleRates[nrSampleRates++] = 44100; 999 } 1000 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_48000) { 1001 sampleRates[nrSampleRates++] = 48000; 1002 } 1003 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_64000) { 1004 sampleRates[nrSampleRates++] = 64000; 1005 } 1006 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_88200) { 1007 sampleRates[nrSampleRates++] = 88200; 1008 } 1009 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_96000) { 1010 sampleRates[nrSampleRates++] = 96000; 1011 } 1012 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_176400) { 1013 sampleRates[nrSampleRates++] = 176400; 1014 } 1015 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_192000) { 1016 sampleRates[nrSampleRates++] = 192000; 1017 } 1018 if(nrSampleRates > 2) { 1019 _usfind_matching_sample_rate(&ulSampleRate, nrSampleRates, (ULONG FAR *)sampleRates); 1020 } 1021 else { 1022 //fixed rate -> we support all sample rates by manually performing sample rate conversion 1023 if(nrSampleRates <= 2 && pulFixedSampleRate) { 1024 //sampleRates[0] = 44100; /* hardware set to 44100 */ 1025 *pulFixedSampleRate = sampleRates[0]; 1026 nrSampleRates = 1; 1027 } 1028 } 1029 1030 *pulNrSampleRates = nrSampleRates; 1031 return ulSampleRate; 1032 1032 } 1033 1033 … … 1040 1040 void WAVEAUDIO::DevCaps(PAUDIO_CAPS pCaps) 1041 1041 { 1042 USHORT usSampleRateIndex; 1043 ULONG ulSampleRate; 1044 PWAVE_CAPS pWaveCaps; 1045 1042 USHORT usSampleRateIndex; 1043 ULONG ulSampleRate; 1044 PWAVE_CAPS pWaveCaps; 1045 1046 dprintf(("WAVEAUDIO::DevCaps1")); 1047 1048 pCaps->ulFlags = 0; 1049 1050 // This device driver supports Playback or Record Operations 1051 // anything else makes no sence. Note: This a per stream operation so 1052 // even if this sevice can do full-duplex, it can not do PLAY_AND_RECORD 1053 1054 if ( pCaps->ulOperation != OPERATION_PLAY && 1055 pCaps->ulOperation != OPERATION_RECORD ) 1056 { 1057 dprintf(("DevCaps1 not play/record")); 1058 pCaps->ulSupport = UNSUPPORTED_OPERATION; 1059 return; 1060 } 1061 1062 if(pCaps->ulOperation == OPERATION_PLAY) 1063 { 1064 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 1065 } 1066 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; 1067 1068 // We always support stereo and mono 1069 if (pCaps->ulChannels != 1 && pCaps->ulChannels != 2) 1070 { 1071 if(pCaps->ulChannels > pWaveCaps->ulMaxChannels) 1072 { 1073 dprintf(("DevCaps1 not channel")); 1074 pCaps->ulSupport = UNSUPPORTED_CHANNELS; 1075 return; 1076 } 1077 } 1078 if (pCaps->ulSamplingRate == 0) 1079 { 1080 dprintf(("DevCaps1 not rate")); 1081 pCaps->ulSupport = UNSUPPORTED_RATE; 1082 return; 1083 } 1084 1085 //Determine supported rates 1086 ulSampleRate = pCaps->ulSamplingRate; //save the sampling rate called with 1087 1088 if(pWaveCaps->ulRateFlags & OSS32_CAPS_PCM_RATE_CONTINUOUS) 1089 {//supports all sample rates from min to max 1090 if (ulSampleRate < pWaveCaps->ulMinRate) { 1091 ulSampleRate = pWaveCaps->ulMinRate; 1092 } 1093 else 1094 if(ulSampleRate > pWaveCaps->ulMaxRate) { 1095 ulSampleRate = pWaveCaps->ulMaxRate; 1096 } 1097 } 1098 else { 1099 ULONG ulNrSampleRates; 1100 1101 ulSampleRate = FindMatchingSampleRate(ulSampleRate, pWaveCaps->ulRateFlags, &ulNrSampleRates); 1102 } 1103 1104 // If we don't support the requested samplerate, then fill in the best fit flag. 1105 if (ulSampleRate != pCaps->ulSamplingRate) 1106 pCaps->ulFlags |= BESTFIT_PROVIDED; 1107 1108 // find out the closest sampling rate (may or may not be the same ) 1109 // from one of the following: 11025Hz, 22050Hz, 44100Hz and 8000Hz 1110 // _usfind_matching_sample_rate will update pCaps->ulSamplingRate if there 1111 // is not an exact match. 1112 usSampleRateIndex = _usfind_matching_sample_rate(&pCaps->ulSamplingRate); 1113 1114 //query flags for this wave data format 1115 pCaps->ulFlags |= QueryDataFlags(pCaps->ulOperation, pCaps->ulDataType, pCaps->ulBitsPerSample); 1116 1117 // Determine the ulDataSubType and update any format specific flags 1118 // Note: All data types have more than one value. 1119 switch ( pCaps->ulDataType ) 1120 { 1121 case DATATYPE_NULL: //Warp 3 buggy data type 1122 case DATATYPE_WAVEFORM: 1123 case PCM: 1124 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1125 // and 16 (for 2's complement PCM) 1126 switch(pCaps->ulBitsPerSample) { 1127 case 8: 1128 case 16: 1129 //NOTE: We always support 8 & 16 bits playback & recording; if the card 1130 // can't handle one of these formats, then we'll convert the 1131 // wave data ourselves (same for mono/stereo). 1132 break; 1133 case 24: 1134 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS)) 1135 { 1136 dprintf(("DevCaps1 not 24BPS")); 1137 pCaps->ulSupport = UNSUPPORTED_BPS; 1138 return; 1139 } 1140 break; 1141 case 32: 1142 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS)) 1143 { 1144 pCaps->ulSupport = UNSUPPORTED_BPS; 1145 dprintf(("DevCaps1 not 32BPS")); 1146 return; 1147 } 1148 break; 1149 default: 1150 dprintf(("DevCaps1 not BPS %d",(USHORT)pCaps->ulBitsPerSample)); 1151 pCaps->ulSupport = UNSUPPORTED_BPS; 1152 return; 1153 } 1154 1155 // determine subtype for PCM: 1156 pCaps->ulDataSubType = aaulWave[usSampleRateIndex] 1157 [(pCaps->ulBitsPerSample-8)/8] 1158 [pCaps->ulChannels-1]; 1159 break; 1160 1161 case DATATYPE_ALAW: 1162 case DATATYPE_RIFF_ALAW: 1163 case A_LAW: 1164 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ALAW)) 1165 { 1166 dprintf(("DevCaps1 not ALAW")); 1167 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1168 return; 1169 } 1170 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1171 if (pCaps->ulBitsPerSample != 8) 1172 { 1173 dprintf(("DevCaps1 not ALAW BPS8")); 1174 pCaps->ulSupport = UNSUPPORTED_BPS; 1175 return; 1176 } 1177 // determine subtype for A_LAW 1178 pCaps->ulDataSubType = aaulAlaw[usSampleRateIndex][pCaps->ulChannels-1]; 1179 break; 1180 1181 case DATATYPE_MULAW: 1182 case DATATYPE_RIFF_MULAW: 1183 case MU_LAW: 1184 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_MULAW)) 1185 { 1186 dprintf(("DevCaps1 not MULAW")); 1187 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1188 return; 1189 } 1190 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1191 if (pCaps->ulBitsPerSample != 8) 1192 { 1193 dprintf(("DevCaps1 not MULAW BPS8")); 1194 pCaps->ulSupport = UNSUPPORTED_BPS; 1195 return; 1196 } 1197 // determine subtype for MU_LAW 1198 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1199 break; 1200 1201 case DATATYPE_ADPCM_AVC: 1202 case DATATYPE_CT_ADPCM: 1203 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ADPCM)) 1204 { 1205 dprintf(("DevCaps1 not ADPCM")); 1206 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1207 return; 1208 } 1209 // supported bits per sample are 4 1210 if (pCaps->ulBitsPerSample != 4) 1211 { 1212 dprintf(("DevCaps1 not ADPCM BPS4")); 1213 pCaps->ulSupport = UNSUPPORTED_BPS; 1214 return; 1215 } 1216 // determine subtype for ADPCM 1217 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1218 break; 1219 1220 default: 1221 dprintf(("DevCaps1 not dattype")); 1222 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1223 return; 1224 } // end switch 1225 1226 pCaps->ulFlags |= FIXED | // Fixed length data 1227 LEFT_ALIGNED | // Left align bits on byte bndry 1228 INPUT | // Input select is supported 1229 OUTPUT | // Output select is supported 1230 MONITOR | // Monitor is supported 1231 VOLUME; // Volume control is supported 1232 1233 // Full Duplex Enabling Stuff here !! 1234 // The number of resource units is described in the MMPM2.INI 1235 // This can be thought of the number of active streams the 1236 // driver can manage at one time. We list this number as 2. 1237 // we tell MMPM here how many of these units THIS stream will consume. 1238 // The answer is so simple it's brilliant, (Thanks to Joe Nord at Crystal 1239 // Semi) If we are enabled to do full-duplex this stream will consume 1 1240 // unit, If we are not enabled to do full-duplex this stream will consume 2 1241 // (or all the available units) 1242 // Along with the resource units, we defined 2 resources classes, 1243 // one for playback and one for capture. We tell MMPM (in the MMPM2.INI) 1244 // that we can handle doing 1 playback and 1 capture stream or 1 capture and 1245 // one playback stream at the same time. (Valid Resource combos in the 1246 // MMPM2.INI) check if we are a playback or capture and set the correct 1247 // resource class (Playback = 1, Capture = 2) 1248 1249 if(pCaps->ulOperation == OPERATION_PLAY) 1250 { 1251 if(pWaveCaps->nrStreams) { 1252 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS/pWaveCaps->nrStreams; 1253 } 1254 else { 1255 DebugInt3(); //should never happen! 1256 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS; 1257 } 1258 dprintf(("RU used by playback stream: %d", (int)pCaps->ulResourceUnits)); 1259 } 1260 else { 1261 if(pWaveCaps->nrStreams < OSS32_MAX_WAVE_CAPTURE_STREAMS) { 1262 DebugInt3(); 1263 } 1264 pCaps->ulResourceUnits = 1; 1265 } 1266 1267 if ( pCaps->ulOperation == OPERATION_PLAY) 1268 pCaps->ulResourceClass = 1; 1269 else 1270 pCaps->ulResourceClass = 2; 1271 pCaps->fCanRecord = 1; // Yes Virgina we can record 1272 pCaps->ulBlockAlign = 1; // Block alignment for this mode 1273 1274 //return success 1275 pCaps->ulSupport = SUPPORT_SUCCESS; 1276 dprintf(("WAVEAUDIO::DevCaps %ld %ld %ld ", pCaps->ulBitsPerSample, pCaps->ulSamplingRate, pCaps->ulChannels)); 1277 dprintf(("Op %ld ResourceClass %ld ResourceUnits %ld", pCaps->ulOperation, pCaps->ulResourceClass, pCaps->ulResourceUnits)); 1278 dprintf(("Data type %ld, data subtype %ld", pCaps->ulDataType, pCaps->ulDataSubType)); 1046 1279 #ifdef DEBUG 1047 dprintf(("WAVEAUDIO::DevCaps1")); 1048 #endif 1049 1050 pCaps->ulFlags = 0; 1051 1052 // This device driver supports Playback or Record Operations 1053 // anything else makes no sence. Note: This a per stream operation so 1054 // even if this sevice can do full-duplex, it can not do PLAY_AND_RECORD 1055 1056 if ( pCaps->ulOperation != OPERATION_PLAY && 1057 pCaps->ulOperation != OPERATION_RECORD ) 1058 { 1059 dprintf(("DevCaps1 not play/record")); 1060 pCaps->ulSupport = UNSUPPORTED_OPERATION; 1061 return; 1062 } 1063 1064 if(pCaps->ulOperation == OPERATION_PLAY) 1065 { 1066 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 1067 } 1068 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; 1069 1070 // We always support stereo and mono 1071 if (pCaps->ulChannels != 1 && pCaps->ulChannels != 2) 1072 { 1073 if(pCaps->ulChannels > pWaveCaps->ulMaxChannels) 1074 { 1075 dprintf(("DevCaps1 not channel")); 1076 pCaps->ulSupport = UNSUPPORTED_CHANNELS; 1077 return; 1078 } 1079 } 1080 if (pCaps->ulSamplingRate == 0) 1081 { 1082 dprintf(("DevCaps1 not rate")); 1083 pCaps->ulSupport = UNSUPPORTED_RATE; 1084 return; 1085 } 1086 1087 //Determine supported rates 1088 ulSampleRate = pCaps->ulSamplingRate; //save the sampling rate called with 1089 1090 if(pWaveCaps->ulRateFlags & OSS32_CAPS_PCM_RATE_CONTINUOUS) 1091 {//supports all sample rates from min to max 1092 if (ulSampleRate < pWaveCaps->ulMinRate) { 1093 ulSampleRate = pWaveCaps->ulMinRate; 1094 } 1095 else 1096 if(ulSampleRate > pWaveCaps->ulMaxRate) { 1097 ulSampleRate = pWaveCaps->ulMaxRate; 1098 } 1099 } 1100 else { 1101 ULONG ulNrSampleRates; 1102 1103 ulSampleRate = FindMatchingSampleRate(ulSampleRate, pWaveCaps->ulRateFlags, &ulNrSampleRates); 1104 } 1105 1106 // If we don't support the requested samplerate, then fill in the best fit flag. 1107 if (ulSampleRate != pCaps->ulSamplingRate) 1108 pCaps->ulFlags |= BESTFIT_PROVIDED; 1109 1110 // find out the closest sampling rate (may or may not be the same ) 1111 // from one of the following: 11025Hz, 22050Hz, 44100Hz and 8000Hz 1112 // _usfind_matching_sample_rate will update pCaps->ulSamplingRate if there 1113 // is not an exact match. 1114 usSampleRateIndex = _usfind_matching_sample_rate(&pCaps->ulSamplingRate); 1115 1116 //query flags for this wave data format 1117 pCaps->ulFlags |= QueryDataFlags(pCaps->ulOperation, pCaps->ulDataType, pCaps->ulBitsPerSample); 1118 1119 // Determine the ulDataSubType and update any format specific flags 1120 // Note: All data types have more than one value. 1121 switch ( pCaps->ulDataType ) 1122 { 1123 case DATATYPE_NULL: //Warp 3 buggy data type 1124 case DATATYPE_WAVEFORM: 1125 case PCM: 1126 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1127 // and 16 (for 2's complement PCM) 1128 switch(pCaps->ulBitsPerSample) { 1129 case 8: 1130 case 16: 1131 //NOTE: We always support 8 & 16 bits playback & recording; if the card 1132 // can't handle one of these formats, then we'll convert the 1133 // wave data ourselves (same for mono/stereo). 1134 break; 1135 case 24: 1136 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS)) 1137 { 1138 dprintf(("DevCaps1 not 24BPS")); 1139 pCaps->ulSupport = UNSUPPORTED_BPS; 1140 return; 1141 } 1142 break; 1143 case 32: 1144 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS)) 1145 { 1146 pCaps->ulSupport = UNSUPPORTED_BPS; 1147 dprintf(("DevCaps1 not 32BPS")); 1148 return; 1149 } 1150 break; 1151 default: 1152 dprintf(("DevCaps1 not BPS %d",(USHORT)pCaps->ulBitsPerSample)); 1153 pCaps->ulSupport = UNSUPPORTED_BPS; 1154 return; 1155 } 1156 1157 // determine subtype for PCM: 1158 pCaps->ulDataSubType = aaulWave[usSampleRateIndex] 1159 [(pCaps->ulBitsPerSample-8)/8] 1160 [pCaps->ulChannels-1]; 1161 break; 1162 1163 case DATATYPE_ALAW: 1164 case DATATYPE_RIFF_ALAW: 1165 case A_LAW: 1166 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ALAW)) 1167 { 1168 dprintf(("DevCaps1 not ALAW")); 1169 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1170 return; 1171 } 1172 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1173 if (pCaps->ulBitsPerSample != 8) 1174 { 1175 dprintf(("DevCaps1 not ALAW BPS8")); 1176 pCaps->ulSupport = UNSUPPORTED_BPS; 1177 return; 1178 } 1179 // determine subtype for A_LAW 1180 pCaps->ulDataSubType = aaulAlaw[usSampleRateIndex][pCaps->ulChannels-1]; 1181 break; 1182 1183 case DATATYPE_MULAW: 1184 case DATATYPE_RIFF_MULAW: 1185 case MU_LAW: 1186 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_MULAW)) 1187 { 1188 dprintf(("DevCaps1 not MULAW")); 1189 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1190 return; 1191 } 1192 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1193 if (pCaps->ulBitsPerSample != 8) 1194 { 1195 dprintf(("DevCaps1 not MULAW BPS8")); 1196 pCaps->ulSupport = UNSUPPORTED_BPS; 1197 return; 1198 } 1199 // determine subtype for MU_LAW 1200 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1201 break; 1202 1203 case DATATYPE_ADPCM_AVC: 1204 case DATATYPE_CT_ADPCM: 1205 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ADPCM)) 1206 { 1207 dprintf(("DevCaps1 not ADPCM")); 1208 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1209 return; 1210 } 1211 // supported bits per sample are 4 1212 if (pCaps->ulBitsPerSample != 4) 1213 { 1214 dprintf(("DevCaps1 not ADPCM BPS4")); 1215 pCaps->ulSupport = UNSUPPORTED_BPS; 1216 return; 1217 } 1218 // determine subtype for ADPCM 1219 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1220 break; 1221 1222 default: 1223 dprintf(("DevCaps1 not dattype")); 1224 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1225 return; 1226 } // end switch 1227 1228 pCaps->ulFlags |= FIXED | // Fixed length data 1229 LEFT_ALIGNED | // Left align bits on byte bndry 1230 INPUT | // Input select is supported 1231 OUTPUT | // Output select is supported 1232 MONITOR | // Monitor is supported 1233 VOLUME; // Volume control is supported 1234 1235 // Full Duplex Enabling Stuff here !! 1236 // The number of resource units is described in the MMPM2.INI 1237 // This can be thought of the number of active streams the 1238 // driver can manage at one time. We list this number as 2. 1239 // we tell MMPM here how many of these units THIS stream will consume. 1240 // The answer is so simple it's brilliant, (Thanks to Joe Nord at Crystal 1241 // Semi) If we are enabled to do full-duplex this stream will consume 1 1242 // unit, If we are not enabled to do full-duplex this stream will consume 2 1243 // (or all the available units) 1244 // Along with the resource units, we defined 2 resources classes, 1245 // one for playback and one for capture. We tell MMPM (in the MMPM2.INI) 1246 // that we can handle doing 1 playback and 1 capture stream or 1 capture and 1247 // one playback stream at the same time. (Valid Resource combos in the 1248 // MMPM2.INI) check if we are a playback or capture and set the correct 1249 // resource class (Playback = 1, Capture = 2) 1250 1251 if(pCaps->ulOperation == OPERATION_PLAY) 1252 { 1253 if(pWaveCaps->nrStreams) { 1254 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS/pWaveCaps->nrStreams; 1255 } 1256 else { 1257 DebugInt3(); //should never happen! 1258 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS; 1259 } 1260 dprintf(("RU used by playback stream: %d", (int)pCaps->ulResourceUnits)); 1261 } 1262 else { 1263 if(pWaveCaps->nrStreams < OSS32_MAX_WAVE_CAPTURE_STREAMS) { 1264 DebugInt3(); 1265 } 1266 pCaps->ulResourceUnits = 1; 1267 } 1268 1269 if ( pCaps->ulOperation == OPERATION_PLAY) 1270 pCaps->ulResourceClass = 1; 1271 else 1272 pCaps->ulResourceClass = 2; 1273 pCaps->fCanRecord = 1; // Yes Virgina we can record 1274 pCaps->ulBlockAlign = 1; // Block alignment for this mode 1275 1276 //return success 1277 pCaps->ulSupport = SUPPORT_SUCCESS; 1278 dprintf(("WAVEAUDIO::DevCaps %ld %ld %ld ", pCaps->ulBitsPerSample, pCaps->ulSamplingRate, pCaps->ulChannels)); 1279 dprintf(("Op %ld ResourceClass %ld ResourceUnits %ld", pCaps->ulOperation, pCaps->ulResourceClass, pCaps->ulResourceUnits)); 1280 dprintf(("Data type %ld, data subtype %ld", pCaps->ulDataType, pCaps->ulDataSubType)); 1281 #ifdef DEBUG 1282 dprintf(("Flags:")); 1283 1284 for(int i=0;i<32;i++) { 1285 if(pCaps->ulFlags & (1UL << (ULONG)i)) { 1286 dprintf(("%s", szCapsFlags[i])); 1287 } 1288 } 1280 dprintf(("Flags:")); 1281 1282 for(int i=0;i<32;i++) { 1283 if(pCaps->ulFlags & (1UL << (ULONG)i)) { 1284 dprintf(("%s", szCapsFlags[i])); 1285 } 1286 } 1289 1287 #endif 1290 1288 } … … 1297 1295 void WAVEAUDIO::DevCaps(LPOSS32_DEVCAPS lpCaps) 1298 1296 { 1299 #ifdef DEBUG 1300 dprintf(("WAVEAUDIO::DevCaps")); 1301 #endif 1302 ddmemmov(lpCaps, &devCaps[current_device], sizeof(OSS32_DEVCAPS)); 1297 //dprintf(("WAVEAUDIO::DevCaps")); 1298 ddmemmov(lpCaps, &devCaps[current_device], sizeof(OSS32_DEVCAPS)); 1303 1299 } 1304 1300 … … 1313 1309 #pragma on (unreferenced) 1314 1310 { 1315 ULONG ulBytesPerIRQ; 1316 1317 #ifdef DEBUG 1318 //dprintf(("WAVEAUDIO::ConfigDev")); 1319 #endif 1320 //Reset sample rate conversion position 1321 pConfigInfo->ulSRatePosition = 0; 1322 1323 // Set the clock select bits (_ucClockData) 1324 1325 // Set up _ucFormatData and write usSilence for the WAVESTREAM 1326 switch (pConfigInfo->ulDataType) { 1327 case DATATYPE_NULL: //Warp 3 buggy data type 1328 case DATATYPE_WAVEFORM: 1329 case PCM: 1330 if (pConfigInfo->ulBitsPerSample == 16) { 1331 pConfigInfo->usSilence = 0x0000; 1332 } 1333 else { 1334 pConfigInfo->usSilence = 0x8080; 1335 } 1336 break; 1337 1338 case DATATYPE_ALAW: 1339 case DATATYPE_RIFF_ALAW: 1340 case A_LAW: 1341 pConfigInfo->usSilence = 0x5555; 1342 break; 1343 1344 case DATATYPE_MULAW: 1345 case DATATYPE_RIFF_MULAW: 1346 case MU_LAW: 1347 pConfigInfo->usSilence = 0x7F7F; 1348 break; 1349 } /* endswitch */ 1350 1351 // Calculate the PCMConsumeRate 1352 // The consume rate is the number of bytes consumed by this data format 1353 // per second. It calculated by taking the following equation: 1354 // sampling rate * (BitsPerSample/8) * NumChannels 1355 // This info is returned to the WAVESTREAM and used to calculate stream time 1356 1357 pConfigInfo->ulSampleSize = (pConfigInfo->ulBitsPerSample*pConfigInfo->ulNumChannels)/8; 1358 pConfigInfo->ulPCMConsumeRate = pConfigInfo->ulSampleRate * pConfigInfo->ulSampleSize; 1359 1360 // Calculate the BytesPerIRQ 1361 // The BytesPerIRQ is the number of bytes consumed by this data format 1362 // for every interrupt generated by the codec. 1363 // This information is returned to the WAVESTREAM which uses it in 1364 // buffer management decisions.... 1365 // basic formula is (sampling rate * ((BitsPerSample * NumChannels) /8) / Number of Interrupts per Second 1366 // or pConfigInfo->ulPCMConsumeRate / Number of Interrupts Per Second 1367 // rjj Fix for Bug #18 28082008 1368 1369 //ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 5; // 32 interrupts per second 1370 ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 6; // 64 interrupts per second 1371 // we can tweak this as needed but generally this should do rjj 1372 // make sure it's an even multiple of 64 1373 ulBytesPerIRQ += 0x00000040; 1374 ulBytesPerIRQ &= 0xFFFFFFC0; 1375 1376 if (ulBytesPerIRQ > 0x800) { 1377 ulBytesPerIRQ = 0x800; 1378 } 1379 pConfigInfo->ulBytesPerIRQ = ulBytesPerIRQ; 1380 dprintf4(("WAVEAUDIO::ConfigDev BytesPerIRQ:%ld",ulBytesPerIRQ)); 1381 1382 1383 return TRUE; 1311 ULONG ulBytesPerIRQ; 1312 1313 //dprintf(("WAVEAUDIO::ConfigDev")); 1314 //Reset sample rate conversion position 1315 pConfigInfo->ulSRatePosition = 0; 1316 1317 // Set the clock select bits (_ucClockData) 1318 1319 // Set up _ucFormatData and write usSilence for the WAVESTREAM 1320 switch (pConfigInfo->ulDataType) { 1321 case DATATYPE_NULL: //Warp 3 buggy data type 1322 case DATATYPE_WAVEFORM: 1323 case PCM: 1324 if (pConfigInfo->ulBitsPerSample == 16) { 1325 pConfigInfo->usSilence = 0x0000; 1326 } 1327 else { 1328 pConfigInfo->usSilence = 0x8080; 1329 } 1330 break; 1331 1332 case DATATYPE_ALAW: 1333 case DATATYPE_RIFF_ALAW: 1334 case A_LAW: 1335 pConfigInfo->usSilence = 0x5555; 1336 break; 1337 1338 case DATATYPE_MULAW: 1339 case DATATYPE_RIFF_MULAW: 1340 case MU_LAW: 1341 pConfigInfo->usSilence = 0x7F7F; 1342 break; 1343 } /* endswitch */ 1344 1345 // Calculate the PCMConsumeRate 1346 // The consume rate is the number of bytes consumed by this data format 1347 // per second. It calculated by taking the following equation: 1348 // sampling rate * (BitsPerSample/8) * NumChannels 1349 // This info is returned to the WAVESTREAM and used to calculate stream time 1350 1351 pConfigInfo->ulSampleSize = (pConfigInfo->ulBitsPerSample*pConfigInfo->ulNumChannels)/8; 1352 pConfigInfo->ulPCMConsumeRate = pConfigInfo->ulSampleRate * pConfigInfo->ulSampleSize; 1353 1354 // Calculate the BytesPerIRQ 1355 // The BytesPerIRQ is the number of bytes consumed by this data format 1356 // for every interrupt generated by the codec. 1357 // This information is returned to the WAVESTREAM which uses it in 1358 // buffer management decisions.... 1359 // basic formula is (sampling rate * ((BitsPerSample * NumChannels) /8) / Number of Interrupts per Second 1360 // or pConfigInfo->ulPCMConsumeRate / Number of Interrupts Per Second 1361 // rjj Fix for Bug #18 28082008 1362 1363 //ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 5; // 32 interrupts per second 1364 ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 6; // 64 interrupts per second 1365 // we can tweak this as needed but generally this should do rjj 1366 // make sure it's an even multiple of 64 1367 ulBytesPerIRQ += 0x00000040; 1368 ulBytesPerIRQ &= 0xFFFFFFC0; 1369 1370 if (ulBytesPerIRQ > 0x800) { 1371 ulBytesPerIRQ = 0x800; 1372 } 1373 pConfigInfo->ulBytesPerIRQ = ulBytesPerIRQ; 1374 dprintf4(("WAVEAUDIO::ConfigDev BytesPerIRQ:%ld",ulBytesPerIRQ)); 1375 1376 1377 return TRUE; 1384 1378 } 1385 1379 /**@internal Pause 1386 * @param 1387 * @return 1380 * @param None 1381 * @return int 1 1388 1382 * @notes 1389 1383 * stub function pause is implemented as a stop by the stream … … 1396 1390 } 1397 1391 /**@internal Resume 1398 * @param 1399 * @return 1392 * @param None 1393 * @return int 1 1400 1394 * @notes 1401 1395 * stub function resume is implemented as a start by the stream … … 1405 1399 #pragma on (unreferenced) 1406 1400 { 1407 1401 return 1; 1408 1402 } 1409 1403 /******************************************************************************/ 1410 /* WAVEAUDIO::Start(void) 1411 /* 1404 /* WAVEAUDIO::Start(void) */ 1405 /* */ 1412 1406 /******************************************************************************/ 1413 1407 int WAVEAUDIO::Start(OSSSTREAMID StreamId) 1414 1408 { 1415 #ifdef DEBUG 1416 // dprintf(("WAVEAUDIO::Start")); 1417 #endif 1418 1419 return OSS16_WaveStart(StreamId) == OSSERR_SUCCESS; 1409 //dprintf(("WAVEAUDIO::Start")); 1410 1411 return OSS16_WaveStart(StreamId) == OSSERR_SUCCESS; 1420 1412 } 1421 1413 1422 1414 /******************************************************************************/ 1423 /* WAVEAUDIO::Stop(void) 1424 /* 1415 /* WAVEAUDIO::Stop(void) */ 1416 /* */ 1425 1417 /******************************************************************************/ 1426 1418 int WAVEAUDIO::Stop(OSSSTREAMID StreamId) 1427 1419 { 1428 #ifdef DEBUG 1429 // dprintf(("WAVEAUDIO::Stop")); 1430 #endif 1431 1432 if(OSS16_WaveStop(StreamId) != OSSERR_SUCCESS) 1433 { 1434 DebugInt3(); 1435 return FALSE; 1436 } 1437 //Reset cleans up waveout instance 1438 if(OSS16_WaveReset(StreamId) != OSSERR_SUCCESS) 1439 { 1440 DebugInt3(); 1441 return FALSE; 1442 } 1443 return TRUE; 1420 //dprintf(("WAVEAUDIO::Stop")); 1421 1422 if(OSS16_WaveStop(StreamId) != OSSERR_SUCCESS) 1423 { 1424 DebugInt3(); 1425 return FALSE; 1426 } 1427 //Reset cleans up waveout instance 1428 if(OSS16_WaveReset(StreamId) != OSSERR_SUCCESS) 1429 { 1430 DebugInt3(); 1431 return FALSE; 1432 } 1433 return TRUE; 1444 1434 } 1445 1435 /******************************************************************************/ 1446 /* WAVEAUDIO::Prepare(void) 1447 /* 1436 /* WAVEAUDIO::Prepare(void) */ 1437 /* */ 1448 1438 /******************************************************************************/ 1449 1439 int WAVEAUDIO::Prepare(OSSSTREAMID StreamId) 1450 1440 { 1451 #ifdef DEBUG 1452 // dprintf(("WAVEAUDIO::Prepare")); 1453 #endif 1454 1455 if(OSS16_WavePrepare(StreamId) != OSSERR_SUCCESS) { 1456 DebugInt3(); 1457 return FALSE; 1458 } 1459 return TRUE; 1441 //dprintf(("WAVEAUDIO::Prepare")); 1442 1443 if(OSS16_WavePrepare(StreamId) != OSSERR_SUCCESS) { 1444 DebugInt3(); 1445 return FALSE; 1446 } 1447 return TRUE; 1460 1448 } 1461 1449 //****************************************************************************** … … 1463 1451 ULONG WAVEAUDIO::ConvertPosition(ULONG length, PWAVECONFIGINFO pConfigInfo) 1464 1452 { 1465 1466 1467 1468 1469 1470 1471 1472 1453 ULONG newlen; 1454 1455 newlen = CONVERT_LENGTH(length, pConfigInfo->ulConversionFactor); 1456 1457 if(newlen && pConfigInfo->fSampleRateConversion) { 1458 newlen = SRATE_CONVERT_POSITION(newlen, pConfigInfo->ulSampleRate, pConfigInfo->ulHwSampleRate); 1459 } 1460 return newlen; 1473 1461 } 1474 1462 //****************************************************************************** … … 1476 1464 ULONG WAVEAUDIO::ConvertPositionInvert(ULONG length, PWAVECONFIGINFO pConfigInfo) 1477 1465 { 1478 1479 1480 1481 1482 1483 1484 1485 1466 ULONG newlen; 1467 1468 newlen = CONVERT_LENGTH(length, CONVERSION_INVERT(pConfigInfo->ulConversionFactor)); 1469 1470 if(newlen && pConfigInfo->fSampleRateConversion) { 1471 newlen = SRATE_CONVERT_POSITION(newlen, pConfigInfo->ulSampleRate, pConfigInfo->ulHwSampleRate); 1472 } 1473 return newlen; 1486 1474 } 1487 1475 //****************************************************************************** … … 1490 1478 ULONG WAVEAUDIO::ConvertLength(ULONG length, PWAVECONFIGINFO pConfigInfo) 1491 1479 { 1492 1493 1494 1480 ULONG newlen; 1481 1482 newlen = CONVERT_LENGTH(length, pConfigInfo->ulConversionFactor); 1495 1483 1496 1484 //PS+++ 1497 1485 #ifdef WhatIsIt 1498 1499 1500 DebugInt3();//this shouldn't happen!!1501 1502 1486 if(newlen >= 4UL*1024UL*1024UL) { 1487 //oh, oh 1488 DebugInt3(); //this shouldn't happen!! 1489 return newlen; 1490 } 1503 1491 #endif 1504 1505 1506 1507 1508 1509 } 1510 1511 #define CONVERT_POSITION_INVERT(pos, ulFactor) 1512 #define CONVERT_LENGTH_INVERT(pos, ulFactor) 1492 if(newlen && pConfigInfo->fSampleRateConversion) { 1493 newlen = SRATE_CONVERT_LENGTH(newlen, pConfigInfo->ulSRatePosition, 1494 pConfigInfo->ulSRateIncrement); 1495 } 1496 return newlen; 1497 } 1498 1499 #define CONVERT_POSITION_INVERT(pos, ulFactor) ( ( pos << CONVERSION_RSHIFT(ulFactor)) >> CONVERSION_LSHIFT(ulFactor) ) 1500 #define CONVERT_LENGTH_INVERT(pos, ulFactor) CONVERT_POSITION_INVERT(pos, ulFactor) 1513 1501 //****************************************************************************** 1514 1502 //NOTE: Can only be used for small numbers (up to about 4mb)!! (overflow) … … 1516 1504 ULONG WAVEAUDIO::ConvertLengthInvert(ULONG length, PWAVECONFIGINFO pConfigInfo) 1517 1505 { 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 // 1545 1546 // 1547 1548 } 1549 //****************************************************************************** 1550 //****************************************************************************** 1551 1506 ULONG newlen,tmp,len; 1507 1508 if (!length) return 0; 1509 1510 len = length; 1511 1512 if (pConfigInfo->fSampleRateConversion) 1513 { 1514 tmp = SRATE_CONVERT_LENGTH_INVERT(len, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement); 1515 if (tmp && (len != SRATE_CONVERT_LENGTH (tmp, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement))) 1516 tmp--; 1517 } 1518 else 1519 tmp = len; 1520 1521 if (!tmp) return 0; 1522 1523 if (pConfigInfo->usConversion != CONVERT_NONE) 1524 { 1525 newlen = CONVERT_LENGTH_INVERT (tmp, pConfigInfo->ulConversionFactor); 1526 if (newlen && (tmp != CONVERT_LENGTH (newlen, pConfigInfo->ulConversionFactor)) ) 1527 newlen--; 1528 } 1529 else 1530 newlen = tmp; 1531 1532 // if ( newlen > length ) dprintf(("!!!!Back len %ld tmp %ld new %ld",length,tmp,newlen )); 1533 1534 // dprintf(("Overflow len %ld in:%ld inc:%ld pos:%lx",length, len, pConfigInfo->ulSRateIncrement, pConfigInfo->ulSRatePosition)); 1535 return newlen; 1536 } 1537 //****************************************************************************** 1538 //****************************************************************************** 1539
Note:
See TracChangeset
for help on using the changeset viewer.