From 437891da43e6925a15592de3aaa6be46420f1b3b Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 26 Dec 2016 02:15:24 +0100 Subject: [PATCH] Corrected number of audio samples pulled considering interpolation --- plugins/channeltx/modam/ammod.cpp | 9 +++++---- plugins/channeltx/modnfm/nfmmod.cpp | 10 ++++++---- plugins/channeltx/modssb/ssbmod.cpp | 10 ++++++---- plugins/channeltx/modwfm/wfmmod.cpp | 9 +++++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/plugins/channeltx/modam/ammod.cpp b/plugins/channeltx/modam/ammod.cpp index 4cb60acb9..d177ad556 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -121,7 +121,6 @@ void AMMod::pull(Sample& sample) } } - m_audioBufferFill++; m_interpolatorDistanceRemain += m_interpolatorDistance; ci *= m_carrierNco.nextIQ(); // shift to carrier frequency @@ -140,13 +139,14 @@ void AMMod::pull(Sample& sample) void AMMod::pullAudio(int nbSamples) { // qDebug("AMMod::pullAudio: %d", nbSamples); + int nbAudioSamples = nbSamples * m_interpolatorDistance; - if (nbSamples > m_audioBuffer.size()) + if (nbAudioSamples > m_audioBuffer.size()) { - m_audioBuffer.resize(nbSamples); + m_audioBuffer.resize(nbAudioSamples); } - m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamples*sizeof(AudioSample), 10); + m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbAudioSamples*sizeof(AudioSample), 10); m_audioBufferFill = 0; } @@ -156,6 +156,7 @@ void AMMod::modulateSample() pullAF(t); calculateLevel(t); + m_audioBufferFill++; m_modSample.real((t*m_running.m_modFactor + 1.0f) * 16384.0f); // modulate and scale zero frequency carrier m_modSample.imag(0.0f); diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index ce6f4a75d..05c288665 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -136,7 +136,6 @@ void NFMMod::pull(Sample& sample) } } - m_audioBufferFill++; m_interpolatorDistanceRemain += m_interpolatorDistance; ci *= m_carrierNco.nextIQ(); // shift to carrier frequency @@ -154,12 +153,14 @@ void NFMMod::pull(Sample& sample) void NFMMod::pullAudio(int nbSamples) { - if (nbSamples > m_audioBuffer.size()) + int nbSamplesAudio = nbSamples * m_interpolatorDistance; + + if (nbSamplesAudio > m_audioBuffer.size()) { - m_audioBuffer.resize(nbSamples); + m_audioBuffer.resize(nbSamplesAudio); } - m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamples*sizeof(AudioSample), 10); + m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamplesAudio*sizeof(AudioSample), 10); m_audioBufferFill = 0; } @@ -169,6 +170,7 @@ void NFMMod::modulateSample() pullAF(t); calculateLevel(t); + m_audioBufferFill++; if (m_running.m_ctcssOn) { diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index 9e2cebcc4..19b50504c 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -166,7 +166,6 @@ void SSBMod::pull(Sample& sample) } } - m_audioBufferFill++; m_interpolatorDistanceRemain += m_interpolatorDistance; ci *= m_carrierNco.nextIQ(); // shift to carrier frequency @@ -185,12 +184,14 @@ void SSBMod::pull(Sample& sample) void SSBMod::pullAudio(int nbSamples) { - if (nbSamples > m_audioBuffer.size()) + int nbSamplesAudio = nbSamples * m_interpolatorDistance; + + if (nbSamplesAudio > m_audioBuffer.size()) { - m_audioBuffer.resize(nbSamples); + m_audioBuffer.resize(nbSamplesAudio); } - m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamples*sizeof(AudioSample), 10); + m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamplesAudio*sizeof(AudioSample), 10); m_audioBufferFill = 0; } @@ -198,6 +199,7 @@ void SSBMod::modulateSample() { pullAF(m_modSample); calculateLevel(m_modSample); + m_audioBufferFill++; } void SSBMod::pullAF(Complex& sample) diff --git a/plugins/channeltx/modwfm/wfmmod.cpp b/plugins/channeltx/modwfm/wfmmod.cpp index 0c45a7ec7..814df9a29 100644 --- a/plugins/channeltx/modwfm/wfmmod.cpp +++ b/plugins/channeltx/modwfm/wfmmod.cpp @@ -119,7 +119,6 @@ void WFMMod::pull(Sample& sample) m_audioBufferFill++; } - m_audioBufferFill++; m_interpolatorDistanceRemain += m_interpolatorDistance; m_modPhasor += (m_running.m_fmDeviation / (float) m_running.m_outputSampleRate) * ri.real() * M_PI; @@ -143,12 +142,14 @@ void WFMMod::pull(Sample& sample) void WFMMod::pullAudio(int nbSamples) { - if (nbSamples > m_audioBuffer.size()) + int nbSamplesAudio = nbSamples * m_interpolatorDistance; + + if (nbSamplesAudio > m_audioBuffer.size()) { - m_audioBuffer.resize(nbSamples); + m_audioBuffer.resize(nbSamplesAudio); } - m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamples*sizeof(AudioSample), 10); + m_audioFifo.read(reinterpret_cast(&m_audioBuffer[0]), nbSamplesAudio*sizeof(AudioSample), 10); m_audioBufferFill = 0; }