diff options
author | waker <wakeroid@gmail.com> | 2010-11-20 23:41:32 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2010-11-20 23:48:41 +0100 |
commit | ba64cb98eb826e2fb91a47a09854dac8aac52f71 (patch) | |
tree | e2d514cbf29d6296394cff513d18354b4f286f07 /premix.c | |
parent | d8398bdf9a50b1828afbb2b9943907ab707fc311 (diff) |
new SRC module compatible with premix
Diffstat (limited to 'premix.c')
-rw-r--r-- | premix.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -22,6 +22,7 @@ #include <stdlib.h> #include "deadbeef.h" #include "premix.h" +#include "optmath.h" #define trace(...) { fprintf(stderr, __VA_ARGS__); } //#define trace(fmt,...) @@ -201,6 +202,23 @@ pcm_write_samples_24_to_24 (const ddb_waveformat_t * restrict inputfmt, const ch output += outputsamplesize; } } +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; + fpu_setround (&ctl); + 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]); + float sample = *((float*)input); + *out = (int16_t)ftoi (sample*0x7fff); + } + input += 4; + } + output += outputsamplesize; + } + fpu_restore (ctl); +} int pcm_convert (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int inputsize) { @@ -285,6 +303,9 @@ pcm_convert (const ddb_waveformat_t * restrict inputfmt, const char * restrict i 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 == 16) { + pcm_write_samples_float_to_16 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); + } else { trace ("no converter from %d to %d\n", inputfmt->bps, outputfmt->bps); } |