From 9d3d4674d790a3f9b44ca46db726ce001fc0e413 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 19 Feb 2019 23:27:00 +0100 Subject: [PATCH] Optimize A-Law and Mu-Law compressors --- sdrbase/audio/audiocompressor.cpp | 10 +++++----- sdrbase/audio/audiocompressor.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdrbase/audio/audiocompressor.cpp b/sdrbase/audio/audiocompressor.cpp index 65e901cce..55235c8fe 100644 --- a/sdrbase/audio/audiocompressor.cpp +++ b/sdrbase/audio/audiocompressor.cpp @@ -86,15 +86,15 @@ void AudioCompressor::fillLUT2() void AudioCompressor::fillALaw() { - for (int i=-32768; i<32768; i++) { - m_lut[i+32768] = ALaw_Encode(i); + for (int i=-16384; i<16384; i++) { + m_lut[i+16384] = ALaw_Encode(2*i); } } void AudioCompressor::fillULaw() { - for (int i=-32768; i<32768; i++) { - m_lut[i+32768] = MuLaw_Encode(i); + for (int i=-16384; i<16384; i++) { + m_lut[i+16384] = MuLaw_Encode(2*i); } } @@ -107,7 +107,7 @@ int16_t AudioCompressor::compress(int16_t sample) int8_t AudioCompressor::compress8(int16_t sample) { - return m_lut[sample + 32768]; + return m_lut[sample/2 + 16384]; } /* http://dystopiancode.blogspot.com/2012/02/pcm-law-and-u-law-companding-algorithms.html diff --git a/sdrbase/audio/audiocompressor.h b/sdrbase/audio/audiocompressor.h index 0e924e1f4..5ad144ad5 100644 --- a/sdrbase/audio/audiocompressor.h +++ b/sdrbase/audio/audiocompressor.h @@ -37,7 +37,7 @@ private: int8_t ALaw_Encode(int16_t number); int8_t MuLaw_Encode(int16_t number); - int16_t m_lut[65536]; + int16_t m_lut[32768]; static const uint16_t ALAW_MAX; static const uint16_t MULAW_MAX; static const uint16_t MULAW_BIAS;