opus

package module
v0.0.0-...-5105b27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 5 Imported by: 3

README


Pion Opus

Pure Go implementation of the Opus Codec

Opus Slack Widget
GitHub Workflow Status Go Reference Coverage Status Go Report Card


This package provides a Pure Go implementation of the Opus Codec

Why Opus?

  • open and royalty-free - No license fees or restrictions. Use it as you wish!
  • versatile - Wide bitrate support. Can be used in constrained networks and high quality stereo.
  • ubiquitous - Used in video streaming, gaming, storing music and video conferencing.

Why a Go implementation?

  • empower interesting use cases - This project also exports the internals of the Encoder and Decoder. Allowing for things like analysis of a Opus bitstream without decoding the entire thing.
  • learning - This project was written to be read by others. It includes excerpts and links to RFC 6716
  • safety - Go provides memory safety. Avoids a class of bugs that are devastating in sensitive environments.
  • maintainability - Go was designed to build simple, reliable, and efficient software.
  • inspire - Go is a power language, but lacking in media libraries. We hope this project inspires the next generation to build more media libraries for Go.

You can read more here

RFCs

Implemented

Running

See our examples for demonstrations of how to use this package.

Roadmap

The library is used as a part of our WebRTC implementation. Please refer to that roadmap to track our major milestones.

See also Issue 9

Community

Pion has an active community on the Slack.

Follow the Pion Twitter for project updates and important WebRTC news.

We are always looking to support your projects. Please reach out if you have something to build! If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible

License

MIT License - see LICENSE for full text

Documentation

Overview

Package opus provides a Opus Audio Codec RFC 6716 implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bandwidth

type Bandwidth byte

The Bandwidth the Opus codec scales from 6 kbit/s narrowband mono speech to 510 kbit/s fullband stereo music, with algorithmic delays ranging from 5 ms to 65.2 ms. At any given time, either the LP layer, the MDCT layer, or both, may be active. It can seamlessly switch between all of its various operating modes, giving it a great deal of flexibility to adapt to varying content and network conditions without renegotiating the current session. The codec allows input and output of various audio bandwidths, defined as follows: +----------------------+-----------------+-------------------------+ | Abbreviation | Audio Bandwidth | Sample Rate (Effective) | +----------------------+-----------------+-------------------------+ | NB (narrowband) | 4 kHz | 8 kHz | | | | | | MB (medium-band) | 6 kHz | 12 kHz | | | | | | WB (wideband) | 8 kHz | 16 kHz | | | | | | SWB (super-wideband) | 12 kHz | 24 kHz | | | | | | FB (fullband) | 20 kHz (*) | 48 kHz | +----------------------+-----------------+-------------------------+

https://datatracker.ietf.org/doc/html/rfc6716#section-2

const (
	BandwidthNarrowband Bandwidth = iota + 1
	BandwidthMediumband
	BandwidthWideband
	BandwidthSuperwideband
	BandwidthFullband
)

Bandwidth constants.

func (Bandwidth) SampleRate

func (b Bandwidth) SampleRate() int

SampleRate returns the effective SampleRate for a given bandwidth.

func (Bandwidth) String

func (b Bandwidth) String() string

type Configuration

type Configuration byte

Configuration numbers in each range (e.g., 0...3 for NB SILK- only) correspond to the various choices of frame size, in the same order. For example, configuration 0 has a 10 ms frame size and configuration 3 has a 60 ms frame size. +-----------------------+-----------+-----------+-------------------+ | Configuration | Mode | Bandwidth | Frame Sizes | | Number(s) | | | | +-----------------------+-----------+-----------+-------------------+ | 0...3 | SILK-only | NB | 10, 20, 40, 60 ms | | | | | | | 4...7 | SILK-only | MB | 10, 20, 40, 60 ms | | | | | | | 8...11 | SILK-only | WB | 10, 20, 40, 60 ms | | | | | | | 12...13 | Hybrid | SWB | 10, 20 ms | | | | | | | 14...15 | Hybrid | FB | 10, 20 ms | | | | | | | 16...19 | CELT-only | NB | 2.5, 5, 10, 20 ms | | | | | | | 20...23 | CELT-only | WB | 2.5, 5, 10, 20 ms | | | | | | | 24...27 | CELT-only | SWB | 2.5, 5, 10, 20 ms | | | | | | | 28...31 | CELT-only | FB | 2.5, 5, 10, 20 ms | +-----------------------+-----------+-----------+-------------------+

https://datatracker.ietf.org/doc/html/rfc6716#section-3.1

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes the Opus bitstream into PCM.

func NewDecoder

func NewDecoder() Decoder

NewDecoder creates a new Opus Decoder.

func (*Decoder) Decode

func (d *Decoder) Decode(in, out []byte) (bandwidth Bandwidth, isStereo bool, err error)

Decode decodes the Opus bitstream into S16LE PCM.

func (*Decoder) DecodeFloat32

func (d *Decoder) DecodeFloat32(in []byte, out []float32) (bandwidth Bandwidth, isStereo bool, err error)

DecodeFloat32 decodes the Opus bitstream into F32LE PCM.

Directories

Path Synopsis
examples
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL