8000 GitHub - hujinhai/gobcg729: Go Bindings for the bcg729 C library · GitHub
[go: up one dir, main page]

Skip to content
hujinhaiPublic
forked from novartc/gobcg729

About

Go Bindings for the bcg729 C library

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobcg729

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.

Features

  • 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.

Prerequisites

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-dev

Installation

go get github.com/novartc/gobcg729

Usage

Encoding (PCM to G.729)

package 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)
}

Decoding (G.729 to PCM)

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))
}

API Reference

Encoder

  • 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).

Decoder

  • 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).

About

Go Bindings for the bcg729 C library

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0