Changeset 526 for OCO/trunk/drv16/waudio.cpp
- Timestamp:
- Jul 22, 2010, 9:33:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OCO/trunk/drv16/waudio.cpp
r496 r526 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 dprintf(("DataFormat wrong:%x",ulBitsPerSample));410 411 409 rprintf(("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 if(pConfigInfo->ulHwBitsPerSample) { 825 //already determined; 826 return TRUE; 827 } 828 if(pConfigInfo->fSampleRateConversion) 829 { 830 pConfigInfo->ulHwSampleRate = pConfigInfo->ulFixedSampleRate; 831 #ifdef DEBUG 832 dprintf(("WA::QuerySampleFormat: SampleRate1 %d", pConfigInfo->ulHwSampleRate)); 833 #endif 834 } 835 else 836 { 837 pConfigInfo->ulHwSampleRate = pConfigInfo->ulSampleRate; 838 #ifdef DEBUG 839 dprintf(("WA::QuerySampleFormat: SampleRate2 %d", pConfigInfo->ulHwSampleRate)); 840 #endif 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; 824 if(pConfigInfo->ulHwBitsPerSample) { 825 //already determined; 826 return TRUE; 827 } 828 if(pConfigInfo->fSampleRateConversion) 829 { 830 pConfigInfo->ulHwSampleRate = pConfigInfo->ulFixedSampleRate; 831 dprintf(("WA::QuerySampleFormat: SampleRate1 %d", pConfigInfo->ulHwSampleRate)); 832 } 833 else 834 { 835 pConfigInfo->ulHwSampleRate = pConfigInfo->ulSampleRate; 836 dprintf(("WA::QuerySampleFormat: SampleRate2 %d", pConfigInfo->ulHwSampleRate)); 837 } 838 839 pConfigInfo->ulHwBitsPerSample = pConfigInfo->ulBitsPerSample; 840 pConfigInfo->ulHwNumChannels = pConfigInfo->ulNumChannels; 841 842 switch(pConfigInfo->usConversion) { 843 case CONVERT_NONE: 844 case CONVERT_8_UNSIGNED_TO_8_SIGNED: 845 case CONVERT_8_SIGNED_TO_8_UNSIGNED: 846 case CONVERT_16_UNSIGNED_TO_16_SIGNED: 847 case CONVERT_16_SIGNED_TO_16_UNSIGNED: 848 //no change 849 break; 850 851 case CONVERT_8_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 852 case CONVERT_8_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 853 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 854 case CONVERT_8_SIGNED_TO_8_SIGNED_MONO_STEREO: 855 case CONVERT_16_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 856 case CONVERT_16_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 857 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 858 case CONVERT_16_SIGNED_TO_16_SIGNED_MONO_STEREO: 859 if(ulOperation == OPERATION_PLAY) { 860 pConfigInfo->ulHwNumChannels = 2; 861 } 862 else pConfigInfo->ulHwNumChannels = 1; 863 break; 864 865 case CONVERT_8_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 866 case CONVERT_8_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 867 case CONVERT_8_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 868 case CONVERT_8_SIGNED_TO_8_SIGNED_STEREO_MONO: 869 case CONVERT_16_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 870 case CONVERT_16_SIGNED_TO_16_SIGNED_STEREO_MONO: 871 case CONVERT_16_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 872 case CONVERT_16_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 873 if(ulOperation == OPERATION_PLAY) { 874 pConfigInfo->ulHwNumChannels = 1; 875 } 876 else pConfigInfo->ulHwNumChannels = 2; 877 break; 878 879 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED: 880 case CONVERT_8_UNSIGNED_TO_16_SIGNED: 881 case CONVERT_8_SIGNED_TO_16_SIGNED: 882 case CONVERT_8_SIGNED_TO_16_UNSIGNED: 883 if(ulOperation == OPERATION_PLAY) { 884 pConfigInfo->ulHwBitsPerSample = 16; 885 } 886 else pConfigInfo->ulHwBitsPerSample = 8; 887 break; 888 889 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_STEREO_MONO: 890 case CONVERT_8_UNSIGNED_TO_16_SIGNED_STEREO_MONO: 891 case CONVERT_8_SIGNED_TO_16_SIGNED_STEREO_MONO: 892 case CONVERT_8_SIGNED_TO_16_UNSIGNED_STEREO_MONO: 893 if(ulOperation == OPERATION_PLAY) { 894 pConfigInfo->ulHwBitsPerSample = 16; 895 pConfigInfo->ulHwNumChannels = 1; 896 } 897 else { 898 pConfigInfo->ulHwBitsPerSample = 8; 899 pConfigInfo->ulHwNumChannels = 2; 900 } 901 break; 902 903 case CONVERT_8_UNSIGNED_TO_16_UNSIGNED_MONO_STEREO: 904 case CONVERT_8_UNSIGNED_TO_16_SIGNED_MONO_STEREO: 905 case CONVERT_8_SIGNED_TO_16_SIGNED_MONO_STEREO: 906 case CONVERT_8_SIGNED_TO_16_UNSIGNED_MONO_STEREO: 907 if(ulOperation == OPERATION_PLAY) { 908 pConfigInfo->ulHwBitsPerSample = 16; 909 pConfigInfo->ulHwNumChannels = 2; 910 } 911 else { 912 pConfigInfo->ulHwBitsPerSample = 8; 913 pConfigInfo->ulHwNumChannels = 1; 914 } 915 break; 916 917 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED: 918 case CONVERT_16_UNSIGNED_TO_8_SIGNED: 919 case CONVERT_16_SIGNED_TO_8_SIGNED: 920 case CONVERT_16_SIGNED_TO_8_UNSIGNED: 921 if(ulOperation == OPERATION_PLAY) { 922 pConfigInfo->ulHwBitsPerSample = 8; 923 } 924 else pConfigInfo->ulHwBitsPerSample = 16; 925 break; 926 927 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_MONO_STEREO: 928 case CONVERT_16_UNSIGNED_TO_8_SIGNED_MONO_STEREO: 929 case CONVERT_16_SIGNED_TO_8_SIGNED_MONO_STEREO: 930 case CONVERT_16_SIGNED_TO_8_UNSIGNED_MONO_STEREO: 931 if(ulOperation == OPERATION_PLAY) { 932 pConfigInfo->ulHwBitsPerSample = 8; 933 pConfigInfo->ulHwNumChannels = 2; 934 } 935 else { 936 pConfigInfo->ulHwBitsPerSample = 16; 937 pConfigInfo->ulHwNumChannels = 1; 938 } 939 break; 940 941 case CONVERT_16_UNSIGNED_TO_8_UNSIGNED_STEREO_MONO: 942 case CONVERT_16_UNSIGNED_TO_8_SIGNED_STEREO_MONO: 943 case CONVERT_16_SIGNED_TO_8_SIGNED_STEREO_MONO: 944 case CONVERT_16_SIGNED_TO_8_UNSIGNED_STEREO_MONO: 945 if(ulOperation == OPERATION_PLAY) { 946 pConfigInfo->ulHwBitsPerSample = 8; 947 pConfigInfo->ulHwNumChannels = 1; 948 } 949 else { 950 pConfigInfo->ulHwBitsPerSample = 16; 951 pConfigInfo->ulHwNumChannels = 2; 952 } 953 break; 954 955 default: 956 DebugInt3(); 957 return FALSE; 958 } 959 960 pConfigInfo->ulHwSampleSize = (pConfigInfo->ulHwBitsPerSample * pConfigInfo->ulHwNumChannels) / 8; 961 return TRUE; 966 962 } 967 963 //****************************************************************************** … … 969 965 //****************************************************************************** 970 966 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 967 ULONG FAR *pulNrSampleRates, ULONG FAR *pulFixedSampleRate) 968 { 969 ULONG sampleRates[31]; 970 int nrSampleRates = 0; 971 972 if(pulFixedSampleRate) { 973 *pulFixedSampleRate = -1; 974 } 975 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_5512) { 976 sampleRates[nrSampleRates++] = 5512; 977 } 978 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_8000) { 979 sampleRates[nrSampleRates++] = 8000; 980 } 981 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_11025) { 982 sampleRates[nrSampleRates++] = 11025; 983 } 984 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_16000) { 985 sampleRates[nrSampleRates++] = 16000; 986 } 987 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_22050) { 988 sampleRates[nrSampleRates++] = 22050; 989 } 990 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_32000) { 991 sampleRates[nrSampleRates++] = 32000; 992 } 993 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_44100) { 994 sampleRates[nrSampleRates++] = 44100; 995 } 996 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_48000) { 997 sampleRates[nrSampleRates++] = 48000; 998 } 999 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_64000) { 1000 sampleRates[nrSampleRates++] = 64000; 1001 } 1002 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_88200) { 1003 sampleRates[nrSampleRates++] = 88200; 1004 } 1005 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_96000) { 1006 sampleRates[nrSampleRates++] = 96000; 1007 } 1008 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_176400) { 1009 sampleRates[nrSampleRates++] = 176400; 1010 } 1011 if(ulOSSSRateFlags & OSS32_CAPS_PCM_RATE_192000) { 1012 sampleRates[nrSampleRates++] = 192000; 1013 } 1014 if(nrSampleRates > 2) { 1015 _usfind_matching_sample_rate(&ulSampleRate, nrSampleRates, (ULONG FAR *)sampleRates); 1016 } 1017 else { 1018 //fixed rate -> we support all sample rates by manually performing sample rate conversion 1019 if(nrSampleRates <= 2 && pulFixedSampleRate) { 1020 //sampleRates[0] = 44100; /* hardware set to 44100 */ 1021 *pulFixedSampleRate = sampleRates[0]; 1022 nrSampleRates = 1; 1023 } 1024 } 1025 1026 *pulNrSampleRates = nrSampleRates; 1027 return ulSampleRate; 1032 1028 } 1033 1029 … … 1040 1036 void WAVEAUDIO::DevCaps(PAUDIO_CAPS pCaps) 1041 1037 { 1042 USHORT usSampleRateIndex; 1043 ULONG ulSampleRate; 1044 PWAVE_CAPS pWaveCaps; 1045 1038 USHORT usSampleRateIndex; 1039 ULONG ulSampleRate; 1040 PWAVE_CAPS pWaveCaps; 1041 1042 dprintf(("WAVEAUDIO::DevCaps1")); 1043 1044 pCaps->ulFlags = 0; 1045 1046 // This device driver supports Playback or Record Operations 1047 // anything else makes no sence. Note: This a per stream operation so 1048 // even if this sevice can do full-duplex, it can not do PLAY_AND_RECORD 1049 1050 if ( pCaps->ulOperation != OPERATION_PLAY && 1051 pCaps->ulOperation != OPERATION_RECORD ) 1052 { 1053 dprintf(("DevCaps1 not play/record")); 1054 pCaps->ulSupport = UNSUPPORTED_OPERATION; 1055 return; 1056 } 1057 1058 if(pCaps->ulOperation == OPERATION_PLAY) 1059 { 1060 pWaveCaps = &devCaps[ulDeviceNr].waveOutCaps; 1061 } 1062 else pWaveCaps = &devCaps[ulDeviceNr].waveInCaps; 1063 1064 // We always support stereo and mono 1065 if (pCaps->ulChannels != 1 && pCaps->ulChannels != 2) 1066 { 1067 if(pCaps->ulChannels > pWaveCaps->ulMaxChannels) 1068 { 1069 dprintf(("DevCaps1 not channel")); 1070 pCaps->ulSupport = UNSUPPORTED_CHANNELS; 1071 return; 1072 } 1073 } 1074 if (pCaps->ulSamplingRate == 0) 1075 { 1076 dprintf(("DevCaps1 not rate")); 1077 pCaps->ulSupport = UNSUPPORTED_RATE; 1078 return; 1079 } 1080 1081 //Determine supported rates 1082 ulSampleRate = pCaps->ulSamplingRate; //save the sampling rate called with 1083 1084 if(pWaveCaps->ulRateFlags & OSS32_CAPS_PCM_RATE_CONTINUOUS) 1085 {//supports all sample rates from min to max 1086 if (ulSampleRate < pWaveCaps->ulMinRate) { 1087 ulSampleRate = pWaveCaps->ulMinRate; 1088 } 1089 else 1090 if(ulSampleRate > pWaveCaps->ulMaxRate) { 1091 ulSampleRate = pWaveCaps->ulMaxRate; 1092 } 1093 } 1094 else { 1095 ULONG ulNrSampleRates; 1096 1097 ulSampleRate = FindMatchingSampleRate(ulSampleRate, pWaveCaps->ulRateFlags, &ulNrSampleRates); 1098 } 1099 1100 // If we don't support the requested samplerate, then fill in the best fit flag. 1101 if (ulSampleRate != pCaps->ulSamplingRate) 1102 pCaps->ulFlags |= BESTFIT_PROVIDED; 1103 1104 // find out the closest sampling rate (may or may not be the same ) 1105 // from one of the following: 11025Hz, 22050Hz, 44100Hz and 8000Hz 1106 // _usfind_matching_sample_rate will update pCaps->ulSamplingRate if there 1107 // is not an exact match. 1108 usSampleRateIndex = _usfind_matching_sample_rate(&pCaps->ulSamplingRate); 1109 1110 //query flags for this wave data format 1111 pCaps->ulFlags |= QueryDataFlags(pCaps->ulOperation, pCaps->ulDataType, pCaps->ulBitsPerSample); 1112 1113 // Determine the ulDataSubType and update any format specific flags 1114 // Note: All data types have more than one value. 1115 switch ( pCaps->ulDataType ) 1116 { 1117 case DATATYPE_NULL: //Warp 3 buggy data type 1118 case DATATYPE_WAVEFORM: 1119 case PCM: 1120 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1121 // and 16 (for 2's complement PCM) 1122 switch(pCaps->ulBitsPerSample) { 1123 case 8: 1124 case 16: 1125 //NOTE: We always support 8 & 16 bits playback & recording; if the card 1126 // can't handle one of these formats, then we'll convert the 1127 // wave data ourselves (same for mono/stereo). 1128 break; 1129 case 24: 1130 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_24BPS)) 1131 { 1132 dprintf(("DevCaps1 not 24BPS")); 1133 pCaps->ulSupport = UNSUPPORTED_BPS; 1134 return; 1135 } 1136 break; 1137 case 32: 1138 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_32BPS)) 1139 { 1140 pCaps->ulSupport = UNSUPPORTED_BPS; 1141 dprintf(("DevCaps1 not 32BPS")); 1142 return; 1143 } 1144 break; 1145 default: 1146 dprintf(("DevCaps1 not BPS %d",(USHORT)pCaps->ulBitsPerSample)); 1147 pCaps->ulSupport = UNSUPPORTED_BPS; 1148 return; 1149 } 1150 1151 // determine subtype for PCM: 1152 pCaps->ulDataSubType = aaulWave[usSampleRateIndex] 1153 [(pCaps->ulBitsPerSample-8)/8] 1154 [pCaps->ulChannels-1]; 1155 break; 1156 1157 case DATATYPE_ALAW: 1158 case DATATYPE_RIFF_ALAW: 1159 case A_LAW: 1160 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ALAW)) 1161 { 1162 dprintf(("DevCaps1 not ALAW")); 1163 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1164 return; 1165 } 1166 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1167 if (pCaps->ulBitsPerSample != 8) 1168 { 1169 dprintf(("DevCaps1 not ALAW BPS8")); 1170 pCaps->ulSupport = UNSUPPORTED_BPS; 1171 return; 1172 } 1173 // determine subtype for A_LAW 1174 pCaps->ulDataSubType = aaulAlaw[usSampleRateIndex][pCaps->ulChannels-1]; 1175 break; 1176 1177 case DATATYPE_MULAW: 1178 case DATATYPE_RIFF_MULAW: 1179 case MU_LAW: 1180 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_MULAW)) 1181 { 1182 dprintf(("DevCaps1 not MULAW")); 1183 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1184 return; 1185 } 1186 // supported bits per sample are 8 (for unsigned PCM, u-law or A-law ) 1187 if (pCaps->ulBitsPerSample != 8) 1188 { 1189 dprintf(("DevCaps1 not MULAW BPS8")); 1190 pCaps->ulSupport = UNSUPPORTED_BPS; 1191 return; 1192 } 1193 // determine subtype for MU_LAW 1194 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1195 break; 1196 1197 case DATATYPE_ADPCM_AVC: 1198 case DATATYPE_CT_ADPCM: 1199 if(!(pWaveCaps->ulDataFormats & OSS32_CAPS_PCM_FORMAT_ADPCM)) 1200 { 1201 dprintf(("DevCaps1 not ADPCM")); 1202 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1203 return; 1204 } 1205 // supported bits per sample are 4 1206 if (pCaps->ulBitsPerSample != 4) 1207 { 1208 dprintf(("DevCaps1 not ADPCM BPS4")); 1209 pCaps->ulSupport = UNSUPPORTED_BPS; 1210 return; 1211 } 1212 // determine subtype for ADPCM 1213 pCaps->ulDataSubType = aaulMulaw[usSampleRateIndex][pCaps->ulChannels-1]; 1214 break; 1215 1216 default: 1217 dprintf(("DevCaps1 not dattype")); 1218 pCaps->ulSupport = UNSUPPORTED_DATATYPE; 1219 return; 1220 } // end switch 1221 1222 pCaps->ulFlags |= FIXED | // Fixed length data 1223 LEFT_ALIGNED | // Left align bits on byte bndry 1224 INPUT | // Input select is supported 1225 OUTPUT | // Output select is supported 1226 MONITOR | // Monitor is supported 1227 VOLUME; // Volume control is supported 1228 1229 // Full Duplex Enabling Stuff here !! 1230 // The number of resource units is described in the MMPM2.INI 1231 // This can be thought of the number of active streams the 1232 // driver can manage at one time. We list this number as 2. 1233 // we tell MMPM here how many of these units THIS stream will consume. 1234 // The answer is so simple it's brilliant, (Thanks to Joe Nord at Crystal 1235 // Semi) If we are enabled to do full-duplex this stream will consume 1 1236 // unit, If we are not enabled to do full-duplex this stream will consume 2 1237 // (or all the available units) 1238 // Along with the resource units, we defined 2 resources classes, 1239 // one for playback and one for capture. We tell MMPM (in the MMPM2.INI) 1240 // that we can handle doing 1 playback and 1 capture stream or 1 capture and 1241 // one playback stream at the same time. (Valid Resource combos in the 1242 // MMPM2.INI) check if we are a playback or capture and set the correct 1243 // resource class (Playback = 1, Capture = 2) 1244 1245 if(pCaps->ulOperation == OPERATION_PLAY) 1246 { 1247 if(pWaveCaps->nrStreams) { 1248 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS/pWaveCaps->nrStreams; 1249 } 1250 else { 1251 DebugInt3(); //should never happen! 1252 pCaps->ulResourceUnits = OSS32_MAX_WAVE_PLAYBACK_STREAMS; 1253 } 1254 dprintf(("RU used by playback stream: %d", (int)pCaps->ulResourceUnits)); 1255 } 1256 else { 1257 if(pWaveCaps->nrStreams < OSS32_MAX_WAVE_CAPTURE_STREAMS) { 1258 DebugInt3(); 1259 } 1260 pCaps->ulResourceUnits = 1; 1261 } 1262 1263 if ( pCaps->ulOperation == OPERATION_PLAY) 1264 pCaps->ulResourceClass = 1; 1265 else 1266 pCaps->ulResourceClass = 2; 1267 pCaps->fCanRecord = 1; // Yes Virgina we can record 1268 pCaps->ulBlockAlign = 1; // Block alignment for this mode 1269 1270 //return success 1271 pCaps->ulSupport = SUPPORT_SUCCESS; 1272 dprintf(("WAVEAUDIO::DevCaps %ld %ld %ld ", pCaps->ulBitsPerSample, pCaps->ulSamplingRate, pCaps->ulChannels)); 1273 dprintf(("Op %ld ResourceClass %ld ResourceUnits %ld", pCaps->ulOperation, pCaps->ulResourceClass, pCaps->ulResourceUnits)); 1274 dprintf(("Data type %ld, data subtype %ld", pCaps->ulDataType, pCaps->ulDataSubType)); 1046 1275 #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 } 1276 dprintf(("Flags:")); 1277 1278 for(int i=0;i<32;i++) { 1279 if(pCaps->ulFlags & (1UL << (ULONG)i)) { 1280 dprintf(("%s", szCapsFlags[i])); 1281 } 1282 } 1289 1283 #endif 1290 1284 } … … 1297 1291 void WAVEAUDIO::DevCaps(LPOSS32_DEVCAPS lpCaps) 1298 1292 { 1299 #ifdef DEBUG 1300 dprintf(("WAVEAUDIO::DevCaps")); 1301 #endif 1302 ddmemmov(lpCaps, &devCaps[current_device], sizeof(OSS32_DEVCAPS)); 1293 //dprintf(("WAVEAUDIO::DevCaps")); 1294 ddmemmov(lpCaps, &devCaps[current_device], sizeof(OSS32_DEVCAPS)); 1303 1295 } 1304 1296 … … 1313 1305 #pragma on (unreferenced) 1314 1306 { 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; 1307 ULONG ulBytesPerIRQ; 1308 1309 //dprintf(("WAVEAUDIO::ConfigDev")); 1310 //Reset sample rate conversion position 1311 pConfigInfo->ulSRatePosition = 0; 1312 1313 // Set the clock select bits (_ucClockData) 1314 1315 // Set up _ucFormatData and write usSilence for the WAVESTREAM 1316 switch (pConfigInfo->ulDataType) { 1317 case DATATYPE_NULL: //Warp 3 buggy data type 1318 case DATATYPE_WAVEFORM: 1319 case PCM: 1320 if (pConfigInfo->ulBitsPerSample == 16) { 1321 pConfigInfo->usSilence = 0x0000; 1322 } 1323 else { 1324 pConfigInfo->usSilence = 0x8080; 1325 } 1326 break; 1327 1328 case DATATYPE_ALAW: 1329 case DATATYPE_RIFF_ALAW: 1330 case A_LAW: 1331 pConfigInfo->usSilence = 0x5555; 1332 break; 1333 1334 case DATATYPE_MULAW: 1335 case DATATYPE_RIFF_MULAW: 1336 case MU_LAW: 1337 pConfigInfo->usSilence = 0x7F7F; 1338 break; 1339 } /* endswitch */ 1340 1341 // Calculate the PCMConsumeRate 1342 // The consume rate is the number of bytes consumed by this data format 1343 // per second. It calculated by taking the following equation: 1344 // sampling rate * (BitsPerSample/8) * NumChannels 1345 // This info is returned to the WAVESTREAM and used to calculate stream time 1346 1347 pConfigInfo->ulSampleSize = (pConfigInfo->ulBitsPerSample*pConfigInfo->ulNumChannels)/8; 1348 pConfigInfo->ulPCMConsumeRate = pConfigInfo->ulSampleRate * pConfigInfo->ulSampleSize; 1349 1350 // Calculate the BytesPerIRQ 1351 // The BytesPerIRQ is the number of bytes consumed by this data format 1352 // for every interrupt generated by the codec. 1353 // This information is returned to the WAVESTREAM which uses it in 1354 // buffer management decisions.... 1355 // basic formula is (sampling rate * ((BitsPerSample * NumChannels) /8) / Number of Interrupts per Second 1356 // or pConfigInfo->ulPCMConsumeRate / Number of Interrupts Per Second 1357 // rjj Fix for Bug #18 28082008 1358 1359 //ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 5; // 32 interrupts per second 1360 ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 6; // 64 interrupts per second 1361 // we can tweak this as needed but generally this should do rjj 1362 // make sure it's an even multiple of 64 1363 ulBytesPerIRQ += 0x00000040; 1364 ulBytesPerIRQ &= 0xFFFFFFC0; 1365 1366 if (ulBytesPerIRQ > 0x800) { 1367 ulBytesPerIRQ = 0x800; 1368 } 1369 pConfigInfo->ulBytesPerIRQ = ulBytesPerIRQ; 1370 dprintf4(("WAVEAUDIO::ConfigDev BytesPerIRQ:%ld",ulBytesPerIRQ)); 1371 1372 1373 return TRUE; 1384 1374 } 1385 1375 /**@internal Pause 1386 * @param 1387 * @return 1376 * @param None 1377 * @return int 1 1388 1378 * @notes 1389 1379 * stub function pause is implemented as a stop by the stream … … 1396 1386 } 1397 1387 /**@internal Resume 1398 * @param 1399 * @return 1388 * @param None 1389 * @return int 1 1400 1390 * @notes 1401 1391 * stub function resume is implemented as a start by the stream … … 1405 1395 #pragma on (unreferenced) 1406 1396 { 1407 1397 return 1; 1408 1398 } 1409 1399 /******************************************************************************/ 1410 /* WAVEAUDIO::Start(void) 1411 /* 1400 /* WAVEAUDIO::Start(void) */ 1401 /* */ 1412 1402 /******************************************************************************/ 1413 1403 int WAVEAUDIO::Start(OSSSTREAMID StreamId) 1414 1404 { 1415 #ifdef DEBUG 1416 // dprintf(("WAVEAUDIO::Start")); 1417 #endif 1418 1419 return OSS16_WaveStart(StreamId) == OSSERR_SUCCESS; 1405 //dprintf(("WAVEAUDIO::Start")); 1406 1407 return OSS16_WaveStart(StreamId) == OSSERR_SUCCESS; 1420 1408 } 1421 1409 1422 1410 /******************************************************************************/ 1423 /* WAVEAUDIO::Stop(void) 1424 /* 1411 /* WAVEAUDIO::Stop(void) */ 1412 /* */ 1425 1413 /******************************************************************************/ 1426 1414 int WAVEAUDIO::Stop(OSSSTREAMID StreamId) 1427 1415 { 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; 1416 //dprintf(("WAVEAUDIO::Stop")); 1417 1418 if(OSS16_WaveStop(StreamId) != OSSERR_SUCCESS) 1419 { 1420 DebugInt3(); 1421 return FALSE; 1422 } 1423 //Reset cleans up waveout instance 1424 if(OSS16_WaveReset(StreamId) != OSSERR_SUCCESS) 1425 { 1426 DebugInt3(); 1427 return FALSE; 1428 } 1429 return TRUE; 1444 1430 } 1445 1431 /******************************************************************************/ 1446 /* WAVEAUDIO::Prepare(void) 1447 /* 1432 /* WAVEAUDIO::Prepare(void) */ 1433 /* */ 1448 1434 /******************************************************************************/ 1449 1435 int WAVEAUDIO::Prepare(OSSSTREAMID StreamId) 1450 1436 { 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; 1437 //dprintf(("WAVEAUDIO::Prepare")); 1438 1439 if(OSS16_WavePrepare(StreamId) != OSSERR_SUCCESS) { 1440 DebugInt3(); 1441 return FALSE; 1442 } 1443 return TRUE; 1460 1444 } 1461 1445 //****************************************************************************** … … 1463 1447 ULONG WAVEAUDIO::ConvertPosition(ULONG length, PWAVECONFIGINFO pConfigInfo) 1464 1448 { 1465 1466 1467 1468 1469 1470 1471 1472 1449 ULONG newlen; 1450 1451 newlen = CONVERT_LENGTH(length, pConfigInfo->ulConversionFactor); 1452 1453 if(newlen && pConfigInfo->fSampleRateConversion) { 1454 newlen = SRATE_CONVERT_POSITION(newlen, pConfigInfo->ulSampleRate, pConfigInfo->ulHwSampleRate); 1455 } 1456 return newlen; 1473 1457 } 1474 1458 //****************************************************************************** … … 1476 1460 ULONG WAVEAUDIO::ConvertPositionInvert(ULONG length, PWAVECONFIGINFO pConfigInfo) 1477 1461 { 1478 1479 1480 1481 1482 1483 1484 1485 1462 ULONG newlen; 1463 1464 newlen = CONVERT_LENGTH(length, CONVERSION_INVERT(pConfigInfo->ulConversionFactor)); 1465 1466 if(newlen && pConfigInfo->fSampleRateConversion) { 1467 newlen = SRATE_CONVERT_POSITION(newlen, pConfigInfo->ulSampleRate, pConfigInfo->ulHwSampleRate); 1468 } 1469 return newlen; 1486 1470 } 1487 1471 //****************************************************************************** … … 1490 1474 ULONG WAVEAUDIO::ConvertLength(ULONG length, PWAVECONFIGINFO pConfigInfo) 1491 1475 { 1492 1493 1494 1476 ULONG newlen; 1477 1478 newlen = CONVERT_LENGTH(length, pConfigInfo->ulConversionFactor); 1495 1479 1496 1480 //PS+++ 1497 1481 #ifdef WhatIsIt 1498 1499 1500 DebugInt3();//this shouldn't happen!!1501 1502 1482 if(newlen >= 4UL*1024UL*1024UL) { 1483 //oh, oh 1484 DebugInt3(); //this shouldn't happen!! 1485 return newlen; 1486 } 1503 1487 #endif 1504 1505 1506 1507 1508 1509 } 1510 1511 #define CONVERT_POSITION_INVERT(pos, ulFactor) 1512 #define CONVERT_LENGTH_INVERT(pos, ulFactor) 1488 if(newlen && pConfigInfo->fSampleRateConversion) { 1489 newlen = SRATE_CONVERT_LENGTH(newlen, pConfigInfo->ulSRatePosition, 1490 pConfigInfo->ulSRateIncrement); 1491 } 1492 return newlen; 1493 } 1494 1495 #define CONVERT_POSITION_INVERT(pos, ulFactor) ( ( pos << CONVERSION_RSHIFT(ulFactor)) >> CONVERSION_LSHIFT(ulFactor) ) 1496 #define CONVERT_LENGTH_INVERT(pos, ulFactor) CONVERT_POSITION_INVERT(pos, ulFactor) 1513 1497 //****************************************************************************** 1514 1498 //NOTE: Can only be used for small numbers (up to about 4mb)!! (overflow) … … 1516 1500 ULONG WAVEAUDIO::ConvertLengthInvert(ULONG length, PWAVECONFIGINFO pConfigInfo) 1517 1501 { 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 1502 ULONG newlen,tmp,len; 1503 1504 if (!length) return 0; 1505 1506 len = length; 1507 1508 if (pConfigInfo->fSampleRateConversion) 1509 { 1510 tmp = SRATE_CONVERT_LENGTH_INVERT(len, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement); 1511 if (tmp && (len != SRATE_CONVERT_LENGTH (tmp, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement))) 1512 tmp--; 1513 } 1514 else 1515 tmp = len; 1516 1517 if (!tmp) return 0; 1518 1519 if (pConfigInfo->usConversion != CONVERT_NONE) 1520 { 1521 newlen = CONVERT_LENGTH_INVERT (tmp, pConfigInfo->ulConversionFactor); 1522 if (newlen && (tmp != CONVERT_LENGTH (newlen, pConfigInfo->ulConversionFactor)) ) 1523 newlen--; 1524 } 1525 else 1526 newlen = tmp; 1527 1528 // if ( newlen > length ) dprintf(("!!!!Back len %ld tmp %ld new %ld",length,tmp,newlen )); 1529 1530 // dprintf(("Overflow len %ld in:%ld inc:%ld pos:%lx",length, len, pConfigInfo->ulSRateIncrement, pConfigInfo->ulSRatePosition)); 1531 return newlen; 1532 } 1533 //****************************************************************************** 1534 //****************************************************************************** 1535
Note:
See TracChangeset
for help on using the changeset viewer.