Documentation
¶
Index ¶
- Constants
- func Version() string
- type Application
- type Bandwidth
- 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 Encoder
- func (enc *Encoder) Bitrate() (int, error)
- func (enc *Encoder) Complexity() (int, error)
- func (enc *Encoder) DTX() (bool, error)
- func (enc *Encoder) Encode(pcm []int16, data []byte) (int, error)
- func (enc *Encoder) EncodeFloat32(pcm []float32, data []byte) (int, error)
- func (enc *Encoder) InBandFEC() (bool, error)
- func (enc *Encoder) InDTX() (bool, error)
- func (enc *Encoder) Init(sample_rate int, channels int, application Application) error
- func (enc *Encoder) MaxBandwidth() (Bandwidth, error)
- func (enc *Encoder) PacketLossPerc() (int, error)
- func (enc *Encoder) Reset() error
- func (enc *Encoder) SampleRate() (int, error)
- func (enc *Encoder) SetBitrate(bitrate int) error
- func (enc *Encoder) SetBitrateToAuto() error
- func (enc *Encoder) SetBitrateToMax() error
- func (enc *Encoder) SetComplexity(complexity int) error
- func (enc *Encoder) SetDTX(dtx bool) error
- func (enc *Encoder) SetInBandFEC(fec bool) error
- func (enc *Encoder) SetMaxBandwidth(maxBw Bandwidth) error
- func (enc *Encoder) SetPacketLossPerc(lossPerc int) error
- type Error
Constants ¶
const ( // 4 kHz passband Narrowband = Bandwidth(C.OPUS_BANDWIDTH_NARROWBAND) // 6 kHz passband Mediumband = Bandwidth(C.OPUS_BANDWIDTH_MEDIUMBAND) // 8 kHz passband Wideband = Bandwidth(C.OPUS_BANDWIDTH_WIDEBAND) // 12 kHz passband SuperWideband = Bandwidth(C.OPUS_BANDWIDTH_SUPERWIDEBAND) // 20 kHz passband Fullband = Bandwidth(C.OPUS_BANDWIDTH_FULLBAND) )
const ( ErrOK = Error(OPUS_OK) ErrBadArg = Error(OPUS_BAD_ARG) ErrBufferTooSmall = Error(OPUS_BUFFER_TOO_SMALL) ErrInternalError = Error(OPUS_INTERNAL_ERROR) ErrInvalidPacket = Error(OPUS_INVALID_PACKET) ErrUnimplemented = Error(OPUS_UNIMPLEMENTED) ErrInvalidState = Error(OPUS_INVALID_STATE) ErrAllocFail = Error(OPUS_ALLOC_FAIL) )
Libopus errors
const ( // Optimize encoding for VoIP AppVoIP = Application(OPUS_APPLICATION_VOIP) // Optimize encoding for non-voice signals like music AppAudio = Application(OPUS_APPLICATION_AUDIO) // Optimize encoding for low latency applications AppRestrictedLowdelay = Application(OPUS_APPLICATION_RESTRICTED_LOWDELAY) )
const OPUS_ALLOC_FAIL = -0x7
const OPUS_APPLICATION_AUDIO = 0x801
const OPUS_APPLICATION_RESTRICTED_LOWDELAY = 0x803
const OPUS_APPLICATION_VOIP = 0x800
const OPUS_AUTO = -0x3e8
const OPUS_BAD_ARG = -0x1
const OPUS_BANDWIDTH_FULLBAND = 0x451
const OPUS_BANDWIDTH_MEDIUMBAND = 0x44e
const OPUS_BANDWIDTH_NARROWBAND = 0x44d
const OPUS_BANDWIDTH_SUPERWIDEBAND = 0x450
const OPUS_BANDWIDTH_WIDEBAND = 0x44f
const OPUS_BITRATE_MAX = -0x1
const OPUS_BUFFER_TOO_SMALL = -0x2
const OPUS_INTERNAL_ERROR = -0x3
const OPUS_INVALID_PACKET = -0x4
const OPUS_INVALID_STATE = -0x6
const OPUS_OK = 0x0
const OPUS_UNIMPLEMENTED = -0x5
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Application ¶
type Application int
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 Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder contains the state of an Opus encoder for libopus.
func NewEncoder ¶
func NewEncoder(sample_rate int, channels int, application Application) (*Encoder, error)
NewEncoder allocates a new Opus encoder and initializes it with the appropriate parameters. All related memory is managed by the Go GC.
func (*Encoder) Complexity ¶
Complexity returns the computational complexity used by the encoder
func (*Encoder) DTX ¶
DTX reports whether this encoder is configured to use discontinuous transmission (DTX).
func (*Encoder) Encode ¶
Encode raw PCM data and store the result in the supplied buffer. On success, returns the number of bytes used up by the encoded data.
func (*Encoder) EncodeFloat32 ¶
Encode raw PCM data and store the result in the supplied buffer. On success, returns the number of bytes used up by the encoded data.
func (*Encoder) InBandFEC ¶
InBandFEC gets the encoder's configured inband forward error correction (FEC)
func (*Encoder) InDTX ¶
InDTX returns whether the last encoded frame was either a comfort noise update during DTX or not encoded because of DTX.
func (*Encoder) Init ¶
func (enc *Encoder) Init(sample_rate int, channels int, application Application) error
Init initializes a pre-allocated opus encoder. Unless the encoder has been created using NewEncoder, this method must be called exactly once in the life-time of this object, before calling any other methods.
func (*Encoder) MaxBandwidth ¶
MaxBandwidth gets the encoder's configured maximum allowed bandpass.
func (*Encoder) PacketLossPerc ¶
PacketLossPerc gets the encoder's configured packet loss percentage.
func (*Encoder) Reset ¶
Reset resets the codec state to be equivalent to a freshly initialized state.
func (*Encoder) SampleRate ¶
SampleRate returns the encoder sample rate in Hz.
func (*Encoder) SetBitrate ¶
SetBitrate sets the bitrate of the Encoder
func (*Encoder) SetBitrateToAuto ¶
SetBitrateToAuto will allow the encoder to automatically set the bitrate
func (*Encoder) SetBitrateToMax ¶
SetBitrateToMax causes the encoder to use as much rate as it can. This can be useful for controlling the rate by adjusting the output buffer size.
func (*Encoder) SetComplexity ¶
SetComplexity sets the encoder's computational complexity
func (*Encoder) SetInBandFEC ¶
SetInBandFEC configures the encoder's use of inband forward error correction (FEC)
func (*Encoder) SetMaxBandwidth ¶
SetMaxBandwidth configures the maximum bandpass that the encoder will select automatically
func (*Encoder) SetPacketLossPerc ¶
SetPacketLossPerc configures the encoder's expected packet loss percentage.