Permalink
Browse files

wavpack: Fix decoding of some bit depths (12-bit, 20-bit, float).

Closes: #854.
  • Loading branch information...
jlindgren90 committed Dec 25, 2018
1 parent 9223a1a commit 9be0ca32b05c49badb66872b6f6e579249955cf8
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/wavpack/wavpack.cc
@@ -11,8 +11,8 @@
#include <libaudcore/audstrings.h>

#define BUFFER_SIZE 256 /* read buffer size, in samples / frames */
#define SAMPLE_SIZE(a) (a == 8 ? sizeof(uint8_t) : (a == 16 ? sizeof(uint16_t) : sizeof(uint32_t)))
#define SAMPLE_FMT(a) (a == 8 ? FMT_S8 : (a == 16 ? FMT_S16_NE : (a == 24 ? FMT_S24_NE : FMT_S32_NE)))
#define SAMPLE_SIZE(a) (a <= 8 ? sizeof(uint8_t) : (a <= 16 ? sizeof(uint16_t) : sizeof(uint32_t)))
#define SAMPLE_FMT(a) (a <= 8 ? FMT_S8 : (a <= 16 ? FMT_S16_NE : (a <= 24 ? FMT_S24_NE : FMT_S32_NE)))

class WavpackPlugin : public InputPlugin
{
@@ -139,7 +139,11 @@ bool WavpackPlugin::play (const char * filename, VFSFile & file)
num_samples = WavpackGetNumSamples(ctx);

set_stream_bitrate(WavpackGetAverageBitrate(ctx, num_channels));
open_audio(SAMPLE_FMT(bits_per_sample), sample_rate, num_channels);

if(bits_per_sample == 32 && (WavpackGetMode(ctx) & MODE_FLOAT))
open_audio(FMT_FLOAT, sample_rate, num_channels);
else
open_audio(SAMPLE_FMT(bits_per_sample), sample_rate, num_channels);

Index<int32_t> input;
input.resize (BUFFER_SIZE * num_channels);
@@ -174,17 +178,17 @@ bool WavpackPlugin::play (const char * filename, VFSFile & file)
int16_t * wp2 = (int16_t *) output.begin ();
int32_t * wp4 = (int32_t *) output.begin ();

if (bits_per_sample == 8)
if (bits_per_sample <= 8)
{
for (int i = 0; i < ret * num_channels; i++, wp++, rp++)
*wp = *rp & 0xff;
}
else if (bits_per_sample == 16)
else if (bits_per_sample <= 16)
{
for (int i = 0; i < ret * num_channels; i++, wp2++, rp++)
*wp2 = *rp & 0xffff;
}
else if (bits_per_sample == 24 || bits_per_sample == 32)
else
{
for (int i = 0; i < ret * num_channels; i++, wp4++, rp++)
*wp4 = *rp;

0 comments on commit 9be0ca3

Please sign in to comment.