summaryrefslogtreecommitdiff
path: root/plugins/wavpack
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-09-27 16:18:02 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-09-27 16:18:02 +0200
commita43fef70a9b13d35d358d6ba44c4e1e884bbbc3e (patch)
tree5c121595fe5468fc5144e2dbd3191c9a9bc52fbb /plugins/wavpack
parent40cdc329bac46ee7ea0ce6d6a4c0b9ea69e2cf2d (diff)
wavpack float32 decoding
Diffstat (limited to 'plugins/wavpack')
-rw-r--r--plugins/wavpack/wavpack.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/plugins/wavpack/wavpack.c b/plugins/wavpack/wavpack.c
index 717bf2e5..85bbaaaa 100644
--- a/plugins/wavpack/wavpack.c
+++ b/plugins/wavpack/wavpack.c
@@ -72,7 +72,6 @@ wv_free (void) {
memset (&wvctx, 0, sizeof (wvctx));
}
-
static int
wv_read_int16 (char *bytes, int size) {
int currentsample = WavpackGetSampleIndex (wvctx.ctx);
@@ -101,6 +100,34 @@ wv_read_int16 (char *bytes, int size) {
}
static int
+wv_read_float32 (char *bytes, int size) {
+ int currentsample = WavpackGetSampleIndex (wvctx.ctx);
+ if (size / (4 * plugin.info.channels) + currentsample > wvctx.endsample) {
+ size = (wvctx.endsample - currentsample + 1) * 4 * plugin.info.channels;
+ trace ("wv: size truncated to %d bytes, cursample=%d, endsample=%d\n", size, currentsample, wvctx.endsample);
+ if (size <= 0) {
+ return 0;
+ }
+ }
+ int32_t buffer[size/4];
+ int nchannels = WavpackGetNumChannels (wvctx.ctx);
+ int n = WavpackUnpackSamples (wvctx.ctx, buffer, size/(4*nchannels));
+ size = n * 4 * nchannels;
+ // convert to int16
+ int32_t *p = buffer;
+ n *= nchannels;
+ float mul = 1.f/ ((1 << (plugin.info.bps-1))-1);
+ while (n > 0) {
+ *((float *)bytes) = (*p) * mul;
+ bytes += sizeof (float);
+ p++;
+ n--;
+ }
+ plugin.info.readpos = (float)(WavpackGetSampleIndex (wvctx.ctx)-wvctx.startsample)/WavpackGetSampleRate (wvctx.ctx);
+ return size;
+}
+
+static int
wv_seek_sample (int sample) {
WavpackSeekSample (wvctx.ctx, sample + wvctx.startsample);
plugin.info.readpos = (float)(WavpackGetSampleIndex (wvctx.ctx) - wvctx.startsample) / WavpackGetSampleRate (wvctx.ctx);
@@ -171,7 +198,7 @@ static DB_decoder_t plugin = {
.init = wv_init,
.free = wv_free,
.read_int16 = wv_read_int16,
-// .read_float32 = wv_read_float32,
+ .read_float32 = wv_read_float32,
.seek = wv_seek,
.seek_sample = wv_seek_sample,
.insert = wv_insert,