HydrogenAudio

Lossy Audio Compression => Opus => Topic started by: stigc on 2018-03-14 21:21:30

Title: Opus sample-rate
Post by: stigc on 2018-03-14 21:21:30
I don't get it, where do I find the sample-rate of the PCM from a decoded Opus stream? I can only see where the the original sample rate is in the header.

https://wiki.xiph.org/OggOpus#ID_Header
Title: Re: Opus sample-rate
Post by: radorn on 2018-03-15 00:08:56
Isn't it supposed to be always 48000?

EDIT: A little further down there's what seems to be the answer you need:

Quote
Opus has a handful of coding modes, with internal audio bandwidths of 4, 6, 8, 12, and 20 kHz. Each packet in the stream may have a different audio bandwidth. Regardless of the audio bandwidth, the reference decoder supports decoding any stream at a sample rate of 8, 12, 16, 24, or 48 kHz. The original sample rate of the encoder input is not preserved by the lossy compression.

An Ogg Opus player SHOULD select the playback sample rate according to the following procedure:

    If the hardware supports 48 kHz playback, decode at 48 kHz,
    else if the hardware's highest available sample rate is a supported rate, decode at this sample rate,
    else if the hardware's highest available sample rate is less than 48 kHz, decode at the next higher supported rate and resample,
    else decode at 48 kHz and resample.
Title: Re: Opus sample-rate
Post by: saratoga on 2018-03-15 02:45:05
I don't get it, where do I find the sample-rate of the PCM from a decoded Opus stream? I can only see where the the original sample rate is in the header.

https://wiki.xiph.org/OggOpus#ID_Header

That is specification for the Ogg container when holding Opus.  The actual sampling rate of a given Opus packet is specified in the underlying Opus bitstream:

https://tools.ietf.org/html/rfc6716

See table 2.