[opus] Issue with decoding 8-bit PCM data

Ralph Giles giles at thaumas.net
Thu Jan 7 10:21:57 PST 2016


On 07/01/16 10:04 AM, Amit Ashara wrote:

> opus_decoder_ctl(sOpusDec, OPUS_SET_LSB_DEPTH(ui32BitsPerSample));

OPUS_SET_LSB_DEPTH only affects the encoder. If you check the return
value here you should get OPUS_UNIMPLEMENTED.

> output_samples = opus_decode(sOpusDec, (const unsigned char
> *)&pcRdBuf[0], len, opi16_out, (ui32SizeOfWrBuf/ui8ScaleFactor), 0);

I suspect the issue is dividing by ui8ScaleFactor = 1 here.
OPUS_SET_LSB_DEPTH works as a precision hint to the encoder about where
to set the noise floor, but opus_decode still returns 16 bit samples. It
always returns 16 bit samples, regardless of whether the original input
as 8 bit, 16 bit or 24 bit precision (from opus_encode_float).

To actually output 8-bit wav, you have to keep track of this out-of-band
and truncate each sample before writing it out.

Likewise opus_encode() takes 16 bit samples, so you need to extend each
sample from an 8 bit source before encoding.

HTH,
 -r


More information about the opus mailing list