Documentation
¶
Index ¶
- Constants
- type Decoder
- func (dec *Decoder) Decode(data []byte, pcm []int16) (int, error)
- func (dec *Decoder) DecodeFEC(data []byte, pcm []int16) error
- func (dec *Decoder) DecodeFECFloat32(data []byte, pcm []float32) error
- func (dec *Decoder) DecodeFloat32(data []byte, pcm []float32) (int, error)
- func (dec *Decoder) DecodePLC(pcm []int16) error
- func (dec *Decoder) DecodePLCFloat32(pcm []float32) error
- func (dec *Decoder) Init(sample_rate int, channels int) error
- func (dec *Decoder) LastPacketDuration() (int, error)
- type Error
- type Latency
- type Params
Constants ¶
const ( ErrOK = Error(C.OPUS_OK) ErrBadArg = Error(C.OPUS_BAD_ARG) ErrBufferTooSmall = Error(C.OPUS_BUFFER_TOO_SMALL) ErrInternalError = Error(C.OPUS_INTERNAL_ERROR) ErrInvalidPacket = Error(C.OPUS_INVALID_PACKET) ErrUnimplemented = Error(C.OPUS_UNIMPLEMENTED) ErrInvalidState = Error(C.OPUS_INVALID_STATE) ErrAllocFail = Error(C.OPUS_ALLOC_FAIL) )
Libopus errors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
NewDecoder allocates a new Opus decoder and initializes it with the appropriate parameters. All related memory is managed by the Go GC.
func (*Decoder) Decode ¶
Decode encoded Opus data into the supplied buffer. On success, returns the number of samples correctly written to the target buffer.
func (*Decoder) DecodeFEC ¶
DecodeFEC encoded Opus data into the supplied buffer with forward error correction.
It is to be used on the packet directly following the lost one. The supplied buffer needs to be exactly the duration of audio that is missing
When a packet is considered "lost", DecodeFEC can be called on the next packet in order to try and recover some of the lost data. The PCM needs to be exactly the duration of audio that is missing. `LastPacketDuration()` can be used on the decoder to get the length of the last packet. Note also that in order to use this feature the encoder needs to be configured with SetInBandFEC(true) and SetPacketLossPerc(x) options.
Note that DecodeFEC automatically falls back to PLC when no FEC data is available in the provided packet.
func (*Decoder) DecodeFECFloat32 ¶
DecodeFECFloat32 encoded Opus data into the supplied buffer with forward error correction. It is to be used on the packet directly following the lost one. The supplied buffer needs to be exactly the duration of audio that is missing
func (*Decoder) DecodeFloat32 ¶
Decode encoded Opus data into the supplied buffer. On success, returns the number of samples correctly written to the target buffer.
func (*Decoder) DecodePLC ¶
DecodePLC recovers a lost packet using Opus Packet Loss Concealment feature.
The supplied buffer needs to be exactly the duration of audio that is missing. When a packet is considered "lost", `DecodePLC` and `DecodePLCFloat32` methods can be called in order to obtain something better sounding than just silence. The PCM needs to be exactly the duration of audio that is missing. `LastPacketDuration()` can be used on the decoder to get the length of the last packet.
This option does not require any additional encoder options. Unlike FEC, PLC does not introduce additional latency. It is calculated from the previous packet, not from the next one.
func (*Decoder) DecodePLCFloat32 ¶
DecodePLCFloat32 recovers a lost packet using Opus Packet Loss Concealment feature. The supplied buffer needs to be exactly the duration of audio that is missing.
func (*Decoder) LastPacketDuration ¶
LastPacketDuration gets the duration (in samples) of the last packet successfully decoded or concealed.
type Latency ¶
Latency is a type of OPUS codec frame duration.
const ( Latency2500us Latency = Latency(2500 * time.Microsecond) Latency5ms Latency = Latency(5 * time.Millisecond) Latency10ms Latency = Latency(10 * time.Millisecond) Latency20ms Latency = Latency(20 * time.Millisecond) Latency40ms Latency = Latency(40 * time.Millisecond) Latency60ms Latency = Latency(60 * time.Millisecond) )
Latency values available in OPUS codec.
type Params ¶
type Params struct {
codec.BaseParams
// ChannelMixer is a mixer to be used if number of given and expected channels differ.
ChannelMixer mixer.ChannelMixer
// Expected latency of the codec.
Latency Latency
}
Params stores opus specific encoding parameters.
func (*Params) BuildAudioEncoder ¶
BuildAudioEncoder builds opus encoder with given params