Documentation ¶
Overview ¶
Opus gives bindings to libopus https://www.opus-codec.org/
Index ¶
- Constants
- func GetDecoderSize(channels int) int
- func GetEncoderSize(channels int) int
- func GetError(error int) error
- func GetRepacketizerSize() int
- func GetVersionString() string
- func PacketGetNbChannels(data []byte) (int, error)
- func PacketGetNbFrames(data []byte) (int, error)
- func PacketGetNbSamples(data []byte, sampleRate int) (int, error)
- func PacketGetSamplesPerFrame(data []byte, sampleRate int) int
- type Application
- type Bandwidth
- type Decoder
- func (e *Decoder) Bandwidth() Bandwidth
- func (e *Decoder) DecodeFloat32(data []byte, frameSize int, fec bool) ([]float32, error)
- func (e *Decoder) DecodeInt16(data []byte, frameSize int, fec bool) ([]int16, error)
- func (e *Decoder) Gain() int
- func (e *Decoder) GetFinalRange() uint32
- func (e *Decoder) GetNbSamples(data []byte) (int, error)
- func (e *Decoder) Pitch() int
- func (e *Decoder) Reset()
- func (e *Decoder) SetGain(v int)
- type Encoder
- func (e *Encoder) Application() Application
- func (e *Encoder) Bandwidth() Bandwidth
- func (e *Encoder) Bitrate() int
- func (e *Encoder) Complexity() int
- func (e *Encoder) DTX() bool
- func (e *Encoder) EncodeFloat32(pcm []float32, frameSize int, maxData int) ([]byte, error)
- func (e *Encoder) EncodeInt16(pcm []int16, frameSize int, maxData int) ([]byte, error)
- func (e *Encoder) ForceChannels() int
- func (e *Encoder) GetFinalRange() uint32
- func (e *Encoder) InbandFEC() bool
- func (e *Encoder) LSBDepth() int
- func (e *Encoder) LastPacketDuration() int
- func (e *Encoder) Lookahead() int
- func (e *Encoder) MaxBandwidth() Bandwidth
- func (e *Encoder) PacketLossPerc() int
- func (e *Encoder) Reset()
- func (e *Encoder) SampleRate() int
- func (e *Encoder) SetApplication(v Application)
- func (e *Encoder) SetBandwidth(v Bandwidth)
- func (e *Encoder) SetBitrate(v int)
- func (e *Encoder) SetComplexity(v int)
- func (e *Encoder) SetDTX(vb bool)
- func (e *Encoder) SetForceChannels(v int)
- func (e *Encoder) SetInbandFEC(vb bool)
- func (e *Encoder) SetLSBDepth(v int)
- func (e *Encoder) SetMaxBandwidth(v Bandwidth)
- func (e *Encoder) SetPacketLossPerc(v int)
- func (e *Encoder) SetSignal(v Signal)
- func (e *Encoder) SetVBR(v int)
- func (e *Encoder) SetVBRConstraint(v int)
- func (e *Encoder) Signal() Signal
- func (e *Encoder) VBR() int
- func (e *Encoder) VBRConstraint() int
- type Error
- type Repacketizer
- type Signal
Constants ¶
const ( //Auto/default setting Auto int = C.OPUS_AUTO //Maximum bitrate BitrateMax int = C.OPUS_BITRATE_MAX )
Variables ¶
This section is empty.
Functions ¶
func GetDecoderSize ¶
GetDecoderSize returns the size of a Decoder
func GetEncoderSize ¶
GetEncoderSize returns the size of a Encoder
func GetRepacketizerSize ¶
func GetRepacketizerSize() int
Gets the size of an OpusRepacketizer structure.
func GetVersionString ¶
func GetVersionString() string
GetVersionString Gets the libopus version string.
func PacketGetNbChannels ¶
Gets the number of channels from a Opus packet.
func PacketGetNbFrames ¶
Gets the number of frames in an Opus packet.
func PacketGetNbSamples ¶
Gets the number of samples of an Opus packet
func PacketGetSamplesPerFrame ¶
Gets the number of samples per frame from an Opus packet
Types ¶
type Application ¶
type Application int
const ( // Best for most VoIP/videoconference applications where listening quality and intelligibility matter most ApplicationVoip Application = C.OPUS_APPLICATION_VOIP // Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input ApplicationAudio Application = C.OPUS_APPLICATION_AUDIO // Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used. ApplicationRestrictedLowdelay Application = C.OPUS_APPLICATION_RESTRICTED_LOWDELAY )
type Bandwidth ¶
type Bandwidth int
const ( BandwidthAutoband Bandwidth = C.OPUS_AUTO //4kHz bandpass BandwidthNarrowband Bandwidth = C.OPUS_BANDWIDTH_NARROWBAND //6kHz bandpass BandwidthMediumband Bandwidth = C.OPUS_BANDWIDTH_MEDIUMBAND //8kHz bandpass BandwidthWideband Bandwidth = C.OPUS_BANDWIDTH_WIDEBAND //12kHz bandpass BandwidthSuperWideband Bandwidth = C.OPUS_BANDWIDTH_SUPERWIDEBAND //20kHz bandpass BandwidthFullband Bandwidth = C.OPUS_BANDWIDTH_FULLBAND )
func PacketGetBandwidth ¶
Gets the bandwidth of an Opus packet.
type Decoder ¶
type Decoder C.struct_OpusDecoder
Decoder is a opus decoder
func NewDecoder ¶
NewDecoder Allocates and initializes an decoder state.
func (*Decoder) DecodeFloat32 ¶
Decodes an Opus frame from floating point input.
func (*Decoder) DecodeInt16 ¶
Decodes a opus frame from pcm input
func (*Decoder) GetFinalRange ¶
Gets the final state of the codec's entropy coder.
func (*Decoder) GetNbSamples ¶
Gets the number of samples of an Opus packet.
func (*Decoder) Pitch ¶
Gets the pitch of the last decoded frame, if available. This can be used for any post-processing algorithm requiring the use of pitch, e.g. time stretching/shortening. If the last frame was not voiced, or if the pitch was not coded in the frame, then zero is returned. This CTL is only implemented for decoder instances.
func (*Decoder) Reset ¶
func (e *Decoder) Reset()
Resets the codec state to be equivalent to a freshly initialized state. This should be called when switching streams in order to prevent the back to back decoding from giving different results from one at a time decoding.
func (*Decoder) SetGain ¶
Configures decoder gain adjustment. Scales the decoded output by a factor specified in Q8 dB units. This has a maximum range of -32768 to 32767 inclusive, and returns OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. This setting survives decoder reset. gain = pow(10, x/(20.0*256))
type Encoder ¶
type Encoder C.struct_OpusEncoder
Encoder is a opus encoder
func NewEncoder ¶
func NewEncoder(sampleRate int, channels int, application Application) (*Encoder, error)
NewEncoder Allocates and initializes an encoder state.
func (*Encoder) Application ¶
func (e *Encoder) Application() Application
Gets the encoder's configured application.
func (*Encoder) Complexity ¶
Gets the encoder's complexity configuration.
func (*Encoder) EncodeFloat32 ¶
Encodes an Opus frame from floating point input.
func (*Encoder) EncodeInt16 ¶
Encodes a opus frame from pcm input
func (*Encoder) ForceChannels ¶
Gets the encoder's forced channel configuration.
func (*Encoder) GetFinalRange ¶
Gets the final state of the codec's entropy coder.
func (*Encoder) LastPacketDuration ¶
Gets the duration (in samples) of the last packet successfully decoded or concealed.
func (*Encoder) Lookahead ¶
Gets the total samples of delay added by the entire codec. This can be queried by the encoder and then the provided number of samples can be skipped on from the start of the decoder's output to provide time aligned input and output. From the perspective of a decoding application the real data begins this many samples late. The decoder contribution to this delay is identical for all decoders, but the encoder portion of the delay may vary from implementation to implementation, version to version, or even depend on the encoder's initial configuration. Applications needing delay compensation should call this CTL rather than hard-coding a value.
func (*Encoder) MaxBandwidth ¶
Gets the encoder's configured maximum allowed bandpass.
func (*Encoder) PacketLossPerc ¶
Gets the encoder's configured packet loss percentage.
func (*Encoder) Reset ¶
func (e *Encoder) Reset()
Resets the codec state to be equivalent to a freshly initialized state. This should be called when switching streams in order to prevent the back to back decoding from giving different results from one at a time decoding.
func (*Encoder) SampleRate ¶
Gets the sampling rate the encoder or decoder was initialized with. This simply returns the frameSize value passed to NewEncoder()
func (*Encoder) SetApplication ¶
func (e *Encoder) SetApplication(v Application)
Configures the encoder's intended application. The initial value is a mandatory argument to the encoder_create function.
func (*Encoder) SetBandwidth ¶
Sets the encoder's bandpass to a specific value. This prevents the encoder from automatically selecting the bandpass based on the available bitrate. If an application knows the bandpass of the input audio it is providing, it should normally use OPUS_SET_MAX_BANDWIDTH instead, which still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.
func (*Encoder) SetBitrate ¶
Configures the bitrate in the encoder. Rates from 500 to 512000 bits per second are meaningful, as well as the special values OPUS_AUTO and OPUS_BITRATE_MAX. The value OPUS_BITRATE_MAX can be used to cause the codec to use as much rate as it can, which is useful for controlling the rate by adjusting the output buffer size.
func (*Encoder) SetComplexity ¶
Configures the encoder's computational complexity. The supported range is 0-10 inclusive with 10 representing the highest complexity.
func (*Encoder) SetForceChannels ¶
Configures mono/stereo forcing in the encoder. This can force the encoder to produce packets encoded as either mono or stereo, regardless of the format of the input audio. This is useful when the caller knows that the input signal is currently a mono source embedded in a stereo stream. Auto is applicable
func (*Encoder) SetInbandFEC ¶
Configures the encoder's use of inband forward error correction (FEC). Note: This is only applicable to the LPC layer
func (*Encoder) SetLSBDepth ¶
Configures the depth of signal being encoded. This is a hint which helps the encoder identify silence and near-silence.
func (*Encoder) SetMaxBandwidth ¶
Configures the maximum bandpass that the encoder will select automatically. Applications should normally use this instead of OPUS_SET_BANDWIDTH (leaving that set to the default, OPUS_AUTO). This allows the application to set an upper bound based on the type of input it is providing, but still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.
func (*Encoder) SetPacketLossPerc ¶
Configures the encoder's expected packet loss percentage. Higher values with trigger progressively more loss resistant behavior in the encoder at the expense of quality at a given bitrate in the lossless case, but greater quality under loss.
func (*Encoder) SetSignal ¶
Configures the type of signal being encoded. This is a hint which helps the encoder's mode selection.
func (*Encoder) SetVBR ¶
Enables or disables variable bitrate (VBR) in the encoder. The configured bitrate may not be met exactly because frames must be an integer number of bytes in length. Warning: Only the MDCT mode of Opus can provide hard CBR behavior.
func (*Encoder) SetVBRConstraint ¶
Enables or disables constrained VBR in the encoder. This setting is ignored when the encoder is in CBR mode. Warning: Only the MDCT mode of Opus currently heeds the constraint. Speech mode ignores it completely, hybrid mode may fail to obey it if the LPC layer uses more bitrate than the constraint would have permitted.
func (*Encoder) VBRConstraint ¶
Configures the encoder's intended application. The initial value is a mandatory argument to the encoder_create function.
type Error ¶
type Error int
Error represents a Opus Error
const ( //No Error OK Error = C.OPUS_OK //One or more invalid/out of range arguments BadArg Error = C.OPUS_BAD_ARG // The mode struct passed is invalid BufferToSmall Error = C.OPUS_BUFFER_TOO_SMALL // An internal error was detected InternalError Error = C.OPUS_INTERNAL_ERROR // The compressed data passed is corrupted InvalidPacket Error = C.OPUS_INVALID_PACKET // Invalid/unsupported request number Unimplemented Error = C.OPUS_UNIMPLEMENTED // An encoder or decoder structure is invalid or already freed InvalidState Error = C.OPUS_INVALID_STATE // Memory allocation has failed AllocFail Error = C.OPUS_ALLOC_FAIL )
type Repacketizer ¶
type Repacketizer C.struct_OpusRepacketizer
The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged.
func NewRepacketizer ¶
func NewRepacketizer() *Repacketizer
Allocates memory and initializes the new repacketizer with opus_repacketizer_init().
func (*Repacketizer) Cat ¶
func (e *Repacketizer) Cat(data []byte) error
Add a packet to the current repacketizer state. This packet must match the configuration of any packets already submitted for repacketization since the last call to opus_repacketizer_init(). This means that it must have the same coding mode, audio bandwidth, frame size, and channel count. This can be checked in advance by examining the top 6 bits of the first byte of the packet, and ensuring they match the top 6 bits of the first byte of any previously submitted packet. The total duration of audio in the repacketizer state also must not exceed 120 ms, the maximum duration of a single packet, after adding this packet. The contents of the current repacketizer state can be extracted into new packets using opus_repacketizer_out() or opus_repacketizer_out_range(). In order to add a packet with a different configuration or to add more audio beyond 120 ms, you must clear the repacketizer state by calling opus_repacketizer_init(). If a packet is too large to add to the current repacketizer state, no part of it is added, even if it contains multiple frames, some of which might fit. If you wish to be able to add parts of such packets, you should first use another repacketizer to split the packet into pieces and add them individually.
func (*Repacketizer) GetNBFrames ¶
func (e *Repacketizer) GetNBFrames() int
Return the total number of frames contained in packet data submitted to the repacketizer state so far via opus_repacketizer_cat() since the last call to opus_repacketizer_init() or opus_repacketizer_create(). This defines the valid range of packets that can be extracted with opus_repacketizer_out_range() or opus_repacketizer_out().
func (*Repacketizer) Out ¶
func (e *Repacketizer) Out(maxlen int) ([]byte, error)
Construct a new packet from data previously submitted to the repacketizer state via opus_repacketizer_cat(). This is a convenience routine that returns all the data submitted so far in a single packet. It is equivalent to calling OutRange(0,GetNBFrames(),maxlen)
type Signal ¶
type Signal int
const ( //Signal being encoded is voice SignalVoice Signal = C.OPUS_SIGNAL_VOICE //Signal being encoded is music SignalMusic Signal = C.OPUS_SIGNAL_MUSIC )