Changeset 88269 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Mar 24, 2021 11:45:54 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 143474
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioHlp.cpp
r88235 r88269 179 179 bool AudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg) 180 180 { 181 AssertPtrReturn(pCfg, false); 182 183 AssertReturn(PDMAudioStrmCfgIsValid(pCfg), false); 184 185 bool fValid = ( pCfg->enmDir == PDMAUDIODIR_IN 186 || pCfg->enmDir == PDMAUDIODIR_OUT); 187 188 fValid &= ( pCfg->enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED 189 || pCfg->enmLayout == PDMAUDIOSTREAMLAYOUT_RAW); 190 191 if (fValid) 192 fValid = AudioHlpPcmPropsAreValid(&pCfg->Props); 193 194 return fValid; 181 /* Ugly! HDA attach code calls us with uninitialized (all zero) config. */ 182 if ( pCfg->enmLayout != PDMAUDIOSTREAMLAYOUT_INVALID 183 || PDMAudioPropsHz(&pCfg->Props) != 0) 184 { 185 if (PDMAudioStrmCfgIsValid(pCfg)) 186 { 187 if ( pCfg->enmDir == PDMAUDIODIR_IN 188 || pCfg->enmDir == PDMAUDIODIR_OUT) 189 { 190 if ( pCfg->enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED 191 || pCfg->enmLayout == PDMAUDIOSTREAMLAYOUT_RAW) 192 return AudioHlpPcmPropsAreValid(&pCfg->Props); 193 } 194 } 195 } 196 return false; 195 197 } 196 198 … … 219 221 * function will flag such properties as not valid. 220 222 * 221 * @todo r=bird: See note and explain properly. 223 * @todo r=bird: See note and explain properly. Perhaps rename to 224 * AudioHlpPcmPropsAreValidAndSupported? 222 225 * 223 226 * @returns @c true if the properties are valid, @c false if not. … … 227 230 { 228 231 AssertPtrReturn(pProps, false); 229 230 232 AssertReturn(PDMAudioPropsAreValid(pProps), false); 231 233 232 /** @todo r=bird: This code is cannot make up its mind whether to return on233 * false, or whether to return at the end. (hint: just return234 * immediately, duh.) */235 236 234 /* Minimum 1 channel (mono), maximum 7.1 (= 8) channels. */ 237 bool fValid = ( pProps->cChannels >= 1 238 && pProps->cChannels <= 8); 239 240 if (fValid) 241 { 242 switch (pProps->cbSample) 235 if (PDMAudioPropsChannels(pProps) >= 1 && PDMAudioPropsChannels(pProps) <= 8) 236 { 237 switch (PDMAudioPropsSampleSize(pProps)) 243 238 { 244 239 case 1: /* 8 bit */ 245 if ( pProps->fSigned)246 fValid =false;240 if (PDMAudioPropsIsSigned(pProps)) 241 return false; 247 242 break; 248 243 case 2: /* 16 bit */ 249 if (! pProps->fSigned)250 fValid =false;244 if (!PDMAudioPropsIsSigned(pProps)) 245 return false; 251 246 break; 252 247 /** @todo Do we need support for 24 bit samples? */ 253 248 case 4: /* 32 bit */ 254 if (!pProps->fSigned) 255 fValid = false; 249 if (!PDMAudioPropsIsSigned(pProps)) 250 return false; 251 break; 252 case 8: /* 64-bit raw */ 253 if ( !PDMAudioPropsIsSigned(pProps) 254 || !pProps->fRaw) 255 return false; 256 256 break; 257 257 default: 258 fValid = false; 259 break; 260 } 261 } 262 263 if (!fValid) 264 return false; 265 266 fValid &= pProps->uHz > 0; 267 fValid &= pProps->cShift == PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pProps->cbSample, pProps->cChannels); 268 fValid &= pProps->fSwapEndian == false; /** @todo Handling Big Endian audio data is not supported yet. */ 269 270 return fValid; 258 return false; 259 } 260 261 if (pProps->uHz > 0) 262 { 263 if (!pProps->fSwapEndian) /** @todo Handling Big Endian audio data is not supported yet. */ 264 return true; 265 } 266 } 267 return false; 271 268 } 272 269 … … 520 517 /** @todo Validate fOpen flags. */ 521 518 AssertPtrReturn(pProps, VERR_INVALID_POINTER); 519 Assert(PDMAudioPropsAreValid(pProps)); 522 520 523 521 int rc; … … 529 527 else if (pFile->enmType == PDMAUDIOFILETYPE_WAV) 530 528 { 531 Assert(pProps->cChannels);532 Assert(pProps->uHz);533 Assert(pProps->cbSample);534 535 529 pFile->pvData = (PAUDIOWAVFILEDATA)RTMemAllocZ(sizeof(AUDIOWAVFILEDATA)); 536 530 if (pFile->pvData) … … 549 543 pData->Hdr.u32Size1 = 16; /* Means PCM. */ 550 544 pData->Hdr.u16AudioFormat = 1; /* PCM, linear quantization. */ 551 pData->Hdr.u16NumChannels = pProps->cChannels;545 pData->Hdr.u16NumChannels = PDMAudioPropsChannels(pProps); 552 546 pData->Hdr.u32SampleRate = pProps->uHz; 553 547 pData->Hdr.u32ByteRate = PDMAudioPropsGetBitrate(pProps) / 8; 554 pData->Hdr.u16BlockAlign = pProps->cChannels * pProps->cbSample;555 pData->Hdr.u16BitsPerSample = pProps->cbSample * 8;548 pData->Hdr.u16BlockAlign = PDMAudioPropsFrameSize(pProps); 549 pData->Hdr.u16BitsPerSample = PDMAudioPropsSampleBits(pProps); 556 550 557 551 /* Data chunk. */ … … 584 578 585 579 if (RT_SUCCESS(rc)) 586 {587 580 LogRel2(("Audio: Opened file '%s'\n", pFile->szName)); 588 }589 581 else 590 582 LogRel(("Audio: Failed opening file '%s', rc=%Rrc\n", pFile->szName, rc)); -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r88253 r88269 47 47 #endif 48 48 #include <VBox/err.h> 49 #include <VBox/vmm/pdmaudioinline.h> 49 50 50 51 #include "AudioMixBuffer.h" … … 53 54 # ifdef DEBUG 54 55 # define AUDMIXBUF_LOG(x) LogFlowFunc(x) 56 # define AUDMIXBUF_LOG_ENABLED 55 57 # else 56 # define AUDMIXBUF_LOG(x) do {} while (0)58 # define AUDMIXBUF_LOG(x) do {} while (0) 57 59 # endif 58 60 #else /* VBOX_AUDIO_TESTCASE */ 59 61 # define AUDMIXBUF_LOG(x) RTPrintf x 62 # define AUDMIXBUF_LOG_ENABLED 60 63 #endif 61 64 … … 136 139 137 140 /** 138 * Peeks for audio frames without any conversion done.139 * This will get the raw frame data out of a mixing buffer.140 *141 * @return IPRT status code or VINF_AUDIO_MORE_DATA_AVAILABLE if more data is available to read.142 *143 * @param pMixBuf Mixing buffer to acquire audio frames from.144 * @param cFramesToRead Number of audio frames to read.145 * @param paFrameBuf Buffer where to store the returned audio frames.146 * @param cFrameBuf Size (in frames) of the buffer to store audio frames into.147 * @param pcFramesRead Returns number of read audio frames. Optional.148 *149 * @remark This function is not thread safe!150 */151 /** @todo r=bird: This isn't a 'ing Peek function, it's a Read function!152 * Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg!!!!!!!!!!!!!!!!!!! */153 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead,154 PPDMAUDIOFRAME paFrameBuf, uint32_t cFrameBuf, uint32_t *pcFramesRead)155 {156 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);157 AssertPtrReturn(paFrameBuf, VERR_INVALID_POINTER);158 AssertReturn(cFrameBuf, VERR_INVALID_PARAMETER);159 /* pcRead is optional. */160 161 int rc;162 163 if (!cFramesToRead)164 {165 if (pcFramesRead)166 *pcFramesRead = 0;167 return VINF_SUCCESS;168 }169 170 uint32_t cRead;171 if (pMixBuf->offRead + cFramesToRead > pMixBuf->cFrames)172 {173 cRead = pMixBuf->cFrames - pMixBuf->offRead;174 rc = VINF_AUDIO_MORE_DATA_AVAILABLE;175 }176 else177 {178 cRead = cFramesToRead;179 rc = VINF_SUCCESS;180 }181 182 if (cRead > cFrameBuf)183 {184 cRead = cFrameBuf;185 rc = VINF_AUDIO_MORE_DATA_AVAILABLE;186 }187 188 if (cRead)189 {190 memcpy(paFrameBuf, &pMixBuf->pFrames[pMixBuf->offRead], sizeof(PDMAUDIOFRAME) * cRead);191 192 pMixBuf->offRead = (pMixBuf->offRead + cRead) % pMixBuf->cFrames;193 Assert(pMixBuf->offRead <= pMixBuf->cFrames);194 pMixBuf->cUsed -= RT_MIN(cRead, pMixBuf->cUsed);195 }196 197 if (pcFramesRead)198 *pcFramesRead = cRead;199 200 return rc;201 }202 203 /**204 141 * Returns a mutable pointer to the mixing buffer's audio frame buffer for writing raw 205 142 * audio frames. … … 213 150 * @remark This function is not thread safe! 214 151 */ 152 /** @todo r=bird: This isn't a 'ing Peek function, it's a Read function! 153 * Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg!!!!!!!!!!!!!!!!!!! */ 215 154 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames, 216 155 PPDMAUDIOFRAME *ppvFrames, uint32_t *pcFramesToWrite) … … 281 220 AssertStmt(cFramesToClear <= pMixBuf->cFrames, cFramesToClear = pMixBuf->cFrames); 282 221 222 /** @todo r=bird: Why isn't this done when reading/releaseing ? */ 283 223 PPDMAUDIOMIXBUF pIter; 284 224 RTListForEach(&pMixBuf->lstChildren, pIter, PDMAUDIOMIXBUF, Node) … … 291 231 } 292 232 233 /** @todo r=bird: waste of time? */ 293 234 uint32_t cClearOff; 294 235 uint32_t cClearLen; … … 559 500 560 501 #undef AUDMIXBUF_CONVERT 502 503 /* 504 * Manually coded signed 64-bit conversion. 505 */ 506 #if 0 507 DECLCALLBACK(uint32_t) audioMixBufConvFromS64Stereo(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, 508 PCPDMAUDMIXBUFCONVOPTS pOpts) 509 { 510 _aType const *pSrc = (_aType const *)pvSrc; 511 uint32_t cFrames = RT_MIN(pOpts->cFrames, cbSrc / sizeof(_aType)); 512 AUDMIXBUF_MACRO_LOG(("cFrames=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", 513 pOpts->cFrames, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); 514 for (uint32_t i = 0; i < cFrames; i++) 515 { 516 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->From.Volume.uLeft ) >> AUDIOMIXBUF_VOL_SHIFT; \ 517 paDst->i64RSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->From.Volume.uRight) >> AUDIOMIXBUF_VOL_SHIFT; \ 518 paDst++; 519 } 520 521 return cFrames; 522 } 523 #endif 524 525 DECLCALLBACK(void) audioMixBufConvToRawS64Stereo(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) 526 { 527 AssertCompile(sizeof(paSrc[0]) == sizeof(int64_t) * 2); 528 memcpy(pvDst, paSrc, sizeof(int64_t) * 2 * pOpts->cFrames); 529 } 530 531 532 561 533 562 534 #define AUDMIXBUF_MIXOP(_aName, _aOp) \ … … 674 646 675 647 /** 676 * Looks up the matching conversion (macro) routine for converting 677 * audio frames from a source format. 678 * 679 ** @todo Speed up the lookup by binding it to the actual stream state. 680 * 681 * @return PAUDMIXBUF_FN_CONVFROM Function pointer to conversion macro if found, NULL if not supported. 682 * @param enmFmt Audio format to lookup conversion macro for. 683 */ 684 static PFNPDMAUDIOMIXBUFCONVFROM audioMixBufConvFromLookup(PDMAUDIOMIXBUFFMT enmFmt) 685 { 686 if (AUDMIXBUF_FMT_SIGNED(enmFmt)) 687 { 688 if (AUDMIXBUF_FMT_CHANNELS(enmFmt) == 2) 648 * Looks up the matching conversion function for converting audio frames from a 649 * source format. 650 * 651 * @returns Pointer to matching conversion function, NULL if not supported. 652 * @param pProp The audio format to find a "from" converter for. 653 */ 654 static PFNPDMAUDIOMIXBUFCONVFROM audioMixBufConvFromLookup(PCPDMAUDIOPCMPROPS pProps) 655 { 656 if (PDMAudioPropsIsSigned(pProps)) 657 { 658 switch (PDMAudioPropsChannels(pProps)) 689 659 { 690 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 691 { 692 case 8: return audioMixBufConvFromS8Stereo; 693 case 16: return audioMixBufConvFromS16Stereo; 694 case 32: return audioMixBufConvFromS32Stereo; 695 default: return NULL; 696 } 660 case 2: 661 switch (PDMAudioPropsSampleSize(pProps)) 662 { 663 case 1: return audioMixBufConvFromS8Stereo; 664 case 2: return audioMixBufConvFromS16Stereo; 665 case 4: return audioMixBufConvFromS32Stereo; 666 //case 8: return pProps->fRaw ? audioMixBufConvToRawS64Stereo : NULL; 667 default: return NULL; 668 } 669 670 case 1: 671 switch (PDMAudioPropsSampleSize(pProps)) 672 { 673 case 1: return audioMixBufConvFromS8Mono; 674 case 2: return audioMixBufConvFromS16Mono; 675 case 4: return audioMixBufConvFromS32Mono; 676 default: return NULL; 677 } 678 default: 679 return NULL; 697 680 } 698 else 681 } 682 else /* Unsigned */ 683 { 684 switch (PDMAudioPropsChannels(pProps)) 699 685 { 700 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 701 { 702 case 8: return audioMixBufConvFromS8Mono; 703 case 16: return audioMixBufConvFromS16Mono; 704 case 32: return audioMixBufConvFromS32Mono; 705 default: return NULL; 706 } 686 case 2: 687 switch (PDMAudioPropsSampleSize(pProps)) 688 { 689 case 1: return audioMixBufConvFromU8Stereo; 690 case 2: return audioMixBufConvFromU16Stereo; 691 case 4: return audioMixBufConvFromU32Stereo; 692 default: return NULL; 693 } 694 695 case 1: 696 switch (PDMAudioPropsSampleSize(pProps)) 697 { 698 case 1: return audioMixBufConvFromU8Mono; 699 case 2: return audioMixBufConvFromU16Mono; 700 case 4: return audioMixBufConvFromU32Mono; 701 default: return NULL; 702 } 703 default: 704 return NULL; 707 705 } 708 706 } 707 /* not reached */ 708 } 709 710 /** 711 * Looks up the matching conversion function for converting audio frames to a 712 * destination format. 713 * 714 * @returns Pointer to matching conversion function, NULL if not supported. 715 * @param pProp The audio format to find a "to" converter for. 716 */ 717 static PFNPDMAUDIOMIXBUFCONVTO audioMixBufConvToLookup(PCPDMAUDIOPCMPROPS pProps) 718 { 719 if (PDMAudioPropsIsSigned(pProps)) 720 { 721 switch (PDMAudioPropsChannels(pProps)) 722 { 723 case 2: 724 switch (PDMAudioPropsSampleSize(pProps)) 725 { 726 case 1: return audioMixBufConvToS8Stereo; 727 case 2: return audioMixBufConvToS16Stereo; 728 case 4: return audioMixBufConvToS32Stereo; 729 case 8: return pProps->fRaw ? audioMixBufConvToRawS64Stereo : NULL; 730 default: return NULL; 731 } 732 733 case 1: 734 switch (PDMAudioPropsSampleSize(pProps)) 735 { 736 case 1: return audioMixBufConvToS8Mono; 737 case 2: return audioMixBufConvToS16Mono; 738 case 4: return audioMixBufConvToS32Mono; 739 default: return NULL; 740 } 741 default: 742 return NULL; 743 } 744 } 709 745 else /* Unsigned */ 710 746 { 711 if (AUDMIXBUF_FMT_CHANNELS(enmFmt) == 2)747 switch (PDMAudioPropsChannels(pProps)) 712 748 { 713 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 714 { 715 case 8: return audioMixBufConvFromU8Stereo; 716 case 16: return audioMixBufConvFromU16Stereo; 717 case 32: return audioMixBufConvFromU32Stereo; 718 default: return NULL; 719 } 720 } 721 else 722 { 723 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 724 { 725 case 8: return audioMixBufConvFromU8Mono; 726 case 16: return audioMixBufConvFromU16Mono; 727 case 32: return audioMixBufConvFromU32Mono; 728 default: return NULL; 729 } 730 } 731 } 732 /* not reached */ 733 } 734 735 /** 736 * Looks up the matching conversion (macro) routine for converting 737 * audio frames to a destination format. 738 * 739 ** @todo Speed up the lookup by binding it to the actual stream state. 740 * 741 * @return PAUDMIXBUF_FN_CONVTO Function pointer to conversion macro if found, NULL if not supported. 742 * @param enmFmt Audio format to lookup conversion macro for. 743 */ 744 static PFNPDMAUDIOMIXBUFCONVTO audioMixBufConvToLookup(PDMAUDIOMIXBUFFMT enmFmt) 745 { 746 if (AUDMIXBUF_FMT_SIGNED(enmFmt)) 747 { 748 if (AUDMIXBUF_FMT_CHANNELS(enmFmt) == 2) 749 { 750 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 751 { 752 case 8: return audioMixBufConvToS8Stereo; 753 case 16: return audioMixBufConvToS16Stereo; 754 case 32: return audioMixBufConvToS32Stereo; 755 default: return NULL; 756 } 757 } 758 else 759 { 760 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 761 { 762 case 8: return audioMixBufConvToS8Mono; 763 case 16: return audioMixBufConvToS16Mono; 764 case 32: return audioMixBufConvToS32Mono; 765 default: return NULL; 766 } 767 } 768 } 769 else /* Unsigned */ 770 { 771 if (AUDMIXBUF_FMT_CHANNELS(enmFmt) == 2) 772 { 773 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 774 { 775 case 8: return audioMixBufConvToU8Stereo; 776 case 16: return audioMixBufConvToU16Stereo; 777 case 32: return audioMixBufConvToU32Stereo; 778 default: return NULL; 779 } 780 } 781 else 782 { 783 switch (AUDMIXBUF_FMT_BITS_PER_SAMPLE(enmFmt)) 784 { 785 case 8: return audioMixBufConvToU8Mono; 786 case 16: return audioMixBufConvToU16Mono; 787 case 32: return audioMixBufConvToU32Mono; 788 default: return NULL; 789 } 749 case 2: 750 switch (PDMAudioPropsSampleSize(pProps)) 751 { 752 case 1: return audioMixBufConvToU8Stereo; 753 case 2: return audioMixBufConvToU16Stereo; 754 case 4: return audioMixBufConvToU32Stereo; 755 default: return NULL; 756 } 757 758 case 1: 759 switch (PDMAudioPropsSampleSize(pProps)) 760 { 761 case 1: return audioMixBufConvToU8Mono; 762 case 2: return audioMixBufConvToU16Mono; 763 case 4: return audioMixBufConvToU32Mono; 764 default: return NULL; 765 } 766 default: 767 return NULL; 790 768 } 791 769 } … … 826 804 * @param cFrames Maximum number of audio frames the mixing buffer can hold. 827 805 */ 828 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, P PDMAUDIOPCMPROPS pProps, uint32_t cFrames)806 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames) 829 807 { 830 808 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 831 809 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 832 810 AssertPtrReturn(pProps, VERR_INVALID_POINTER); 811 Assert(PDMAudioPropsAreValid(pProps)); 833 812 834 813 pMixBuf->uMagic = PDMAUDIOMIXBUF_MAGIC; … … 857 836 pMixBuf->pRate = NULL; 858 837 838 /** @todo r=bird: Why invent a new representation for the mixer? See also 839 * comment in pdmaudioifs.h about missing MAKE macros. */ 859 840 pMixBuf->uAudioFmt = AUDMIXBUF_AUDIO_FMT_MAKE(pProps->uHz, 860 pProps->cChannels,861 pProps->cbSample * 8 /* Bit */,862 pProps->fSigned);863 864 pMixBuf-> pfnConvFrom = audioMixBufConvFromLookup(pMixBuf->uAudioFmt);865 pMixBuf->pfnConv To = audioMixBufConvToLookup(pMixBuf->uAudioFmt);866 867 pMixBuf->cShift = pProps->cShift; 841 PDMAudioPropsChannels(pProps), 842 PDMAudioPropsSampleBits(pProps), 843 pProps->fSigned); 844 845 pMixBuf->Props = *pProps; 846 pMixBuf->pfnConvFrom = audioMixBufConvFromLookup(pProps); 847 pMixBuf->pfnConvTo = audioMixBufConvToLookup(pProps); 848 868 849 pMixBuf->pszName = RTStrDup(pszName); 869 850 if (!pMixBuf->pszName) 870 851 return VERR_NO_MEMORY; 871 852 872 AUDMIXBUF_LOG(("%s: uHz=%RU32, cChan=%RU8, cBits=%RU8, fSigned=%RTbool\n", 873 pMixBuf->pszName, 874 AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->uAudioFmt), 875 AUDMIXBUF_FMT_CHANNELS(pMixBuf->uAudioFmt), 876 AUDMIXBUF_FMT_BITS_PER_SAMPLE(pMixBuf->uAudioFmt), 877 RT_BOOL(AUDMIXBUF_FMT_SIGNED(pMixBuf->uAudioFmt)))); 853 854 #ifdef AUDMIXBUF_LOG_ENABLED 855 char szTmp[PDMAUDIOPROPSTOSTRING_MAX]; 856 AUDMIXBUF_LOG(("%s: %s\n", pMixBuf->pszName, PDMAudioPropsToString(pProps, szTmp, sizeof(szTmp)))); 857 #endif 878 858 879 859 return audioMixBufAlloc(pMixBuf, cFrames); … … 1456 1436 * @param pcbRead Size (in bytes) of data read. Optional. 1457 1437 */ 1458 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, 1459 uint32_t offFrames, 1460 void *pvBuf, uint32_t cbBuf, 1461 uint32_t *pcbRead) 1462 { 1463 return AudioMixBufReadAtEx(pMixBuf, pMixBuf->uAudioFmt, 1464 offFrames, pvBuf, cbBuf, pcbRead); 1438 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead) 1439 { 1440 return AudioMixBufReadAtEx(pMixBuf, &pMixBuf->Props, offFrames, pvBuf, cbBuf, pcbRead); 1465 1441 } 1466 1442 … … 1471 1447 * 1472 1448 * @return IPRT status code. 1473 * @param pMixBuf Mixing buffer to read audio frames from. 1474 * @param enmFmt Audio format to use for output. 1475 * @param offFrames Offset (in audio frames) to start reading from. 1476 * @param pvBuf Pointer to buffer to write output to. 1477 * @param cbBuf Size (in bytes) of buffer to write to. 1478 * @param pcbRead Size (in bytes) of data read. Optional. 1479 */ 1480 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1481 uint32_t offFrames, 1482 void *pvBuf, uint32_t cbBuf, 1483 uint32_t *pcbRead) 1449 * @param pMixBuf Mixing buffer to read audio frames from. 1450 * @param pDstProps The target format. 1451 * @param offFrames Offset (in audio frames) to start reading from. 1452 * @param pvBuf Pointer to buffer to write output to. 1453 * @param cbBuf Size (in bytes) of buffer to write to. 1454 * @param pcbRead Size (in bytes) of data read. Optional. 1455 */ 1456 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps, 1457 uint32_t offFrames, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead) 1484 1458 { 1485 1459 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 1501 1475 { 1502 1476 PFNPDMAUDIOMIXBUFCONVTO pfnConvTo = NULL; 1503 if ( pMixBuf->uAudioFmt != enmFmt)1504 pfnConvTo = audioMixBufConvToLookup(enmFmt);1477 if (PDMAudioPropsAreEqual(&pMixBuf->Props, pDstProps)) 1478 pfnConvTo = pMixBuf->pfnConvTo; 1505 1479 else 1506 pfnConvTo = pMixBuf->pfnConvTo; 1507 1480 pfnConvTo = audioMixBufConvToLookup(pDstProps); 1508 1481 if (pfnConvTo) 1509 1482 { … … 1552 1525 int AudioMixBufAcquireReadBlock(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames) 1553 1526 { 1554 return AudioMixBufAcquireReadBlockEx(pMixBuf, pMixBuf->uAudioFmt, pvBuf, cbBuf, pcAcquiredFrames);1527 return AudioMixBufAcquireReadBlockEx(pMixBuf, &pMixBuf->Props, pvBuf, cbBuf, pcAcquiredFrames); 1555 1528 } 1556 1529 1557 1530 /** 1558 1531 * Reads audio frames in a specific audio format. 1532 * 1559 1533 * If the audio format of the mixing buffer and the requested audio format do 1560 1534 * not match the output will be converted accordingly. 1561 1535 * 1562 * @return IPRTstatus code.1536 * @returns VBox status code. 1563 1537 * @param pMixBuf Mixing buffer to read audio frames from. 1564 * @param enmFmt Audio format to use for output.1538 * @param pDstProps The target format. 1565 1539 * @param pvBuf Pointer to buffer to write output to. 1566 1540 * @param cbBuf Size (in bytes) of buffer to write to. … … 1568 1542 * the block that was acquired. 1569 1543 */ 1570 int AudioMixBufAcquireReadBlockEx(PPDMAUDIOMIXBUF pMixBuf, P DMAUDIOMIXBUFFMT enmFmt,1544 int AudioMixBufAcquireReadBlockEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps, 1571 1545 void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames) 1572 1546 { … … 1581 1555 uint32_t cFramesToRead = RT_MIN(pMixBuf->cUsed, AUDIOMIXBUF_B2F(pMixBuf, cbBuf)); 1582 1556 1583 AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 frames), cFramesToRead=%RU32, fmtSrc=0x%x, fmtDst=0x%x\n", 1584 pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cFramesToRead, pMixBuf->uAudioFmt, enmFmt)); 1585 1557 #ifdef AUDMIXBUF_LOG_ENABLED 1558 char szTmp1[PDMAUDIOPROPSTOSTRING_MAX], szTmp2[PDMAUDIOPROPSTOSTRING_MAX]; 1559 #endif 1560 AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 frames), cFramesToRead=%RU32, MixBuf=%s, pDstProps=%s\n", 1561 pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cFramesToRead, 1562 PDMAudioPropsToString(&pMixBuf->Props, szTmp1, sizeof(szTmp1)), 1563 PDMAudioPropsToString(pDstProps, szTmp2, sizeof(szTmp2)))); 1586 1564 if (!cFramesToRead) 1587 1565 { … … 1594 1572 1595 1573 PFNPDMAUDIOMIXBUFCONVTO pfnConvTo; 1596 if ( pMixBuf->uAudioFmt == enmFmt)1574 if (PDMAudioPropsAreEqual(&pMixBuf->Props, pDstProps)) 1597 1575 pfnConvTo = pMixBuf->pfnConvTo; 1598 1576 else 1599 pfnConvTo = audioMixBufConvToLookup( enmFmt);1577 pfnConvTo = audioMixBufConvToLookup(pDstProps); 1600 1578 AssertReturn(pfnConvTo, VERR_NOT_SUPPORTED); 1601 1579 … … 1799 1777 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten) 1800 1778 { 1801 return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->uAudioFmt, offFrames, pvBuf, cbBuf, pcWritten);1779 return AudioMixBufWriteAtEx(pMixBuf, &pMixBuf->Props, offFrames, pvBuf, cbBuf, pcWritten); 1802 1780 } 1803 1781 … … 1812 1790 * 1813 1791 * @return IPRT status code. 1814 * @param pMixBuf Pointer to mixing buffer to write to. 1815 * @param enmFmt Audio format supplied in the buffer. 1816 * @param offFrames Offset (in frames) starting to write at. 1817 * @param pvBuf Pointer to audio buffer to be written. 1818 * @param cbBuf Size (in bytes) of audio buffer. 1819 * @param pcWritten Returns number of audio frames written. Optional. 1820 */ 1821 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1822 uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, 1823 uint32_t *pcWritten) 1792 * @param pMixBuf Pointer to mixing buffer to write to. 1793 * @param pSrcProps The source format. 1794 * @param offFrames Offset (in frames) starting to write at. 1795 * @param pvBuf Pointer to audio buffer to be written. 1796 * @param cbBuf Size (in bytes) of audio buffer. 1797 * @param pcWritten Returns number of audio frames written. Optional. 1798 */ 1799 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps, 1800 uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten) 1824 1801 { 1825 1802 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 1860 1837 if (!pMixBuf->Volume.fMuted) 1861 1838 { 1862 if ( pMixBuf->uAudioFmt != enmFmt)1863 pfnConvFrom = audioMixBufConvFromLookup(enmFmt);1839 if (PDMAudioPropsAreEqual(&pMixBuf->Props, pSrcProps)) 1840 pfnConvFrom = pMixBuf->pfnConvFrom; 1864 1841 else 1865 pfnConvFrom = pMixBuf->pfnConvFrom; 1842 pfnConvFrom = audioMixBufConvFromLookup(pSrcProps); 1843 AssertReturn(pfnConvFrom, VERR_NOT_SUPPORTED); 1866 1844 } 1867 1845 else … … 1871 1849 1872 1850 uint32_t cWritten; 1873 if ( pfnConvFrom 1874 && cToWrite) 1851 if (cToWrite) 1875 1852 { 1876 1853 PDMAUDMIXBUFCONVOPTS convOpts; 1877 1854 1878 convOpts.cFrames = cToWrite;1855 convOpts.cFrames = cToWrite; 1879 1856 convOpts.From.Volume.fMuted = pMixBuf->Volume.fMuted; 1880 1857 convOpts.From.Volume.uLeft = pMixBuf->Volume.uLeft; … … 1884 1861 } 1885 1862 else 1886 {1887 1863 cWritten = 0; 1888 if (!pfnConvFrom)1889 {1890 AssertFailed();1891 rc = VERR_NOT_SUPPORTED;1892 }1893 }1894 1864 1895 1865 AUDMIXBUF_LOG(("%s: offFrames=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n", … … 1929 1899 * @param pcWritten Returns number of audio frames written. Optional. 1930 1900 */ 1931 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, 1932 const void *pvBuf, uint32_t cbBuf, 1933 uint32_t *pcWritten) 1934 { 1935 return AudioMixBufWriteCircEx(pMixBuf, pMixBuf->uAudioFmt, pvBuf, cbBuf, pcWritten); 1901 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten) 1902 { 1903 return AudioMixBufWriteCircEx(pMixBuf, &pMixBuf->Props, pvBuf, cbBuf, pcWritten); 1936 1904 } 1937 1905 … … 1941 1909 * 1942 1910 * @return IPRT status code, or VERR_BUFFER_OVERFLOW no space is available for writing anymore. 1943 * @param pMixBuf Pointer to mixing buffer to write to. 1944 * @param enmFmt Audio format supplied in the buffer. 1945 * @param pvBuf Pointer to audio buffer to be written. 1946 * @param cbBuf Size (in bytes) of audio buffer. 1947 * @param pcWritten Returns number of audio frames written. Optional. 1948 */ 1949 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1911 * @param pMixBuf Pointer to mixing buffer to write to. 1912 * @param pSrcProps The source format. 1913 * @param enmFmt Audio format supplied in the buffer. 1914 * @param pvBuf Pointer to audio buffer to be written. 1915 * @param cbBuf Size (in bytes) of audio buffer. 1916 * @param pcWritten Returns number of audio frames written. Optional. 1917 */ 1918 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps, 1950 1919 const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten) 1951 1920 { 1952 1921 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 1953 1922 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER); 1954 /* pcbWritten is optional. */1923 AssertPtrNullReturn(pcWritten, VERR_INVALID_POINTER); 1955 1924 1956 1925 if (!cbBuf) … … 1970 1939 if (!pMixBuf->Volume.fMuted) 1971 1940 { 1972 if ( pMixBuf->uAudioFmt != enmFmt)1973 pfnConvFrom = audioMixBufConvFromLookup(enmFmt);1941 if (PDMAudioPropsAreEqual(&pMixBuf->Props, pSrcProps)) 1942 pfnConvFrom = pMixBuf->pfnConvFrom; 1974 1943 else 1975 pfnConvFrom = pMixBuf->pfnConvFrom; 1944 pfnConvFrom = audioMixBufConvFromLookup(pSrcProps); 1945 AssertReturn(pfnConvFrom, VERR_NOT_SUPPORTED); 1976 1946 } 1977 1947 else 1978 1948 pfnConvFrom = &audioMixBufConvFromSilence; 1979 1980 if (!pfnConvFrom)1981 {1982 AssertFailed();1983 return VERR_NOT_SUPPORTED;1984 }1985 1949 1986 1950 int rc = VINF_SUCCESS; … … 2034 1998 *pcWritten = cWritten; 2035 1999 2036 AUDMIXBUF_LOG(("%s: enmFmt=0x%x, cbBuf=%RU32 (%RU32 frames), cWritten=%RU32, rc=%Rrc\n", 2037 pMixBuf->pszName, enmFmt, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cWritten, rc)); 2000 #ifdef AUDMIXBUF_LOG_ENABLED 2001 char szTmp[PDMAUDIOPROPSTOSTRING_MAX]; 2002 #endif 2003 AUDMIXBUF_LOG(("%s: pSrcProps=%s, cbBuf=%RU32 (%RU32 frames), cWritten=%RU32, rc=%Rrc\n", pMixBuf->pszName, 2004 PDMAudioPropsToString(pSrcProps, szTmp, sizeof(szTmp)), cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cWritten, rc)); 2038 2005 return rc; 2039 2006 } -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
r88253 r88269 26 26 27 27 /** Constructs 32 bit value for given frequency, number of channels, bits per sample and signed bit. 28 * Note:This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */28 * @note This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */ 29 29 #define AUDMIXBUF_AUDIO_FMT_MAKE(freq, c, bps, s) ((((s) & 0x1) << 28) + (((bps) & 0xFF) << 20) + (((c) & 0xF) << 16) + ((freq) & 0xFFFF)) 30 30 … … 40 40 #define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8) 41 41 42 /** Converts frames to bytes. */ 43 #define AUDIOMIXBUF_F2B(pBuf, frames) ((frames) << (pBuf)->cShift) 42 /** Converts (audio) frames to bytes. */ 43 #define AUDIOMIXBUF_F2B(a_pMixBuf, a_cFrames) PDMAUDIOPCMPROPS_F2B(&(a_pMixBuf)->Props, a_cFrames) 44 /** Converts bytes to (audio) frames. 45 * @note Does *not* take the conversion ratio into account. */ 46 #define AUDIOMIXBUF_B2F(a_pMixBuf, a_cb) PDMAUDIOPCMPROPS_B2F(&(a_pMixBuf)->Props, a_cb) 47 44 48 /** Converts frames to bytes, respecting the conversion ratio to 45 49 * a linked buffer. */ 46 #define AUDIOMIXBUF_F2B_RATIO(pBuf, frames) ((((int64_t) frames << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift) 47 /** Converts bytes to frames, *not* taking the conversion ratio 48 * into account. */ 49 #define AUDIOMIXBUF_B2F(pBuf, cb) (cb >> (pBuf)->cShift) 50 /** Converts number of frames according to the buffer's ratio. */ 51 #define AUDIOMIXBUF_F2F_RATIO(pBuf, frames) (((int64_t) frames << 32) / (pBuf)->iFreqRatio) 50 #define AUDIOMIXBUF_F2B_RATIO(a_pMixBuf, a_cFrames) AUDIOMIXBUF_F2B(a_pMixBuf, AUDIOMIXBUF_F2F_RATIO(a_pMixBuf, a_cFrames)) 51 /** Converts number of frames according to the buffer's ratio. 52 * @todo r=bird: Why the *signed* cast? */ 53 #define AUDIOMIXBUF_F2F_RATIO(a_pMixBuf, a_cFrames) (((int64_t)(a_cFrames) << 32) / (a_pMixBuf)->iFreqRatio) 52 54 53 55 … … 58 60 uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf); 59 61 uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf); 60 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, P PDMAUDIOPCMPROPS pProps, uint32_t cFrames);62 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames); 61 63 bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf); 62 64 int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent); … … 64 66 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed); 65 67 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed); 66 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME paSampleBuf, uint32_t cSampleBuf, uint32_t *pcFramesRead);67 68 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME *ppvSamples, uint32_t *pcFramesRead); 68 69 uint32_t AudioMixBufUsed(PPDMAUDIOMIXBUF pMixBuf); 69 70 uint32_t AudioMixBufUsedBytes(PPDMAUDIOMIXBUF pMixBuf); 70 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 71 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 72 int AudioMixBufAcquireReadBlock(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames); 73 int AudioMixBufAcquireReadBlockEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames); 71 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 72 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps, uint32_t offFrames, 73 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 74 int AudioMixBufAcquireReadBlock(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames); 75 int AudioMixBufAcquireReadBlockEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps, 76 void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames); 74 77 void AudioMixBufReleaseReadBlock(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames); 75 78 uint32_t AudioMixBufReadPos(PPDMAUDIOMIXBUF pMixBuf); … … 79 82 uint32_t AudioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf); 80 83 void AudioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf); 81 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 82 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 83 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 84 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 84 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 85 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps, uint32_t offFrames, 86 const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 87 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 88 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps, 89 const void *pvBuf,uint32_t cbBuf, uint32_t *pcWritten); 85 90 uint32_t AudioMixBufWritePos(PPDMAUDIOMIXBUF pMixBuf); 86 91 -
trunk/src/VBox/Devices/Audio/AudioMixer.cpp
r88235 r88269 264 264 } 265 265 else 266 RTMemFree(pMixer); 266 RTMemFree(pMixer); /** @todo leaks pszName due to badly structured code */ 267 267 } 268 268 else … … 611 611 return rc; 612 612 613 LogFlowFunc(("[%s] fFlags=0x%x (enmDir=%ld, %u bits, %RU8 channels, %RU32Hz)\n", 614 pSink->pszName, fFlags, pCfg->enmDir, pCfg->Props.cbSample * 8, pCfg->Props.cChannels, pCfg->Props.uHz));613 LogFlowFunc(("[%s] fFlags=0x%x (enmDir=%ld, %u bits, %RU8 channels, %RU32Hz)\n", pSink->pszName, fFlags, pCfg->enmDir, 614 PDMAudioPropsSampleBits(&pCfg->Props), PDMAudioPropsChannels(&pCfg->Props), pCfg->Props.uHz)); 615 615 616 616 /* … … 1488 1488 1489 1489 if (pSink->PCMProps.uHz) 1490 LogFlowFunc(("[%s] Old format: %u bit, %RU8 channels, %RU32Hz\n", 1491 pSink->pszName, pSink->PCMProps.cbSample * 8, pSink->PCMProps.cChannels, pSink->PCMProps.uHz));1490 LogFlowFunc(("[%s] Old format: %u bit, %RU8 channels, %RU32Hz\n", pSink->pszName, 1491 PDMAudioPropsSampleBits(&pSink->PCMProps), PDMAudioPropsChannels(&pSink->PCMProps), pSink->PCMProps.uHz)); 1492 1492 1493 1493 memcpy(&pSink->PCMProps, pPCMProps, sizeof(PDMAUDIOPCMPROPS)); 1494 1494 1495 LogFlowFunc(("[%s] New format %u bit, %RU8 channels, %RU32Hz\n", 1496 pSink->pszName, pSink->PCMProps.cbSample * 8, pSink->PCMProps.cChannels, pSink->PCMProps.uHz));1495 LogFlowFunc(("[%s] New format %u bit, %RU8 channels, %RU32Hz\n", pSink->pszName, PDMAudioPropsSampleBits(&pSink->PCMProps), 1496 PDMAudioPropsChannels(&pSink->PCMProps), pSink->PCMProps.uHz)); 1497 1497 1498 1498 /* Also update the sink's mixing buffer format. */ -
trunk/src/VBox/Devices/Audio/DevHda.cpp
r88235 r88269 1449 1449 1450 1450 # ifdef LOG_ENABLED 1451 PDMAUDIOPCMPROPS Props; 1452 rc2 = hdaR3SDFMTToPCMProps(HDA_STREAM_REG(pThis, FMT, uSD), &Props); 1453 AssertRC(rc2); 1454 LogFunc(("[SD%RU8] %RU32Hz, %RU8bit, %RU8 channel(s)\n", 1455 uSD, Props.uHz, Props.cbSample * 8 /* Bit */, Props.cChannels)); 1451 if (LogIsEnabled()) 1452 { 1453 PDMAUDIOPCMPROPS Props = { 0 }; 1454 rc2 = hdaR3SDFMTToPCMProps(HDA_STREAM_REG(pThis, FMT, uSD), &Props); AssertRC(rc2); 1455 LogFunc(("[SD%RU8] %RU32Hz, %RU8bit, %RU8 channel(s)\n", 1456 uSD, Props.uHz, PDMAudioPropsSampleBits(&Props), PDMAudioPropsChannels(&Props))); 1457 } 1456 1458 # endif 1457 1459 /* (Re-)initialize the stream with current values. */ … … 1667 1669 1668 1670 /** @todo Make the following configurable through mixer API and/or CFGM? */ 1669 switch ( pCfg->Props.cChannels)1671 switch (PDMAudioPropsGetChannels(&pCfg->Props)) 1670 1672 { 1671 1673 case 3: /* 2.1: Front (Stereo) + LFE. */ … … 1706 1708 if (rc == VERR_NOT_SUPPORTED) 1707 1709 { 1708 LogRel2(("HDA: Warning: Unsupported channel count (%RU8), falling back to stereo channels (2)\n", pCfg->Props.cChannels ));1710 LogRel2(("HDA: Warning: Unsupported channel count (%RU8), falling back to stereo channels (2)\n", pCfg->Props.cChannelsX)); 1709 1711 1710 1712 /* Fall back to 2 channels (see below in fUseFront block). */ … … 1723 1725 pCfg->u.enmDst = PDMAUDIOPLAYBACKDST_FRONT; 1724 1726 pCfg->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 1725 1726 pCfg->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cbSample, pCfg->Props.cChannels); 1727 /// @todo PDMAudioPropsSetChannels(&pCfg->Props, 2); ? 1727 1728 1728 1729 rc = hdaR3CodecAddStream(pThisCC->pCodec, PDMAUDIOMIXERCTL_FRONT, pCfg); … … 1737 1738 pCfg->u.enmDst = PDMAUDIOPLAYBACKDST_CENTER_LFE; 1738 1739 pCfg->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 1739 1740 pCfg->Props.cChannels = (fUseCenter && fUseLFE) ? 2 : 1; 1741 pCfg->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cbSample, pCfg->Props.cChannels); 1740 PDMAudioPropsSetChannels(&pCfg->Props, fUseCenter && fUseLFE ? 2 : 1); 1742 1741 1743 1742 rc = hdaR3CodecAddStream(pThisCC->pCodec, PDMAUDIOMIXERCTL_CENTER_LFE, pCfg); … … 1751 1750 pCfg->u.enmDst = PDMAUDIOPLAYBACKDST_REAR; 1752 1751 pCfg->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 1753 1754 pCfg->Props.cChannels = 2; 1755 pCfg->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cbSample, pCfg->Props.cChannels); 1752 PDMAudioPropsSetChannels(&pCfg->Props, 2); 1756 1753 1757 1754 rc = hdaR3CodecAddStream(pThisCC->pCodec, PDMAUDIOMIXERCTL_REAR, pCfg); … … 1912 1909 int rc2 = hdaR3SDFMTToPCMProps(RT_LO_U16(u32Value), &Props); 1913 1910 AssertRC(rc2); 1914 LogFunc(("[SD%RU8] Set to %#x (%RU32Hz, %RU8bit, %RU8 channel(s))\n", 1915 HDA_SD_NUM_FROM_REG(pThis, FMT, iReg), u32Value, Props.uHz, Props.cbSample * 8 /* Bit */, Props.cChannels));1911 LogFunc(("[SD%RU8] Set to %#x (%RU32Hz, %RU8bit, %RU8 channel(s))\n", HDA_SD_NUM_FROM_REG(pThis, FMT, iReg), u32Value, 1912 PDMAudioPropsHz(&Props), PDMAudioPropsSampleBits(&Props), PDMAudioPropsChannels(&Props))); 1916 1913 1917 1914 /* … … 2319 2316 AssertPtrReturn(pCfg, VERR_INVALID_POINTER); 2320 2317 2321 LogFunc(("szSink=%s, szStream=%s, cChannels=%RU8\n", pMixSink->pszName, pCfg->szName, pCfg->Props.cChannels));2318 LogFunc(("szSink=%s, szStream=%s, cChannels=%RU8\n", pMixSink->pszName, pCfg->szName, PDMAudioPropsChannels(&pCfg->Props))); 2322 2319 2323 2320 PPDMAUDIOSTREAMCFG pStreamCfg = PDMAudioStrmCfgDup(pCfg); … … 5356 5353 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStreams[idxStream].State.Cfg.Props.uHz, STAMTYPE_U32, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5357 5354 "The stream frequency.", "Stream%u/Cfg/Hz", idxStream); 5358 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStreams[idxStream].State.Cfg.Props.cChannels, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5355 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStreams[idxStream].State.Cfg.Props.cbFrame, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5356 "The number of channels.", "Stream%u/Cfg/FrameSize-Host", idxStream); 5357 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aStreams[idxStream].State.Mapping.GuestProps.cbFrame, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5358 "The number of channels.", "Stream%u/Cfg/FrameSize-Guest", idxStream); 5359 #if 0 /** @todo this would require some callback */ 5360 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStreams[idxStream].State.Cfg.Props.cChannelsX, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5359 5361 "The number of channels.", "Stream%u/Cfg/Channels-Host", idxStream); 5360 5362 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aStreams[idxStream].State.Mapping.GuestProps.cChannels, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, … … 5362 5364 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aStreams[idxStream].State.Cfg.Props.cbSample, STAMTYPE_U8, STAMVISIBILITY_USED, STAMUNIT_BYTES, 5363 5365 "The size of a sample (per channel).", "Stream%u/Cfg/cbSample", idxStream); 5366 #endif 5364 5367 } 5365 5368 -
trunk/src/VBox/Devices/Audio/DevHdaCommon.cpp
r88235 r88269 22 22 * Header Files * 23 23 *********************************************************************************************************************************/ 24 #define LOG_GROUP LOG_GROUP_DEV_HDA 24 25 #include <iprt/assert.h> 25 26 #include <iprt/errcore.h> … … 27 28 28 29 #include <VBox/AssertGuest.h> 29 30 #define LOG_GROUP LOG_GROUP_DEV_HDA 30 #include <VBox/vmm/pdmaudioinline.h> 31 31 32 #include <VBox/log.h> 32 33 … … 34 35 #include "DevHdaCommon.h" 35 36 #include "DevHdaStream.h" 37 36 38 37 39 … … 304 306 } 305 307 306 uint8_t c Bytes= 0;308 uint8_t cbSample = 0; 307 309 switch (EXTRACT_VALUE(u16SDFMT, HDA_SDFMT_BITS_MASK, HDA_SDFMT_BITS_SHIFT)) 308 310 { 309 311 case 0: 310 c Bytes= 1;312 cbSample = 1; 311 313 break; 312 314 case 1: 313 c Bytes= 2;315 cbSample = 2; 314 316 break; 315 317 case 4: 316 c Bytes= 4;318 cbSample = 4; 317 319 break; 318 320 default: … … 324 326 325 327 if (RT_SUCCESS(rc)) 326 { 327 RT_BZERO(pProps, sizeof(PDMAUDIOPCMPROPS)); 328 329 pProps->cbSample = cBytes; 330 pProps->fSigned = true; 331 pProps->cChannels = (u16SDFMT & 0xf) + 1; 332 pProps->uHz = u32Hz * u32HzMult / u32HzDiv; 333 pProps->cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pProps->cbSample, pProps->cChannels); 334 } 328 PDMAudioPropsInit(pProps, cbSample, true /*fSigned*/, (u16SDFMT & 0xf) + 1 /*cChannels*/, u32Hz * u32HzMult / u32HzDiv); 335 329 336 330 # undef EXTRACT_VALUE -
trunk/src/VBox/Devices/Audio/DevHdaStream.cpp
r88235 r88269 739 739 740 740 /* Serious paranoia: */ 741 ASSERT_GUEST_LOGREL_MSG_STMT(cbCircBuf % (pCfg->Props.cbSample * pCfg->Props.cChannels) == 0,741 ASSERT_GUEST_LOGREL_MSG_STMT(cbCircBuf % PDMAudioPropsFrameSize(&pCfg->Props) == 0, 742 742 ("Ring buffer size (%RU32) for stream #%RU8 not aligned to the (host) frame size (%RU8)\n", 743 cbCircBuf, uSD, pCfg->Props.cbSample * pCfg->Props.cChannels),743 cbCircBuf, uSD, PDMAudioPropsFrameSize(&pCfg->Props)), 744 744 rc = VERR_INVALID_PARAMETER); 745 745 ASSERT_GUEST_LOGREL_MSG_STMT(cbCircBuf, ("Ring buffer size for stream #%RU8 is invalid\n", uSD), -
trunk/src/VBox/Devices/Audio/DevHdaStreamMap.cpp
r88235 r88269 209 209 * - have a simple (raw) data layout 210 210 * - work in a non-striped fashion, e.g. interleaved (only on one SDn, not spread over multiple SDns) */ 211 if ( pProps->cChannels == 1 /* Mono */ 212 || pProps->cChannels == 2 /* Stereo */ 213 || pProps->cChannels == 4 /* Quadrophonic */ 214 || pProps->cChannels == 6) /* Surround (5.1) */ 211 uint8_t cChannels = PDMAudioPropsChannels(pProps); 212 if ( cChannels == 1 /* Mono */ 213 || cChannels == 2 /* Stereo */ 214 || cChannels == 4 /* Quadrophonic */ 215 || cChannels == 6) /* Surround (5.1) */ 215 216 { 216 217 /* … … 218 219 */ 219 220 memcpy(&pMap->GuestProps, pProps, sizeof(PDMAUDIOPCMPROPS)); 220 if ( pProps->cChannels != cHostChannels)221 if (cChannels != cHostChannels) 221 222 { 222 if ( pProps->cChannels == 1)223 if (cChannels == 1) 223 224 LogRelMax(32, ("HDA: Warning: Guest mono, host stereo.\n")); 224 else if (cHostChannels == 1 && pProps->cChannels == 2)225 else if (cHostChannels == 1 && cChannels == 2) 225 226 LogRelMax(32, ("HDA: Warning: Host mono, guest stereo.\n")); 226 227 else 227 228 #ifndef VBOX_WITH_AUDIO_HDA_51_SURROUND 228 229 LogRelMax(32, ("HDA: Warning: Guest configured %u channels, host only supports %u. Ignoring additional channels.\n", 229 pProps->cChannels, cHostChannels));230 cChannels, cHostChannels)); 230 231 #else 231 232 # error reconsider the above logic 232 233 #endif 233 pProps->cChannels = cHostChannels; 234 pProps->cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps); 234 PDMAudioPropsSetChannels(pProps, cHostChannels); 235 235 } 236 236 … … 238 238 * Pick conversion functions. 239 239 */ 240 Assert( pMap->GuestProps.cbSample == pProps->cbSample);240 Assert(PDMAudioPropsSampleSize(&pMap->GuestProps) == PDMAudioPropsSampleSize(pProps)); 241 241 242 242 /* If the channel count matches, we can use the memcpy converters: */ 243 if ( pProps->cChannels == pMap->GuestProps.cChannels)243 if (PDMAudioPropsChannels(pProps) == PDMAudioPropsChannels(&pMap->GuestProps)) 244 244 { 245 245 pMap->pfnGuestToHost = hdaR3StreamMap_GenericCopy; … … 252 252 first two channels and map this onto the host stereo ones. */ 253 253 AssertReturn(cHostChannels == 2, VERR_NOT_SUPPORTED); 254 switch ( pMap->GuestProps.cbSample)254 switch (PDMAudioPropsSampleSize(&pMap->GuestProps)) 255 255 { 256 256 case 2: 257 if ( pMap->GuestProps.cChannels> 1)257 if (PDMAudioPropsChannels(&pMap->GuestProps) > 1) 258 258 { 259 259 pMap->pfnGuestToHost = hdaR3StreamMap_G2H_GenericS16_NonMono2Stereo; … … 268 268 269 269 case 4: 270 if ( pMap->GuestProps.cChannels> 1)270 if (PDMAudioPropsChannels(&pMap->GuestProps) > 1) 271 271 { 272 272 pMap->pfnGuestToHost = hdaR3StreamMap_G2H_GenericS32_NonMono2Stereo; … … 281 281 282 282 default: 283 AssertMsgFailedReturn(("cbSample=%u\n", pMap->GuestProps.cbSample), VERR_NOT_SUPPORTED);283 AssertMsgFailedReturn(("cbSample=%u\n", PDMAudioPropsChannels(&pMap->GuestProps)), VERR_NOT_SUPPORTED); 284 284 } 285 285 pMap->fMappingNeeded = true; … … 297 297 pMapLR->aenmIDs[0] = PDMAUDIOSTREAMCHANNELID_FRONT_LEFT; 298 298 pMapLR->aenmIDs[1] = PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT; 299 pMapLR->cbFrame = pProps->cbSample * pProps->cChannels;300 pMapLR->cbStep = pProps->cbSample* 2 /* Front left + Front right channels */;299 pMapLR->cbFrame = PDMAudioPropsFrameSize(pProps); 300 pMapLR->cbStep = PDMAudioPropsSampleSize(pProps) * 2 /* Front left + Front right channels */; 301 301 pMapLR->offFirst = 0; 302 302 pMapLR->offNext = pMapLR->offFirst; … … 334 334 hdaR3StreamMapReset(pMap); 335 335 336 pMap->cbGuestFrame = pProps->cChannels * pProps->cbSample;336 pMap->cbGuestFrame = PDMAudioPropsFrameSize(pProps); 337 337 int rc = hdaR3StreamMapSetup(pMap, pProps, cHostChannels); 338 338 if (RT_SUCCESS(rc)) … … 346 346 { 347 347 LogFunc(("cChannels=%RU8, cBytes=%RU8 -> cbGuestFrame=%RU32\n", 348 pProps->cChannels, pProps->cbSample, pMap->cbGuestFrame));348 PDMAudioPropsChannels(pProps), PDMAudioPropsSampleSize(pProps), pMap->cbGuestFrame)); 349 349 350 350 Assert(pMap->cbGuestFrame); /* Frame size must not be 0. */ -
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r88234 r88269 2137 2137 static int ichac97R3StreamOpen(PAC97STATE pThis, PAC97STATER3 pThisCC, PAC97STREAM pStream, PAC97STREAMR3 pStreamCC, bool fForce) 2138 2138 { 2139 PDMAUDIOSTREAMCFG Cfg; 2139 int rc = VINF_SUCCESS; 2140 PAUDMIXSINK pMixSink; 2141 PDMAUDIOSTREAMCFG Cfg; 2140 2142 RT_ZERO(Cfg); 2141 Cfg.Props.cChannels = 2;2142 Cfg.Props.cbSample = 2 /* 16-bit */;2143 Cfg.Props.fSigned = true;2144 Cfg.Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(Cfg.Props.cbSample, Cfg.Props.cChannels);2145 2146 int rc = VINF_SUCCESS;2147 PAUDMIXSINK pMixSink;2148 2143 switch (pStream->u8SD) 2149 2144 { 2150 2145 case AC97SOUNDSOURCE_PI_INDEX: 2151 2146 { 2152 Cfg.Props.uHz = ichac97MixerGet(pThis, AC97_PCM_LR_ADC_Rate); 2147 PDMAudioPropsInit(&Cfg.Props, 2 /*16-bit*/, true /*signed*/, 2 /*stereo*/, 2148 ichac97MixerGet(pThis, AC97_PCM_LR_ADC_Rate)); 2153 2149 Cfg.enmDir = PDMAUDIODIR_IN; 2154 2150 Cfg.u.enmSrc = PDMAUDIORECSRC_LINE; … … 2162 2158 case AC97SOUNDSOURCE_MC_INDEX: 2163 2159 { 2164 Cfg.Props.uHz = ichac97MixerGet(pThis, AC97_MIC_ADC_Rate); 2160 PDMAudioPropsInit(&Cfg.Props, 2 /*16-bit*/, true /*signed*/, 2 /*stereo*/, 2161 ichac97MixerGet(pThis, AC97_MIC_ADC_Rate)); 2165 2162 Cfg.enmDir = PDMAUDIODIR_IN; 2166 2163 Cfg.u.enmSrc = PDMAUDIORECSRC_MIC; … … 2174 2171 case AC97SOUNDSOURCE_PO_INDEX: 2175 2172 { 2176 Cfg.Props.uHz = ichac97MixerGet(pThis, AC97_PCM_Front_DAC_Rate); 2173 PDMAudioPropsInit(&Cfg.Props, 2 /*16-bit*/, true /*signed*/, 2 /*stereo*/, 2174 ichac97MixerGet(pThis, AC97_PCM_Front_DAC_Rate)); 2177 2175 Cfg.enmDir = PDMAUDIODIR_OUT; 2178 2176 Cfg.u.enmDst = PDMAUDIOPLAYBACKDST_FRONT; … … 2197 2195 || fForce) 2198 2196 { 2199 LogRel2(("AC97: (Re-)Opening stream '%s' (%RU32Hz, %RU8 channels, %s%RU8)\n", 2200 Cfg.szName, Cfg.Props.uHz, Cfg.Props.cChannels, Cfg.Props.fSigned ? "S" : "U", Cfg.Props.cbSample * 8));2197 LogRel2(("AC97: (Re-)Opening stream '%s' (%RU32Hz, %RU8 channels, %s%RU8)\n", Cfg.szName, Cfg.Props.uHz, 2198 PDMAudioPropsChannels(&Cfg.Props), Cfg.Props.fSigned ? "S" : "U", PDMAudioPropsSampleBits(&Cfg.Props))); 2201 2199 2202 2200 LogFlowFunc(("[SD%RU8] uHz=%RU32\n", pStream->u8SD, Cfg.Props.uHz)); -
trunk/src/VBox/Devices/Audio/DevSB16.cpp
r88234 r88269 910 910 pCfg->u.enmDst = PDMAUDIOPLAYBACKDST_FRONT; 911 911 pCfg->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 912 913 pCfg->Props.uHz = pThis->freq; 914 pCfg->Props.cChannels = 1; /* Mono */ 915 pCfg->Props.cbSample = 1 /* 8-bit */; 916 pCfg->Props.fSigned = false; 917 pCfg->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cbSample, pCfg->Props.cChannels); 912 PDMAudioPropsInit(&pCfg->Props, 1 /*8-bit*/, false /*fSigned*/, 1 /*mono*/, pThis->freq); 918 913 919 914 AssertCompile(sizeof(pCfg->szName) >= sizeof("Output")); … … 1833 1828 PDMAUDIOSTREAMCFG Cfg; 1834 1829 RT_ZERO(Cfg); 1835 1836 Cfg.Props.uHz = pThis->freq; 1837 Cfg.Props.cChannels = 1 << pThis->fmt_stereo; 1838 Cfg.Props.cbSample = pThis->fmt_bits / 8; 1839 Cfg.Props.fSigned = RT_BOOL(pThis->fmt_signed); 1840 Cfg.Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(Cfg.Props.cbSample, Cfg.Props.cChannels); 1830 PDMAudioPropsInit(&Cfg.Props, pThis->fmt_bits / 8, pThis->fmt_signed != 0, 1 << pThis->fmt_stereo, pThis->freq); 1841 1831 1842 1832 if (!PDMAudioStrmCfgMatchesProps(&Cfg, &pThis->Out.Cfg.Props)) -
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r88259 r88269 716 716 717 717 LogRel2(("Audio: Creating stream '%s'\n", pStream->szName)); 718 LogRel2(("Audio: Guest %s format for '%s': %RU32Hz, %u%s, %RU8 %s\n",718 LogRel2(("Audio: Guest %s format for '%s': %RU32Hz, %u%s, %RU8 channel%s\n", 719 719 pCfgGuest->enmDir == PDMAUDIODIR_IN ? "recording" : "playback", pStream->szName, 720 pCfgGuest->Props.uHz, pCfgGuest->Props.cbSample * 8, pCfgGuest->Props.fSigned ? "S" : "U",721 pCfgGuest->Props.cChannels, pCfgGuest->Props.cChannels == 1 ? "Channel" : "Channels"));722 LogRel2(("Audio: Requested host %s format for '%s': %RU32Hz, %u%s, %RU8 %s\n",720 pCfgGuest->Props.uHz, PDMAudioPropsSampleBits(&pCfgGuest->Props), pCfgGuest->Props.fSigned ? "S" : "U", 721 PDMAudioPropsChannels(&pCfgGuest->Props), PDMAudioPropsChannels(&pCfgGuest->Props) == 1 ? "" : "s")); 722 LogRel2(("Audio: Requested host %s format for '%s': %RU32Hz, %u%s, %RU8 channel%s\n", 723 723 pCfgHost->enmDir == PDMAUDIODIR_IN ? "recording" : "playback", pStream->szName, 724 pCfgHost->Props.uHz, pCfgHost->Props.cbSample * 8, pCfgHost->Props.fSigned ? "S" : "U",725 pCfgHost->Props.cChannels, pCfgHost->Props.cChannels == 1 ? "Channel" : "Channels"));724 pCfgHost->Props.uHz, PDMAudioPropsSampleBits(&pCfgHost->Props), pCfgHost->Props.fSigned ? "S" : "U", 725 PDMAudioPropsChannels(&pCfgHost->Props), PDMAudioPropsChannels(&pCfgHost->Props) == 1 ? "" : "s")); 726 726 727 727 PDMAUDIOSTREAMCFG CfgHostAcq; … … 730 730 return rc; 731 731 732 #ifdef LOG_ENABLED733 732 LogFunc(("[%s] Acquired host format:\n", pStream->szName)); 734 733 PDMAudioStrmCfgLog(&CfgHostAcq); 735 #endif 736 737 LogRel2(("Audio: Acquired host %s format for '%s': %RU32Hz, %u%s, %RU8 %s\n", 734 LogRel2(("Audio: Acquired host %s format for '%s': %RU32Hz, %u%s, %RU8 channel%s\n", 738 735 CfgHostAcq.enmDir == PDMAUDIODIR_IN ? "recording" : "playback", pStream->szName, 739 CfgHostAcq.Props.uHz, CfgHostAcq.Props.cbSample * 8, CfgHostAcq.Props.fSigned ? "S" : "U", 740 CfgHostAcq.Props.cChannels, CfgHostAcq.Props.cChannels == 1 ? "Channel" : "Channels")); 736 CfgHostAcq.Props.uHz, PDMAudioPropsSampleBits(&CfgHostAcq.Props), CfgHostAcq.Props.fSigned ? "S" : "U", 737 PDMAudioPropsChannels(&CfgHostAcq.Props), PDMAudioPropsChannels(&CfgHostAcq.Props) == 1 ? "" : "s")); 738 Assert(PDMAudioPropsAreValid(&CfgHostAcq.Props)); 741 739 742 740 /* Let the user know if the backend changed some of the tweakable values. */ … … 755 753 PDMAudioPropsFramesToMilli(&pCfgHost->Props, pCfgHost->Backend.cFramesPreBuffering), pCfgHost->Backend.cFramesPreBuffering, 756 754 PDMAudioPropsFramesToMilli(&CfgHostAcq.Props, CfgHostAcq.Backend.cFramesPreBuffering), CfgHostAcq.Backend.cFramesPreBuffering)); 755 757 756 /* 758 757 * Configure host buffers. … … 801 800 AudioMixBufDestroy(&pStream->Host.MixBuf); 802 801 803 /* Make sure to (re-)set the host buffer's shift size. */804 CfgHostAcq.Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(CfgHostAcq.Props.cbSample, CfgHostAcq.Props.cChannels);805 806 802 rc = AudioMixBufInit(&pStream->Host.MixBuf, pStream->szName, &CfgHostAcq.Props, CfgHostAcq.Backend.cFramesBufferSize); 807 803 AssertRC(rc); … … 825 821 /* Set the guests's default audio data layout. */ 826 822 pCfgGuest->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 827 828 /* Make sure to (re-)set the guest buffer's shift size. */829 pCfgGuest->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfgGuest->Props.cbSample, pCfgGuest->Props.cChannels);830 823 831 824 rc = AudioMixBufInit(&pStream->Guest.MixBuf, pStream->szName, &pCfgGuest->Props, CfgHostAcq.Backend.cFramesBufferSize); … … 1448 1441 1449 1442 /** 1450 * Worker for drvAudioStreamPlay that plays non-interleaved data.1443 * Worker for drvAudioStreamPlay that does the actual playing. 1451 1444 * 1452 1445 * @returns VBox status code. 1453 1446 * @param pThis The audio driver instance data. 1454 1447 * @param pStream The stream to play. 1455 * @param cFramesToPlay Number of audio frames to play. 1448 * @param cFramesToPlay Number of audio frames to play. The backend is 1449 * supposed to have buffer space for this. 1456 1450 * @param pcFramesPlayed Where to return the number of audio frames played. 1457 1451 */ 1458 static int drvAudioStreamPlayNonInterleaved(PDRVAUDIO pThis, PPDMAUDIOSTREAM pStream, 1459 uint32_t cFramesToPlay, uint32_t *pcFramesPlayed) 1452 static int drvAudioStreamPlayDoIt(PDRVAUDIO pThis, PPDMAUDIOSTREAM pStream, uint32_t cFramesToPlay, uint32_t *pcFramesPlayed) 1460 1453 { 1461 1454 Assert(pStream->enmDir == PDMAUDIODIR_OUT); 1462 Assert(pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED);1463 1455 1464 1456 /* … … 1490 1482 if (RT_SUCCESS(rc)) 1491 1483 { 1492 if (cbPlayed) 1493 { 1494 if (pThis->Out.Cfg.Dbg.fEnabled) 1495 AudioHlpFileWrite(pStream->Out.Dbg.pFilePlayNonInterleaved, abChunk, cbPlayed, 0 /* fFlags */); 1496 1497 if (cbRead != cbPlayed) 1498 LogRel2(("Audio: Host stream '%s' played wrong amount (%RU32 bytes read but played %RU32)\n", 1499 pStream->szName, cbRead, cbPlayed)); 1500 1501 cFramesPlayed = AUDIOMIXBUF_B2F(&pStream->Host.MixBuf, cbPlayed); 1502 AssertStmt(cFramesLeft >= cFramesPlayed, cFramesPlayed = cFramesLeft); 1503 cFramesLeft -= cFramesPlayed; 1504 } 1505 else 1506 { 1507 /** @todo r=bird: If the backend is doing non-blocking writes, we'll probably 1508 * be spinning like crazy here... The ALSA backend is non-blocking. */ 1509 } 1484 if (pThis->Out.Cfg.Dbg.fEnabled) 1485 AudioHlpFileWrite(pStream->Out.Dbg.pFilePlayNonInterleaved, abChunk, cbPlayed, 0 /* fFlags */); 1486 1487 if (cbRead != cbPlayed) 1488 LogRel2(("Audio: Host stream '%s' played wrong amount (%RU32 bytes read but played %RU32)\n", 1489 pStream->szName, cbRead, cbPlayed)); 1490 1491 cFramesPlayed = AUDIOMIXBUF_B2F(&pStream->Host.MixBuf, cbPlayed); 1492 AssertStmt(cFramesLeft >= cFramesPlayed, cFramesPlayed = cFramesLeft); 1493 cFramesLeft -= cFramesPlayed; 1510 1494 } 1511 1495 … … 1513 1497 1514 1498 AssertRCBreak(rc); /* (this is here for Acquire/Release symmetry - which isn't at all necessary) */ 1499 AssertBreak(cbPlayed > 0); /* (ditto) */ 1515 1500 } 1516 1501 1517 1502 Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pStream->szName, cFramesToPlay - cFramesLeft, cFramesToPlay, rc)); 1518 1503 *pcFramesPlayed = cFramesToPlay - cFramesLeft; 1519 return rc;1520 }1521 1522 /**1523 * Plays an audio host output stream which has been configured for raw audio (layout) data.1524 *1525 * @returns VBox status code.1526 * @param pThis Pointer to driver instance.1527 * @param pStream Stream to play.1528 * @param cFramesToPlay Number of audio frames to play.1529 * @param pcFramesPlayed Where to return number of audio frames played.1530 */1531 static int drvAudioStreamPlayRaw(PDRVAUDIO pThis, PPDMAUDIOSTREAM pStream, uint32_t cFramesToPlay, uint32_t *pcFramesPlayed)1532 {1533 Assert(pStream->enmDir == PDMAUDIODIR_OUT);1534 Assert(pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW);1535 1536 /*1537 * ...1538 */1539 int rc = VINF_SUCCESS;1540 uint32_t cFramesLeft = cFramesToPlay;1541 while (cFramesLeft > 0)1542 {1543 PDMAUDIOFRAME aFrames[_2K];1544 uint32_t cFramesRead = 0;1545 /** @todo r=bird: Peek functions do _not_ generally drop stuff from what they're1546 * peeking into. We normally name such functions Read. (Oh man, am I1547 * getting tired of this kind of crap.) */1548 rc = AudioMixBufPeek(&pStream->Host.MixBuf, cFramesLeft, aFrames,1549 RT_MIN(cFramesLeft, RT_ELEMENTS(aFrames)), &cFramesRead);1550 if (RT_SUCCESS(rc))1551 {1552 Assert(cFramesRead <= RT_ELEMENTS(aFrames));1553 if (cFramesRead)1554 {1555 uint32_t cbPlayed = 0;1556 rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pStream->pvBackend,1557 aFrames, cFramesRead * sizeof(aFrames[0]), &cbPlayed);1558 AssertRCBreak(rc);1559 /** @todo r=bird: This is a natural follow up to the non-peeking peek crap1560 * above. It works because VRDE is the only consumer and it always1561 * processes all that it gets. */1562 AssertBreakStmt(cbPlayed == cFramesRead * sizeof(aFrames[0]), rc = VERR_INTERNAL_ERROR_2);1563 1564 Assert(cFramesRead <= cFramesLeft);1565 cFramesLeft -= cFramesRead;1566 }1567 else1568 {1569 /** @todo r=bird: This looks totally loopy. Why should another call return data1570 * when the first one didn't? */1571 if (rc == VINF_AUDIO_MORE_DATA_AVAILABLE) /* Do another peeking round if there is more data available. */1572 continue;1573 break;1574 }1575 }1576 else1577 break;1578 }1579 1580 *pcFramesPlayed = cFramesToPlay - cFramesLeft;1581 Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pStream->szName, cFramesToPlay - cFramesLeft, cFramesToPlay, rc));1582 1504 return rc; 1583 1505 } … … 1675 1597 if (cFramesLive >= pStream->Host.Cfg.Backend.cFramesPreBuffering) 1676 1598 { 1677 LogRel2(("Audio: Stream '%s' buffering complete\n", pStream->szName)); 1678 Log3Func(("[%s] Dbg: Buffering complete!\n", pStream->szName)); 1599 LogRel2(("Audio: Stream '%s' buffering complete!\n", pStream->szName)); 1679 1600 pStream->fThresholdReached = fJustStarted = true; 1680 1601 } … … 1690 1611 && (pStream->fStatus & PDMAUDIOSTREAMSTS_FLAGS_PENDING_DISABLE)) 1691 1612 { 1692 LogRel2(("Audio: Stream '%s' buffering complete (short sound)\n", pStream->szName)); 1693 Log3Func(("[%s] Dbg: Buffering complete (short)!\n", pStream->szName)); 1613 LogRel2(("Audio: Stream '%s' buffering complete (short sound)!\n", pStream->szName)); 1694 1614 pStream->fThresholdReached = fJustStarted = true; 1695 1615 } … … 1756 1676 * https://stackoverflow.com/questions/17879933/whats-the-interleaved-audio 1757 1677 */ 1758 if (RT_LIKELY(pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED)) 1759 rc = drvAudioStreamPlayNonInterleaved(pThis, pStream, cFramesToPlay, pcFramesPlayed); 1760 else if (pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW) 1761 rc = drvAudioStreamPlayRaw(pThis, pStream, cFramesToPlay, pcFramesPlayed); 1762 else 1763 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 1678 rc = drvAudioStreamPlayDoIt(pThis, pStream, cFramesToPlay, pcFramesPlayed); 1764 1679 1765 1680 if (pThis->pHostDrvAudio->pfnStreamPlayEnd) … … 3085 3000 * PCM 3086 3001 */ 3087 if (pDrvCfg->Props.cbSample) /* Anything set via custom extra-data? */ 3088 { 3089 pCfgReq->Props.cbSample = pDrvCfg->Props.cbSample; 3090 LogRel2(("Audio: Using custom sample size of %RU8 bytes for stream '%s'\n", pCfgReq->Props.cbSample, pStream->szName)); 3002 if (PDMAudioPropsSampleSize(&pDrvCfg->Props) != 0) /* Anything set via custom extra-data? */ 3003 { 3004 PDMAudioPropsSetSampleSize(&pCfgReq->Props, PDMAudioPropsSampleSize(&pDrvCfg->Props)); 3005 LogRel2(("Audio: Using custom sample size of %RU8 bytes for stream '%s'\n", 3006 PDMAudioPropsSampleSize(&pCfgReq->Props), pStream->szName)); 3091 3007 } 3092 3008 … … 3111 3027 } 3112 3028 3113 if (pDrvCfg->Props.cChannels) /* Anything set via custom extra-data? */ 3114 { 3115 pCfgReq->Props.cChannels = pDrvCfg->Props.cChannels; 3116 LogRel2(("Audio: Using custom %RU8 channel(s) for stream '%s'\n", pCfgReq->Props.cChannels, pStream->szName)); 3117 } 3118 3119 /* Make sure to (re-)set the host buffer's shift size. */ 3120 pCfgReq->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfgReq->Props.cbSample, pCfgReq->Props.cChannels); 3029 if (PDMAudioPropsChannels(&pDrvCfg->Props) != 0) /* Anything set via custom extra-data? */ 3030 { 3031 PDMAudioPropsSetChannels(&pCfgReq->Props, PDMAudioPropsChannels(&pDrvCfg->Props)); 3032 LogRel2(("Audio: Using custom %RU8 channel(s) for stream '%s'\n", PDMAudioPropsChannels(&pDrvCfg->Props), pStream->szName)); 3033 } 3121 3034 3122 3035 /* Validate PCM properties. */ … … 3237 3150 3238 3151 /* Validate acquired configuration. */ 3239 if (!AudioHlpStreamCfgIsValid(pCfgAcq))3240 {3241 LogRel(("Audio: Creating stream '%s' returned an invalid backend configuration, skipping\n", pStream->szName));3242 return VERR_INVALID_PARAMETER;3243 }3152 char szTmp[PDMAUDIOPROPSTOSTRING_MAX]; 3153 AssertLogRelMsgReturn(AudioHlpStreamCfgIsValid(pCfgAcq), 3154 ("Audio: Creating stream '%s' returned an invalid backend configuration (%s), skipping\n", 3155 pStream->szName, PDMAudioPropsToString(&pCfgAcq->Props, szTmp, sizeof(szTmp))), 3156 VERR_INVALID_PARAMETER); 3244 3157 3245 3158 /* Let the user know that the backend changed one of the values requested above. */ … … 3637 3550 } 3638 3551 3552 PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->Out.StatsReBuffering); 3639 3553 #ifdef VBOX_WITH_STATISTICS 3640 3554 PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->Stats.TotalStreamsActive); … … 3787 3701 AssertRCReturn(rc, rc); 3788 3702 3789 QUERY_VAL_RET(8, "PCMSampleBit", &pAudioCfg->Props.cbSample, 0, 3790 pAudioCfg->Props.cbSample == 0 3791 || pAudioCfg->Props.cbSample == 8 3792 || pAudioCfg->Props.cbSample == 16 3793 || pAudioCfg->Props.cbSample == 32 3794 || pAudioCfg->Props.cbSample == 64, 3703 uint8_t cSampleBits = 0; 3704 QUERY_VAL_RET(8, "PCMSampleBit", &cSampleBits, 0, 3705 cSampleBits == 0 3706 || cSampleBits == 8 3707 || cSampleBits == 16 3708 || cSampleBits == 32 3709 || cSampleBits == 64, 3795 3710 "Must be either 0, 8, 16, 32 or 64"); 3796 pAudioCfg->Props.cbSample /= 8; 3797 3798 QUERY_VAL_RET(8, "PCMSampleChannels", &pAudioCfg->Props.cChannels, 0, 3799 pAudioCfg->Props.cChannels <= 16, "Max 16"); 3711 if (cSampleBits) 3712 PDMAudioPropsSetSampleSize(&pAudioCfg->Props, cSampleBits / 8); 3713 3714 uint8_t cChannels; 3715 QUERY_VAL_RET(8, "PCMSampleChannels", &cChannels, 0, cChannels <= 16, "Max 16"); 3716 if (cChannels) 3717 PDMAudioPropsSetChannels(&pAudioCfg->Props, cChannels); 3800 3718 3801 3719 QUERY_VAL_RET(32, "PCMSampleHz", &pAudioCfg->Props.uHz, 0, -
trunk/src/VBox/Devices/Audio/DrvHostAudioAlsa.cpp
r88235 r88269 149 149 static snd_pcm_format_t alsaAudioPropsToALSA(PPDMAUDIOPCMPROPS pProps) 150 150 { 151 switch ( pProps->cbSample)151 switch (PDMAudioPropsSampleSize(pProps)) 152 152 { 153 153 case 1: … … 155 155 156 156 case 2: 157 return pProps->fSigned ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_U16_LE; 157 if (PDMAudioPropsIsLittleEndian(pProps)) 158 return pProps->fSigned ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_U16_LE; 159 return pProps->fSigned ? SND_PCM_FORMAT_S16_BE : SND_PCM_FORMAT_U16_BE; 158 160 159 161 case 4: 160 return pProps->fSigned ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_U32_LE; 162 if (PDMAudioPropsIsLittleEndian(pProps)) 163 return pProps->fSigned ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_U32_LE; 164 return pProps->fSigned ? SND_PCM_FORMAT_S32_BE : SND_PCM_FORMAT_U32_BE; 161 165 162 166 default: 163 break; 164 } 165 166 AssertMsgFailed(("%RU8 bytes not supported\n", pProps->cbSample)); 167 return SND_PCM_FORMAT_U8; 167 AssertMsgFailed(("%RU8 bytes not supported\n", PDMAudioPropsSampleSize(pProps))); 168 return SND_PCM_FORMAT_U8; 169 } 168 170 } 169 171 … … 173 175 * 174 176 * @returns VBox status code. 175 * @param fmt ALSA PCM format to convert. 176 * @param pProps Where to store the converted PCM properties on success. 177 */ 178 static int alsaALSAToAudioProps(snd_pcm_format_t fmt, PPDMAUDIOPCMPROPS pProps) 179 { 177 * @param pProps Where to store the converted PCM properties on success. 178 * @param fmt ALSA PCM format to convert. 179 * @param cChannels Number of channels. 180 * @param uHz Frequency. 181 */ 182 static int alsaALSAToAudioProps(PPDMAUDIOPCMPROPS pProps, snd_pcm_format_t fmt, int cChannels, unsigned uHz) 183 { 184 AssertReturn(cChannels > 0, VERR_INVALID_PARAMETER); 185 AssertReturn(cChannels < 16, VERR_INVALID_PARAMETER); 180 186 switch (fmt) 181 187 { 182 188 case SND_PCM_FORMAT_S8: 183 pProps->cbSample = 1; 184 pProps->fSigned = true; 185 pProps->fSwapEndian = false; 189 PDMAudioPropsInit(pProps, 1 /*8-bit*/, true /*signed*/, cChannels, uHz); 186 190 break; 187 191 188 192 case SND_PCM_FORMAT_U8: 189 pProps->cbSample = 1; 190 pProps->fSigned = false; 191 pProps->fSwapEndian = false; 193 PDMAudioPropsInit(pProps, 1 /*8-bit*/, false /*signed*/, cChannels, uHz); 192 194 break; 193 195 194 196 case SND_PCM_FORMAT_S16_LE: 195 pProps->cbSample = 2; 196 pProps->fSigned = true; 197 pProps->fSwapEndian = false; 197 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 198 198 break; 199 199 200 200 case SND_PCM_FORMAT_U16_LE: 201 pProps->cbSample = 2; 202 pProps->fSigned = false; 203 pProps->fSwapEndian = false; 201 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 204 202 break; 205 203 206 204 case SND_PCM_FORMAT_S16_BE: 207 pProps->cbSample = 2; 208 pProps->fSigned = true; 209 #ifdef RT_LITTLE_ENDIAN 210 pProps->fSwapEndian = true; 211 #endif 205 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 212 206 break; 213 207 214 208 case SND_PCM_FORMAT_U16_BE: 215 pProps->cbSample = 2; 216 pProps->fSigned = false; 217 #ifdef RT_LITTLE_ENDIAN 218 pProps->fSwapEndian = true; 219 #endif 209 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 220 210 break; 221 211 222 212 case SND_PCM_FORMAT_S32_LE: 223 pProps->cbSample = 4; 224 pProps->fSigned = true; 225 pProps->fSwapEndian = false; 213 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 226 214 break; 227 215 228 216 case SND_PCM_FORMAT_U32_LE: 229 pProps->cbSample = 4; 230 pProps->fSigned = false; 231 pProps->fSwapEndian = false; 217 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 232 218 break; 233 219 234 220 case SND_PCM_FORMAT_S32_BE: 235 pProps->cbSample = 4; 236 pProps->fSigned = true; 237 #ifdef RT_LITTLE_ENDIAN 238 pProps->fSwapEndian = true; 239 #endif 221 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 240 222 break; 241 223 242 224 case SND_PCM_FORMAT_U32_BE: 243 pProps->cbSample = 4; 244 pProps->fSigned = false; 245 #ifdef RT_LITTLE_ENDIAN 246 pProps->fSwapEndian = true; 247 #endif 225 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 248 226 break; 249 227 … … 251 229 AssertMsgFailedReturn(("Format %d not supported\n", fmt), VERR_NOT_SUPPORTED); 252 230 } 253 254 AssertReturn(pProps->cbSample > 0, VERR_NOT_SUPPORTED);255 AssertReturn(pProps->cChannels > 0, VERR_INVALID_PARAMETER);256 257 pProps->cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pProps->cbSample, pProps->cChannels);258 259 231 return VINF_SUCCESS; 260 232 } … … 937 909 ALSAAUDIOSTREAMCFG req; 938 910 req.fmt = alsaAudioPropsToALSA(&pCfgReq->Props); 939 req.freq = pCfgReq->Props.uHz;940 req.nchannels = pCfgReq->Props.cChannels;911 req.freq = PDMAudioPropsHz(&pCfgReq->Props); 912 req.nchannels = PDMAudioPropsChannels(&pCfgReq->Props); 941 913 req.period_size = pCfgReq->Backend.cFramesPeriod; 942 914 req.buffer_size = pCfgReq->Backend.cFramesBufferSize; … … 948 920 break; 949 921 950 pCfgAcq->Props.uHz = obt.freq; 951 pCfgAcq->Props.cChannels = obt.nchannels; 952 953 rc = alsaALSAToAudioProps(obt.fmt, &pCfgAcq->Props); 922 rc = alsaALSAToAudioProps(&pCfgAcq->Props, obt.fmt, obt.nchannels, obt.freq); 954 923 if (RT_FAILURE(rc)) 955 924 break; … … 1000 969 ALSAAUDIOSTREAMCFG req; 1001 970 req.fmt = alsaAudioPropsToALSA(&pCfgReq->Props); 1002 req.freq = pCfgReq->Props.uHz;1003 req.nchannels = pCfgReq->Props.cChannels;971 req.freq = PDMAudioPropsHz(&pCfgReq->Props); 972 req.nchannels = PDMAudioPropsChannels(&pCfgReq->Props); 1004 973 req.period_size = PDMAudioPropsMilliToFrames(&pCfgReq->Props, 50 /*ms*/); /** @todo Make this configurable. */ 1005 974 req.buffer_size = req.period_size * 2; /** @todo Make this configurable. */ … … 1011 980 break; 1012 981 1013 pCfgAcq->Props.uHz = obt.freq; 1014 pCfgAcq->Props.cChannels = obt.nchannels; 1015 1016 rc = alsaALSAToAudioProps(obt.fmt, &pCfgAcq->Props); 982 rc = alsaALSAToAudioProps(&pCfgAcq->Props, obt.fmt, obt.nchannels, obt.freq); 1017 983 if (RT_FAILURE(rc)) 1018 984 break; -
trunk/src/VBox/Devices/Audio/DrvHostAudioCoreAudio.cpp
r88235 r88269 150 150 char pszSampleRate[32]; 151 151 LogRel2(("CoreAudio: %s description:\n", pszDesc)); 152 LogRel2(("CoreAudio: \tFormat ID: %RU32 (%c%c%c%c)\n", pASBD->mFormatID,152 LogRel2(("CoreAudio: Format ID: %RU32 (%c%c%c%c)\n", pASBD->mFormatID, 153 153 RT_BYTE4(pASBD->mFormatID), RT_BYTE3(pASBD->mFormatID), 154 154 RT_BYTE2(pASBD->mFormatID), RT_BYTE1(pASBD->mFormatID))); 155 LogRel2(("CoreAudio: \tFlags: %RU32", pASBD->mFormatFlags));155 LogRel2(("CoreAudio: Flags: %RU32", pASBD->mFormatFlags)); 156 156 if (pASBD->mFormatFlags & kAudioFormatFlagIsFloat) 157 157 LogRel2((" Float")); … … 171 171 LogRel2((" AllClear")); 172 172 LogRel2(("\n")); 173 snprintf(pszSampleRate, 32, "%.2f", (float)pASBD->mSampleRate); /** @todo r=andy Use RTStrPrint*. */174 LogRel2(("CoreAudio:\tSampleRate : %s\n", pszSampleRate));175 LogRel2(("CoreAudio: \tChannelsPerFrame: %RU32\n", pASBD->mChannelsPerFrame));176 LogRel2(("CoreAudio: \tFramesPerPacket : %RU32\n", pASBD->mFramesPerPacket));177 LogRel2(("CoreAudio: \tBitsPerChannel : %RU32\n", pASBD->mBitsPerChannel));178 LogRel2(("CoreAudio: \tBytesPerFrame : %RU32\n", pASBD->mBytesPerFrame));179 LogRel2(("CoreAudio: \tBytesPerPacket : %RU32\n", pASBD->mBytesPerPacket));180 } 181 182 static void coreAudioPCMPropsToASBD(P DMAUDIOPCMPROPS *pPCMProps, AudioStreamBasicDescription *pASBD)183 { 184 AssertPtrReturnVoid(pP CMProps);173 LogRel2(("CoreAudio: SampleRate : %RU64.%02u Hz\n", 174 (uint64_t)pASBD->mSampleRate, (unsigned)(pASBD->mSampleRate * 100) % 100)); 175 LogRel2(("CoreAudio: ChannelsPerFrame: %RU32\n", pASBD->mChannelsPerFrame)); 176 LogRel2(("CoreAudio: FramesPerPacket : %RU32\n", pASBD->mFramesPerPacket)); 177 LogRel2(("CoreAudio: BitsPerChannel : %RU32\n", pASBD->mBitsPerChannel)); 178 LogRel2(("CoreAudio: BytesPerFrame : %RU32\n", pASBD->mBytesPerFrame)); 179 LogRel2(("CoreAudio: BytesPerPacket : %RU32\n", pASBD->mBytesPerPacket)); 180 } 181 182 static void coreAudioPCMPropsToASBD(PCPDMAUDIOPCMPROPS pProps, AudioStreamBasicDescription *pASBD) 183 { 184 AssertPtrReturnVoid(pProps); 185 185 AssertPtrReturnVoid(pASBD); 186 186 … … 189 189 pASBD->mFormatID = kAudioFormatLinearPCM; 190 190 pASBD->mFormatFlags = kAudioFormatFlagIsPacked; 191 if (pProps->fSigned) 192 pASBD->mFormatFlags |= kAudioFormatFlagIsSignedInteger; 193 if (PDMAudioPropsIsBigEndian(pProps)) 194 pASBD->mFormatFlags |= kAudioFormatFlagIsBigEndian; 195 pASBD->mSampleRate = PDMAudioPropsHz(pProps); 196 pASBD->mChannelsPerFrame = PDMAudioPropsChannels(pProps); 197 pASBD->mBitsPerChannel = PDMAudioPropsSampleBits(pProps); 198 pASBD->mBytesPerFrame = PDMAudioPropsFrameSize(pProps); 191 199 pASBD->mFramesPerPacket = 1; /* For uncompressed audio, set this to 1. */ 192 pASBD->mSampleRate = (Float64)pPCMProps->uHz; 193 pASBD->mChannelsPerFrame = pPCMProps->cChannels; 194 pASBD->mBitsPerChannel = pPCMProps->cbSample * 8; 195 if (pPCMProps->fSigned) 196 pASBD->mFormatFlags |= kAudioFormatFlagIsSignedInteger; 197 pASBD->mBytesPerFrame = pASBD->mChannelsPerFrame * (pASBD->mBitsPerChannel / 8); 198 pASBD->mBytesPerPacket = pASBD->mFramesPerPacket * pASBD->mBytesPerFrame; 200 pASBD->mBytesPerPacket = PDMAudioPropsFrameSize(pProps) * pASBD->mFramesPerPacket; 199 201 } 200 202 … … 205 207 AssertPtrReturn(pCfg, VERR_INVALID_PARAMETER); 206 208 207 pCfg->Props.cChannels = pASBD->mChannelsPerFrame; 208 pCfg->Props.uHz = (uint32_t)pASBD->mSampleRate; 209 AssertMsg(!(pASBD->mBitsPerChannel & 7), ("%u\n", pASBD->mBitsPerChannel)); 210 pCfg->Props.cbSample = pASBD->mBitsPerChannel / 8; 211 pCfg->Props.fSigned = RT_BOOL(pASBD->mFormatFlags & kAudioFormatFlagIsSignedInteger); 212 pCfg->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cbSample, pCfg->Props.cChannels); 213 /** @todo r=bird: pCfg->Props.fSwapEndian is not initialized here! */ 214 209 AssertLogRelMsgReturn(pASBD->mChannelsPerFrame > 0, VERR_NOT_SUPPORTED); 210 AssertLogRelMsgReturn(pASBD->mChannelsPerFrame < 16, VERR_NOT_SUPPORTED); 211 AssertLogRelMsgReturn( pASBD->mBitsPerChannel == 8 212 || pASBD->mBitsPerChannel == 16 213 || pASBD->mBitsPerChannel == 32, 214 ("%u\n", pASBD->mBitsPerChannel), VERR_NOT_SUPPORTED); 215 AssertLogRelMsgReturn(!(pASBD->mFormatFlags & (kAudioFormatFlagIsFloat /** @todo more we don't like?*/)), 216 ("%#x\n", pASBD->mFormatFlags), VERR_NOT_SUPPORTED); 217 218 PDMAudioPropsInitEx(&pCfg->Props, 219 pASBD->mBitsPerChannel / 8, 220 RT_BOOL(pASBD->mFormatFlags & kAudioFormatFlagIsSignedInteger), 221 pASBD->mChannelsPerFrame, 222 (uint32_t)pASBD->mSampleRate, 223 RT_BOOL(pASBD->mFormatFlags & kAudioFormatFlagIsBigEndian), 224 false /*fRaw*/); 215 225 return VINF_SUCCESS; 216 226 } -
trunk/src/VBox/Devices/Audio/DrvHostAudioDSound.cpp
r88235 r88269 269 269 270 270 pFmt->wFormatTag = WAVE_FORMAT_PCM; 271 pFmt->nChannels = pCfg->Props.cChannels;272 pFmt->wBitsPerSample = pCfg->Props.cbSample * 8;273 pFmt->nSamplesPerSec = pCfg->Props.uHz;274 pFmt->nBlockAlign = pFmt->nChannels * pFmt->wBitsPerSample / 8;275 pFmt->nAvgBytesPerSec = pFmt->nSamplesPerSec * pFmt->nBlockAlign;271 pFmt->nChannels = PDMAudioPropsChannels(&pCfg->Props); 272 pFmt->wBitsPerSample = PDMAudioPropsSampleBits(&pCfg->Props); 273 pFmt->nSamplesPerSec = PDMAudioPropsHz(&pCfg->Props); 274 pFmt->nBlockAlign = PDMAudioPropsFrameSize(&pCfg->Props); 275 pFmt->nAvgBytesPerSec = PDMAudioPropsFramesToBytes(&pCfg->Props, PDMAudioPropsHz(&pCfg->Props)); 276 276 pFmt->cbSize = 0; /* No extra data specified. */ 277 277 … … 614 614 AssertPtrReturn(pCfgAcq, E_POINTER); 615 615 616 /** @todo r=bird: I cannot see any code populating pCfgAcq... */ 617 616 618 LogFlowFuncEnter(); 617 619 618 620 Assert(pStreamDS->Out.pDSB == NULL); 619 621 620 DSLOG(("DSound: Opening playback stream (uHz=%RU32, cChannels=%RU8, cBits=%u, fSigned=%RTbool)\n", 621 pCfgReq->Props.uHz, pCfgReq->Props.cChannels, pCfgReq->Props.cbSample * 8, pCfgReq->Props.fSigned));622 DSLOG(("DSound: Opening playback stream (uHz=%RU32, cChannels=%RU8, cBits=%u, fSigned=%RTbool)\n", pCfgReq->Props.uHz, 623 PDMAudioPropsChannels(&pCfgReq->Props), PDMAudioPropsSampleBits(&pCfgReq->Props), pCfgReq->Props.fSigned)); 622 624 623 625 WAVEFORMATEX wfx; … … 1369 1371 AssertPtrReturn(pCfgAcq, E_POINTER); 1370 1372 1373 /** @todo r=bird: I cannot see any code populating pCfgAcq... */ 1374 1371 1375 LogFlowFuncEnter(); 1372 1376 1373 1377 Assert(pStreamDS->In.pDSCB == NULL); 1374 1378 1375 DSLOG(("DSound: Opening capturing stream (uHz=%RU32, cChannels=%RU8, cBits=%u, fSigned=%RTbool)\n", 1376 pCfgReq->Props.uHz, pCfgReq->Props.cChannels, pCfgReq->Props.cbSample * 8, pCfgReq->Props.fSigned));1379 DSLOG(("DSound: Opening capturing stream (uHz=%RU32, cChannels=%RU8, cBits=%u, fSigned=%RTbool)\n", pCfgReq->Props.uHz, 1380 PDMAudioPropsChannels(&pCfgReq->Props), PDMAudioPropsSampleBits(&pCfgReq->Props), pCfgReq->Props.fSigned)); 1377 1381 1378 1382 WAVEFORMATEX wfx; … … 2067 2071 pStreamDS, pCfgReq, PDMAudioRecSrcGetName(pCfgReq->u.enmSrc))); 2068 2072 2069 int rc = VINF_SUCCESS;2070 2073 2071 2074 /* Try to open capture in case the device is already there. */ 2075 int rc; 2072 2076 HRESULT hr = directSoundCaptureOpen(pThis, pStreamDS, pCfgReq, pCfgAcq); 2073 2077 if (SUCCEEDED(hr)) … … 2363 2367 if (RT_SUCCESS(rc)) 2364 2368 { 2369 /** @todo already copied */ 2365 2370 rc = PDMAudioStrmCfgCopy(&pStreamDS->Cfg, pCfgAcq); 2366 2371 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Devices/Audio/DrvHostAudioDebug.cpp
r88235 r88269 16 16 */ 17 17 18 #include <iprt/ alloc.h>18 #include <iprt/mem.h> 19 19 #include <iprt/rand.h> 20 20 #include <iprt/uuid.h> /* For PDMIBASE_2_PDMDRV. */ … … 211 211 */ 212 212 static DECLCALLBACK(int) drvHostDebugAudioHA_StreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, 213 const void *pvBuf, uint32_t uBufSize, uint32_t *puWritten)214 { 215 RT_NOREF(pInterface);216 PDEBUGAUDIOSTREAM pStreamDbg = (PDEBUGAUDIOSTREAM)pStream;217 218 int rc = AudioHlpFileWrite(pStreamDbg->pFile, pvBuf, uBufSize, 0 /* fFlags */);213 const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten) 214 { 215 PDEBUGAUDIOSTREAM pStreamDbg = (PDEBUGAUDIOSTREAM)pStream; 216 RT_NOREF(pInterface); 217 218 int rc = AudioHlpFileWrite(pStreamDbg->pFile, pvBuf, cbBuf, 0 /* fFlags */); 219 219 if (RT_FAILURE(rc)) 220 220 { … … 223 223 } 224 224 225 if (puWritten) 226 *puWritten = uBufSize; 227 225 *pcbWritten = cbBuf; 228 226 return VINF_SUCCESS; 229 227 } … … 243 241 AssertPtr(pCfg); 244 242 245 Assert(uBufSize % pCfg->Props.cbSample == 0); 243 Assert(uBufSize % PDMAudioPropsSampleSize(&pCfg->Props) == 0); 244 size_t const cSamples = uBufSize / PDMAudioPropsSampleSize(&pCfg->Props); 246 245 247 246 uint16_t *paBuf = (uint16_t *)pvBuf; 248 247 249 248 /* Generate a simple mono sine wave. */ 250 for (size_t i = 0; i < uBufSize / pCfg->Props.cbSample; i++)249 for (size_t i = 0; i < cSamples; i++) 251 250 { 252 251 paBuf[i] = 32760 * sin((2.f * float(3.1415) * pStreamDbg->In.uFreqHz) / pCfg->Props.uHz * pStreamDbg->In.uSample); -
trunk/src/VBox/Devices/Audio/DrvHostAudioOss.cpp
r88235 r88269 151 151 152 152 153 static int ossOSSToAudioProps(int fmt, PPDMAUDIOPCMPROPS pProps) 154 { 155 RT_BZERO(pProps, sizeof(PDMAUDIOPCMPROPS)); 156 157 /** @todo r=bird: What's the assumption about the incoming pProps? Code is 158 * clearly ASSUMING something about how it's initialized, but even so, 159 * the fSwapEndian isn't correct in a portable way. */ 153 static int ossOSSToAudioProps(PPDMAUDIOPCMPROPS pProps, int fmt, int cChannels, int uHz) 154 { 160 155 switch (fmt) 161 156 { 162 157 case AFMT_S8: 163 pProps->cbSample = 1; 164 pProps->fSigned = true; 158 PDMAudioPropsInit(pProps, 1 /*8-bit*/, true /*signed*/, cChannels, uHz); 165 159 break; 166 160 167 161 case AFMT_U8: 168 pProps->cbSample = 1; 169 pProps->fSigned = false; 162 PDMAudioPropsInit(pProps, 1 /*8-bit*/, false /*signed*/, cChannels, uHz); 170 163 break; 171 164 172 165 case AFMT_S16_LE: 173 pProps->cbSample = 2; 174 pProps->fSigned = true; 166 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 175 167 break; 176 168 177 169 case AFMT_U16_LE: 178 pProps->cbSample = 2; 179 pProps->fSigned = false; 180 break; 181 182 case AFMT_S16_BE: 183 pProps->cbSample = 2; 184 pProps->fSigned = true; 185 #ifdef RT_LITTLE_ENDIAN 186 pProps->fSwapEndian = true; 187 #endif 170 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 171 break; 172 173 case AFMT_S16_BE: 174 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 188 175 break; 189 176 190 177 case AFMT_U16_BE: 191 pProps->cbSample = 2; 192 pProps->fSigned = false; 193 #ifdef RT_LITTLE_ENDIAN 194 pProps->fSwapEndian = true; 195 #endif 178 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 196 179 break; 197 180 … … 240 223 241 224 int iFormat; 242 switch ( pOSSReq->Props.cbSample)225 switch (PDMAudioPropsSampleSize(&pOSSReq->Props)) 243 226 { 244 227 case 1: … … 266 249 } 267 250 268 int cChannels = pOSSReq->Props.cChannels;251 int cChannels = PDMAudioPropsChannels(&pOSSReq->Props); 269 252 if (ioctl(fdFile, SNDCTL_DSP_CHANNELS, &cChannels)) 270 253 { 271 254 LogRel(("OSS: Failed to set number of audio channels (%RU8): %s (%d)\n", 272 pOSSReq->Props.cChannels, strerror(errno), errno));255 PDMAudioPropsChannels(&pOSSReq->Props), strerror(errno), errno)); 273 256 break; 274 257 } … … 311 294 } 312 295 313 rc = ossOSSToAudioProps( iFormat, &pOSSAcq->Props);296 rc = ossOSSToAudioProps(&pOSSAcq->Props, iFormat, cChannels, freq); 314 297 if (RT_SUCCESS(rc)) 315 298 { 316 pOSSAcq->Props.cChannels = cChannels;317 pOSSAcq->Props.uHz = freq;318 pOSSAcq->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pOSSAcq->Props.cbSample, pOSSAcq->Props.cChannels);319 320 299 pOSSAcq->cFragments = abinfo.fragstotal; 321 300 pOSSAcq->cbFragmentSize = abinfo.fragsize; -
trunk/src/VBox/Devices/Audio/DrvHostAudioPulseAudio.cpp
r88235 r88269 217 217 static pa_sample_format_t paAudioPropsToPulse(PPDMAUDIOPCMPROPS pProps) 218 218 { 219 switch ( pProps->cbSample)219 switch (PDMAudioPropsSampleSize(pProps)) 220 220 { 221 221 case 1: … … 226 226 case 2: 227 227 if (pProps->fSigned) 228 return P A_SAMPLE_S16LE;228 return PDMAudioPropsIsLittleEndian(pProps) ? PA_SAMPLE_S16LE : PA_SAMPLE_S16BE; 229 229 break; 230 230 … … 232 232 case 4: 233 233 if (pProps->fSigned) 234 return P A_SAMPLE_S32LE;234 return PDMAudioPropsIsLittleEndian(pProps) ? PA_SAMPLE_S32LE : PA_SAMPLE_S32BE; 235 235 break; 236 236 #endif 237 238 default: 239 break; 240 } 241 242 AssertMsgFailed(("%RU8%s not supported\n", pProps->cbSample, pProps->fSigned ? "S" : "U")); 237 } 238 239 AssertMsgFailed(("%RU8%s not supported\n", PDMAudioPropsSampleSize(pProps), pProps->fSigned ? "S" : "U")); 243 240 return PA_SAMPLE_INVALID; 244 241 } 245 242 246 243 247 static int paPulseToAudioProps(pa_sample_format_t pulsefmt, PPDMAUDIOPCMPROPS pProps) 248 { 249 /** @todo r=bird: You are assuming undocumented stuff about 250 * pProps->fSwapEndian. */ 244 static int paPulseToAudioProps(PPDMAUDIOPCMPROPS pProps, pa_sample_format_t pulsefmt, uint8_t cChannels, uint32_t uHz) 245 { 246 AssertReturn(cChannels > 0, VERR_INVALID_PARAMETER); 247 AssertReturn(cChannels < 16, VERR_INVALID_PARAMETER); 248 251 249 switch (pulsefmt) 252 250 { 253 251 case PA_SAMPLE_U8: 254 pProps->cbSample = 1; 255 pProps->fSigned = false; 252 PDMAudioPropsInit(pProps, 1 /*8-bit*/, false /*signed*/, cChannels, uHz); 256 253 break; 257 254 258 255 case PA_SAMPLE_S16LE: 259 pProps->cbSample = 2; 260 pProps->fSigned = true; 256 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 261 257 break; 262 258 263 259 case PA_SAMPLE_S16BE: 264 pProps->cbSample = 2; 265 pProps->fSigned = true; 266 /** @todo Handle Endianess. */ 260 PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 267 261 break; 268 262 269 263 #ifdef PA_SAMPLE_S32LE 270 264 case PA_SAMPLE_S32LE: 271 pProps->cbSample = 4; 272 pProps->fSigned = true; 265 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/); 273 266 break; 274 267 #endif … … 276 269 #ifdef PA_SAMPLE_S32BE 277 270 case PA_SAMPLE_S32BE: 278 pProps->cbSample = 4; 279 pProps->fSigned = true; 280 /** @todo Handle Endianess. */ 271 PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/); 281 272 break; 282 273 #endif 283 274 284 275 default: 285 AssertLogRelMsgFailed(("PulseAudio: Format (% ld) not supported\n", pulsefmt));276 AssertLogRelMsgFailed(("PulseAudio: Format (%d) not supported\n", pulsefmt)); 286 277 return VERR_NOT_SUPPORTED; 287 278 } … … 789 780 790 781 pStreamPA->SampleSpec.format = paAudioPropsToPulse(&pCfgReq->Props); 791 pStreamPA->SampleSpec.rate = pCfgReq->Props.uHz;792 pStreamPA->SampleSpec.channels = pCfgReq->Props.cChannels;782 pStreamPA->SampleSpec.rate = PDMAudioPropsHz(&pCfgReq->Props); 783 pStreamPA->SampleSpec.channels = PDMAudioPropsChannels(&pCfgReq->Props); 793 784 794 785 pStreamPA->curLatencyUs = PDMAudioPropsFramesToMilli(&pCfgReq->Props, pCfgReq->Backend.cFramesBufferSize) * RT_US_1MS; … … 816 807 return rc; 817 808 818 rc = paPulseToAudioProps(pStreamPA->SampleSpec.format, &pCfgAcq->Props); 809 rc = paPulseToAudioProps(&pCfgAcq->Props, pStreamPA->SampleSpec.format, 810 pStreamPA->SampleSpec.channels, pStreamPA->SampleSpec.rate); 819 811 if (RT_FAILURE(rc)) 820 812 { … … 822 814 return rc; 823 815 } 824 825 pCfgAcq->Props.uHz = pStreamPA->SampleSpec.rate;826 pCfgAcq->Props.cChannels = pStreamPA->SampleSpec.channels;827 pCfgAcq->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfgAcq->Props.cbSample, pCfgAcq->Props.cChannels);828 816 829 817 LogFunc(("Acquired: BufAttr tlength=%RU32, maxLength=%RU32, minReq=%RU32\n", … … 844 832 { 845 833 pStreamPA->SampleSpec.format = paAudioPropsToPulse(&pCfgReq->Props); 846 pStreamPA->SampleSpec.rate = pCfgReq->Props.uHz;847 pStreamPA->SampleSpec.channels = pCfgReq->Props.cChannels;834 pStreamPA->SampleSpec.rate = PDMAudioPropsHz(&pCfgReq->Props); 835 pStreamPA->SampleSpec.channels = PDMAudioPropsChannels(&pCfgReq->Props); 848 836 849 837 pStreamPA->BufAttr.fragsize = PDMAudioPropsFramesToBytes(&pCfgReq->Props, pCfgReq->Backend.cFramesPeriod); … … 860 848 return rc; 861 849 862 rc = paPulseToAudioProps(pStreamPA->SampleSpec.format, &pCfgAcq->Props); 850 rc = paPulseToAudioProps(&pCfgAcq->Props, pStreamPA->SampleSpec.format, 851 pStreamPA->SampleSpec.channels, pStreamPA->SampleSpec.rate); 863 852 if (RT_FAILURE(rc)) 864 853 { … … 869 858 pStreamPA->pDrv = pThis; 870 859 pStreamPA->pu8PeekBuf = NULL; 871 872 pCfgAcq->Props.uHz = pStreamPA->SampleSpec.rate;873 pCfgAcq->Props.cChannels = pStreamPA->SampleSpec.channels;874 860 875 861 pCfgAcq->Backend.cFramesPeriod = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamPA->BufAttr.fragsize); -
trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
r88234 r88269 38 38 RTTestSub(hTest, "Basics"); 39 39 40 const PDMAUDIOPCMPROPS Cfg441StereoS16 = PDMAUDIOPCMPROPS_INITIALIZ OR(40 const PDMAUDIOPCMPROPS Cfg441StereoS16 = PDMAUDIOPCMPROPS_INITIALIZER( 41 41 /* a_cb: */ 2, 42 42 /* a_fSigned: */ true, 43 43 /* a_cChannels: */ 2, 44 44 /* a_uHz: */ 44100, 45 /* a_cShift: */ PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* cb */, 2 /* cChannels */),46 45 /* a_fSwapEndian: */ false 47 46 ); 48 const PDMAUDIOPCMPROPS Cfg441StereoU16 = PDMAUDIOPCMPROPS_INITIALIZ OR(47 const PDMAUDIOPCMPROPS Cfg441StereoU16 = PDMAUDIOPCMPROPS_INITIALIZER( 49 48 /* a_cb: */ 2, 50 49 /* a_fSigned: */ false, 51 50 /* a_cChannels: */ 2, 52 51 /* a_uHz: */ 44100, 53 /* a_cShift: */ PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* cb */, 2 /* cChannels */),54 52 /* a_fSwapEndian: */ false 55 53 ); 56 const PDMAUDIOPCMPROPS Cfg441StereoU32 = PDMAUDIOPCMPROPS_INITIALIZ OR(54 const PDMAUDIOPCMPROPS Cfg441StereoU32 = PDMAUDIOPCMPROPS_INITIALIZER( 57 55 /* a_cb: */ 4, 58 56 /* a_fSigned: */ false, 59 57 /* a_cChannels: */ 2, 60 58 /* a_uHz: */ 44100, 61 /* a_cShift: */ PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(4 /* cb */, 2 /* cChannels */),62 59 /* a_fSwapEndian: */ false 63 60 ); … … 191 188 192 189 /* 44100Hz, 2 Channels, S16 */ 193 PDMAUDIOPCMPROPS config = PDMAUDIOPCMPROPS_INITIALIZ OR(190 PDMAUDIOPCMPROPS config = PDMAUDIOPCMPROPS_INITIALIZER( 194 191 2, /* Bytes */ 195 192 true, /* Signed */ 196 193 2, /* Channels */ 197 194 44100, /* Hz */ 198 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 2 /* Channels */), /* Shift */199 195 false /* Swap Endian */ 200 196 ); … … 312 308 313 309 /* 44100Hz, 2 Channels, S16 */ 314 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZ OR(310 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZER( 315 311 2, /* Bytes */ 316 312 true, /* Signed */ 317 313 2, /* Channels */ 318 314 44100, /* Hz */ 319 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 2 /* Channels */), /* Shift */320 315 false /* Swap Endian */ 321 316 ); … … 327 322 328 323 /* 22050Hz, 2 Channels, S16 */ 329 PDMAUDIOPCMPROPS cfg_c1 = PDMAUDIOPCMPROPS_INITIALIZ OR(/* Upmixing to parent */324 PDMAUDIOPCMPROPS cfg_c1 = PDMAUDIOPCMPROPS_INITIALIZER(/* Upmixing to parent */ 330 325 2, /* Bytes */ 331 326 true, /* Signed */ 332 327 2, /* Channels */ 333 328 22050, /* Hz */ 334 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 2 /* Channels */), /* Shift */335 329 false /* Swap Endian */ 336 330 ); … … 346 340 347 341 /* 48000Hz, 2 Channels, S16 */ 348 PDMAUDIOPCMPROPS cfg_c2 = PDMAUDIOPCMPROPS_INITIALIZ OR(/* Downmixing to parent */342 PDMAUDIOPCMPROPS cfg_c2 = PDMAUDIOPCMPROPS_INITIALIZER(/* Downmixing to parent */ 349 343 2, /* Bytes */ 350 344 true, /* Signed */ 351 345 2, /* Channels */ 352 346 48000, /* Hz */ 353 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 2 /* Channels */), /* Shift */354 347 false /* Swap Endian */ 355 348 ); … … 460 453 461 454 /* 44100Hz, 1 Channel, U8 */ 462 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZ OR(455 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZER( 463 456 1, /* Bytes */ 464 457 false, /* Signed */ 465 458 1, /* Channels */ 466 459 44100, /* Hz */ 467 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(1 /* Bytes */, 1 /* Channels */), /* Shift */468 460 false /* Swap Endian */ 469 461 ); … … 483 475 484 476 /* 22050Hz, 1 Channel, U8 */ 485 PDMAUDIOPCMPROPS cfg_c = PDMAUDIOPCMPROPS_INITIALIZ OR( /* Upmixing to parent */477 PDMAUDIOPCMPROPS cfg_c = PDMAUDIOPCMPROPS_INITIALIZER( /* Upmixing to parent */ 486 478 1, /* Bytes */ 487 479 false, /* Signed */ 488 480 1, /* Channels */ 489 481 22050, /* Hz */ 490 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(1 /* Bytes */, 1 /* Channels */), /* Shift */491 482 false /* Swap Endian */ 492 483 ); … … 514 505 515 506 /**** 8-bit unsigned samples ****/ 516 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 8-bit\n", cfg_c.uHz, cfg_c.cChannels);507 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 8-bit\n", cfg_c.uHz, PDMAudioPropsChannels(&cfg_c)); 517 508 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames8U, sizeof(aFrames8U), &cFramesWritten)); 518 509 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); … … 565 556 566 557 /* 44100Hz, 1 Channel, S16 */ 567 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZ OR(558 PDMAUDIOPCMPROPS cfg_p = PDMAUDIOPCMPROPS_INITIALIZER( 568 559 2, /* Bytes */ 569 560 true, /* Signed */ 570 561 1, /* Channels */ 571 562 44100, /* Hz */ 572 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 1 /* Channels */), /* Shift */573 563 false /* Swap Endian */ 574 564 ); … … 580 570 581 571 /* 22050Hz, 1 Channel, S16 */ 582 PDMAUDIOPCMPROPS cfg_c = PDMAUDIOPCMPROPS_INITIALIZ OR( /* Upmixing to parent */572 PDMAUDIOPCMPROPS cfg_c = PDMAUDIOPCMPROPS_INITIALIZER( /* Upmixing to parent */ 583 573 2, /* Bytes */ 584 574 true, /* Signed */ 585 575 1, /* Channels */ 586 576 22050, /* Hz */ 587 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 1 /* Channels */), /* Shift */588 577 false /* Swap Endian */ 589 578 ); … … 611 600 612 601 /**** 16-bit signed samples ****/ 613 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 16-bit\n", cfg_c.uHz, cfg_c.cChannels);602 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 16-bit\n", cfg_c.uHz, PDMAudioPropsChannels(&cfg_c)); 614 603 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten)); 615 604 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); … … 662 651 /* Same for parent/child. */ 663 652 /* 44100Hz, 2 Channels, S16 */ 664 PDMAUDIOPCMPROPS cfg = PDMAUDIOPCMPROPS_INITIALIZ OR(653 PDMAUDIOPCMPROPS cfg = PDMAUDIOPCMPROPS_INITIALIZER( 665 654 2, /* Bytes */ 666 655 true, /* Signed */ 667 656 2, /* Channels */ 668 657 44100, /* Hz */ 669 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* Bytes */, 2 /* Channels */), /* Shift */670 658 false /* Swap Endian */ 671 659 ); … … 699 687 700 688 /**** Volume control test ****/ 701 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Volume control test %uHz %uch \n", cfg.uHz, cfg.cChannels);689 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Volume control test %uHz %uch \n", cfg.uHz, PDMAudioPropsChannels(&cfg)); 702 690 703 691 /* 1) Full volume/0dB attenuation (255). */
Note:
See TracChangeset
for help on using the changeset viewer.