1*575526ffSbeveloper /* Copyright (C) 2003 Marcus Overhagen 2*575526ffSbeveloper * Released under terms of the MIT license. 3*575526ffSbeveloper * 4*575526ffSbeveloper * A simple resampling class for the audio mixer. 5*575526ffSbeveloper * You pick the conversation function on object creation, 6*575526ffSbeveloper * and then call the Resample() function, specifying data pointer, 7*575526ffSbeveloper * offset (in bytes) to the next sample, and count of samples for 8*575526ffSbeveloper * both source and destination. 9*575526ffSbeveloper * 10*575526ffSbeveloper */ 11*575526ffSbeveloper 12*575526ffSbeveloper #include "Resampler.h" 13*575526ffSbeveloper #include "debug.h" 14*575526ffSbeveloper 15*575526ffSbeveloper Resampler::Resampler(uint32 src_format, uint32 dst_format) 16*575526ffSbeveloper : fFunc(0) 17*575526ffSbeveloper { 18*575526ffSbeveloper if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) { 19*575526ffSbeveloper switch (src_format) { 20*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_FLOAT: 21*575526ffSbeveloper fFunc = &Resampler::float_to_float; 22*575526ffSbeveloper return; 23*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_INT: 24*575526ffSbeveloper fFunc = &Resampler::int32_to_float; 25*575526ffSbeveloper return; 26*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_SHORT: 27*575526ffSbeveloper fFunc = &Resampler::int16_to_float; 28*575526ffSbeveloper return; 29*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_CHAR: 30*575526ffSbeveloper fFunc = &Resampler::int8_to_float; 31*575526ffSbeveloper return; 32*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_UCHAR: 33*575526ffSbeveloper fFunc = &Resampler::uint8_to_float; 34*575526ffSbeveloper return; 35*575526ffSbeveloper default: 36*575526ffSbeveloper FATAL("Resampler::Resampler: unknown source format 0x%x\n", src_format); 37*575526ffSbeveloper return; 38*575526ffSbeveloper } 39*575526ffSbeveloper } 40*575526ffSbeveloper 41*575526ffSbeveloper if (src_format == media_raw_audio_format::B_AUDIO_FLOAT) { 42*575526ffSbeveloper switch (dst_format) { 43*575526ffSbeveloper // float=>float already handled above 44*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_INT: 45*575526ffSbeveloper fFunc = &Resampler::float_to_int32; 46*575526ffSbeveloper return; 47*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_SHORT: 48*575526ffSbeveloper fFunc = &Resampler::float_to_int16; 49*575526ffSbeveloper return; 50*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_CHAR: 51*575526ffSbeveloper fFunc = &Resampler::float_to_int8; 52*575526ffSbeveloper return; 53*575526ffSbeveloper case media_raw_audio_format::B_AUDIO_UCHAR: 54*575526ffSbeveloper fFunc = &Resampler::float_to_uint8; 55*575526ffSbeveloper return; 56*575526ffSbeveloper default: 57*575526ffSbeveloper FATAL("Resampler::Resampler: unknown destination format 0x%x\n", dst_format); 58*575526ffSbeveloper return; 59*575526ffSbeveloper } 60*575526ffSbeveloper } 61*575526ffSbeveloper 62*575526ffSbeveloper FATAL("Resampler::Resampler: source or destination format must be B_AUDIO_FLOAT\n"); 63*575526ffSbeveloper } 64*575526ffSbeveloper 65*575526ffSbeveloper Resampler::~Resampler() 66*575526ffSbeveloper { 67*575526ffSbeveloper } 68*575526ffSbeveloper 69*575526ffSbeveloper status_t 70*575526ffSbeveloper Resampler::InitCheck() 71*575526ffSbeveloper { 72*575526ffSbeveloper return (fFunc != 0) ? B_OK : B_ERROR; 73*575526ffSbeveloper } 74*575526ffSbeveloper 75*575526ffSbeveloper void 76*575526ffSbeveloper Resampler::float_to_float(const void *src, int32 src_sample_offset, int32 src_sample_count, 77*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 78*575526ffSbeveloper { 79*575526ffSbeveloper } 80*575526ffSbeveloper 81*575526ffSbeveloper void 82*575526ffSbeveloper Resampler::int32_to_float(const void *src, int32 src_sample_offset, int32 src_sample_count, 83*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 84*575526ffSbeveloper { 85*575526ffSbeveloper } 86*575526ffSbeveloper 87*575526ffSbeveloper void 88*575526ffSbeveloper Resampler::int16_to_float(const void *src, int32 src_sample_offset, int32 src_sample_count, 89*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 90*575526ffSbeveloper { 91*575526ffSbeveloper } 92*575526ffSbeveloper 93*575526ffSbeveloper void 94*575526ffSbeveloper Resampler::int8_to_float(const void *src, int32 src_sample_offset, int32 src_sample_count, 95*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 96*575526ffSbeveloper { 97*575526ffSbeveloper } 98*575526ffSbeveloper 99*575526ffSbeveloper void 100*575526ffSbeveloper Resampler::uint8_to_float(const void *src, int32 src_sample_offset, int32 src_sample_count, 101*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 102*575526ffSbeveloper { 103*575526ffSbeveloper } 104*575526ffSbeveloper 105*575526ffSbeveloper void 106*575526ffSbeveloper Resampler::float_to_int32(const void *src, int32 src_sample_offset, int32 src_sample_count, 107*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 108*575526ffSbeveloper { 109*575526ffSbeveloper } 110*575526ffSbeveloper 111*575526ffSbeveloper void 112*575526ffSbeveloper Resampler::float_to_int16(const void *src, int32 src_sample_offset, int32 src_sample_count, 113*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 114*575526ffSbeveloper { 115*575526ffSbeveloper } 116*575526ffSbeveloper 117*575526ffSbeveloper void 118*575526ffSbeveloper Resampler::float_to_int8(const void *src, int32 src_sample_offset, int32 src_sample_count, 119*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 120*575526ffSbeveloper { 121*575526ffSbeveloper } 122*575526ffSbeveloper 123*575526ffSbeveloper void 124*575526ffSbeveloper Resampler::float_to_uint8(const void *src, int32 src_sample_offset, int32 src_sample_count, 125*575526ffSbeveloper void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 126*575526ffSbeveloper { 127*575526ffSbeveloper } 128*575526ffSbeveloper 129