AM mod: put AF input mode in settings

This commit is contained in:
f4exb 2018-04-05 21:58:45 +02:00
parent cc3483aabe
commit 376e0d9b1f
6 changed files with 36 additions and 62 deletions

View File

@ -33,7 +33,6 @@ MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureAMMod, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureChannelizer, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceName, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceSeek, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureAFInput, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceStreamTiming, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamData, Message)
MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamTiming, Message)
@ -53,7 +52,6 @@ AMMod::AMMod(DeviceSinkAPI *deviceAPI) :
m_fileSize(0),
m_recordLength(0),
m_sampleRate(48000),
m_afInput(AMModInputNone),
m_levelCalcCount(0),
m_peakLevel(0.0f),
m_levelSum(0.0f)
@ -165,12 +163,12 @@ void AMMod::modulateSample()
void AMMod::pullAF(Real& sample)
{
switch (m_afInput)
switch (m_settings.m_modAFInput)
{
case AMModInputTone:
case AMModSettings::AMModInputTone:
sample = m_toneNco.next();
break;
case AMModInputFile:
case AMModSettings::AMModInputFile:
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
// ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw
if (m_ifstream.is_open())
@ -199,10 +197,10 @@ void AMMod::pullAF(Real& sample)
sample = 0.0f;
}
break;
case AMModInputAudio:
case AMModSettings::AMModInputAudio:
sample = ((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f) * m_settings.m_volumeFactor;
break;
case AMModInputCWTone:
case AMModSettings::AMModInputCWTone:
Real fadeFactor;
if (m_cwKeyer.getSample())
@ -223,7 +221,7 @@ void AMMod::pullAF(Real& sample)
}
}
break;
case AMModInputNone:
case AMModSettings::AMModInputNone:
default:
sample = 0.0f;
break;
@ -313,13 +311,6 @@ bool AMMod::handleMessage(const Message& cmd)
return true;
}
else if (MsgConfigureAFInput::match(cmd))
{
MsgConfigureAFInput& conf = (MsgConfigureAFInput&) cmd;
m_afInput = conf.getAFInput();
return true;
}
else if (MsgConfigureFileSourceStreamTiming::match(cmd))
{
std::size_t samplesCount;
@ -457,6 +448,7 @@ void AMMod::applySettings(const AMModSettings& settings, bool force)
<< " m_volumeFactor: " << settings.m_volumeFactor
<< " m_audioMute: " << settings.m_channelMute
<< " m_playLoop: " << settings.m_playLoop
<< " m_modAFInput " << settings.m_modAFInput
<< " m_audioDeviceName: " << settings.m_audioDeviceName
<< " force: " << force;

View File

@ -89,15 +89,6 @@ public:
{ }
};
typedef enum
{
AMModInputNone,
AMModInputTone,
AMModInputFile,
AMModInputAudio,
AMModInputCWTone
} AMModInputAF;
class MsgConfigureFileSourceName : public Message
{
MESSAGE_CLASS_DECLARATION
@ -157,27 +148,6 @@ public:
{ }
};
class MsgConfigureAFInput : public Message
{
MESSAGE_CLASS_DECLARATION
public:
AMModInputAF getAFInput() const { return m_afInput; }
static MsgConfigureAFInput* create(AMModInputAF afInput)
{
return new MsgConfigureAFInput(afInput);
}
private:
AMModInputAF m_afInput;
MsgConfigureAFInput(AMModInputAF afInput) :
Message(),
m_afInput(afInput)
{ }
};
class MsgReportFileSourceStreamTiming : public Message
{
MESSAGE_CLASS_DECLARATION
@ -302,7 +272,6 @@ private:
quint32 m_recordLength; //!< record length in seconds computed from file size
int m_sampleRate;
AMModInputAF m_afInput;
quint32 m_levelCalcCount;
Real m_peakLevel;
Real m_levelSum;

View File

@ -186,9 +186,8 @@ void AMModGUI::on_play_toggled(bool checked)
ui->tone->setEnabled(!checked); // release other source inputs
ui->morseKeyer->setEnabled(!checked);
ui->mic->setEnabled(!checked);
m_modAFInput = checked ? AMMod::AMModInputFile : AMMod::AMModInputNone;
AMMod::MsgConfigureAFInput* message = AMMod::MsgConfigureAFInput::create(m_modAFInput);
m_amMod->getInputMessageQueue()->push(message);
m_settings.m_modAFInput = checked ? AMModSettings::AMModInputFile : AMModSettings::AMModInputNone;
applySettings();
ui->navTimeSlider->setEnabled(!checked);
m_enableNavTime = !checked;
}
@ -198,9 +197,8 @@ void AMModGUI::on_tone_toggled(bool checked)
ui->play->setEnabled(!checked); // release other source inputs
ui->morseKeyer->setEnabled(!checked);
ui->mic->setEnabled(!checked);
m_modAFInput = checked ? AMMod::AMModInputTone : AMMod::AMModInputNone;
AMMod::MsgConfigureAFInput* message = AMMod::MsgConfigureAFInput::create(m_modAFInput);
m_amMod->getInputMessageQueue()->push(message);
m_settings.m_modAFInput = checked ? AMModSettings::AMModInputTone : AMModSettings::AMModInputNone;
applySettings();
}
void AMModGUI::on_morseKeyer_toggled(bool checked)
@ -208,9 +206,8 @@ void AMModGUI::on_morseKeyer_toggled(bool checked)
ui->play->setEnabled(!checked); // release other source inputs
ui->tone->setEnabled(!checked); // release other source inputs
ui->mic->setEnabled(!checked);
m_modAFInput = checked ? AMMod::AMModInputCWTone : AMMod::AMModInputNone;
AMMod::MsgConfigureAFInput* message = AMMod::MsgConfigureAFInput::create(m_modAFInput);
m_amMod->getInputMessageQueue()->push(message);
m_settings.m_modAFInput = checked ? AMModSettings::AMModInputCWTone : AMModSettings::AMModInputNone;
applySettings();
}
void AMModGUI::on_mic_toggled(bool checked)
@ -218,9 +215,8 @@ void AMModGUI::on_mic_toggled(bool checked)
ui->play->setEnabled(!checked); // release other source inputs
ui->morseKeyer->setEnabled(!checked);
ui->tone->setEnabled(!checked); // release other source inputs
m_modAFInput = checked ? AMMod::AMModInputAudio : AMMod::AMModInputNone;
AMMod::MsgConfigureAFInput* message = AMMod::MsgConfigureAFInput::create(m_modAFInput);
m_amMod->getInputMessageQueue()->push(message);
m_settings.m_modAFInput = checked ? AMModSettings::AMModInputAudio : AMModSettings::AMModInputNone;
applySettings();
}
void AMModGUI::on_navTimeSlider_valueChanged(int value)
@ -272,8 +268,7 @@ AMModGUI::AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampl
m_recordSampleRate(48000),
m_samplesCount(0),
m_tickCount(0),
m_enableNavTime(false),
m_modAFInput(AMMod::AMModInputNone)
m_enableNavTime(false)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
@ -413,7 +408,7 @@ void AMModGUI::tick()
m_channelPowerDbAvg(powDb);
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1));
if (((++m_tickCount & 0xf) == 0) && (m_modAFInput == AMMod::AMModInputFile))
if (((++m_tickCount & 0xf) == 0) && (m_settings.m_modAFInput == AMModSettings::AMModInputFile))
{
AMMod::MsgConfigureFileSourceStreamTiming* message = AMMod::MsgConfigureFileSourceStreamTiming::create();
m_amMod->getInputMessageQueue()->push(message);

View File

@ -74,7 +74,6 @@ private:
int m_samplesCount;
std::size_t m_tickCount;
bool m_enableNavTime;
AMMod::AMModInputAF m_modAFInput;
MessageQueue m_inputMessageQueue;
explicit AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent = 0);

View File

@ -39,6 +39,7 @@ void AMModSettings::resetToDefaults()
m_playLoop = false;
m_rgbColor = QColor(255, 255, 0).rgb();
m_title = "AM Modulator";
m_modAFInput = AMModInputAF::AMModInputNone;
m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName;
}
@ -63,6 +64,7 @@ QByteArray AMModSettings::serialize() const
s.writeString(9, m_title);
s.writeString(10, m_audioDeviceName);
s.writeS32(11, (int) m_modAFInput);
return s.final();
}
@ -103,6 +105,13 @@ bool AMModSettings::deserialize(const QByteArray& data)
d.readString(9, &m_title, "AM Modulator");
d.readString(10, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName);
d.readS32(11, &tmp, 0);
if ((tmp < 0) || (tmp > (int) AMModInputAF::AMModInputTone)) {
m_modAFInput = AMModInputNone;
} else {
m_modAFInput = (AMModInputAF) tmp;
}
return true;
}
else

View File

@ -23,6 +23,15 @@ class Serializable;
struct AMModSettings
{
typedef enum
{
AMModInputNone,
AMModInputTone,
AMModInputFile,
AMModInputAudio,
AMModInputCWTone
} AMModInputAF;
qint64 m_inputFrequencyOffset;
Real m_rfBandwidth;
float m_modFactor;
@ -32,6 +41,7 @@ struct AMModSettings
bool m_playLoop;
quint32 m_rgbColor;
QString m_title;
AMModInputAF m_modAFInput;
QString m_audioDeviceName;
Serializable *m_channelMarker;