Changeset 88269 in vbox for trunk/src/VBox/Devices/Audio/DrvHostAudioAlsa.cpp
- Timestamp:
- Mar 24, 2021 11:45:54 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 143474
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.