gobcg729 provides Go bindings for the bcg729 C library. It supports the G.729 audio codec and provides a simple API for converting between PCM data and G.729 bitstreams.
- Supports G.729 encoding and decoding.
- Supports VAD (Voice Activity Detection) / DTX.
- Automatic memory management for C-allocated resources (via
runtime.SetFinalizer). - Compatible with standard G.729 bitstream formats.
Before installing this Go module, the bcg729 development library must be installed on your system.
On Debian/Ubuntu systems, you can install it using:
sudo apt-get install libbcg729-devgo get github.com/novartc/gobcg729package main
import (
"fmt"
"github.com/novartc/gobcg729"
)
func main() {
// Initialize the encoder with VAD enabled
encoder := gobcg729.NewEncoder(true)
defer encoder.Close()
// Prepare 80 samples (160 bytes) of PCM data (int16)
pcm := make([]int16, 80)
// Fill pcm with data...
// Encode
encoded := make([]byte, 10)
n := encoder.Encode(pcm, encoded)
// Depending on the VAD state, n may be 0, 2, or 10 bytes
fmt.Printf("Encoded length: %d bytes\n", n)
}package main
import (
"fmt"
"github.com/novartc/gobcg729"
)
func main() {
// Initialize the decoder
decoder := gobcg729.NewDecoder()
defer decoder.Close()
// Prepare G.729 bitstream data (usually 10 bytes)
bitstream := make([]byte, 10)
// Fill bitstream with data...
// Decode
// Parameters: bitstream, output PCM, frameErasure, SIDFrame, rfc3389Payload
pcm := make([]int16, 80)
decoder.Decode(bitstream, pcm, false, false, false)
fmt.Printf("Decoded %d samples\n", len(pcm))
}NewEncoder(enableVAD bool) *Encoder: Creates a new encoder instance.(e *Encoder) Encode(pcm []int16, bitStream []byte) int: Encodes 80 PCM samples into the provided bitStream. Returns the length of encoded data (0, 2, or 10 bytes). bitStream must be at least 10 bytes.(e *Encoder) Close(): Manually releases resources (optional, handled automatically by GC).
NewDecoder() *Decoder: Creates a new decoder instance.(d *Decoder) Decode(bitStream []byte, pcm []int16, frameErasure bool, SIDFrame bool, rfc3389Payload bool): Decodes a bitstream back into the provided 80 PCM samples. pcm must be at least 80 samples.(d *Decoder) Close(): Manually releases resources (optional, handled automatically by GC).