1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 12:51:49 -05:00

AM Modulator: handle record file play loop

This commit is contained in:
f4exb 2016-11-28 18:19:23 +01:00
parent 3f3a58772b
commit cb2e99f540
3 changed files with 58 additions and 24 deletions

View File

@ -35,7 +35,11 @@ MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamTiming, Message)
AMMod::AMMod() : AMMod::AMMod() :
m_settingsMutex(QMutex::Recursive) m_settingsMutex(QMutex::Recursive),
m_fileSize(0),
m_recordLength(0),
m_sampleRate(48000),
m_afInput(AMModInputNone)
{ {
setObjectName("AMMod"); setObjectName("AMMod");
@ -56,17 +60,20 @@ AMMod::AMMod() :
m_magsq = 0.0; m_magsq = 0.0;
m_toneNco.setFreq(1000.0, m_config.m_audioSampleRate); m_toneNco.setFreq(1000.0, m_config.m_audioSampleRate);
m_afInput = AMModInputNone;
} }
AMMod::~AMMod() AMMod::~AMMod()
{ {
} }
void AMMod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute) void AMMod::configure(MessageQueue* messageQueue,
Real rfBandwidth,
Real afBandwidth,
float modFactor,
bool audioMute,
bool playLoop)
{ {
Message* cmd = MsgConfigureAMMod::create(rfBandwidth, afBandwidth, modFactor, audioMute); Message* cmd = MsgConfigureAMMod::create(rfBandwidth, afBandwidth, modFactor, audioMute, playLoop);
messageQueue->push(cmd); messageQueue->push(cmd);
} }
@ -127,14 +134,24 @@ void AMMod::pullAF(Real& sample)
// ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw // ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw
if (m_ifstream.is_open()) if (m_ifstream.is_open())
{ {
if (m_ifstream.eof()) // TODO: handle loop playback situation if (m_ifstream.eof())
{
if (m_running.m_playLoop)
{ {
m_ifstream.clear(); m_ifstream.clear();
m_ifstream.seekg(0, std::ios::beg); m_ifstream.seekg(0, std::ios::beg);
} }
}
if (m_ifstream.eof())
{
sample = 0.0f;
}
else
{
m_ifstream.read(reinterpret_cast<char*>(&sample), sizeof(Real)); m_ifstream.read(reinterpret_cast<char*>(&sample), sizeof(Real));
} }
}
else else
{ {
sample = 0.0f; sample = 0.0f;
@ -189,6 +206,7 @@ bool AMMod::handleMessage(const Message& cmd)
m_config.m_afBandwidth = cfg.getAFBandwidth(); m_config.m_afBandwidth = cfg.getAFBandwidth();
m_config.m_modFactor = cfg.getModFactor(); m_config.m_modFactor = cfg.getModFactor();
m_config.m_audioMute = cfg.getAudioMute(); m_config.m_audioMute = cfg.getAudioMute();
m_config.m_playLoop = cfg.getPlayLoop();
apply(); apply();
@ -196,7 +214,8 @@ bool AMMod::handleMessage(const Message& cmd)
<< " m_rfBandwidth: " << m_config.m_rfBandwidth << " m_rfBandwidth: " << m_config.m_rfBandwidth
<< " m_afBandwidth: " << m_config.m_afBandwidth << " m_afBandwidth: " << m_config.m_afBandwidth
<< " m_modFactor: " << m_config.m_modFactor << " m_modFactor: " << m_config.m_modFactor
<< " m_audioMute: " << m_config.m_audioMute; << " m_audioMute: " << m_config.m_audioMute
<< " m_playLoop: " << m_config.m_playLoop;
return true; return true;
} }
@ -224,7 +243,14 @@ bool AMMod::handleMessage(const Message& cmd)
} }
else if (MsgConfigureFileSourceStreamTiming::match(cmd)) else if (MsgConfigureFileSourceStreamTiming::match(cmd))
{ {
std::size_t samplesCount = m_ifstream.tellg() / sizeof(Real); std::size_t samplesCount;
if (m_ifstream.eof()) {
samplesCount = m_fileSize / sizeof(Real);
} else {
samplesCount = m_ifstream.tellg() / sizeof(Real);
}
MsgReportFileSourceStreamTiming *report; MsgReportFileSourceStreamTiming *report;
report = MsgReportFileSourceStreamTiming::create(samplesCount); report = MsgReportFileSourceStreamTiming::create(samplesCount);
getOutputMessageQueue()->push(report); getOutputMessageQueue()->push(report);
@ -274,6 +300,7 @@ void AMMod::apply()
m_running.m_modFactor = m_config.m_modFactor; m_running.m_modFactor = m_config.m_modFactor;
m_running.m_audioSampleRate = m_config.m_audioSampleRate; m_running.m_audioSampleRate = m_config.m_audioSampleRate;
m_running.m_audioMute = m_config.m_audioMute; m_running.m_audioMute = m_config.m_audioMute;
m_running.m_playLoop = m_config.m_playLoop;
} }
void AMMod::openFileStream() void AMMod::openFileStream()
@ -283,14 +310,14 @@ void AMMod::openFileStream()
} }
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate); m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
quint64 fileSize = m_ifstream.tellg(); m_fileSize = m_ifstream.tellg();
m_ifstream.seekg(0,std::ios_base::beg); m_ifstream.seekg(0,std::ios_base::beg);
m_sampleRate = 48000; // fixed rate m_sampleRate = 48000; // fixed rate
m_recordLength = fileSize / (sizeof(Real) * m_sampleRate); m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate);
qDebug() << "AMMod::openFileStream: " << m_fileName.toStdString().c_str() qDebug() << "AMMod::openFileStream: " << m_fileName.toStdString().c_str()
<< " fileSize: " << fileSize << "bytes" << " fileSize: " << m_fileSize << "bytes"
<< " length: " << m_recordLength << " seconds"; << " length: " << m_recordLength << " seconds";
MsgReportFileSourceStreamData *report; MsgReportFileSourceStreamData *report;

View File

@ -174,7 +174,7 @@ public:
AMMod(); AMMod();
~AMMod(); ~AMMod();
void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute); void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop);
virtual void pull(Sample& sample); virtual void pull(Sample& sample);
virtual void start(); virtual void start();
@ -193,10 +193,11 @@ private:
Real getAFBandwidth() const { return m_afBandwidth; } Real getAFBandwidth() const { return m_afBandwidth; }
float getModFactor() const { return m_modFactor; } float getModFactor() const { return m_modFactor; }
bool getAudioMute() const { return m_audioMute; } bool getAudioMute() const { return m_audioMute; }
bool getPlayLoop() const { return m_playLoop; }
static MsgConfigureAMMod* create(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute) static MsgConfigureAMMod* create(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop)
{ {
return new MsgConfigureAMMod(rfBandwidth, afBandwidth, modFactor, audioMute); return new MsgConfigureAMMod(rfBandwidth, afBandwidth, modFactor, audioMute, playLoop);
} }
private: private:
@ -204,13 +205,15 @@ private:
Real m_afBandwidth; Real m_afBandwidth;
float m_modFactor; float m_modFactor;
bool m_audioMute; bool m_audioMute;
bool m_playLoop;
MsgConfigureAMMod(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute) : MsgConfigureAMMod(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop) :
Message(), Message(),
m_rfBandwidth(rfBandwidth), m_rfBandwidth(rfBandwidth),
m_afBandwidth(afBandwidth), m_afBandwidth(afBandwidth),
m_modFactor(modFactor), m_modFactor(modFactor),
m_audioMute(audioMute) m_audioMute(audioMute),
m_playLoop(playLoop)
{ } { }
}; };
@ -235,6 +238,7 @@ private:
float m_modFactor; float m_modFactor;
quint32 m_audioSampleRate; quint32 m_audioSampleRate;
bool m_audioMute; bool m_audioMute;
bool m_playLoop;
Config() : Config() :
m_outputSampleRate(-1), m_outputSampleRate(-1),
@ -243,7 +247,8 @@ private:
m_afBandwidth(-1), m_afBandwidth(-1),
m_modFactor(0.2f), m_modFactor(0.2f),
m_audioSampleRate(0), m_audioSampleRate(0),
m_audioMute(false) m_audioMute(false),
m_playLoop(false)
{ } { }
}; };
@ -274,6 +279,7 @@ private:
std::ifstream m_ifstream; std::ifstream m_ifstream;
QString m_fileName; QString m_fileName;
quint64 m_fileSize; //!< raw file size (bytes)
quint32 m_recordLength; //!< record length in seconds computed from file size quint32 m_recordLength; //!< record length in seconds computed from file size
int m_sampleRate; int m_sampleRate;

View File

@ -74,7 +74,7 @@ void AMModGUI::resetToDefaults()
{ {
blockApplySettings(true); blockApplySettings(true);
ui->rfBW->setValue(4); ui->rfBW->setValue(6);
ui->afBW->setValue(3); ui->afBW->setValue(3);
ui->modPercent->setValue(20); ui->modPercent->setValue(20);
ui->deltaFrequency->setValue(0); ui->deltaFrequency->setValue(0);
@ -226,7 +226,7 @@ void AMModGUI::on_audioMute_toggled(bool checked)
void AMModGUI::on_playLoop_toggled(bool checked) void AMModGUI::on_playLoop_toggled(bool checked)
{ {
// TODO: do something about it! applySettings();
} }
void AMModGUI::on_play_toggled(bool checked) void AMModGUI::on_play_toggled(bool checked)
@ -391,7 +391,8 @@ void AMModGUI::applySettings()
m_rfBW[ui->rfBW->value()], m_rfBW[ui->rfBW->value()],
ui->afBW->value() * 1000.0, ui->afBW->value() * 1000.0,
ui->modPercent->value() / 100.0f, ui->modPercent->value() / 100.0f,
ui->audioMute->isChecked()); ui->audioMute->isChecked(),
ui->playLoop->isChecked());
} }
} }