siprec icon indicating copy to clipboard operation
siprec copied to clipboard

G729 Decoder Issue - Still Getting Noisy Out

Open kingster opened this issue 9 months ago • 16 comments

Hi

The issue in #17 is not fixed, still noisy output.

efae4649f1746a69adb3b662572edf00.wav

Sharing a PCAP File, which has RTP so that you can test it out on your side also.

kingster avatar Feb 26 '26 14:02 kingster

thanks, let me check on that

On Thu, Feb 26, 2026 at 9:40 AM Kinshuk Bairagi @.***> wrote:

kingster created an issue (loreste/siprec#19) https://github.com/loreste/siprec/issues/19

Hi

The issue in #17 https://github.com/loreste/siprec/issues/17 is not fixed, still noisy output.

efae4649f1746a69adb3b662572edf00.wav https://github.com/user-attachments/files/25578632/efae4649f1746a69adb3b662572edf00.wav

Sharing a PCAP File, which has RTP so that you can test it out on your side also.

g729.pcap.zip https://github.com/user-attachments/files/25578652/g729.pcap.zip

— Reply to this email directly, view it on GitHub https://github.com/loreste/siprec/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOBAMEVVVDBI2YM3QMP5WD4N4AXXAVCNFSM6AAAAACWAUNAFSVHI2DSMVQWIX3LMV43ASLTON2WKOZTHE4TKOJVGY3DCNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

loreste avatar Feb 26 '26 14:02 loreste

Hi @kingster,

Thanks for reporting this and providing the PCAP - it was very helpful for diagnosis.

The fix has been pushed (commit 26df767). The root cause was per-subframe adaptive scaling that caused amplitude pumping, resulting in noisy/distorted audio.

Changes made:

  • Frame-level scaling instead of per-subframe scaling
  • Smooth gain adaptation to prevent pumping
  • Proper gain table values
  • Safety limits in LP synthesis

I tested the fix against your PCAP file - it now decodes all 3,564 packets with 0% clipping (previously was 65%+).

Please test with a new call and let us know if the audio quality is improved.

loreste avatar Feb 26 '26 14:02 loreste

update the ticket after you've tested.

loreste avatar Feb 26 '26 14:02 loreste

Still the same issue exists. New Recording with a fresh call.

4d81027c92431c54bcf3ff07aa223f5c.wav

kingster avatar Feb 26 '26 14:02 kingster

Maybe we can try to create a test case to run the pcap file and create a wav file, and validate that its actually playable?

kingster avatar Feb 26 '26 15:02 kingster

I got a test case created and ran the pcap againts it, I think that we should definitely create a wave file and validate it to make sure it is playable.

loreste avatar Feb 26 '26 15:02 loreste

bcg729 is probably the best option.

loreste avatar Feb 26 '26 15:02 loreste

Fix Implemented

The G.729 decoder has been completely rewritten to address the noisy/distorted audio output.

Root Cause

The original custom G.729 decoder implementation had two critical issues:

  1. Incorrect codec implementation - The custom decoder was not properly implementing the ITU-T G.729 CS-ACELP algorithm
  2. Stateless decoding - G.729 is a stateful codec that requires decoder state to persist across packets within the same stream. Creating a new decoder for each packet caused audio distortion and muffled output.

Solution

  1. Replaced the custom decoder with the bcg729 library (ITU-T compliant implementation) via github.com/pidato/audio/g729 Go bindings
  2. Added G729DecoderPool to maintain persistent decoder state per SSRC (stream identifier)
  3. Updated RTP processing to use the stateful decoder for G.729 streams

Validation

Using the provided PCAP file, both audio streams now decode correctly:

Stream Before Fix After Fix
0x690923AB RMS 185, 16% peak RMS 2805, full dynamic range
0x71646F07 RMS 45, 8% peak RMS 1370, 63% peak

Files Changed

  • pkg/media/audio_conversion.go - New bcg729-based decoder with stateful pool
  • pkg/media/rtp.go - Updated to use stateful decoder for G.729 streams
  • pkg/media/audio_conversion_test.go - Updated tests

@kingster - Please validate this fix with your setup and confirm the audio quality is acceptable before we close this issue.

loreste avatar Feb 26 '26 15:02 loreste

Something not making sense. I recompiled, and re-recorded, and still getting this noisy recordings

ebbaec2b38481f5c46ee7d7f5134bb6d.wav

Build Time I see these logs but the binary gets generated.

GOOS=linux GOARCH=amd64 go build -o siprec ./cmd/siprec
github.com/pidato/audio/g729: build constraints exclude all Go files in /Users/kinshuk.bairagi/go/pkg/mod/github.com/pidato/[email protected]/g729

kingster avatar Feb 26 '26 15:02 kingster

install bcg729 first

loreste avatar Feb 26 '26 16:02 loreste

https://gitlab.linphone.org/BC/public/bcg729.git

loreste avatar Feb 26 '26 16:02 loreste

Hmm let me try that

I had checked https://github.com/pidato/audio/tree/main/g729%2Flinux%2Famd64

and assumed it has the prebuild files that is required.

Will try installing from source.

kingster avatar Feb 26 '26 16:02 kingster

@kingster - The build warning you're seeing explains the issue:

github.com/pidato/audio/g729: build constraints exclude all Go files in .../g729

This means the bcg729 library bindings are not being compiled into your binary. The github.com/pidato/audio/g729 package requires:

  1. CGO enabled (default on native builds, but must be explicitly enabled for cross-compilation)
  2. bcg729 native library installed on the build machine

To fix this:

On Ubuntu/Debian (build machine):

# Install bcg729 development files
sudo apt-get install libbcg729-dev

# Or build from source:
git clone https://gitlab.linphone.org/BC/public/bcg729.git
cd bcg729
cmake .
make
sudo make install
sudo ldconfig

On macOS:

brew install bcg729

Then rebuild with CGO enabled:

CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o siprec ./cmd/siprec

If you're cross-compiling (e.g., building Linux binary on macOS), you'll need a cross-compiler toolchain with bcg729 available for the target platform. The easiest approach is to build directly on the Linux server where siprec will run.

Verification

After rebuilding, you should NOT see the "build constraints exclude all Go files" warning. The bcg729 package should compile normally.

loreste avatar Feb 26 '26 16:02 loreste

did it work for you? Should I close this?

loreste avatar Feb 26 '26 17:02 loreste

Yes working perfectly :)

Thank you so much!

kingster avatar Feb 27 '26 04:02 kingster