1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

AM mod: reworked input audio. Implements #495

This commit is contained in:
f4exb 2020-11-22 12:34:12 +01:00
parent 2a2ab520ba
commit bafb694b74
2 changed files with 47 additions and 6 deletions

View File

@ -25,15 +25,18 @@ AMModSource::AMModSource() :
m_channelSampleRate(48000),
m_channelFrequencyOffset(0),
m_audioSampleRate(48000),
m_audioFifo(4800),
m_audioFifo(12000),
m_feedbackAudioFifo(48000),
m_levelCalcCount(0),
m_peakLevel(0.0f),
m_levelSum(0.0f),
m_ifstream(nullptr)
m_ifstream(nullptr),
m_mutex(QMutex::Recursive)
{
m_audioBuffer.resize(1<<14);
m_audioBuffer.resize(24000);
m_audioBufferFill = 0;
m_audioReadBuffer.resize(24000);
m_audioReadBufferFill = 0;
m_feedbackAudioBuffer.resize(1<<14);
m_feedbackAudioBufferFill = 0;
@ -107,13 +110,20 @@ void AMModSource::prefetch(unsigned int nbSamples)
void AMModSource::pullAudio(unsigned int nbSamples)
{
QMutexLocker mlock(&m_mutex);
if (nbSamples > m_audioBuffer.size()) {
m_audioBuffer.resize(nbSamples);
}
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamples);
std::copy(&m_audioReadBuffer[0], &m_audioReadBuffer[nbSamples], &m_audioBuffer[0]);
m_audioBufferFill = 0;
if (m_audioReadBufferFill > nbSamples) // copy back remaining samples at the start of the read buffer
{
std::copy(&m_audioReadBuffer[nbSamples], &m_audioReadBuffer[m_audioReadBufferFill], &m_audioReadBuffer[0]);
m_audioReadBufferFill = m_audioReadBufferFill - nbSamples; // adjust current read buffer fill pointer
}
}
void AMModSource::modulateSample()
@ -314,6 +324,15 @@ void AMModSource::applySettings(const AMModSettings& settings, bool force)
m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate);
}
if ((settings.m_modAFInput != m_settings.m_modAFInput) || force)
{
if (settings.m_modAFInput == AMModSettings::AMModInputAudio) {
connect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
} else {
disconnect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
}
}
m_settings = settings;
}
@ -340,3 +359,16 @@ void AMModSource::applyChannelSettings(int channelSampleRate, int channelFrequen
m_channelSampleRate = channelSampleRate;
m_channelFrequencyOffset = channelFrequencyOffset;
}
void AMModSource::handleAudio()
{
QMutexLocker mlock(&m_mutex);
unsigned int nbRead;
while ((nbRead = m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0)
{
if (m_audioReadBufferFill + nbRead + 4096 < m_audioReadBuffer.size()) {
m_audioReadBufferFill += nbRead;
}
}
}

View File

@ -18,6 +18,7 @@
#ifndef INCLUDE_AMMODSOURCE_H
#define INCLUDE_AMMODSOURCE_H
#include <QObject>
#include <QMutex>
#include <iostream>
@ -33,8 +34,9 @@
#include "ammodsettings.h"
class AMModSource : public ChannelSampleSource
class AMModSource : public QObject, public ChannelSampleSource
{
Q_OBJECT
public:
AMModSource();
virtual ~AMModSource();
@ -85,7 +87,9 @@ private:
int m_audioSampleRate;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
unsigned int m_audioBufferFill;
AudioVector m_audioReadBuffer;
unsigned int m_audioReadBufferFill;
AudioFifo m_audioFifo;
int m_feedbackAudioSampleRate;
@ -102,6 +106,8 @@ private:
std::ifstream *m_ifstream;
CWKeyer m_cwKeyer;
QMutex m_mutex;
static const int m_levelNbSamples;
void processOneSample(Complex& ci);
@ -110,6 +116,9 @@ private:
void pushFeedback(Real sample);
void calculateLevel(Real& sample);
void modulateSample();
private slots:
void handleAudio();
};