diff --git a/sdrbase/audio/audiofilter.cpp b/sdrbase/audio/audiofilter.cpp index 5cf963c96..980df959a 100644 --- a/sdrbase/audio/audiofilter.cpp +++ b/sdrbase/audio/audiofilter.cpp @@ -37,14 +37,13 @@ AudioFilter::~AudioFilter() {} -void AudioFilter::setDecimFilters(int sr, uint32_t decim) +void AudioFilter::setDecimFilters(int srHigh, int srLow, float fcHigh, float fcLow) { - int downSR = sr / (decim == 0 ? 1 : decim); - double fcH = (0.45 * downSR) / (sr <= 0 ? 1 : sr); // high cut frequency normalized to SR - double fcL = 300.0 / downSR; // low cut frequency normalized to downsampled SR + double fcNormHigh = fcHigh / srHigh; + double fcNormLow = fcLow / srLow; - calculate2(false, fcH, m_lpva, m_lpvb); - calculate2(true, fcL, m_hpva, m_hpvb); + calculate2(false, fcNormHigh, m_lpva, m_lpvb); + calculate2(true, fcNormLow, m_hpva, m_hpvb); m_filterLP.setCoeffs(m_lpva, m_lpvb); m_filterHP.setCoeffs(m_hpva, m_hpvb); diff --git a/sdrbase/audio/audiofilter.h b/sdrbase/audio/audiofilter.h index de2dbddf6..935351b31 100644 --- a/sdrbase/audio/audiofilter.h +++ b/sdrbase/audio/audiofilter.h @@ -47,7 +47,7 @@ public: void useHP(bool useHP) { m_useHP = useHP; } bool usesHP() const { return m_useHP; } - void setDecimFilters(int sr, uint32_t decim); + void setDecimFilters(int srHigh, int srLow, float fcHigh, float fcLow); float run(const float& sample); float runHP(const float& sample); float runLP(const float& sample); diff --git a/sdrbase/audio/audiog722.cpp b/sdrbase/audio/audiog722.cpp index ad3fa74c0..addbb9a5b 100644 --- a/sdrbase/audio/audiog722.cpp +++ b/sdrbase/audio/audiog722.cpp @@ -93,6 +93,9 @@ void AudioG722::g722_encode_state::init(int rate, int options) out_buffer = 0; out_bits = 0; + char *pBand = (char *) band; + std::fill(pBand, pBand + sizeof(band), 0); + if (rate == 48000) { bits_per_sample = 6; } else if (rate == 56000) { @@ -263,8 +266,8 @@ int AudioG722::encode(uint8_t g722_data[], const int16_t amp[], int len) { if (state.itu_test_mode) { - xlow = xhigh = amp[j++] >> 1; + xlow = xhigh; } else { diff --git a/sdrbase/audio/audionetsink.cpp b/sdrbase/audio/audionetsink.cpp index 1eb8e47a1..974c23f37 100644 --- a/sdrbase/audio/audionetsink.cpp +++ b/sdrbase/audio/audionetsink.cpp @@ -115,7 +115,8 @@ void AudioNetSink::setParameters(Codec codec, bool stereo, int sampleRate) m_codec = codec; m_sampleRate = sampleRate; - m_audioFilter.setDecimFilters(m_sampleRate, m_decimation); + + setDecimationFilters(); if (m_rtpBufferAudio) { @@ -147,17 +148,38 @@ void AudioNetSink::setDecimation(uint32_t decimation) { m_decimation = decimation < 1 ? 1 : decimation > 6 ? 6 : decimation; qDebug() << "AudioNetSink::setDecimation: " << m_decimation << " from: " << decimation; - m_audioFilter.setDecimFilters(m_sampleRate, m_decimation); + setDecimationFilters(); m_decimationCount = 0; } +void AudioNetSink::setDecimationFilters() +{ + int decimatedSampleRate = m_sampleRate / m_decimation; + + switch (m_codec) + { + case CodecPCMA: + case CodecPCMU: + m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 3300.0, 300.0); + break; + case CodecG722: + m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 7000.0, 50.0); + break; + case CodecL8: + case CodecL16: + default: + m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 0.45*decimatedSampleRate, 50.0); + break; + } +} + void AudioNetSink::write(qint16 isample) { qint16& sample = isample; if (m_decimation > 1) { - float lpSample = m_audioFilter.runLP(sample / 32768.0f); + float lpSample = m_audioFilter.run(sample / 32768.0f); if (m_decimationCount >= m_decimation - 1) { diff --git a/sdrbase/audio/audionetsink.h b/sdrbase/audio/audionetsink.h index 55589c7ac..52410f547 100644 --- a/sdrbase/audio/audionetsink.h +++ b/sdrbase/audio/audionetsink.h @@ -68,10 +68,12 @@ public: void moveToThread(QThread *thread); static const int m_udpBlockSize; - static const int m_dataBlockSize = 16384*5; // room for G722 conversion (largest to date) - static const int m_g722BlockSize = 16384; // number of resulting G722 bytes + static const int m_dataBlockSize = 65536; // room for G722 conversion (64000 = 12800*5 largest to date) + static const int m_g722BlockSize = 12800; // number of resulting G722 bytes (80*20ms frames) protected: + void setDecimationFilters(); + SinkType m_type; Codec m_codec; QUdpSocket *m_udpSocket; diff --git a/sdrgui/audio.md b/sdrgui/audio.md index 1b85bc31f..cf3a0ccd9 100644 --- a/sdrgui/audio.md +++ b/sdrgui/audio.md @@ -1,8 +1,8 @@