Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Add setting to make HD Radio analog fallback optional
Browse files Browse the repository at this point in the history
  • Loading branch information
djp952 committed Apr 26, 2022
1 parent fe50992 commit cc4357f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ msgctxt "#30111"
msgid "Downsample quality"
msgstr ""

msgctxt "#30112"
msgid "Enable analog signal audio fallback"
msgstr ""

msgctxt "#30200"
msgid "Universal Serial Bus (USB)"
msgstr ""
Expand Down Expand Up @@ -252,3 +256,6 @@ msgctxt "#30511"
msgid "Specifies the Digital Signal Processor (DSP) downsample quality. When set to Fast, downsampling will be optimized for system performance. When set to Maximum, downsampling will be optimized for audio quality."
msgstr ""

msgctxt "#30512"
msgid "When set to ON the Digital Signal Processor (DSP) will decode audio from the analog signal during initial synchronization or when the digitial signal has been lost. When set to OFF, audio will be muted during these events."
msgstr ""
12 changes: 9 additions & 3 deletions pvr.rtlradio/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
<default>false</default>
<control type="toggle"/>
</setting>

</group>
</category>

<category id="fmradio" label="30002">
<group id="1" label="-1">

Expand All @@ -95,7 +95,7 @@
<default>true</default>
<control type="toggle"/>
</setting>

<setting id="fmradio_rds_standard" type="integer" parent="fmradio_enable_rds" label="30104" help="30504">
<level>0</level>
<default>0</default>
Expand Down Expand Up @@ -174,6 +174,12 @@
<category id="hdradio" label="30003">
<group id="1" label="-1">

<setting id="hdradio_enable_fallback" type="boolean" label="30112" help="30512">
<level>0</level>
<default>true</default>
<control type="toggle"/>
</setting>

<setting id="hdradio_output_gain" type="number" label="30109" help="30509">
<level>0</level>
<default>-3.0</default>
Expand Down
26 changes: 21 additions & 5 deletions src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ ADDON_STATUS addon::Create(void)
m_settings.fmradio_output_gain = kodi::addon::GetSettingFloat("fmradio_output_gain", -3.0f);

// Load the HD Radio settings
m_settings.hdradio_enable_fallback = kodi::addon::GetSettingBoolean("hdradio_enable_fallback", true);
m_settings.hdradio_output_gain = kodi::addon::GetSettingFloat("hdradio_output_gain", -3.0f);

// Load the Weather Radio settings
Expand All @@ -597,6 +598,7 @@ ADDON_STATUS addon::Create(void)
log_info(__func__, ": m_settings.fmradio_output_samplerate = ", m_settings.fmradio_output_samplerate);
log_info(__func__, ": m_settings.fmradio_rds_standard = ", static_cast<int>(m_settings.fmradio_rds_standard));
log_info(__func__, ": m_settings.fmradio_sample_rate = ", m_settings.fmradio_sample_rate);
log_info(__func__, ": m_settings.hdradio_enable_fallback = ", m_settings.hdradio_enable_fallback);
log_info(__func__, ": m_settings.hdradio_output_gain = ", m_settings.hdradio_output_gain);
log_info(__func__, ": m_settings.interface_prepend_channel_numbers = ", m_settings.interface_prepend_channel_numbers);
log_info(__func__, ": m_settings.wxradio_output_gain = ", m_settings.wxradio_output_gain);
Expand Down Expand Up @@ -833,16 +835,28 @@ ADDON_STATUS addon::SetSetting(std::string const& settingName, kodi::addon::CSet
}
}

// hdradio_enable_fallback
//
else if(settingName == "hdradio_enable_fallback") {

bool bvalue = settingValue.GetBoolean();
if(bvalue != m_settings.hdradio_enable_fallback) {

m_settings.hdradio_enable_fallback = bvalue;
log_info(__func__, ": setting hdradio_enable_fallback changed to ", bvalue);
}
}

// hdradio_output_gain
//
else if(settingName == "hdradio_output_gain") {

float fvalue = settingValue.GetFloat();
if(fvalue != m_settings.hdradio_output_gain) {
float fvalue = settingValue.GetFloat();
if(fvalue != m_settings.hdradio_output_gain) {

m_settings.hdradio_output_gain = fvalue;
log_info(__func__, ": setting hdradio_output_gain changed to ", fvalue, "dB");
}
m_settings.hdradio_output_gain = fvalue;
log_info(__func__, ": setting hdradio_output_gain changed to ", fvalue, "dB");
}
}

// wxradio_sample_rate
Expand Down Expand Up @@ -1661,11 +1675,13 @@ bool addon::OpenLiveStream(kodi::addon::PVRChannel const& channel)

// Set up the HD Radio digital signal processor properties
struct hdprops hdprops = {};
hdprops.analogfallback = settings.hdradio_enable_fallback;
hdprops.outputgain = settings.hdradio_output_gain;

// Log information about the stream for diagnostic purposes
log_info(__func__, ": Creating hdstream for channel \"", channelprops.name, "\"");
log_info(__func__, ": tunerprops.freqcorrection = ", tunerprops.freqcorrection, " PPM");
log_info(__func__, ": hdprops.analogfallback = ", (hdprops.analogfallback) ? "true" : "false");
log_info(__func__, ": hdprops.outputgain = ", hdprops.outputgain, " dB");
log_info(__func__, ": channelprops.frequency = ", channelprops.frequency, " Hz");
log_info(__func__, ": channelprops.subchannel = ", channelprops.subchannel);
Expand Down
5 changes: 3 additions & 2 deletions src/hdstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ int const hdstream::STREAM_ID_AUDIO = 1;

hdstream::hdstream(std::unique_ptr<rtldevice> device, struct tunerprops const& tunerprops,
struct channelprops const& channelprops, struct hdprops const& hdprops) :
m_device(std::move(device)), m_muxname(""), m_pcmgain(powf(10.0f, hdprops.outputgain / 10.0f))
m_device(std::move(device)), m_analogfallback(hdprops.analogfallback), m_muxname(""),
m_pcmgain(powf(10.0f, hdprops.outputgain / 10.0f))
{
// Initialize the RTL-SDR device instance
m_device->set_frequency_correction(tunerprops.freqcorrection + channelprops.freqcorrection);
Expand Down Expand Up @@ -343,7 +344,7 @@ void hdstream::nrsc5_callback(nrsc5_event_t const* event)
//
// If the HD Radio stream is not generating any audio packets, fall back on the
// analog signal using the Wideband FM demodulator
if((event->event == NRSC5_EVENT_IQ) && (!m_hdaudio)) {
if((event->event == NRSC5_EVENT_IQ) && (m_analogfallback) && (!m_hdaudio)) {

// The byte count must be exact for the analog demodulator to work right
assert(event->iq.count == (m_fmdemod->GetInputBufferLimit() * 2));
Expand Down
1 change: 1 addition & 0 deletions src/hdstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class hdstream : public pvrstream
std::unique_ptr<CDemodulator> m_fmdemod; // CuteSDR demodulator instance
std::unique_ptr<CFractResampler> m_fmresampler; // CuteSDR resampler instance

bool const m_analogfallback = false; // Flag for analog signal fallback
bool m_hdaudio = false; // HD Radio audio flag
std::string m_muxname; // Generated mux name
float m_pcmgain; // Output gain
Expand Down
1 change: 1 addition & 0 deletions src/props.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct fmprops {
// Defines properties for the HD Radio digital signal processor
struct hdprops {

bool analogfallback; // Flag if analog fallback should be used
float outputgain; // Output gain in Decibels
};

Expand Down
5 changes: 5 additions & 0 deletions src/pvrtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ struct settings {
// Specifies the output gain for the FM DSP
float fmradio_output_gain;

// hdradio_enable_fallback
//
// Specifies if analog audio fallback is allowable
bool hdradio_enable_fallback;

// hdradio_output_gain
//
// Specifies the output gain for the HD DSP
Expand Down

0 comments on commit cc4357f

Please sign in to comment.