Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions modemradiopaging/radiopagingtxstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,18 +957,21 @@ void RadioPagingGscTxStream::endLive()
}
}

// The live page: the voice pushed, then the turn-off word. With no voice waiting the carrier is
// left unmodulated for 10 ms at a time. The voice ends at the longest voice length, counted in
// time (what is waiting is sent first)
// The live page: the voice pushed, then the turn-off word. The voice is sent once 100 ms of it is
// waiting, so that the uneven arrival from the audio input does not cut it; before that, and if it
// runs out, the carrier is left unmodulated for 10 ms at a time and the reserve is waited for again.
// The voice ends at the longest voice length, counted in time (what is waiting is sent first)
bool RadioPagingGscTxStream::nextLive(RadioPagingTxBlock& block)
{
const size_t chunk = RadioPagingWav::m_sampleRate / 40; // 25 ms
const size_t silence = RadioPagingWav::m_sampleRate / 100; // 10 ms
const size_t reserve = RadioPagingWav::m_sampleRate / 10; // 100 ms

if (m_live == LiveAlert)
{
m_live = LiveVoice;
m_liveSent = 0;
m_livePlaying = false;
}

bool limit = (m_liveSent >= m_liveLimit);
Expand All @@ -985,8 +988,13 @@ bool RadioPagingGscTxStream::nextLive(RadioPagingTxBlock& block)
block.m_baud = RadioPagingWav::m_sampleRate;
block.m_shaping = RadioPagingWav::m_sampleRate / 2.0;

if (m_liveSamples.empty())
if (!m_livePlaying && ((m_liveSamples.size() >= reserve) || m_liveEnding)) {
m_livePlaying = true;
}

if (!m_livePlaying || m_liveSamples.empty())
{
m_livePlaying = false;
block.m_levels.assign(silence, 0.0f);
m_liveSent += silence;
return true;
Expand Down
1 change: 1 addition & 0 deletions modemradiopaging/radiopagingtxstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class MODEMRADIOPAGING_API RadioPagingGscTxStream : public RadioPagingTxStream
size_t m_liveLimit = 0; //!< Samples of the longest voice
size_t m_liveSent = 0; //!< Voice samples sent
std::deque<float> m_liveSamples; //!< Voice waiting to be sent
bool m_livePlaying = false; //!< The reserve was there: the voice is sent as it comes
RadioPagingVoiceProcessor m_liveProcessor{RadioPagingWav::m_sampleRate}; //!< Voice of the live page
RadioPagingTxBlock m_liveEnd; //!< The turn-off word
bool nextLive(RadioPagingTxBlock& block);
Expand Down
12 changes: 8 additions & 4 deletions modemradiopaging/test/radiopagingtxstreamtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,8 @@ void testGscVoice()
}
}

// A live voice page: the page, the alert time, then the voice pushed (silence when none waits), the turn-off word
// A live voice page: the page, the alert time, then the voice pushed once 100 ms of it waits (silence before),
// the turn-off word
{
RadioPagingGscTxStream stream(RadioPagingGsc::Auto);
std::string error2;
Expand All @@ -1353,7 +1354,10 @@ void testGscVoice()
bool alert = stream.next(block) && (block.m_levels.size() == 76800) && (block.m_levels[100] == 0.0f) && !stream.liveOpen();
bool silent = stream.next(block) && stream.liveOpen() && (block.m_levels.size() == 384) && (block.m_levels[0] == 0.0f);
std::vector<float> voice(2000, 0.5f);
stream.pushLive(voice.data(), voice.size());
stream.pushLive(voice.data(), voice.size()); // 52 ms: less than the reserve, still silence
silent = silent && stream.next(block) && (block.m_levels.size() == 384) && (block.m_levels[0] == 0.0f);
stream.pushLive(voice.data(), voice.size()); // 104 ms waiting: the voice goes
voice.resize(4000, 0.5f);
size_t got = 0;
bool voiced = true;
RadioPagingVoiceProcessor processor(38400);
Expand All @@ -1371,8 +1375,8 @@ void testGscVoice()
stream.endLive();
bool end = stream.next(block) && (block.m_baud == 600) && (block.m_ids == std::vector<uint64_t>{77});
bool over = !stream.next(block) && !stream.liveActive();
check(added && page && alert && silent && voiced && (got == 2000) && end && over,
"GSC live voice page: page, alert, silence then the voice pushed, turn-off word with the id");
check(added && page && alert && silent && voiced && (got == 4000) && end && over,
"GSC live voice page: page, alert, silence until 100 ms of voice waits, the voice, turn-off word with the id");

// The longest voice: the page ends by itself
RadioPagingGscTxStream limited(RadioPagingGsc::Auto);
Expand Down
13 changes: 13 additions & 0 deletions plugins/channelrx/demodbfm/bfmdemodbaseband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ bool BFMDemodBaseband::handleMessage(const Message& cmd)

return true;
}
else if (DSPConfigureAudio::match(cmd)) // the audio device reports its rate (it may differ from the one asked)
{
QMutexLocker mutexLocker(&m_mutex);
const DSPConfigureAudio& cfg = (const DSPConfigureAudio&) cmd;

if ((cfg.getAudioType() == DSPConfigureAudio::AudioOutput) && (cfg.getSampleRate() > 0)
&& (cfg.getSampleRate() != (int) m_sink.getAudioSampleRate()))
{
m_sink.applyAudioSampleRate(cfg.getSampleRate());
}

return true;
}
else
{
return false;
Expand Down
19 changes: 15 additions & 4 deletions plugins/channelrx/demodbfm/bfmdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BFMDemodSink::BFMDemodSink() :
m_deemphasisFilterY.configure(m_settings.getDeEmphasisTimeConstant() * m_audioSampleRate);
m_phaseDiscri.setFMScaling(384000/m_fmExcursion);

m_audioBuffer.resize(1<<14);
m_audioBuffer.resize(m_audioSampleRate / 50); // 20 ms
m_audioBufferFill = 0;

m_demodBuffer.resize(1<<13);
Expand Down Expand Up @@ -232,10 +232,8 @@ void BFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV
{
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));

if (res != m_audioBufferFill)
{
if (res != m_audioBufferFill) { // the FIFO kept what fits: the rest is dropped, not the FIFO
qDebug("BFMDemodSink::feed: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}

m_audioBufferFill = 0;
Expand Down Expand Up @@ -296,6 +294,19 @@ void BFMDemodSink::applyAudioSampleRate(int sampleRate)
m_deemphasisFilterX.configure(m_settings.getDeEmphasisTimeConstant() * sampleRate);
m_deemphasisFilterY.configure(m_settings.getDeEmphasisTimeConstant() * sampleRate);

// audio written in 20 ms blocks
unsigned int audioBlock = std::max(1, sampleRate / 50);

if (m_audioBuffer.size() != audioBlock)
{
if (m_audioBufferFill > 0) {
m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
}

m_audioBuffer.resize(audioBlock);
m_audioBufferFill = 0;
}

m_audioSampleRate = sampleRate;

if (m_channel)
Expand Down
13 changes: 13 additions & 0 deletions plugins/channelrx/demodradiopaging/radiopagingdemodbaseband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ bool RadioPagingDemodBaseband::handleMessage(const Message& cmd)

return true;
}
else if (DSPConfigureAudio::match(cmd)) // the audio device reports its rate (it may differ from the one asked)
{
QMutexLocker mutexLocker(&m_mutex);
const DSPConfigureAudio& cfg = (const DSPConfigureAudio&) cmd;

if ((cfg.getAudioType() == DSPConfigureAudio::AudioOutput) && (cfg.getSampleRate() > 0)
&& (cfg.getSampleRate() != m_sink.getAudioSampleRate()))
{
m_sink.applyAudioSampleRate(cfg.getSampleRate());
}

return true;
}
else
{
return false;
Expand Down
14 changes: 11 additions & 3 deletions plugins/channelrx/demodradiopaging/radiopagingdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const double voiceCutoff = 3000.0; // Hz, upper edge of the voice band
const int voiceWriteSamples = 4096; // Voice samples written to the file at a time
const qint64 voiceMinFreeBytes = 500LL * 1024 * 1024; // No recording on a disk with less free space
const Real dcBlockPole = 0.995f; // About 30 Hz at 38400 Hz
const int audioBufferSize = 1 << 12;
const double huntCentreDecay = 0.967216; // exp(-1 s / 30 s), per second
const double narrowResidual = 300.0; // Hz: a leg is narrowed once a measurement is this close

Expand Down Expand Up @@ -293,7 +292,7 @@ RadioPagingDemodSink::RadioPagingDemodSink() :
m_dcOut(0.0f),
m_statusCount(0)
{
m_audioBuffer.resize(audioBufferSize);
m_audioBuffer.resize(m_audioSampleRate / 50); // 20 ms
m_scopeBuffer.resize(m_scopeBufferSize);
m_audioInterpolator.create(16, RadioPagingDemodSettings::m_channelSampleRate, voiceCutoff);

Expand Down Expand Up @@ -726,7 +725,13 @@ void RadioPagingDemodSink::applyAudioSampleRate(int sampleRate)
}

closeAudio();
m_audioFifo.setSize(sampleRate);

if (sampleRate != m_audioSampleRate) { // setSize empties the FIFO: only when the rate changes
m_audioFifo.setSize(sampleRate);
}

m_audioBuffer.resize(std::max(1, sampleRate / 50)); // 20 ms blocks
m_audioBufferFill = 0;
m_audioDistance = (Real) RadioPagingDemodSettings::m_channelSampleRate / (Real) sampleRate;
m_audioDistanceRemain = m_audioDistance;
m_audioSampleRate = sampleRate;
Expand Down Expand Up @@ -900,6 +905,9 @@ void RadioPagingDemodSink::closeAudio()
m_audioBufferFill = 0;
}

// 50 ms of silence after the voice: the output reads whole blocks, so the end of the voice is played
std::vector<AudioSample> silence(m_audioSampleRate / 20, AudioSample{0, 0});
m_audioFifo.write((const quint8*) silence.data(), silence.size());
m_audioOpen = false;
finishVoiceRecording();
}
Expand Down
2 changes: 2 additions & 0 deletions sdrbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ set(sdrbase_SOURCES
audio/audiodevicemanager.cpp
audio/audiofilereader.cpp
audio/audiofifo.cpp
audio/audiofiforeader.cpp
audio/audiofilter.cpp
audio/audiog722.cpp
audio/audioopus.cpp
Expand Down Expand Up @@ -380,6 +381,7 @@ set(sdrbase_HEADERS
audio/audiodevicemanager.h
audio/audiofilereader.h
audio/audiofifo.h
audio/audiofiforeader.h
audio/audiofilter.h
audio/audiog722.h
audio/audiooutputdevice.h
Expand Down
Loading
Loading