1*ea81d6eaSJerome Leveque /* 2*ea81d6eaSJerome Leveque * Copyright 2012 Jérôme Leveque 3*ea81d6eaSJerome Leveque * Copyright 2012 Jérôme Duval 4*ea81d6eaSJerome Leveque * Copyright 2003 Marcus Overhagen 5*ea81d6eaSJerome Leveque * Distributed under the terms of the MIT License. 6*ea81d6eaSJerome Leveque */ 7*ea81d6eaSJerome Leveque 8*ea81d6eaSJerome Leveque 9*ea81d6eaSJerome Leveque #include "Resampler.h" 10*ea81d6eaSJerome Leveque #include "MultiAudioUtility.h" 11*ea81d6eaSJerome Leveque #include "debug.h" 12*ea81d6eaSJerome Leveque 13*ea81d6eaSJerome Leveque 14*ea81d6eaSJerome Leveque /*! A simple resampling class for the multi_audio add-ons. 15*ea81d6eaSJerome Leveque You pick the conversion function on object creation, 16*ea81d6eaSJerome Leveque and then call the Resample() function, specifying data pointer, 17*ea81d6eaSJerome Leveque offset (in bytes) to the next sample, and count of samples. 18*ea81d6eaSJerome Leveque */ 19*ea81d6eaSJerome Leveque 20*ea81d6eaSJerome Leveque 21*ea81d6eaSJerome Leveque Resampler::Resampler(uint32 sourceFormat, uint32 destFormat) 22*ea81d6eaSJerome Leveque : 23*ea81d6eaSJerome Leveque fFunc(NULL) 24*ea81d6eaSJerome Leveque { 25*ea81d6eaSJerome Leveque PRINT(("Resampler() in 0x%x, out 0x%x\n", (unsigned int)sourceFormat, 26*ea81d6eaSJerome Leveque (unsigned int)destFormat)); 27*ea81d6eaSJerome Leveque 28*ea81d6eaSJerome Leveque switch (sourceFormat) { 29*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 30*ea81d6eaSJerome Leveque switch (destFormat) { 31*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 32*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<float>; 33*ea81d6eaSJerome Leveque break; 34*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 35*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyFloat2Double; 36*ea81d6eaSJerome Leveque break; 37*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 38*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyFloat2Int; 39*ea81d6eaSJerome Leveque break; 40*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 41*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyFloat2Short; 42*ea81d6eaSJerome Leveque break; 43*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 44*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyFloat2UChar; 45*ea81d6eaSJerome Leveque break; 46*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 47*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyFloat2Char; 48*ea81d6eaSJerome Leveque break; 49*ea81d6eaSJerome Leveque } 50*ea81d6eaSJerome Leveque break; 51*ea81d6eaSJerome Leveque 52*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 53*ea81d6eaSJerome Leveque switch (destFormat) { 54*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 55*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyDouble2Float; 56*ea81d6eaSJerome Leveque break; 57*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 58*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<double>; 59*ea81d6eaSJerome Leveque break; 60*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 61*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyDouble2Int; 62*ea81d6eaSJerome Leveque break; 63*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 64*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyDouble2Short; 65*ea81d6eaSJerome Leveque break; 66*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 67*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyDouble2UChar; 68*ea81d6eaSJerome Leveque break; 69*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 70*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyDouble2Char; 71*ea81d6eaSJerome Leveque break; 72*ea81d6eaSJerome Leveque } 73*ea81d6eaSJerome Leveque break; 74*ea81d6eaSJerome Leveque 75*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 76*ea81d6eaSJerome Leveque switch (destFormat) { 77*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 78*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyInt2Float; 79*ea81d6eaSJerome Leveque break; 80*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 81*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyInt2Double; 82*ea81d6eaSJerome Leveque break; 83*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 84*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<int32>; 85*ea81d6eaSJerome Leveque break; 86*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 87*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyInt2Short; 88*ea81d6eaSJerome Leveque break; 89*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 90*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyInt2UChar; 91*ea81d6eaSJerome Leveque break; 92*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 93*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyInt2Char; 94*ea81d6eaSJerome Leveque break; 95*ea81d6eaSJerome Leveque } 96*ea81d6eaSJerome Leveque break; 97*ea81d6eaSJerome Leveque 98*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 99*ea81d6eaSJerome Leveque switch (destFormat) { 100*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 101*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyShort2Float; 102*ea81d6eaSJerome Leveque break; 103*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 104*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyShort2Double; 105*ea81d6eaSJerome Leveque break; 106*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 107*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyShort2Int; 108*ea81d6eaSJerome Leveque break; 109*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 110*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<int16>; 111*ea81d6eaSJerome Leveque break; 112*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 113*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyShort2UChar; 114*ea81d6eaSJerome Leveque break; 115*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 116*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyShort2Char; 117*ea81d6eaSJerome Leveque break; 118*ea81d6eaSJerome Leveque } 119*ea81d6eaSJerome Leveque break; 120*ea81d6eaSJerome Leveque 121*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 122*ea81d6eaSJerome Leveque switch (destFormat) { 123*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 124*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyUChar2Float; 125*ea81d6eaSJerome Leveque break; 126*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 127*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyUChar2Double; 128*ea81d6eaSJerome Leveque break; 129*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 130*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyUChar2Int; 131*ea81d6eaSJerome Leveque break; 132*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 133*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyUChar2Short; 134*ea81d6eaSJerome Leveque break; 135*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 136*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<uint8>; 137*ea81d6eaSJerome Leveque break; 138*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 139*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyUChar2Char; 140*ea81d6eaSJerome Leveque break; 141*ea81d6eaSJerome Leveque } 142*ea81d6eaSJerome Leveque break; 143*ea81d6eaSJerome Leveque 144*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 145*ea81d6eaSJerome Leveque switch (destFormat) { 146*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_FLOAT: 147*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyChar2Float; 148*ea81d6eaSJerome Leveque break; 149*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_DOUBLE: 150*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyChar2Double; 151*ea81d6eaSJerome Leveque break; 152*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_INT: 153*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyChar2Int; 154*ea81d6eaSJerome Leveque break; 155*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_SHORT: 156*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyChar2Short; 157*ea81d6eaSJerome Leveque break; 158*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_UCHAR: 159*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyChar2UChar; 160*ea81d6eaSJerome Leveque break; 161*ea81d6eaSJerome Leveque case media_raw_audio_format::B_AUDIO_CHAR: 162*ea81d6eaSJerome Leveque fFunc = &Resampler::_CopyType2Type<int8>; 163*ea81d6eaSJerome Leveque break; 164*ea81d6eaSJerome Leveque } 165*ea81d6eaSJerome Leveque break; 166*ea81d6eaSJerome Leveque } 167*ea81d6eaSJerome Leveque } 168*ea81d6eaSJerome Leveque 169*ea81d6eaSJerome Leveque 170*ea81d6eaSJerome Leveque Resampler::~Resampler() 171*ea81d6eaSJerome Leveque { 172*ea81d6eaSJerome Leveque } 173*ea81d6eaSJerome Leveque 174*ea81d6eaSJerome Leveque 175*ea81d6eaSJerome Leveque status_t 176*ea81d6eaSJerome Leveque Resampler::InitCheck() const 177*ea81d6eaSJerome Leveque { 178*ea81d6eaSJerome Leveque return fFunc != NULL ? B_OK : B_ERROR; 179*ea81d6eaSJerome Leveque } 180*ea81d6eaSJerome Leveque 181*ea81d6eaSJerome Leveque 182*ea81d6eaSJerome Leveque template<typename T> 183*ea81d6eaSJerome Leveque void 184*ea81d6eaSJerome Leveque Resampler::_CopyType2Type(const void *inputData, uint32 inputStride, 185*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 186*ea81d6eaSJerome Leveque { 187*ea81d6eaSJerome Leveque while (sampleCount > 0) { 188*ea81d6eaSJerome Leveque *(T*)outputData = *(const T*)inputData; 189*ea81d6eaSJerome Leveque 190*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 191*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 192*ea81d6eaSJerome Leveque 193*ea81d6eaSJerome Leveque sampleCount--; 194*ea81d6eaSJerome Leveque } 195*ea81d6eaSJerome Leveque } 196*ea81d6eaSJerome Leveque 197*ea81d6eaSJerome Leveque 198*ea81d6eaSJerome Leveque void 199*ea81d6eaSJerome Leveque Resampler::_CopyFloat2Double(const void *inputData, uint32 inputStride, 200*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 201*ea81d6eaSJerome Leveque { 202*ea81d6eaSJerome Leveque while (sampleCount > 0) { 203*ea81d6eaSJerome Leveque *(double*)outputData = *(const float*)inputData; 204*ea81d6eaSJerome Leveque 205*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 206*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 207*ea81d6eaSJerome Leveque 208*ea81d6eaSJerome Leveque sampleCount--; 209*ea81d6eaSJerome Leveque } 210*ea81d6eaSJerome Leveque } 211*ea81d6eaSJerome Leveque 212*ea81d6eaSJerome Leveque 213*ea81d6eaSJerome Leveque void 214*ea81d6eaSJerome Leveque Resampler::_CopyFloat2Int(const void *inputData, uint32 inputStride, 215*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 216*ea81d6eaSJerome Leveque { 217*ea81d6eaSJerome Leveque while (sampleCount > 0) { 218*ea81d6eaSJerome Leveque *(int32*)outputData = (int32)(*(const float*)inputData * 2147483647.0f); 219*ea81d6eaSJerome Leveque 220*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 221*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 222*ea81d6eaSJerome Leveque 223*ea81d6eaSJerome Leveque sampleCount--; 224*ea81d6eaSJerome Leveque } 225*ea81d6eaSJerome Leveque } 226*ea81d6eaSJerome Leveque 227*ea81d6eaSJerome Leveque void 228*ea81d6eaSJerome Leveque Resampler::_CopyFloat2Short(const void *inputData, uint32 inputStride, 229*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 230*ea81d6eaSJerome Leveque { 231*ea81d6eaSJerome Leveque while (sampleCount > 0) { 232*ea81d6eaSJerome Leveque *(int16*)outputData = (int16)(*(const float*)inputData * 32767.0f); 233*ea81d6eaSJerome Leveque 234*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 235*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 236*ea81d6eaSJerome Leveque 237*ea81d6eaSJerome Leveque sampleCount--; 238*ea81d6eaSJerome Leveque } 239*ea81d6eaSJerome Leveque } 240*ea81d6eaSJerome Leveque 241*ea81d6eaSJerome Leveque 242*ea81d6eaSJerome Leveque void 243*ea81d6eaSJerome Leveque Resampler::_CopyFloat2UChar(const void *inputData, uint32 inputStride, 244*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 245*ea81d6eaSJerome Leveque { 246*ea81d6eaSJerome Leveque while (sampleCount > 0) { 247*ea81d6eaSJerome Leveque *(uint8*)outputData = (uint8)(128.0f + *(const float*)inputData * 127.0f); 248*ea81d6eaSJerome Leveque 249*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 250*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 251*ea81d6eaSJerome Leveque 252*ea81d6eaSJerome Leveque sampleCount--; 253*ea81d6eaSJerome Leveque } 254*ea81d6eaSJerome Leveque } 255*ea81d6eaSJerome Leveque 256*ea81d6eaSJerome Leveque 257*ea81d6eaSJerome Leveque void 258*ea81d6eaSJerome Leveque Resampler::_CopyFloat2Char(const void *inputData, uint32 inputStride, 259*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 260*ea81d6eaSJerome Leveque { 261*ea81d6eaSJerome Leveque while (sampleCount > 0) { 262*ea81d6eaSJerome Leveque *(int8*)outputData = (int8)(*(const float*)inputData * 127.0f); 263*ea81d6eaSJerome Leveque 264*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 265*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 266*ea81d6eaSJerome Leveque 267*ea81d6eaSJerome Leveque sampleCount--; 268*ea81d6eaSJerome Leveque } 269*ea81d6eaSJerome Leveque } 270*ea81d6eaSJerome Leveque 271*ea81d6eaSJerome Leveque 272*ea81d6eaSJerome Leveque void 273*ea81d6eaSJerome Leveque Resampler::_CopyDouble2Float(const void *inputData, uint32 inputStride, 274*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 275*ea81d6eaSJerome Leveque { 276*ea81d6eaSJerome Leveque while (sampleCount > 0) { 277*ea81d6eaSJerome Leveque *(float*)outputData = *(const double*)inputData; 278*ea81d6eaSJerome Leveque 279*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 280*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 281*ea81d6eaSJerome Leveque 282*ea81d6eaSJerome Leveque sampleCount--; 283*ea81d6eaSJerome Leveque } 284*ea81d6eaSJerome Leveque } 285*ea81d6eaSJerome Leveque 286*ea81d6eaSJerome Leveque 287*ea81d6eaSJerome Leveque void 288*ea81d6eaSJerome Leveque Resampler::_CopyDouble2Int(const void *inputData, uint32 inputStride, 289*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 290*ea81d6eaSJerome Leveque { 291*ea81d6eaSJerome Leveque while (sampleCount > 0) { 292*ea81d6eaSJerome Leveque *(int32*)outputData = (int32)(*(const double*)inputData * 2147483647.0f); 293*ea81d6eaSJerome Leveque 294*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 295*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 296*ea81d6eaSJerome Leveque 297*ea81d6eaSJerome Leveque sampleCount--; 298*ea81d6eaSJerome Leveque } 299*ea81d6eaSJerome Leveque } 300*ea81d6eaSJerome Leveque 301*ea81d6eaSJerome Leveque 302*ea81d6eaSJerome Leveque void 303*ea81d6eaSJerome Leveque Resampler::_CopyDouble2Short(const void *inputData, uint32 inputStride, 304*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 305*ea81d6eaSJerome Leveque { 306*ea81d6eaSJerome Leveque while (sampleCount > 0) { 307*ea81d6eaSJerome Leveque *(int16*)outputData = (int16)(*(const double*)inputData * 32767.0f); 308*ea81d6eaSJerome Leveque 309*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 310*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 311*ea81d6eaSJerome Leveque 312*ea81d6eaSJerome Leveque sampleCount--; 313*ea81d6eaSJerome Leveque } 314*ea81d6eaSJerome Leveque } 315*ea81d6eaSJerome Leveque 316*ea81d6eaSJerome Leveque 317*ea81d6eaSJerome Leveque void 318*ea81d6eaSJerome Leveque Resampler::_CopyDouble2UChar(const void *inputData, uint32 inputStride, 319*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 320*ea81d6eaSJerome Leveque { 321*ea81d6eaSJerome Leveque while (sampleCount > 0) { 322*ea81d6eaSJerome Leveque *(uint8*)outputData = (uint8)(128.0f + *(const double*)inputData * 127.0f); 323*ea81d6eaSJerome Leveque 324*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 325*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 326*ea81d6eaSJerome Leveque 327*ea81d6eaSJerome Leveque sampleCount--; 328*ea81d6eaSJerome Leveque } 329*ea81d6eaSJerome Leveque } 330*ea81d6eaSJerome Leveque 331*ea81d6eaSJerome Leveque 332*ea81d6eaSJerome Leveque void 333*ea81d6eaSJerome Leveque Resampler::_CopyDouble2Char(const void *inputData, uint32 inputStride, 334*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 335*ea81d6eaSJerome Leveque { 336*ea81d6eaSJerome Leveque while (sampleCount > 0) { 337*ea81d6eaSJerome Leveque *(int8*)outputData = (int8)(*(const double*)inputData * 127.0f); 338*ea81d6eaSJerome Leveque 339*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 340*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 341*ea81d6eaSJerome Leveque 342*ea81d6eaSJerome Leveque sampleCount--; 343*ea81d6eaSJerome Leveque } 344*ea81d6eaSJerome Leveque } 345*ea81d6eaSJerome Leveque 346*ea81d6eaSJerome Leveque 347*ea81d6eaSJerome Leveque void 348*ea81d6eaSJerome Leveque Resampler::_CopyShort2Float(const void *inputData, uint32 inputStride, 349*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 350*ea81d6eaSJerome Leveque { 351*ea81d6eaSJerome Leveque while (sampleCount > 0) { 352*ea81d6eaSJerome Leveque *(float*)outputData = *(const int16*)inputData / 32767.0f; 353*ea81d6eaSJerome Leveque 354*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 355*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 356*ea81d6eaSJerome Leveque 357*ea81d6eaSJerome Leveque sampleCount--; 358*ea81d6eaSJerome Leveque } 359*ea81d6eaSJerome Leveque } 360*ea81d6eaSJerome Leveque 361*ea81d6eaSJerome Leveque 362*ea81d6eaSJerome Leveque void 363*ea81d6eaSJerome Leveque Resampler::_CopyShort2Double(const void *inputData, uint32 inputStride, 364*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 365*ea81d6eaSJerome Leveque { 366*ea81d6eaSJerome Leveque while (sampleCount > 0) { 367*ea81d6eaSJerome Leveque *(double*)outputData = *(const int16*)inputData / 32767.0; 368*ea81d6eaSJerome Leveque 369*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 370*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 371*ea81d6eaSJerome Leveque 372*ea81d6eaSJerome Leveque sampleCount--; 373*ea81d6eaSJerome Leveque } 374*ea81d6eaSJerome Leveque } 375*ea81d6eaSJerome Leveque 376*ea81d6eaSJerome Leveque 377*ea81d6eaSJerome Leveque void 378*ea81d6eaSJerome Leveque Resampler::_CopyShort2Int(const void *inputData, uint32 inputStride, 379*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 380*ea81d6eaSJerome Leveque { 381*ea81d6eaSJerome Leveque while (sampleCount > 0) { 382*ea81d6eaSJerome Leveque *(int32*)outputData = (int32)*(const int16*)inputData << 16; 383*ea81d6eaSJerome Leveque 384*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 385*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 386*ea81d6eaSJerome Leveque 387*ea81d6eaSJerome Leveque sampleCount--; 388*ea81d6eaSJerome Leveque } 389*ea81d6eaSJerome Leveque } 390*ea81d6eaSJerome Leveque 391*ea81d6eaSJerome Leveque 392*ea81d6eaSJerome Leveque void 393*ea81d6eaSJerome Leveque Resampler::_CopyShort2UChar(const void *inputData, uint32 inputStride, 394*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 395*ea81d6eaSJerome Leveque { 396*ea81d6eaSJerome Leveque while (sampleCount > 0) { 397*ea81d6eaSJerome Leveque *(uint8*)outputData = 128 + (*(const int16*)inputData >> 8); 398*ea81d6eaSJerome Leveque 399*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 400*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 401*ea81d6eaSJerome Leveque 402*ea81d6eaSJerome Leveque sampleCount--; 403*ea81d6eaSJerome Leveque } 404*ea81d6eaSJerome Leveque } 405*ea81d6eaSJerome Leveque 406*ea81d6eaSJerome Leveque 407*ea81d6eaSJerome Leveque void 408*ea81d6eaSJerome Leveque Resampler::_CopyShort2Char(const void *inputData, uint32 inputStride, 409*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 410*ea81d6eaSJerome Leveque { 411*ea81d6eaSJerome Leveque while (sampleCount > 0) { 412*ea81d6eaSJerome Leveque *(int8*)outputData = *(const int16*)inputData >> 8; 413*ea81d6eaSJerome Leveque 414*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 415*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 416*ea81d6eaSJerome Leveque 417*ea81d6eaSJerome Leveque sampleCount--; 418*ea81d6eaSJerome Leveque } 419*ea81d6eaSJerome Leveque } 420*ea81d6eaSJerome Leveque 421*ea81d6eaSJerome Leveque 422*ea81d6eaSJerome Leveque void 423*ea81d6eaSJerome Leveque Resampler::_CopyInt2Float(const void *inputData, uint32 inputStride, 424*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 425*ea81d6eaSJerome Leveque { 426*ea81d6eaSJerome Leveque while (sampleCount > 0) { 427*ea81d6eaSJerome Leveque *(float*)outputData = *(const int32*)inputData / 2147483647.0f; 428*ea81d6eaSJerome Leveque 429*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 430*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 431*ea81d6eaSJerome Leveque 432*ea81d6eaSJerome Leveque sampleCount--; 433*ea81d6eaSJerome Leveque } 434*ea81d6eaSJerome Leveque } 435*ea81d6eaSJerome Leveque 436*ea81d6eaSJerome Leveque 437*ea81d6eaSJerome Leveque void 438*ea81d6eaSJerome Leveque Resampler::_CopyInt2Double(const void *inputData, uint32 inputStride, 439*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 440*ea81d6eaSJerome Leveque { 441*ea81d6eaSJerome Leveque while (sampleCount > 0) { 442*ea81d6eaSJerome Leveque *(double*)outputData = *(const int32*)inputData / 2147483647.0; 443*ea81d6eaSJerome Leveque 444*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 445*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 446*ea81d6eaSJerome Leveque 447*ea81d6eaSJerome Leveque sampleCount--; 448*ea81d6eaSJerome Leveque } 449*ea81d6eaSJerome Leveque } 450*ea81d6eaSJerome Leveque 451*ea81d6eaSJerome Leveque 452*ea81d6eaSJerome Leveque void 453*ea81d6eaSJerome Leveque Resampler::_CopyInt2Short(const void *inputData, uint32 inputStride, 454*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 455*ea81d6eaSJerome Leveque { 456*ea81d6eaSJerome Leveque while (sampleCount > 0) { 457*ea81d6eaSJerome Leveque *(int16*)outputData = *(const int32*)inputData >> 16; 458*ea81d6eaSJerome Leveque 459*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 460*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 461*ea81d6eaSJerome Leveque 462*ea81d6eaSJerome Leveque sampleCount--; 463*ea81d6eaSJerome Leveque } 464*ea81d6eaSJerome Leveque } 465*ea81d6eaSJerome Leveque 466*ea81d6eaSJerome Leveque 467*ea81d6eaSJerome Leveque void 468*ea81d6eaSJerome Leveque Resampler::_CopyInt2UChar(const void *inputData, uint32 inputStride, 469*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 470*ea81d6eaSJerome Leveque { 471*ea81d6eaSJerome Leveque while (sampleCount > 0) { 472*ea81d6eaSJerome Leveque *(uint8*)outputData = 128 + (*(const int32*)inputData >> 24); 473*ea81d6eaSJerome Leveque 474*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 475*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 476*ea81d6eaSJerome Leveque 477*ea81d6eaSJerome Leveque sampleCount--; 478*ea81d6eaSJerome Leveque } 479*ea81d6eaSJerome Leveque } 480*ea81d6eaSJerome Leveque 481*ea81d6eaSJerome Leveque 482*ea81d6eaSJerome Leveque void 483*ea81d6eaSJerome Leveque Resampler::_CopyInt2Char(const void *inputData, uint32 inputStride, 484*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 485*ea81d6eaSJerome Leveque { 486*ea81d6eaSJerome Leveque while (sampleCount > 0) { 487*ea81d6eaSJerome Leveque *(uint8*)outputData = *(const int32*)inputData >> 24; 488*ea81d6eaSJerome Leveque 489*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 490*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 491*ea81d6eaSJerome Leveque 492*ea81d6eaSJerome Leveque sampleCount--; 493*ea81d6eaSJerome Leveque } 494*ea81d6eaSJerome Leveque } 495*ea81d6eaSJerome Leveque 496*ea81d6eaSJerome Leveque 497*ea81d6eaSJerome Leveque void 498*ea81d6eaSJerome Leveque Resampler::_CopyUChar2Float(const void *inputData, uint32 inputStride, 499*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 500*ea81d6eaSJerome Leveque { 501*ea81d6eaSJerome Leveque while (sampleCount > 0) { 502*ea81d6eaSJerome Leveque *(float*)outputData = (*(const uint8*)inputData - 128) / 127.0f; 503*ea81d6eaSJerome Leveque 504*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 505*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 506*ea81d6eaSJerome Leveque 507*ea81d6eaSJerome Leveque sampleCount--; 508*ea81d6eaSJerome Leveque } 509*ea81d6eaSJerome Leveque } 510*ea81d6eaSJerome Leveque 511*ea81d6eaSJerome Leveque 512*ea81d6eaSJerome Leveque void 513*ea81d6eaSJerome Leveque Resampler::_CopyUChar2Double(const void *inputData, uint32 inputStride, 514*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 515*ea81d6eaSJerome Leveque { 516*ea81d6eaSJerome Leveque while (sampleCount > 0) { 517*ea81d6eaSJerome Leveque *(double*)outputData = (*(const uint8*)inputData - 128) / 127.0; 518*ea81d6eaSJerome Leveque 519*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 520*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 521*ea81d6eaSJerome Leveque 522*ea81d6eaSJerome Leveque sampleCount--; 523*ea81d6eaSJerome Leveque } 524*ea81d6eaSJerome Leveque } 525*ea81d6eaSJerome Leveque 526*ea81d6eaSJerome Leveque 527*ea81d6eaSJerome Leveque void 528*ea81d6eaSJerome Leveque Resampler::_CopyUChar2Short(const void *inputData, uint32 inputStride, 529*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 530*ea81d6eaSJerome Leveque { 531*ea81d6eaSJerome Leveque while (sampleCount > 0) { 532*ea81d6eaSJerome Leveque *(int16*)outputData = (int16)(*(const uint8*)inputData - 128) << 8; 533*ea81d6eaSJerome Leveque 534*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 535*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 536*ea81d6eaSJerome Leveque 537*ea81d6eaSJerome Leveque sampleCount--; 538*ea81d6eaSJerome Leveque } 539*ea81d6eaSJerome Leveque } 540*ea81d6eaSJerome Leveque 541*ea81d6eaSJerome Leveque 542*ea81d6eaSJerome Leveque void 543*ea81d6eaSJerome Leveque Resampler::_CopyUChar2Int(const void *inputData, uint32 inputStride, 544*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 545*ea81d6eaSJerome Leveque { 546*ea81d6eaSJerome Leveque while (sampleCount > 0) { 547*ea81d6eaSJerome Leveque *(int32*)outputData = (int32)(*(const uint8*)inputData - 128) << 24; 548*ea81d6eaSJerome Leveque 549*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 550*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 551*ea81d6eaSJerome Leveque 552*ea81d6eaSJerome Leveque sampleCount--; 553*ea81d6eaSJerome Leveque } 554*ea81d6eaSJerome Leveque } 555*ea81d6eaSJerome Leveque 556*ea81d6eaSJerome Leveque 557*ea81d6eaSJerome Leveque void 558*ea81d6eaSJerome Leveque Resampler::_CopyUChar2Char(const void *inputData, uint32 inputStride, 559*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 560*ea81d6eaSJerome Leveque { 561*ea81d6eaSJerome Leveque while (sampleCount > 0) { 562*ea81d6eaSJerome Leveque *(int8*)outputData = *(const uint8*)inputData - 128; 563*ea81d6eaSJerome Leveque 564*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 565*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 566*ea81d6eaSJerome Leveque 567*ea81d6eaSJerome Leveque sampleCount--; 568*ea81d6eaSJerome Leveque } 569*ea81d6eaSJerome Leveque } 570*ea81d6eaSJerome Leveque 571*ea81d6eaSJerome Leveque 572*ea81d6eaSJerome Leveque void 573*ea81d6eaSJerome Leveque Resampler::_CopyChar2Float(const void *inputData, uint32 inputStride, 574*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 575*ea81d6eaSJerome Leveque { 576*ea81d6eaSJerome Leveque while (sampleCount > 0) { 577*ea81d6eaSJerome Leveque *(float*)outputData = *(const int8*)inputData / 127.0f; 578*ea81d6eaSJerome Leveque 579*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 580*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 581*ea81d6eaSJerome Leveque 582*ea81d6eaSJerome Leveque sampleCount--; 583*ea81d6eaSJerome Leveque } 584*ea81d6eaSJerome Leveque } 585*ea81d6eaSJerome Leveque 586*ea81d6eaSJerome Leveque 587*ea81d6eaSJerome Leveque void 588*ea81d6eaSJerome Leveque Resampler::_CopyChar2Double(const void *inputData, uint32 inputStride, 589*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 590*ea81d6eaSJerome Leveque { 591*ea81d6eaSJerome Leveque while (sampleCount > 0) { 592*ea81d6eaSJerome Leveque *(double*)outputData = *(const int8*)inputData / 127.0; 593*ea81d6eaSJerome Leveque 594*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 595*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 596*ea81d6eaSJerome Leveque 597*ea81d6eaSJerome Leveque sampleCount--; 598*ea81d6eaSJerome Leveque } 599*ea81d6eaSJerome Leveque } 600*ea81d6eaSJerome Leveque 601*ea81d6eaSJerome Leveque 602*ea81d6eaSJerome Leveque void 603*ea81d6eaSJerome Leveque Resampler::_CopyChar2Short(const void *inputData, uint32 inputStride, 604*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 605*ea81d6eaSJerome Leveque { 606*ea81d6eaSJerome Leveque while (sampleCount > 0) { 607*ea81d6eaSJerome Leveque *(int16*)outputData = ((int16)*(const int8*)inputData) << 8; 608*ea81d6eaSJerome Leveque 609*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 610*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 611*ea81d6eaSJerome Leveque 612*ea81d6eaSJerome Leveque sampleCount--; 613*ea81d6eaSJerome Leveque } 614*ea81d6eaSJerome Leveque } 615*ea81d6eaSJerome Leveque 616*ea81d6eaSJerome Leveque 617*ea81d6eaSJerome Leveque void 618*ea81d6eaSJerome Leveque Resampler::_CopyChar2Int(const void *inputData, uint32 inputStride, 619*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 620*ea81d6eaSJerome Leveque { 621*ea81d6eaSJerome Leveque while (sampleCount > 0) { 622*ea81d6eaSJerome Leveque *(int32*)outputData = ((int16)*(const int8*)inputData) << 24; 623*ea81d6eaSJerome Leveque 624*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 625*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 626*ea81d6eaSJerome Leveque 627*ea81d6eaSJerome Leveque sampleCount--; 628*ea81d6eaSJerome Leveque } 629*ea81d6eaSJerome Leveque } 630*ea81d6eaSJerome Leveque 631*ea81d6eaSJerome Leveque 632*ea81d6eaSJerome Leveque void 633*ea81d6eaSJerome Leveque Resampler::_CopyChar2UChar(const void *inputData, uint32 inputStride, 634*ea81d6eaSJerome Leveque void *outputData, uint32 outputStride, uint32 sampleCount) 635*ea81d6eaSJerome Leveque { 636*ea81d6eaSJerome Leveque while (sampleCount > 0) { 637*ea81d6eaSJerome Leveque *(uint8*)outputData = *(const int8*)inputData + 128; 638*ea81d6eaSJerome Leveque 639*ea81d6eaSJerome Leveque outputData = (void*)((uint8*)outputData + outputStride); 640*ea81d6eaSJerome Leveque inputData = (void*)((uint8*)inputData + inputStride); 641*ea81d6eaSJerome Leveque 642*ea81d6eaSJerome Leveque sampleCount--; 643*ea81d6eaSJerome Leveque } 644*ea81d6eaSJerome Leveque } 645*ea81d6eaSJerome Leveque 646