Documentation
¶
Overview ¶
Package opus provides a Pure Go implementation of the Opus audio codec. This implementation is based on the official libopus reference implementation and aims for complete compatibility without using CGO.
Index ¶
- Constants
- Variables
- type Application
- type Decoder
- type Encoder
- func (e *Encoder) Encode(pcm []int16, frameSize int) ([]byte, error)
- func (e *Encoder) EncodeFloat(pcm []float64, frameSize int) ([]byte, error)
- func (e *Encoder) Reset() error
- func (e *Encoder) SetApplication(application Application)
- func (e *Encoder) SetBitrate(bitrate int) error
- func (e *Encoder) SetComplexity(complexity int) error
- func (e *Encoder) SetVBR(vbr bool)
Constants ¶
const ( Version = "0.1.0" VersionMajor = 0 VersionMinor = 1 VersionPatch = 0 )
Opus version constants
const ( SampleRate8kHz = 8000 SampleRate12kHz = 12000 SampleRate16kHz = 16000 SampleRate24kHz = 24000 SampleRate48kHz = 48000 )
Sample rates supported by Opus
const ( FrameSize2_5ms = 120 // 2.5ms at 48kHz FrameSize5ms = 240 // 5ms at 48kHz FrameSize10ms = 480 // 10ms at 48kHz FrameSize20ms = 960 // 20ms at 48kHz (most common) FrameSize40ms = 1920 // 40ms at 48kHz FrameSize60ms = 2880 // 60ms at 48kHz )
Frame sizes in samples (at 48kHz)
const ( ApplicationVOIP = 2048 // Voice over IP ApplicationAudio = 2049 // General audio ApplicationRestrictedLowDelay = 2051 // Lowest latency )
Application types
const ( BandwidthNarrowband = 1101 // 4kHz BandwidthMediumband = 1102 // 6kHz BandwidthWideband = 1103 // 8kHz BandwidthSuperWideband = 1104 // 12kHz BandwidthFullband = 1105 // 20kHz )
Bandwidth types
const ( ChannelsMono = 1 ChannelsStereo = 2 )
Channel modes
const ( ModeSILKOnly = 1000 ModeHybrid = 1001 ModeCELTOnly = 1002 )
Opus modes (internal)
const ( BitrateAuto = -1000 BitrateMax = -1 BitrateMin = 500 // 500 bps BitrateMaxVal = 512000 // 512 kbps )
Bitrate constants
const ( SetBitrateRequest = 4002 GetBitrateRequest = 4003 SetForceChannelsRequest = 4022 GetForceChannelsRequest = 4023 SetMaxBandwidthRequest = 4004 GetMaxBandwidthRequest = 4005 SetBandwidthRequest = 4008 GetBandwidthRequest = 4009 SetComplexityRequest = 4010 GetComplexityRequest = 4011 SetInbandFECRequest = 4012 GetInbandFECRequest = 4013 SetPacketLossPercRequest = 4014 GetPacketLossPercRequest = 4015 SetDTXRequest = 4016 GetDTXRequest = 4017 SetVBRRequest = 4006 GetVBRRequest = 4007 SetVBRConstraintRequest = 4020 GetVBRConstraintRequest = 4021 SetSignalRequest = 4024 GetSignalRequest = 4025 SetApplicationRequest = 4000 GetApplicationRequest = 4001 GetLookaheadRequest = 4027 SetExpertFrameDurationRequest = 4040 GetExpertFrameDurationRequest = 4041 SetPredictionDisabledRequest = 4042 GetPredictionDisabledRequest = 4043 ResetStateRequest = 4028 )
Encoder/Decoder control codes (CTL)
const ( SignalAuto = -1000 SignalVoice = 3001 SignalMusic = 3002 )
Signal types
const ( ComplexityMin = 0 ComplexityMax = 10 ComplexityDefault = 9 )
Complexity (0-10)
const ( PacketLossPercMin = 0 PacketLossPercMax = 100 )
Packet loss percentage (0-100)
const ( MaxPacketSize = 1500 // bytes MaxFrameSize = 2880 // samples at 48kHz for 60ms )
Maximum packet size
Variables ¶
var ( // ErrBadArg indicates that one or more arguments are invalid ErrBadArg = errors.New("opus: bad argument") // ErrBufferTooSmall indicates that the provided buffer is too small ErrBufferTooSmall = errors.New("opus: buffer too small") // ErrInternalError indicates an internal error occurred ErrInternalError = errors.New("opus: internal error") // ErrInvalidPacket indicates the packet is invalid or corrupted ErrInvalidPacket = errors.New("opus: invalid packet") // ErrUnimplemented indicates a feature is not yet implemented ErrUnimplemented = errors.New("opus: unimplemented") // ErrInvalidState indicates the encoder/decoder is in an invalid state ErrInvalidState = errors.New("opus: invalid state") // ErrAllocFail indicates memory allocation failed ErrAllocFail = errors.New("opus: allocation failed") // ErrUnsupportedSampleRate indicates the sample rate is not supported ErrUnsupportedSampleRate = errors.New("opus: unsupported sample rate") // ErrUnsupportedChannels indicates the channel count is not supported ErrUnsupportedChannels = errors.New("opus: unsupported number of channels") // ErrUnsupportedFrameSize indicates the frame size is not supported ErrUnsupportedFrameSize = errors.New("opus: unsupported frame size") // ErrUnsupportedBandwidth indicates the bandwidth is not supported ErrUnsupportedBandwidth = errors.New("opus: unsupported bandwidth") )
Common Opus errors
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application = int
Application specifies the encoding mode (use constants from package)
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder represents an Opus decoder instance
func NewDecoder ¶
NewDecoder creates a new Opus decoder
sampleRate must be one of: 8000, 12000, 16000, 24000, 48000 Hz channels must be 1 (mono) or 2 (stereo)
func (*Decoder) Decode ¶
Decode decodes an Opus packet to PCM samples
data is the compressed Opus packet pcm is the output buffer for 16-bit PCM samples Returns the number of samples per channel decoded (clamped to buffer size)
func (*Decoder) DecodeFEC ¶
DecodeFEC decodes forward error correction data This is used for packet loss concealment
func (*Decoder) DecodeFloat ¶
DecodeFloat decodes an Opus packet to floating-point PCM samples
data is the compressed Opus packet Returns float64 samples in range [-1.0, 1.0]
func (*Decoder) GetLastPacketDuration ¶
GetLastPacketDuration returns the duration of the last decoded packet in samples
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder represents an Opus encoder instance
func NewEncoder ¶
func NewEncoder(sampleRate, channels int, application Application) (*Encoder, error)
NewEncoder creates a new Opus encoder
sampleRate must be one of: 8000, 12000, 16000, 24000, 48000 Hz channels must be 1 (mono) or 2 (stereo) application specifies the encoding mode
func (*Encoder) Encode ¶
Encode encodes PCM audio samples
pcm contains interleaved 16-bit PCM samples (left, right, left, right, ...) frameSize is the number of samples per channel (at the encoder's sample rate) Returns compressed Opus packet
func (*Encoder) EncodeFloat ¶
EncodeFloat encodes floating-point PCM samples
pcm contains interleaved float64 samples in range [-1.0, 1.0] frameSize is the number of samples per channel (at the encoder's sample rate)
func (*Encoder) SetApplication ¶
func (e *Encoder) SetApplication(application Application)
SetApplication changes the application mode
func (*Encoder) SetBitrate ¶
SetBitrate sets the target bitrate in bits per second
func (*Encoder) SetComplexity ¶
SetComplexity sets the computational complexity (0-10) Higher values use more CPU but may provide better quality
Directories
¶
| Path | Synopsis |
|---|---|
|
toccheck
command
|
|
|
celt
Package celt implements the CELT (Constrained Energy Lapped Transform) codec.
|
Package celt implements the CELT (Constrained Energy Lapped Transform) codec. |
|
cgoref
Package cgoref is the libopus CGO reference wrapper.
|
Package cgoref is the libopus CGO reference wrapper. |
|
dsp
Package dsp provides digital signal processing utilities for the Opus codec.
|
Package dsp provides digital signal processing utilities for the Opus codec. |
|
entcode
Package entcode provides entropy coding (range coding) for Opus, bit-exact with the range coder in libopus 1.3.1 (celt/entcode.c, celt/entenc.c, celt/entdec.c).
|
Package entcode provides entropy coding (range coding) for Opus, bit-exact with the range coder in libopus 1.3.1 (celt/entcode.c, celt/entenc.c, celt/entdec.c). |
|
resampler
Package resampler provides high-quality sample rate conversion for Opus.
|
Package resampler provides high-quality sample rate conversion for Opus. |
|
silk
Package silk implements the SILK speech codec for Opus.
|
Package silk implements the SILK speech codec for Opus. |
|
testing
Package testing provides verification and comparison tools for Opus library development.
|
Package testing provides verification and comparison tools for Opus library development. |