Hello All I have successfully run the Opus Decoder for 16-bit WAV files. However when doing the same on 8-bit, the decoder produces noise, but on 16 bit data the output is working. Both the 8 and 16 bit files are from the same source and hence except for some loss of quality on 8 bit, they are identical in total play back duration. For both 8 and 16 bit data I have used the following parameters ui32SamplingRate = 8000 ui32Channel = 1 FRAME_SIZE_IN_MS is 20 MAX_PACKET is 1500 ui8ScaleFactor = 1 for 8-bit and 2 for 16-bit data ui32BitsPerSample = 8 for 8-bit data and 16 for 16-bit data The code is as follows sOpusDec = opus_decoder_create(ui32SamplingRate, ui32Channel, &i32error); if (i32error != OPUS_OK) { return((int)i32error); } opus_decoder_ctl(sOpusDec, OPUS_SET_LSB_DEPTH(ui32BitsPerSample)); ui32SizeOfWrBuf (ui32SamplingRate*ui32Channel*FRAME_SIZE_IN_MS*ui8ScaleFactor)/1000; opi16_out (int16_t*)calloc(((ui32SizeOfWrBuf/ui8ScaleFactor)+1),sizeof(int16_t)); pcRdBuf = (uint8_t *)calloc(MAX_PACKET,sizeof(uint8_t)); output_samples = opus_decode(sOpusDec, (const unsigned char *)&pcRdBuf[0], len, opi16_out, (ui32SizeOfWrBuf/ui8ScaleFactor), 0); I am not able to understand what the issue is. Or do I need to look at the encoder? Regards Amit -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/opus/attachments/20160107/806e7004/attachment.htm
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
Hello Ralph,> Likewise opus_encode() takes 16 bit samples, so you need to extend each > sample from an 8 bit source before encoding.Two questions 1. In opusenc.c which API does the extending the 8-bit to 16-bit? 2. If that is the case then how will 24 bit PCM sample work? Regards Amit On Thu, Jan 7, 2016 at 12:21 PM, Ralph Giles <giles at thaumas.net> wrote:> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/opus/attachments/20160107/27b9ecef/attachment.htm