Changeset 89400 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- May 31, 2021 12:46:15 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144751
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer-Convert.cpp.h
r89397 r89400 17 17 18 18 19 #define AUDMIXBUF_CONVERT(a_Name, a_Type, a_Min, a_Max, a_fSigned, a_cShift) \ 20 /* Clips a specific output value to a single sample value. */ \ 21 DECLINLINE(int32_t) audioMixBufSampleFrom##a_Name(a_Type aVal) \ 22 { \ 23 /* left shifting of signed values is not defined, therefore the intermediate uint64_t cast */ \ 24 if (a_fSigned) \ 25 return (int32_t) (((uint32_t) ((int32_t) aVal )) << (32 - a_cShift)); \ 26 return (int32_t) (((uint32_t) ((int32_t) aVal - ((a_Max >> 1) + 1))) << (32 - a_cShift)); \ 27 } \ 28 \ 29 /* Clips a single sample value to a specific output value. */ \ 30 DECLINLINE(a_Type) audioMixBufSampleTo##a_Name(int32_t iVal) \ 31 { \ 32 if (a_fSigned) \ 33 return (a_Type) (iVal >> (32 - a_cShift)); \ 34 return (a_Type) ((iVal >> (32 - a_cShift)) + ((a_Max >> 1) + 1)); \ 35 } \ 36 \ 37 /* Encoders for peek: */ \ 38 \ 39 /* Generic */ \ 40 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncodeGeneric,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, \ 41 PAUDIOMIXBUFPEEKSTATE pState) \ 42 { \ 43 RT_NOREF_PV(pState); \ 44 uintptr_t const cSrcChannels = pState->cSrcChannels; \ 45 uintptr_t const cDstChannels = pState->cDstChannels; \ 46 a_Type *pDst = (a_Type *)pvDst; \ 47 while (cFrames-- > 0) \ 48 { \ 49 uintptr_t idxDst = cDstChannels; \ 50 while (idxDst-- > 0) \ 51 { \ 52 int8_t idxSrc = pState->aidxChannelMap[idxDst]; \ 53 if (idxSrc >= 0) \ 54 pDst[idxDst] = audioMixBufSampleTo##a_Name(pi32Src[idxSrc]); \ 55 else if (idxSrc != -2) \ 56 pDst[idxDst] = (a_fSigned) ? 0 : (a_Max >> 1); \ 57 else \ 58 pDst[idxDst] = 0; \ 59 } \ 60 pDst += cDstChannels; \ 61 pi32Src += cSrcChannels; \ 62 } \ 63 } \ 64 \ 65 /* 2ch -> 2ch */ \ 66 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode2ChTo2Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, \ 67 PAUDIOMIXBUFPEEKSTATE pState) \ 68 { \ 69 RT_NOREF_PV(pState); \ 70 a_Type *pDst = (a_Type *)pvDst; \ 71 while (cFrames-- > 0) \ 72 { \ 73 pDst[0] = audioMixBufSampleTo##a_Name(pi32Src[0]); \ 74 pDst[1] = audioMixBufSampleTo##a_Name(pi32Src[1]); \ 75 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", \ 76 &pi32Src[0], pi32Src[0], pi32Src[1], (int32_t)pDst[0], (int32_t)pDst[1])); \ 77 pDst += 2; \ 78 pi32Src += 2; \ 79 } \ 80 } \ 81 \ 82 /* 2ch -> 1ch */ \ 83 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode2ChTo1Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, \ 84 PAUDIOMIXBUFPEEKSTATE pState) \ 85 { \ 86 RT_NOREF_PV(pState); \ 87 a_Type *pDst = (a_Type *)pvDst; \ 88 while (cFrames-- > 0) \ 89 { \ 90 pDst[0] = audioMixBufSampleTo##a_Name(audioMixBufBlendSampleRet(pi32Src[0], pi32Src[1])); \ 91 pDst += 1; \ 92 pi32Src += 2; \ 93 } \ 94 } \ 95 \ 96 /* 1ch -> 2ch */ \ 97 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode1ChTo2Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, \ 98 PAUDIOMIXBUFPEEKSTATE pState) \ 99 { \ 100 RT_NOREF_PV(pState); \ 101 a_Type *pDst = (a_Type *)pvDst; \ 102 while (cFrames-- > 0) \ 103 { \ 104 pDst[0] = pDst[1] = audioMixBufSampleTo##a_Name(pi32Src[0]); \ 105 pDst += 2; \ 106 pi32Src += 1; \ 107 } \ 108 } \ 109 /* 1ch -> 1ch */ \ 110 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode1ChTo1Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, \ 111 PAUDIOMIXBUFPEEKSTATE pState) \ 112 { \ 113 RT_NOREF_PV(pState); \ 114 a_Type *pDst = (a_Type *)pvDst; \ 115 while (cFrames-- > 0) \ 116 { \ 117 pDst[0] = audioMixBufSampleTo##a_Name(pi32Src[0]); \ 118 pDst += 1; \ 119 pi32Src += 1; \ 120 } \ 121 } \ 122 \ 123 /* Decoders for write: */ \ 124 \ 125 /* Generic */ \ 126 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecodeGeneric,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, \ 127 PAUDIOMIXBUFWRITESTATE pState) \ 128 { \ 129 RT_NOREF_PV(pState); \ 130 uintptr_t const cSrcChannels = pState->cSrcChannels; \ 131 uintptr_t const cDstChannels = pState->cDstChannels; \ 132 a_Type const *pSrc = (a_Type const *)pvSrc; \ 133 while (cFrames-- > 0) \ 134 { \ 135 uintptr_t idxDst = cDstChannels; \ 136 while (idxDst-- > 0) \ 137 { \ 138 int8_t idxSrc = pState->aidxChannelMap[idxDst]; \ 139 if (idxSrc >= 0) \ 140 pi32Dst[idxDst] = audioMixBufSampleTo##a_Name(pSrc[idxSrc]); \ 141 else if (idxSrc != -2) \ 142 pi32Dst[idxDst] = (a_fSigned) ? 0 : (a_Max >> 1); \ 143 else \ 144 pi32Dst[idxDst] = 0; \ 145 } \ 146 pi32Dst += cDstChannels; \ 147 pSrc += cSrcChannels; \ 148 } \ 149 } \ 150 \ 151 /* 2ch -> 2ch */ \ 152 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode2ChTo2Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, \ 153 PAUDIOMIXBUFWRITESTATE pState) \ 154 { \ 155 RT_NOREF_PV(pState); \ 156 a_Type const *pSrc = (a_Type const *)pvSrc; \ 157 while (cFrames-- > 0) \ 158 { \ 159 pi32Dst[0] = audioMixBufSampleFrom##a_Name(pSrc[0]); \ 160 pi32Dst[1] = audioMixBufSampleFrom##a_Name(pSrc[1]); \ 161 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", \ 162 &pSrc[0], (int32_t)pSrc[0], (int32_t)pSrc[1], pi32Dst[0], pi32Dst[1])); \ 163 pi32Dst += 2; \ 164 pSrc += 2; \ 165 } \ 166 } \ 167 \ 168 /* 2ch -> 1ch */ \ 169 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode2ChTo1Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, \ 170 PAUDIOMIXBUFWRITESTATE pState) \ 171 { \ 172 RT_NOREF_PV(pState); \ 173 a_Type const *pSrc = (a_Type const *)pvSrc; \ 174 while (cFrames-- > 0) \ 175 { \ 176 pi32Dst[0] = audioMixBufBlendSampleRet(audioMixBufSampleFrom##a_Name(pSrc[0]), audioMixBufSampleFrom##a_Name(pSrc[1])); \ 177 pi32Dst += 1; \ 178 pSrc += 2; \ 179 } \ 180 } \ 181 \ 182 /* 1ch -> 2ch */ \ 183 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode1ChTo2Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, \ 184 PAUDIOMIXBUFWRITESTATE pState) \ 185 { \ 186 RT_NOREF_PV(pState); \ 187 a_Type const *pSrc = (a_Type const *)pvSrc; \ 188 while (cFrames-- > 0) \ 189 { \ 190 pi32Dst[1] = pi32Dst[0] = audioMixBufSampleFrom##a_Name(pSrc[0]); \ 191 pi32Dst += 2; \ 192 pSrc += 1; \ 193 } \ 194 } \ 195 \ 196 /* 1ch -> 1ch */ \ 197 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode1ChTo1Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, \ 198 PAUDIOMIXBUFWRITESTATE pState) \ 199 { \ 200 RT_NOREF_PV(pState); \ 201 a_Type const *pSrc = (a_Type const *)pvSrc; \ 202 while (cFrames-- > 0) \ 203 { \ 204 pi32Dst[0] = audioMixBufSampleFrom##a_Name(pSrc[0]); \ 205 pi32Dst += 1; \ 206 pSrc += 1; \ 207 } \ 208 } \ 209 \ 210 /* Decoders for blending: */ \ 211 \ 212 /* Generic */ \ 213 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecodeGeneric,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, \ 214 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) \ 215 { \ 216 RT_NOREF_PV(pState); \ 217 uintptr_t const cSrcChannels = pState->cSrcChannels; \ 218 uintptr_t const cDstChannels = pState->cDstChannels; \ 219 a_Type const *pSrc = (a_Type const *)pvSrc; \ 220 while (cFrames-- > 0) \ 221 { \ 222 uintptr_t idxDst = cDstChannels; \ 223 while (idxDst-- > 0) \ 224 { \ 225 int8_t idxSrc = pState->aidxChannelMap[idxDst]; \ 226 if (idxSrc >= 0) \ 227 audioMixBufBlendSample(&pi32Dst[idxDst], audioMixBufSampleTo##a_Name(pSrc[idxSrc])); \ 228 } \ 229 pi32Dst += cDstChannels; \ 230 pSrc += cSrcChannels; \ 231 } \ 232 } \ 233 \ 234 /* 2ch -> 2ch */ \ 235 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode2ChTo2Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, \ 236 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) \ 237 { \ 238 RT_NOREF_PV(pState); \ 239 a_Type const *pSrc = (a_Type const *)pvSrc; \ 240 while (cFrames-- > 0) \ 241 { \ 242 audioMixBufBlendSample(&pi32Dst[0], audioMixBufSampleFrom##a_Name(pSrc[0])); \ 243 audioMixBufBlendSample(&pi32Dst[1], audioMixBufSampleFrom##a_Name(pSrc[1])); \ 244 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", \ 245 &pSrc[0], (int32_t)pSrc[0], (int32_t)pSrc[1], pi32Dst[0], pi32Dst[1])); \ 246 pi32Dst += 2; \ 247 pSrc += 2; \ 248 } \ 249 } \ 250 \ 251 /* 2ch -> 1ch */ \ 252 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode2ChTo1Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, \ 253 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) \ 254 { \ 255 RT_NOREF_PV(pState); \ 256 a_Type const *pSrc = (a_Type const *)pvSrc; \ 257 while (cFrames-- > 0) \ 258 { \ 259 audioMixBufBlendSample(&pi32Dst[0], audioMixBufBlendSampleRet(audioMixBufSampleFrom##a_Name(pSrc[0]), \ 260 audioMixBufSampleFrom##a_Name(pSrc[1]))); \ 261 pi32Dst += 1; \ 262 pSrc += 2; \ 263 } \ 264 } \ 265 \ 266 /* 1ch -> 2ch */ \ 267 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode1ChTo2Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, \ 268 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) \ 269 { \ 270 RT_NOREF_PV(pState); \ 271 a_Type const *pSrc = (a_Type const *)pvSrc; \ 272 while (cFrames-- > 0) \ 273 { \ 274 int32_t const i32Src = audioMixBufSampleFrom##a_Name(pSrc[0]); \ 275 audioMixBufBlendSample(&pi32Dst[0], i32Src); \ 276 audioMixBufBlendSample(&pi32Dst[1], i32Src); \ 277 pi32Dst += 2; \ 278 pSrc += 1; \ 279 } \ 280 } \ 281 \ 282 /* 1ch -> 1ch */ \ 283 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode1ChTo1Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, \ 284 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) \ 285 { \ 286 RT_NOREF_PV(pState); \ 287 a_Type const *pSrc = (a_Type const *)pvSrc; \ 288 while (cFrames-- > 0) \ 289 { \ 290 audioMixBufBlendSample(&pi32Dst[0], audioMixBufSampleFrom##a_Name(pSrc[0])); \ 291 pi32Dst += 1; \ 292 pSrc += 1; \ 293 } \ 294 } 295 19 /* used to be: #define AUDMIXBUF_CONVERT(a_Name, a_Type, a_Min, a_Max, a_fSigned, a_cShift) */ 20 21 /* Clips a specific output value to a single sample value. */ 22 DECLINLINE(int32_t) RT_CONCAT(audioMixBufSampleFrom,a_Name)(a_Type aVal) 23 { 24 /* left shifting of signed values is not defined, therefore the intermediate uint64_t cast */ 25 if (a_fSigned) 26 return (int32_t) (((uint32_t) ((int32_t) aVal )) << (32 - a_cShift)); 27 return (int32_t) (((uint32_t) ((int32_t) aVal - ((a_Max >> 1) + 1))) << (32 - a_cShift)); 28 } 29 30 /* Clips a single sample value to a specific output value. */ 31 DECLINLINE(a_Type) RT_CONCAT(audioMixBufSampleTo,a_Name)(int32_t iVal) 32 { 33 if (a_fSigned) 34 return (a_Type) (iVal >> (32 - a_cShift)); 35 return (a_Type) ((iVal >> (32 - a_cShift)) + ((a_Max >> 1) + 1)); 36 } 37 38 /* Encoders for peek: */ 39 40 /* Generic */ 41 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncodeGeneric,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, 42 PAUDIOMIXBUFPEEKSTATE pState) 43 { 44 RT_NOREF_PV(pState); 45 uintptr_t const cSrcChannels = pState->cSrcChannels; 46 uintptr_t const cDstChannels = pState->cDstChannels; 47 a_Type *pDst = (a_Type *)pvDst; 48 while (cFrames-- > 0) 49 { 50 uintptr_t idxDst = cDstChannels; 51 while (idxDst-- > 0) 52 { 53 int8_t idxSrc = pState->aidxChannelMap[idxDst]; 54 if (idxSrc >= 0) 55 pDst[idxDst] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pi32Src[idxSrc]); 56 else if (idxSrc != -2) 57 pDst[idxDst] = (a_fSigned) ? 0 : (a_Max >> 1); 58 else 59 pDst[idxDst] = 0; 60 } 61 pDst += cDstChannels; 62 pi32Src += cSrcChannels; 63 } 64 } 65 66 /* 2ch -> 2ch */ 67 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode2ChTo2Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, 68 PAUDIOMIXBUFPEEKSTATE pState) 69 { 70 RT_NOREF_PV(pState); 71 a_Type *pDst = (a_Type *)pvDst; 72 while (cFrames-- > 0) 73 { 74 pDst[0] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pi32Src[0]); 75 pDst[1] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pi32Src[1]); 76 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", 77 &pi32Src[0], pi32Src[0], pi32Src[1], (int32_t)pDst[0], (int32_t)pDst[1])); 78 pDst += 2; 79 pi32Src += 2; 80 } 81 } 82 83 /* 2ch -> 1ch */ 84 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode2ChTo1Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, 85 PAUDIOMIXBUFPEEKSTATE pState) 86 { 87 RT_NOREF_PV(pState); 88 a_Type *pDst = (a_Type *)pvDst; 89 while (cFrames-- > 0) 90 { 91 pDst[0] = RT_CONCAT(audioMixBufSampleTo,a_Name)(audioMixBufBlendSampleRet(pi32Src[0], pi32Src[1])); 92 pDst += 1; 93 pi32Src += 2; 94 } 95 } 96 97 /* 1ch -> 2ch */ 98 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode1ChTo2Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, 99 PAUDIOMIXBUFPEEKSTATE pState) 100 { 101 RT_NOREF_PV(pState); 102 a_Type *pDst = (a_Type *)pvDst; 103 while (cFrames-- > 0) 104 { 105 pDst[0] = pDst[1] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pi32Src[0]); 106 pDst += 2; 107 pi32Src += 1; 108 } 109 } 110 /* 1ch -> 1ch */ 111 static DECLCALLBACK(void) RT_CONCAT(audioMixBufEncode1ChTo1Ch,a_Name)(void *pvDst, int32_t const *pi32Src, uint32_t cFrames, 112 PAUDIOMIXBUFPEEKSTATE pState) 113 { 114 RT_NOREF_PV(pState); 115 a_Type *pDst = (a_Type *)pvDst; 116 while (cFrames-- > 0) 117 { 118 pDst[0] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pi32Src[0]); 119 pDst += 1; 120 pi32Src += 1; 121 } 122 } 123 124 /* Decoders for write: */ 125 126 /* Generic */ 127 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecodeGeneric,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, 128 PAUDIOMIXBUFWRITESTATE pState) 129 { 130 RT_NOREF_PV(pState); 131 uintptr_t const cSrcChannels = pState->cSrcChannels; 132 uintptr_t const cDstChannels = pState->cDstChannels; 133 a_Type const *pSrc = (a_Type const *)pvSrc; 134 while (cFrames-- > 0) 135 { 136 uintptr_t idxDst = cDstChannels; 137 while (idxDst-- > 0) 138 { 139 int8_t idxSrc = pState->aidxChannelMap[idxDst]; 140 if (idxSrc >= 0) 141 pi32Dst[idxDst] = RT_CONCAT(audioMixBufSampleTo,a_Name)(pSrc[idxSrc]); 142 else if (idxSrc != -2) 143 pi32Dst[idxDst] = (a_fSigned) ? 0 : (a_Max >> 1); 144 else 145 pi32Dst[idxDst] = 0; 146 } 147 pi32Dst += cDstChannels; 148 pSrc += cSrcChannels; 149 } 150 } 151 152 /* 2ch -> 2ch */ 153 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode2ChTo2Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, 154 PAUDIOMIXBUFWRITESTATE pState) 155 { 156 RT_NOREF_PV(pState); 157 a_Type const *pSrc = (a_Type const *)pvSrc; 158 while (cFrames-- > 0) 159 { 160 pi32Dst[0] = RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]); 161 pi32Dst[1] = RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[1]); 162 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", 163 &pSrc[0], (int32_t)pSrc[0], (int32_t)pSrc[1], pi32Dst[0], pi32Dst[1])); 164 pi32Dst += 2; 165 pSrc += 2; 166 } 167 } 168 169 /* 2ch -> 1ch */ 170 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode2ChTo1Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, 171 PAUDIOMIXBUFWRITESTATE pState) 172 { 173 RT_NOREF_PV(pState); 174 a_Type const *pSrc = (a_Type const *)pvSrc; 175 while (cFrames-- > 0) 176 { 177 pi32Dst[0] = audioMixBufBlendSampleRet(RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]), 178 RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[1])); 179 pi32Dst += 1; 180 pSrc += 2; 181 } 182 } 183 184 /* 1ch -> 2ch */ 185 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode1ChTo2Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, 186 PAUDIOMIXBUFWRITESTATE pState) 187 { 188 RT_NOREF_PV(pState); 189 a_Type const *pSrc = (a_Type const *)pvSrc; 190 while (cFrames-- > 0) 191 { 192 pi32Dst[1] = pi32Dst[0] = RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]); 193 pi32Dst += 2; 194 pSrc += 1; 195 } 196 } 197 198 /* 1ch -> 1ch */ 199 static DECLCALLBACK(void) RT_CONCAT(audioMixBufDecode1ChTo1Ch,a_Name)(int32_t *pi32Dst, void const *pvSrc, uint32_t cFrames, 200 PAUDIOMIXBUFWRITESTATE pState) 201 { 202 RT_NOREF_PV(pState); 203 a_Type const *pSrc = (a_Type const *)pvSrc; 204 while (cFrames-- > 0) 205 { 206 pi32Dst[0] = RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]); 207 pi32Dst += 1; 208 pSrc += 1; 209 } 210 } 211 212 /* Decoders for blending: */ 213 214 /* Generic */ 215 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecodeGeneric,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, 216 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) 217 { 218 RT_NOREF_PV(pState); 219 uintptr_t const cSrcChannels = pState->cSrcChannels; 220 uintptr_t const cDstChannels = pState->cDstChannels; 221 a_Type const *pSrc = (a_Type const *)pvSrc; 222 while (cFrames-- > 0) 223 { 224 uintptr_t idxDst = cDstChannels; 225 while (idxDst-- > 0) 226 { 227 int8_t idxSrc = pState->aidxChannelMap[idxDst]; 228 if (idxSrc >= 0) 229 audioMixBufBlendSample(&pi32Dst[idxDst], RT_CONCAT(audioMixBufSampleTo,a_Name)(pSrc[idxSrc])); 230 } 231 pi32Dst += cDstChannels; 232 pSrc += cSrcChannels; 233 } 234 } 235 236 /* 2ch -> 2ch */ 237 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode2ChTo2Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, 238 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) 239 { 240 RT_NOREF_PV(pState); 241 a_Type const *pSrc = (a_Type const *)pvSrc; 242 while (cFrames-- > 0) 243 { 244 audioMixBufBlendSample(&pi32Dst[0], RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0])); 245 audioMixBufBlendSample(&pi32Dst[1], RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[1])); 246 AUDMIXBUF_MACRO_LOG(("%p: %RI32 / %RI32 => %RI32 / %RI32\n", 247 &pSrc[0], (int32_t)pSrc[0], (int32_t)pSrc[1], pi32Dst[0], pi32Dst[1])); 248 pi32Dst += 2; 249 pSrc += 2; 250 } 251 } 252 253 /* 2ch -> 1ch */ 254 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode2ChTo1Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, 255 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) 256 { 257 RT_NOREF_PV(pState); 258 a_Type const *pSrc = (a_Type const *)pvSrc; 259 while (cFrames-- > 0) 260 { 261 audioMixBufBlendSample(&pi32Dst[0], audioMixBufBlendSampleRet(RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]), 262 RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[1]))); 263 pi32Dst += 1; 264 pSrc += 2; 265 } 266 } 267 268 /* 1ch -> 2ch */ 269 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode1ChTo2Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, 270 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) 271 { 272 RT_NOREF_PV(pState); 273 a_Type const *pSrc = (a_Type const *)pvSrc; 274 while (cFrames-- > 0) 275 { 276 int32_t const i32Src = RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0]); 277 audioMixBufBlendSample(&pi32Dst[0], i32Src); 278 audioMixBufBlendSample(&pi32Dst[1], i32Src); 279 pi32Dst += 2; 280 pSrc += 1; 281 } 282 } 283 284 /* 1ch -> 1ch */ 285 static DECLCALLBACK(void) RT_CONCAT3(audioMixBufDecode1ChTo1Ch,a_Name,Blend)(int32_t *pi32Dst, void const *pvSrc, 286 uint32_t cFrames, PAUDIOMIXBUFWRITESTATE pState) 287 { 288 RT_NOREF_PV(pState); 289 a_Type const *pSrc = (a_Type const *)pvSrc; 290 while (cFrames-- > 0) 291 { 292 audioMixBufBlendSample(&pi32Dst[0], RT_CONCAT(audioMixBufSampleFrom,a_Name)(pSrc[0])); 293 pi32Dst += 1; 294 pSrc += 1; 295 } 296 } 297 298 299 #undef a_Name 300 #undef a_Type 301 #undef a_Min 302 #undef a_Max 303 #undef a_fSigned 304 #undef a_cShift 305 -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r89398 r89400 308 308 /** @todo Currently does not handle any endianness conversion yet! */ 309 309 310 /* audioMixBufConvXXXS8: 8-bit, signed. */ 311 #define a_Name S8 312 #define a_Type int8_t 313 #define a_Min INT8_MIN 314 #define a_Max INT8_MAX 315 #define a_fSigned 1 316 #define a_cShift 8 310 317 #include "AudioMixBuffer-Convert.cpp.h" 311 318 312 /* audioMixBufConvXXXS8: 8-bit, signed. */313 AUDMIXBUF_CONVERT(S8 /* Name */, int8_t, INT8_MIN /* Min */, INT8_MAX /* Max */, true /* fSigned */, 8 /* cShift */)314 319 /* audioMixBufConvXXXU8: 8-bit, unsigned. */ 315 AUDMIXBUF_CONVERT(U8 /* Name */, uint8_t, 0 /* Min */, UINT8_MAX /* Max */, false /* fSigned */, 8 /* cShift */) 320 #define a_Name U8 321 #define a_Type uint8_t 322 #define a_Min 0 323 #define a_Max UINT8_MAX 324 #define a_fSigned 0 325 #define a_cShift 8 326 #include "AudioMixBuffer-Convert.cpp.h" 327 316 328 /* audioMixBufConvXXXS16: 16-bit, signed. */ 317 AUDMIXBUF_CONVERT(S16 /* Name */, int16_t, INT16_MIN /* Min */, INT16_MAX /* Max */, true /* fSigned */, 16 /* cShift */) 329 #define a_Name S16 330 #define a_Type int16_t 331 #define a_Min INT16_MIN 332 #define a_Max INT16_MAX 333 #define a_fSigned 1 334 #define a_cShift 16 335 #include "AudioMixBuffer-Convert.cpp.h" 336 318 337 /* audioMixBufConvXXXU16: 16-bit, unsigned. */ 319 AUDMIXBUF_CONVERT(U16 /* Name */, uint16_t, 0 /* Min */, UINT16_MAX /* Max */, false /* fSigned */, 16 /* cShift */) 338 #define a_Name U16 339 #define a_Type uint16_t 340 #define a_Min 0 341 #define a_Max UINT16_MAX 342 #define a_fSigned 0 343 #define a_cShift 16 344 #include "AudioMixBuffer-Convert.cpp.h" 345 320 346 /* audioMixBufConvXXXS32: 32-bit, signed. */ 321 AUDMIXBUF_CONVERT(S32 /* Name */, int32_t, INT32_MIN /* Min */, INT32_MAX /* Max */, true /* fSigned */, 32 /* cShift */) 347 #define a_Name S32 348 #define a_Type int32_t 349 #define a_Min INT32_MIN 350 #define a_Max INT32_MAX 351 #define a_fSigned 1 352 #define a_cShift 32 353 #include "AudioMixBuffer-Convert.cpp.h" 354 322 355 /* audioMixBufConvXXXU32: 32-bit, unsigned. */ 323 AUDMIXBUF_CONVERT(U32 /* Name */, uint32_t, 0 /* Min */, UINT32_MAX /* Max */, false /* fSigned */, 32 /* cShift */) 356 #define a_Name U32 357 #define a_Type uint32_t 358 #define a_Min 0 359 #define a_Max UINT32_MAX 360 #define a_fSigned 0 361 #define a_cShift 32 362 #include "AudioMixBuffer-Convert.cpp.h" 363 324 364 /* audioMixBufConvXXXRaw: 32-bit stored as 64-bit, signed. */ 325 AUDMIXBUF_CONVERT(Raw /* Name */, int64_t, INT32_MIN /* Min */, INT32_MAX /* Max */, true /* fSigned */, 32 /* cShift */) 365 #define a_Name Raw 366 #define a_Type int64_t 367 #define a_Min INT64_MIN 368 #define a_Max INT64_MAX 369 #define a_fSigned 1 370 #define a_cShift 32 /* Yes, 32! */ 371 #include "AudioMixBuffer-Convert.cpp.h" 326 372 327 373 #undef AUDMIXBUF_CONVERT
Note:
See TracChangeset
for help on using the changeset viewer.