audioformats

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 4 Imported by: 0

README

in the audioformats folder are all audio Codecs with Decoder and if neccessary Encoder. Currently only opus codec is in here.

Documentation

Overview

go wrapper for c opus library. All c functions have a 'w' prefix (wrapper function)

Index

Constants

View Source
const (
	CODEC_OPUS = iota
	CODEC_VORBIS
	CODEC_UNKNOWN
)
View Source
const (
	// Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
	OPUS_APPICATION_VOIP = 2048

	// Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input
	OPUS_APPLICATION_AUDIO = 2049

	// Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
	OPUS_APPLICATION_RESTRICTEDLOWDELAY = 2051

	// Signal being encoded is voice
	OPUS_SIGNAL_VOICE = 3001
	// Signal being encoded is music
	OPUS_SIGNAL_MUSIC = 3002
)

Possible constants to use

View Source
const (
	// samplerate of 48kHz is opus default setting
	OPUS_SAMPLE_RATE = 48000

	// number of channels to use (2 for Stereo, 1 for Mono).
	OPUS_CHANNELS = 2

	//OPUS_BITRATE=128000 // Opus at 128 KB/s (VBR) is pretty much transparentk
	//-1 means MAX_BITRATE
	// MAX_BITRATE means libopus will use as much space it can put in opus packets. So it's controlled by the MAX_PACKET_SIZE in some way.
	OPUS_BITRATE = 40000

	// size in pcm samples (1 sample is int16) (2 bytes = 1 sample) (480 frame_size = 960 bytes
	// samplerate * frame_duration = frame_size = number of pcm sampels in one frame per channel
	OPUS_PCM_FRAME_SIZE = 480 // 48000*10ms = 480
	OPUS_FRAME_DURATION = 10  // 10 ms

	// The Application to use for opus. libopus will automatically
	OPUS_APPLICATION = OPUS_APPLICATION_AUDIO

	// Variable Bit Rate, if set to one libopus will automatically change the bitrate as it sees fit.
	OPUS_VBR = 0
)

Settings for encoding to opus

Variables

This section is empty.

Functions

func GetPacketFrameSize

func GetPacketFrameSize(samplerate int, packet []byte) (int, error)

get the frame size from an opus packet

Types

type Codec

type Codec int

type OpusDecoder

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

func NewOpusDecoder

func NewOpusDecoder(samplerate int32, channels int) (*OpusDecoder, error)

func (*OpusDecoder) Decode

func (dec *OpusDecoder) Decode(opus []byte) ([]int16, error)

type OpusEncoder

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

func NewOpusEncoder

func NewOpusEncoder() (*OpusEncoder, error)

[in] Fs opus_int32: Sampling rate of input signal (Hz) This must be one of 8000, 12000, 16000, 24000, or 48000. [in] channels int: Number of channels (1 or 2) in input signal [in] application int: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY). This parameter is currently ignored and instead OPUS_APPLICATION_AUDIO will be used [out] error int*: Error codes

func (*OpusEncoder) CtlSetBitrate

func (enc *OpusEncoder) CtlSetBitrate(bitrate int) error

func (*OpusEncoder) CtlSetVbr

func (enc *OpusEncoder) CtlSetVbr(vbr int) error

func (*OpusEncoder) Encode

func (enc *OpusEncoder) Encode(pcm []int16) ([]byte, error)

[in] st OpusEncoder*: Encoder state [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16) [in] frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, and 2880. Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes. [out] data unsigned char*: Output payload. This must contain storage for at least max_data_bytes. [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use OPUS_SET_BITRATE to control the bitrate. returns The length of the encoded packet (in bytes) on success or a negative error code (see Error codes) on failure.

Jump to

Keyboard shortcuts

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