diff options
author | waker <wakeroid@gmail.com> | 2010-11-13 23:50:39 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2010-11-13 23:50:39 +0100 |
commit | 94ba195c261f10d3d3809b429eb341313279db66 (patch) | |
tree | 798f7673516507db76eb1bccd2798ceb56fef5a0 | |
parent | 8eada3d6211baeac22c9d0f1977bc90f428247d5 (diff) |
ported wavpack to new API
-rw-r--r-- | plugins/wavpack/wavpack.c | 125 | ||||
-rw-r--r-- | premix.c | 20 | ||||
-rw-r--r-- | scripts/configure_minimal.sh | 2 | ||||
-rw-r--r-- | streamer.c | 2 |
4 files changed, 70 insertions, 79 deletions
diff --git a/plugins/wavpack/wavpack.c b/plugins/wavpack/wavpack.c index 72cc7e3c..05130f87 100644 --- a/plugins/wavpack/wavpack.c +++ b/plugins/wavpack/wavpack.c @@ -31,8 +31,8 @@ #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) static DB_decoder_t plugin; static DB_functions_t *deadbeef; @@ -106,7 +106,7 @@ static WavpackStreamReader wsr = { #endif static DB_fileinfo_t * -wv_open (void) { +wv_open (uint32_t hints) { DB_fileinfo_t *_info = malloc (sizeof (wvctx_t)); memset (_info, 0, sizeof (wvctx_t)); return _info; @@ -143,9 +143,11 @@ wv_init (DB_fileinfo_t *_info, DB_playItem_t *it) { return -1; } _info->plugin = &plugin; - _info->bps = WavpackGetBytesPerSample (info->ctx) * 8; - _info->channels = WavpackGetNumChannels (info->ctx); - _info->samplerate = WavpackGetSampleRate (info->ctx); + _info->fmt.bps = WavpackGetBytesPerSample (info->ctx) * 8; + _info->fmt.channels = WavpackGetNumChannels (info->ctx); + _info->fmt.samplerate = WavpackGetSampleRate (info->ctx); + _info->fmt.is_float = (WavpackGetMode (info->ctx) & MODE_FLOAT) ? 1 : 0; + _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT); _info->readpos = 0; if (it->endsample > 0) { info->startsample = it->startsample; @@ -184,49 +186,57 @@ wv_free (DB_fileinfo_t *_info) { } static int -wv_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) { +wv_read (DB_fileinfo_t *_info, char *bytes, int size) { wvctx_t *info = (wvctx_t *)_info; int currentsample = WavpackGetSampleIndex (info->ctx); - int nchannels = WavpackGetReducedChannels (info->ctx); - if (size / (2 * nchannels) + currentsample > info->endsample) { - size = (info->endsample - currentsample + 1) * 2 * nchannels; +// int nchannels = WavpackGetReducedChannels (info->ctx); + int samplesize = (_info->fmt.bps >> 3) * _info->fmt.channels; + if (size / samplesize + currentsample > info->endsample) { + size = (info->endsample - currentsample + 1) * samplesize; trace ("wv: size truncated to %d bytes, cursample=%d, endsample=%d\n", size, currentsample, info->endsample); if (size <= 0) { return 0; } } - int32_t buffer[size/2]; - int n = WavpackUnpackSamples (info->ctx, buffer, size/(2*nchannels)); - size = n * 2 * nchannels; - // convert to int16 - int32_t *p = buffer; - n *= nchannels; - + int n; if (WavpackGetMode (info->ctx) & MODE_FLOAT) { - while (n > 0) { - float val = *(float*)p; - if (val >= 1.0) - *((int16_t *)bytes) = 32767; - else if (val <= -1.0) - *((int16_t *)bytes) = -32768; - else - *((int16_t *)bytes) = floor (val * 32768.f); - bytes += sizeof (int16_t); - p++; - n--; - } + _info->fmt.is_float = 1; + } + if (_info->fmt.is_float || _info->fmt.bps == 32) { + n = WavpackUnpackSamples (info->ctx, (int32_t *)bytes, size / samplesize); + size = n * samplesize; } else { - while (n > 0) { - if (_info->bps >= 16) { - *((int16_t *)bytes) = (int16_t)((*p) >> (_info->bps-16)); + int32_t buffer[size/(_info->fmt.bps >> 3)]; + n = WavpackUnpackSamples (info->ctx, (int32_t *)buffer, size / samplesize); + size = n * samplesize; + n *= _info->fmt.channels; + + // convert from int32 to input (what???) + int32_t *p = buffer; + if (_info->fmt.bps == 16) { + while (n > 0) { + *((int16_t *)bytes) = (int16_t)(*p); + bytes += sizeof (int16_t); + p++; + n--; + } + } + else if (_info->fmt.bps == 8) { + while (n > 0) { + *bytes++ = (char)(*p); + p++; + n--; } - else { - *((int16_t *)bytes) = (int16_t)((*p) << (16-_info->bps)); + } + else if (_info->fmt.bps == 24) { + while (n > 0) { + *bytes++ = (*p)&0xff; + *bytes++ = ((*p)&0xff00)>>8; + *bytes++ = ((*p)&0xff0000)>>16; + p++; + n--; } - bytes += sizeof (int16_t); - p++; - n--; } } _info->readpos = (float)(WavpackGetSampleIndex (info->ctx)-info->startsample)/WavpackGetSampleRate (info->ctx); @@ -239,44 +249,6 @@ wv_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) { } static int -wv_read_float32 (DB_fileinfo_t *_info, char *bytes, int size) { - wvctx_t *info = (wvctx_t *)_info; - int nchannels = WavpackGetReducedChannels (info->ctx); - int currentsample = WavpackGetSampleIndex (info->ctx); - if (size / (4 * nchannels) + currentsample > info->endsample) { - size = (info->endsample - currentsample + 1) * 4 * nchannels; - trace ("wv: size truncated to %d bytes, cursample=%d, endsample=%d\n", size, currentsample, info->endsample); - if (size <= 0) { - return 0; - } - } - int32_t buffer[size/4]; - int n = WavpackUnpackSamples (info->ctx, buffer, size/(4*nchannels)); - size = n * 4 * nchannels; - // convert to float32 - n *= nchannels; - - if (WavpackGetMode (info->ctx) & MODE_FLOAT) { - memcpy (bytes, buffer, size); - } - else { - float mul = 1.f/ (1UL << (_info->bps-1)); - int32_t *p = buffer; - while (n > 0) { - *((float *)bytes) = (*p) * mul; - bytes += sizeof (float); - p++; - n--; - } - } - _info->readpos = (float)(WavpackGetSampleIndex (info->ctx)-info->startsample)/WavpackGetSampleRate (info->ctx); -#ifndef TINYWV - deadbeef->streamer_set_bitrate (WavpackGetInstantBitrate (info->ctx) / 1000); -#endif - return size; -} - -static int wv_seek_sample (DB_fileinfo_t *_info, int sample) { #ifndef TINYWV wvctx_t *info = (wvctx_t *)_info; @@ -454,8 +426,7 @@ static DB_decoder_t plugin = { .open = wv_open, .init = wv_init, .free = wv_free, - .read_int16 = wv_read_int16, - .read_float32 = wv_read_float32, + .read = wv_read, .seek = wv_seek, .seek_sample = wv_seek_sample, .insert = wv_insert, @@ -127,6 +127,19 @@ pcm_write_samples_16_to_float (const ddb_waveformat_t * restrict inputfmt, const } 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); + } + input += 4; + } + output += outputsamplesize; + } +} + +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++) { @@ -188,6 +201,7 @@ pcm_convert (const ddb_waveformat_t * restrict inputfmt, const char * restrict i } // FIXME: access through function pointer table + //trace ("converting from %d to %d\n", inputfmt->bps, outputfmt->bps); if (inputfmt->bps == 8 && outputfmt->bps == 8) { pcm_write_samples_8_to_8 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); } @@ -212,6 +226,12 @@ 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 == 32 && outputfmt->bps == 32) { + pcm_write_samples_32_to_32 (inputfmt, input, outputfmt, output, nsamples, channelmap, outputsamplesize); + } + else { + trace ("no converter from %d to %d\n", inputfmt->bps, outputfmt->bps); + } } return nsamples * outputsamplesize; } diff --git a/scripts/configure_minimal.sh b/scripts/configure_minimal.sh index 6982df3a..7ec8607d 100644 --- a/scripts/configure_minimal.sh +++ b/scripts/configure_minimal.sh @@ -1 +1 @@ -./configure --enable-maintainer-mode --disable-nullout --disable-oss --disable-sid --disable-ffap --disable-vtx --disable-adplug --disable-vorbis --disable-ffmpeg --disable-flac --disable-sndfile --disable-wavpack --disable-cdda --disable-gme --disable-musepack --disable-wildmidi --disable-tta --disable-dca --disable-aac --disable-mms --disable-shn --disable-ao --disable-supereq --disable-artwork --disable-lfm --disable-vfs-curl --disable-hotkeys --disable-notify --disable-shellexec +./configure --enable-maintainer-mode --disable-nullout --disable-oss --disable-sid --disable-ffap --disable-vtx --disable-adplug --disable-vorbis --disable-ffmpeg --disable-flac --disable-sndfile --disable-cdda --disable-gme --disable-musepack --disable-wildmidi --disable-tta --disable-dca --disable-aac --disable-mms --disable-shn --disable-ao --disable-supereq --disable-artwork --disable-lfm --disable-vfs-curl --disable-hotkeys --disable-notify --disable-shellexec @@ -1526,7 +1526,7 @@ streamer_read_async (char *bytes, int size) { break; } if (fileinfo->fmt.samplerate != -1) { - if (!memcmp (&fileinfo->fmt, &output->fmt, sizeof (ddb_waveformat_t))) { + if (!memcmp (&fileinfo->fmt, &output->fmt, sizeof (ddb_waveformat_t)), 0) { bytesread = fileinfo->plugin->read (fileinfo, bytes, size); } else { |