SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
BaseBandRX.hxx
Go to the documentation of this file.
1#pragma once
2/*
3Copyright (c) 2012,2013,2014, 2026 Matthew H. Reilly (kb1vc)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are
8met:
9
10 Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29#include "SoDaBase.hxx"
30#include "SoDaThread.hxx"
31#include "Params.hxx"
32
33#include "Command.hxx"
35#include "AudioIfc.hxx"
36#include "MedianFilter.hxx"
37
38#include <SoDa/ReSampler.hxx>
39#include <SoDa/OSFilter.hxx>
40#include <SoDa/MailBox.hxx>
41
42#include <queue>
43#include <mutex>
44#include <fstream>
45#include <string>
46#include <memory>
47
48namespace SoDa {
79
80 class BaseBandRX;
81 typedef std::shared_ptr<BaseBandRX> BaseBandRXPtr;
82 typedef std::weak_ptr<BaseBandRX> BaseBandRXWeakPtr;
83
84 class BaseBandRX : public SoDa::Thread {
85 private:
86
95
96 public:
104 auto ret = std::shared_ptr<BaseBandRX>(new BaseBandRX(params, audio_ifc));
105 ret->self = ret;
106 ret->registerThread(ret);
107 return ret;
108 }
109
110
112 void subscribeToMailBoxes(const std::vector<MailBoxBasePtr> & mailboxes);
113
117 void run();
118
119
120
121 private:
126
131
147
157
165
176 float af_gain);
177
191 float af_gain);
192
193
201
207
208 // parameters
209 unsigned int audio_buffer_size;
210 unsigned int rf_buffer_size;
216
218
221 CDatMBox::Subscription rx_subs;
222 CmdMBox::Subscription cmd_subs;
223
225
226 // buffer pool management
227
235
241 void pendNullBuffer(int count = 1);
242
253
254 // flow timing management
257 unsigned int catchup_rand_mask;
258
260
261 // resampler -- downsample from 625K samples / sec to 48K samples/sec
262 SoDa::ReSamplerPtr rf_resampler;
263 // a second resampler for wideband fm
264 SoDa::ReSamplerPtr wbfm_resampler;
265
270
272 SoDa::OSFilterPtr cur_audio_filter;
273 SoDa::OSFilterPtr fm_audio_filter;
274 SoDa::OSFilterPtr am_pre_filter;
275 SoDa::OSFilterPtr nbfm_pre_filter;
276 SoDa::OSFilterPtr am_audio_filter;
277
278 std::map<SoDa::Command::AudioFilterBW, SoDa::OSFilterPtr> filter_map;
279
280 // hilbert transformer
282
283 // audio gain
284 float af_gain;
286 float *cur_af_gain;
287
288 // support for NBFM/WBFM demodulator
290
291 // median filter for FM demods
293
294 // debug helper
295 unsigned int dbg_ctr;
296 std::ofstream dbg_out;
297
298 // audio output file
300 std::ofstream audio_file;
301 std::ofstream audio_file2;
302
303 // recent audio level
306
310 };
311}
312
This is a simple median filter widget.
The Baseclass for all SoDa objects, and useful commonly used classes.
The Baseclass for all SoDa thread objects.
SoDa::OSFilterPtr nbfm_pre_filter
Before NBFM demod, we do some (15KHz) prefilter – rf rate.
SoDa::OSFilterPtr cur_audio_filter
currently selected audio filter
void execSetCommand(CommandPtr cmd)
handle SET commands from the command channel
void demodulateNBFM(SoDa::CBufPtr drxbuf, SoDa::Command::ModulationType mod, float af_gain)
demodulate the input stream as a narrowband frequency modulated signal place the resulting audio buff...
float nbfm_squelch_level
average amplitude must be greater to trigger demod.
void demodulate(SoDa::CBufPtr rxbuf)
apply the currently selected demodulation scheme to the input RX buffer place the resulting audio buf...
unsigned int audio_buffer_size
size of output audio buffer chunk
BaseBandRX(ParamsPtr params, AudioIfcPtr audio_ifc)
the constructor
SoDa::OSFilterPtr am_pre_filter
Before AM demod, we do some (6KHz) prefilter.
float last_phase_samp
history value used to calculate dPhase/dt in FM atan based discriminator.
int nbfm_squelch_hang_time
continue FM audio demod for this many frames after threshold drops
void demodulateWBFM(SoDa::CBufPtr rxbuf, SoDa::Command::ModulationType mod, float af_gain)
demodulate the input stream as a wideband frequency modulated signal place the resulting audio buffer...
unsigned int dbg_ctr
debug counter, used to support one-time or infrequent bulletins
void execRepCommand(CommandPtr cmd)
handle Report commands from the command channel
SoDa::Command::AudioFilterBW af_filter_selection
currently audio filter selector
SoDa::OSFilterPtr am_audio_filter
After AM demod, we do a second filter.
void demodulateAM(SoDa::CBufPtr drxbuf)
demodulate the input stream as an amplitude modulated signal place the resulting audio buffer on the ...
std::ofstream audio_file
float * getNextAudioBuffer()
return the next queued audio buffer to pass to the audio output device
double audio_sample_rate
sample rate of audio output – assumed 48KHz
static BaseBandRXPtr make(ParamsPtr params, AudioIfcPtr audio_ifc)
the maker – produces a shared pointer p
bool in_catchup
when true, the audio server has fallen behind...
void demodulateSSB(SoDa::CBufPtr drxbuf, SoDa::Command::ModulationType mod)
demodulate the input stream as an SSB signal place the resulting audio buffer on the audio output que...
bool audio_rx_stream_enabled
if true, send pending audio buffers to output
SoDa::FBufPtr sidetone_silence
a sequence of zero samples to stuff silence into the audio
float af_sidetone_gain
audio gain setting for TX/CW mode
SoDa::ReSamplerPtr wbfm_resampler
downsample the RF input to 48KS/s for WBFM unit
int nbfm_squelch_hang_count
if > 0 then send audio.
unsigned int rf_buffer_size
size of input RF buffer chunk
void pendNullBuffer(int count=1)
put an empty (zero signal) audio buffer on the pending for output list
float * cur_af_gain
pointer to the gain setting for this mode
float log_audio_buffer_size
double rf_sample_rate
sample rate of RF input from USRP – assumed 625KHz
void flushAudioBuffers()
empty the queue of pending audio buffers, we're going into TX mode.
bool in_fallback
when true, the audio server has gotten ahead...
void run()
the run method – does the work of the audio receiver process
float af_gain
audio gain setting for RX mode
AudioIfcPtr audio_ifc
pointer to the audio interface (output) object
MedianFilter3< float > fmMedianFilter
simple 3 point median filter for FM units
bool sidetone_stream_enabled
if true, send CW sidetone to audio output
bool audio_rx_stream_needs_start
if true, the audio output device needs a wakeup
SoDa::OSFilterPtr fm_audio_filter
audio filter for FM (wider passband)
void subscribeToMailBoxes(const std::vector< MailBoxBasePtr > &mailboxes)
implement the subscription method
CDatMBoxPtr rx_stream
mailbox producing rx sample stream from USRP
void repAFFilterShape()
send a report of the lower and upper edges of the IF passband based on the current filter and modulat...
SoDa::Command::ModulationType rx_modulation
current receive modulation mode (USB,LSB,CW_U,CW_L,NBFM,WBFM,AM,...)
unsigned int catchup_rand_mask
a mask to use for fast selection of a random index into an audio buffer.
SoDa::ReSamplerPtr rf_resampler
downsample the RF input to 48KS/s
void pendAudioBuffer(SoDa::FBufPtr b)
put an audio buffer on the "pending for output" list
CDatMBox::Subscription rx_subs
mailbox subscription ID for rx data stream
void buildFilterMap()
build the audio filter map for selected bandwidths
std::map< SoDa::Command::AudioFilterBW, SoDa::OSFilterPtr > filter_map
map filter selectors to the filter objects
std::ofstream audio_file2
CmdMBoxPtr cmd_stream
mailbox producing command stream from user
void reportAFFilters()
report all filters supported.
void execGetCommand(CommandPtr cmd)
execute GET commands from the command channel
std::ofstream dbg_out
SoDa::HilbertTransformerPtr hilbert
hilbert transform object for SSB/CW widgets
CmdMBox::Subscription cmd_subs
mailbox subscription ID for command stream
void reportModes()
report all demod modes supported.
ModulationType
modulation selector targets take one of these values
Definition Command.hxx:532
AudioFilterBW
these are the possible audio filter bandwidths
Definition Command.hxx:546
3 point Median Filter class – templatized (!)
The Thread baseclass for all SoDa thread objects.
std::shared_ptr< HilbertTransformer > HilbertTransformerPtr
std::shared_ptr< FBuf > FBufPtr
Definition SoDaBase.hxx:61
std::shared_ptr< BaseBandRX > BaseBandRXPtr
std::shared_ptr< Params > ParamsPtr
Definition Params.hxx:42
std::shared_ptr< Command > CommandPtr
Definition Command.hxx:41
std::shared_ptr< AudioIfc > AudioIfcPtr
Definition AudioIfc.hxx:36
std::shared_ptr< CmdMBox > CmdMBoxPtr
Definition SoDaBase.hxx:79
std::shared_ptr< CDatMBox > CDatMBoxPtr
Definition SoDaBase.hxx:91
std::shared_ptr< CBuf > CBufPtr
Definition SoDaBase.hxx:64
std::weak_ptr< BaseBandRX > BaseBandRXWeakPtr