diff options
author | waker <wakeroid@gmail.com> | 2010-11-23 20:41:33 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2010-11-23 20:52:13 +0100 |
commit | 5898772de0ba58b4e1e28c0d86d7f3f780e12f29 (patch) | |
tree | 69b992d3717ec56b29804dbaaa379a5081835be0 | |
parent | a9f494a1681d0131645a3ec7334d4174f4f28b48 (diff) |
added more premix converters;
minor optimization
-rw-r--r-- | plugins/sid/csid.cpp | 3 | ||||
-rw-r--r-- | premix.c | 96 |
2 files changed, 74 insertions, 25 deletions
diff --git a/plugins/sid/csid.cpp b/plugins/sid/csid.cpp index 0682fb3f..f2bb17a5 100644 --- a/plugins/sid/csid.cpp +++ b/plugins/sid/csid.cpp @@ -309,7 +309,6 @@ csid_init (DB_fileinfo_t *_info, DB_playItem_t *it) { info->sidplay = new sidplay2; info->resid = new ReSIDBuilder ("wtf"); info->resid->create (info->sidplay->info ().maxsids); -// resid->create (1); info->resid->filter (true); int samplerate = deadbeef->conf_get_int ("sid.samplerate", 44100); @@ -334,7 +333,7 @@ csid_init (DB_fileinfo_t *_info, DB_playItem_t *it) { info->sidplay->load (info->tune); _info->plugin = &sid_plugin; - _info->fmt.channels = 2;//info->tune->isStereo () ? 2 : 1; + _info->fmt.channels = conf.playback == sid2_stereo ? 2 : 1; _info->fmt.bps = bps; _info->fmt.samplerate = conf.frequency; _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT); @@ -33,7 +33,7 @@ pcm_write_samples_8_to_8 (const ddb_waveformat_t * restrict inputfmt, const char for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - *(output + (outputfmt->bps >> 3) * channelmap[c]) = *input; + *(output + channelmap[c]) = *input; } input++; } @@ -46,7 +46,7 @@ pcm_write_samples_8_to_16 (const ddb_waveformat_t * restrict inputfmt, const cha for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - *((int16_t*)(output + (outputfmt->bps >> 3) * channelmap[c])) = (int16_t)(*input) << 8; + *((int16_t*)(output + 2 * channelmap[c])) = (int16_t)(*input) << 8; } input++; } @@ -59,7 +59,7 @@ pcm_write_samples_8_to_24 (const ddb_waveformat_t * restrict inputfmt, const cha for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - char *out = output + (outputfmt->bps >> 3) * channelmap[c]; + char *out = output + 3 * channelmap[c]; out[0] = 0; out[1] = 0; out[2] = input[0]; @@ -75,7 +75,7 @@ pcm_write_samples_8_to_32 (const ddb_waveformat_t * restrict inputfmt, const cha for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - char *out = output + (outputfmt->bps >> 3) * channelmap[c]; + char *out = output + 4 * channelmap[c]; out[0] = 0; out[1] = 0; out[2] = 0; @@ -93,7 +93,7 @@ pcm_write_samples_8_to_float (const ddb_waveformat_t * restrict inputfmt, const for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { float sample = (*input) / (float)0x7f; - *((float *)(output + (outputfmt->bps >> 3) * channelmap[c])) = sample; + *((float *)(output + 4 * channelmap[c])) = sample; } input++; } @@ -106,7 +106,7 @@ pcm_write_samples_16_to_16 (const ddb_waveformat_t * restrict inputfmt, const ch for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - *((int16_t*)(output + (outputfmt->bps >> 3) * channelmap[c])) = *((int16_t*)input); + *((int16_t*)(output + 2 * channelmap[c])) = *((int16_t*)input); } input += 2; } @@ -119,7 +119,7 @@ pcm_write_samples_16_to_8 (const ddb_waveformat_t * restrict inputfmt, const cha for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - *((int8_t*)(output + (outputfmt->bps >> 3) * channelmap[c])) = *((int16_t*)input) >> 8; + *((int8_t*)(output + channelmap[c])) = *((int16_t*)input) >> 8; } input += 2; } @@ -132,7 +132,7 @@ pcm_write_samples_16_to_24 (const ddb_waveformat_t * restrict inputfmt, const ch for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - char *out = output + (outputfmt->bps >> 3) * channelmap[c]; + char *out = output + 3 * channelmap[c]; out[0] = 0; out[1] = input[0]; out[2] = input[1]; @@ -148,7 +148,7 @@ pcm_write_samples_16_to_32 (const ddb_waveformat_t * restrict inputfmt, const ch for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - char *out = output + (outputfmt->bps >> 3) * channelmap[c]; + char *out = output + 4 * channelmap[c]; out[0] = 0; out[1] = 0; out[2] = input[0]; @@ -166,7 +166,7 @@ pcm_write_samples_16_to_float (const ddb_waveformat_t * restrict inputfmt, const for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { float sample = (*((int16_t*)input)) / (float)0x7fff; - *((float *)(output + (outputfmt->bps >> 3) * channelmap[c])) = sample; + *((float *)(output + 4 * channelmap[c])) = sample; } input += 2; } @@ -175,11 +175,42 @@ pcm_write_samples_16_to_float (const ddb_waveformat_t * restrict inputfmt, const } static inline void +pcm_write_samples_24_to_24 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { + for (int s = 0; s < nsamples; s++) { + for (int c = 0; c < inputfmt->channels; c++) { + if (channelmap[c] != -1) { + char *out = output + 3 * channelmap[c]; + out[0] = input[0]; + out[1] = input[1]; + out[2] = input[2]; + } + input += 3; + } + output += outputsamplesize; + } +} + +static inline void +pcm_write_samples_24_to_float (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { + for (int s = 0; s < nsamples; s++) { + for (int c = 0; c < inputfmt->channels; c++) { + if (channelmap[c] != -1) { + float *out = (float *)(output + 4 * channelmap[c]); + int32_t sample = ((int32_t)input[0]<<16) | ((int32_t)input[1]<<8) | (input[2]); + *out = sample / (float)0x7fffffff; + } + input += 3; + } + output += outputsamplesize; + } +} + +static inline void pcm_write_samples_32_to_32 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - *((int32_t*)(output + (outputfmt->bps >> 3) * channelmap[c])) = *((int32_t*)input); + *((int32_t*)(output + 4 * channelmap[c])) = *((int32_t*)input); } input += 4; } @@ -188,20 +219,30 @@ pcm_write_samples_32_to_32 (const ddb_waveformat_t * restrict inputfmt, const ch } static inline void -pcm_write_samples_24_to_24 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { +pcm_write_samples_float_to_8 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { + fpu_control ctl; + fpu_setround (&ctl); for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - char *out = output + (outputfmt->bps >> 3) * channelmap[c]; - out[0] = input[0]; - out[1] = input[1]; - out[2] = input[2]; + int8_t *out = (int8_t*)(output + channelmap[c]); + float sample = *((float*)input); + // FIXME: sse optimize + if (sample > 1) { + sample = 1; + } + if (sample < -1) { + sample = -1; + } + *out = (int8_t)ftoi (sample*0x7f); } - input += 3; + input += 4; } output += outputsamplesize; } + fpu_restore (ctl); } + static inline void pcm_write_samples_float_to_16 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { fpu_control ctl; @@ -209,7 +250,7 @@ pcm_write_samples_float_to_16 (const ddb_waveformat_t * restrict inputfmt, const for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - int16_t *out = (int16_t*)(output + (outputfmt->bps >> 3) * channelmap[c]); + int16_t *out = (int16_t*)(output + 2 * channelmap[c]); float sample = *((float*)input); // FIXME: sse optimize if (sample > 1) { @@ -228,13 +269,13 @@ pcm_write_samples_float_to_16 (const ddb_waveformat_t * restrict inputfmt, const } static inline void -pcm_write_samples_float_to_8 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { +pcm_write_samples_float_to_24 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { fpu_control ctl; fpu_setround (&ctl); for (int s = 0; s < nsamples; s++) { for (int c = 0; c < inputfmt->channels; c++) { if (channelmap[c] != -1) { - int8_t *out = (int8_t*)(output + (outputfmt->bps >> 3) * channelmap[c]); + char *out = output + 3 * channelmap[c]; float sample = *((float*)input); // FIXME: sse optimize if (sample > 1) { @@ -243,7 +284,10 @@ pcm_write_samples_float_to_8 (const ddb_waveformat_t * restrict inputfmt, const if (sample < -1) { sample = -1; } - *out = (int8_t)ftoi (sample*0x7f); + int32_t outsample = (int32_t)ftoi (sample * 0x7fffffff); + out[0] = (outsample&0x00ff0000)>>16; + out[1] = (outsample&0x0000ff00)>>8; + out[2] = (outsample&0x000000ff); } input += 4; } @@ -332,14 +376,20 @@ pcm_convert (const ddb_waveformat_t * restrict inputfmt, const char * restrict i else if (inputfmt->bps == 24 && outputfmt->bps == 24) { pcm_write_samples_24_to_24 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); } + else if (inputfmt->bps == 24 && outputfmt->bps == 32 && outputfmt->is_float) { + pcm_write_samples_24_to_float (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); + } else if (inputfmt->bps == 32 && outputfmt->bps == 32) { pcm_write_samples_32_to_32 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); } + else if (inputfmt->is_float && inputfmt->bps == 32 && outputfmt->bps == 8) { + pcm_write_samples_float_to_8 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); + } else if (inputfmt->is_float && inputfmt->bps == 32 && outputfmt->bps == 16) { pcm_write_samples_float_to_16 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); } - else if (inputfmt->is_float && inputfmt->bps == 32 && outputfmt->bps == 8) { - pcm_write_samples_float_to_8 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); + else if (inputfmt->is_float && inputfmt->bps == 32 && outputfmt->bps == 24) { + pcm_write_samples_float_to_24 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); } else { trace ("no converter from %d to %d\n", inputfmt->bps, outputfmt->bps); |