From 5898772de0ba58b4e1e28c0d86d7f3f780e12f29 Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 23 Nov 2010 20:41:33 +0100 Subject: added more premix converters; minor optimization --- plugins/sid/csid.cpp | 3 +- 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); diff --git a/premix.c b/premix.c index 43a7ed8f..46036f1e 100644 --- a/premix.c +++ b/premix.c @@ -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; } @@ -174,12 +174,43 @@ 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); -- cgit v1.2.3