ik5 / g711

Go package to encode and decode ITU-T G.711 sound data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

g711

-- import "github.com/zaf/g711"

Package g711 implements encoding and decoding of G711 PCM sound data. G.711 is an ITU-T standard for audio companding.

For usage details please see the code snippets in the cmd folder.

Usage

const (
	// Input and output formats
	Alaw = iota // Alaw G711 encoded PCM data
	Ulaw        // Ulaw G711  encoded PCM data
	Lpcm        // Lpcm 16bit signed linear data
)

func Alaw2Ulaw

func Alaw2Ulaw(alaw []byte) []byte

Alaw2Ulaw performs direct A-law to u-law data conversion

func Alaw2UlawFrame

func Alaw2UlawFrame(frame uint8) uint8

Alaw2UlawFrame directly converts an A-law frame to u-law

func DecodeAlaw

func DecodeAlaw(pcm []byte) []byte

DecodeAlaw decodes A-law PCM data to 16bit LPCM

func DecodeAlawFrame

func DecodeAlawFrame(frame uint8) int16

DecodeAlawFrame decodes an A-law PCM frame to 16bit LPCM

func DecodeUlaw

func DecodeUlaw(pcm []byte) []byte

DecodeUlaw decodes u-law PCM data to 16bit LPCM

func DecodeUlawFrame

func DecodeUlawFrame(frame uint8) int16

DecodeUlawFrame decodes a u-law PCM frame to 16bit LPCM

func EncodeAlaw

func EncodeAlaw(lpcm []byte) []byte

EncodeAlaw encodes 16bit LPCM data to G711 A-law PCM

func EncodeAlawFrame

func EncodeAlawFrame(frame int16) uint8

EncodeAlawFrame encodes a 16bit LPCM frame to G711 A-law PCM

func EncodeUlaw

func EncodeUlaw(lpcm []byte) []byte

EncodeUlaw encodes 16bit LPCM data to G711 u-law PCM

func EncodeUlawFrame

func EncodeUlawFrame(frame int16) uint8

EncodeUlawFrame encodes a 16bit LPCM frame to G711 u-law PCM

func Ulaw2Alaw

func Ulaw2Alaw(ulaw []byte) []byte

Ulaw2Alaw performs direct u-law to A-law data conversion

func Ulaw2AlawFrame

func Ulaw2AlawFrame(frame uint8) uint8

Ulaw2AlawFrame directly converts a u-law frame to A-law

type Decoder

type Decoder struct {
}

Decoder reads G711 PCM data and decodes it to 16bit 8000Hz LPCM

func NewAlawDecoder

func NewAlawDecoder(reader io.Reader) (*Decoder, error)

NewAlawDecoder returns a pointer to a Decoder that implements an io.Reader. It takes as input the source data Reader.

func NewUlawDecoder

func NewUlawDecoder(reader io.Reader) (*Decoder, error)

NewUlawDecoder returns a pointer to a Decoder that implements an io.Reader. It takes as input the source data Reader.

func (*Decoder) Read

func (r *Decoder) Read(p []byte) (i int, err error)

Read decodes G711 data. Reads up to len(p) bytes into p, returns the number of bytes read and any error encountered.

func (*Decoder) Reset

func (r *Decoder) Reset(reader io.Reader) error

Reset discards the Decoder state. This permits reusing a Decoder rather than allocating a new one.

type Encoder

type Encoder struct {
}

Encoder encodes 16bit 8000Hz LPCM data to G711 PCM or directly transcodes between A-law and u-law

func NewAlawEncoder

func NewAlawEncoder(writer io.Writer, input int) (*Encoder, error)

NewAlawEncoder returns a pointer to an Encoder that implements an io.Writer. It takes as input the destination data Writer and the input encoding format.

func NewUlawEncoder

func NewUlawEncoder(writer io.Writer, input int) (*Encoder, error)

NewUlawEncoder returns a pointer to an Encoder that implements an io.Writer. It takes as input the destination data Writer and the input encoding format.

func (*Encoder) Reset

func (w *Encoder) Reset(writer io.Writer) error

Reset discards the Encoder state. This permits reusing an Encoder rather than allocating a new one.

func (*Encoder) Write

func (w *Encoder) Write(p []byte) (i int, err error)

Write encodes G711 Data. Writes len(p) bytes from p to the underlying data stream, returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early.

About

Go package to encode and decode ITU-T G.711 sound data

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 100.0%