Documentation
¶
Index ¶
- Constants
- func Downsample16to8(samples16k []int16) []byte
- func Downsample48to8(samples48k []int16) []byte
- func Upsample8to16(pcm8k []byte) []int16
- func Upsample8to48(pcm8k []byte) []int16
- type CodecType
- type Decoder
- type Encoder
- type G722Decoder
- type G722DecoderReader
- type G722Encoder
- type G722EncoderWriter
- type OpusDecoder
- type OpusEncoder
- type PCMADecoder
- type PCMAEncoder
- type PCMUDecoder
- type PCMUEncoder
Constants ¶
const RTPBufSize = 1500
RTPBufSize is the maximum RTP packet buffer size.
Variables ¶
This section is empty.
Functions ¶
func Downsample16to8 ¶
Downsample16to8 converts 16kHz int16 samples to 8kHz 16-bit LE PCM bytes by taking every other sample.
func Downsample48to8 ¶
Downsample48to8 converts 48kHz int16 samples to 8kHz 16-bit LE PCM bytes by taking every 6th sample.
func Upsample8to16 ¶
Upsample8to16 converts 8kHz 16-bit LE PCM bytes to 16kHz int16 samples by duplicating each sample (zero-order hold).
func Upsample8to48 ¶
Upsample8to48 converts 8kHz 16-bit LE PCM bytes to 48kHz int16 samples by duplicating each sample 6 times (zero-order hold).
Types ¶
type CodecType ¶
type CodecType int
CodecType identifies a supported audio codec.
const ( CodecUnknown CodecType = iota CodecPCMU // PT=0, 8kHz CodecPCMA // PT=8, 8kHz CodecG722 // PT=9, 16kHz internal / 8kHz SDP clock (RFC 3551) CodecOpus // PT=111 (dynamic), 48kHz CodecAMRWB // PT=96 (dynamic), 16kHz (G.722.2, RFC 4867) CodecAMRNB // PT=97 (dynamic), 8kHz (AMR narrowband, RFC 4867) )
func CodecTypeFromName ¶
CodecTypeFromName looks up a CodecType by name (case-insensitive).
func CodecTypeFromPT ¶
CodecTypeFromPT looks up a CodecType by RTP payload type number.
func (CodecType) ClockRate ¶
ClockRate returns the SDP clock rate. Per RFC 3551, G.722 uses 8000 in SDP despite encoding at 16kHz.
func (CodecType) PayloadType ¶
PayloadType returns the RTP payload type number for this codec.
func (CodecType) SampleRate ¶
SampleRate returns the actual internal sample rate.
type Decoder ¶
Decoder decodes compressed codec data to PCM samples.
func NewAMRNBDecoder ¶ added in v0.9.0
NewAMRNBDecoder creates an AMR-NB decoder for the given payload format.
func NewAMRWBDecoder ¶ added in v0.9.0
NewAMRWBDecoder creates an AMR-WB decoder for the given payload format.
func NewDecoder ¶
NewDecoder creates a Decoder for the given codec type.
type Encoder ¶
Encoder encodes PCM samples to compressed codec data.
func NewAMRNBEncoder ¶ added in v0.9.0
NewAMRNBEncoder creates an AMR-NB encoder for the given speech mode (0..7) and payload format (octetAligned=false selects bandwidth-efficient framing).
func NewAMRWBEncoder ¶ added in v0.9.0
NewAMRWBEncoder creates an AMR-WB encoder for the given speech mode (0..8) and payload format (octetAligned=false selects bandwidth-efficient framing).
func NewEncoder ¶
NewEncoder creates an Encoder for the given codec type.
type G722Decoder ¶
type G722Decoder struct {
// contains filtered or unexported fields
}
G722Decoder decodes G.722 encoded data to 16kHz 16-bit PCM samples.
func NewG722Decoder ¶
func NewG722Decoder() *G722Decoder
NewG722Decoder creates a new G.722 decoder with initial state.
func (*G722Decoder) Decode ¶
func (d *G722Decoder) Decode(data []byte) ([]int16, error)
Decode decodes G.722 data to 16kHz PCM samples. Each input byte produces 2 output samples.
func (*G722Decoder) Reset ¶
func (d *G722Decoder) Reset()
Reset resets the decoder to its initial state.
type G722DecoderReader ¶
G722DecoderReader reads G.722 encoded data from Source and produces 8kHz 16-bit LE PCM. Internally decodes to 16kHz then downsamples.
func NewG722DecoderReader ¶
func NewG722DecoderReader(source io.Reader) *G722DecoderReader
NewG722DecoderReader creates a reader that decodes G.722 to 8kHz PCM.
type G722Encoder ¶
type G722Encoder struct {
// contains filtered or unexported fields
}
G722Encoder encodes 16kHz 16-bit PCM samples to G.722.
func NewG722Encoder ¶
func NewG722Encoder() *G722Encoder
NewG722Encoder creates a new G.722 encoder with initial state.
func (*G722Encoder) Encode ¶
func (e *G722Encoder) Encode(samples []int16) ([]byte, error)
Encode encodes 16kHz PCM samples to G.722 data. Input samples must be in pairs (2 samples per encoded byte).
func (*G722Encoder) Reset ¶
func (e *G722Encoder) Reset()
Reset resets the encoder to its initial state.
type G722EncoderWriter ¶
G722EncoderWriter accepts 8kHz 16-bit LE PCM and writes G.722 encoded data.
func NewG722EncoderWriter ¶
func NewG722EncoderWriter(writer io.Writer) *G722EncoderWriter
NewG722EncoderWriter creates a writer that encodes 8kHz PCM to G.722.
type OpusDecoder ¶
type OpusDecoder struct {
// contains filtered or unexported fields
}
OpusDecoder wraps a gopus Decoder for 48kHz mono.
func NewOpusDecoder ¶
func NewOpusDecoder() (*OpusDecoder, error)
NewOpusDecoder creates a new Opus decoder configured for 48kHz mono.
type OpusEncoder ¶
type OpusEncoder struct {
// contains filtered or unexported fields
}
OpusEncoder wraps a gopus Encoder for 48kHz mono VoIP.
func NewOpusEncoder ¶
func NewOpusEncoder() (*OpusEncoder, error)
NewOpusEncoder creates a new Opus encoder configured for 48kHz mono VoIP.
func (*OpusEncoder) Encode ¶
func (e *OpusEncoder) Encode(samples []int16) (out []byte, err error)
Encode encodes 48kHz int16 PCM samples to an Opus packet. Panics in the underlying codec are converted to errors so one bad frame fails just the leg, not the process.
func (*OpusEncoder) SetBitrate ¶ added in v0.6.0
func (e *OpusEncoder) SetBitrate(bps int) error
SetBitrate adjusts the target bitrate in bits per second (gopus accepts 6_000..510_000). Used by transports that want a tighter rate than the library default.
type PCMADecoder ¶
type PCMADecoder struct{}
PCMADecoder decodes G.711 A-law to 16-bit linear PCM. Stateless — one sample per byte.
func (*PCMADecoder) Reset ¶
func (d *PCMADecoder) Reset()
type PCMAEncoder ¶
type PCMAEncoder struct{}
PCMAEncoder encodes 16-bit linear PCM to G.711 A-law. Stateless — one byte per sample.
func (*PCMAEncoder) Reset ¶
func (e *PCMAEncoder) Reset()
type PCMUDecoder ¶
type PCMUDecoder struct{}
PCMUDecoder decodes G.711 mu-law to 16-bit linear PCM. Stateless — one sample per byte.
func (*PCMUDecoder) Reset ¶
func (d *PCMUDecoder) Reset()
type PCMUEncoder ¶
type PCMUEncoder struct{}
PCMUEncoder encodes 16-bit linear PCM to G.711 mu-law. Stateless — one byte per sample.
func (*PCMUEncoder) Reset ¶
func (e *PCMUEncoder) Reset()
Directories
¶
| Path | Synopsis |
|---|---|
|
Package t140 implements ITU-T T.140 real-time text packetization with the RFC 4103 RTP payload format and optional RFC 2198 redundancy (text/red).
|
Package t140 implements ITU-T T.140 real-time text packetization with the RFC 4103 RTP payload format and optional RFC 2198 redundancy (text/red). |