SoDaRadio-5.0.3-master:8901fb5
BaseBandRX.hxx
Go to the documentation of this file.
1 /*
2 Copyright (c) 2012,2013,2014 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef BASEBANDRX_HDR
30 #define BASEBANDRX_HDR
31 #include "SoDaBase.hxx"
32 #include "Params.hxx"
33 #include "MultiMBox.hxx"
34 #include "Command.hxx"
35 #include "OSFilter.hxx"
36 #include "HilbertTransformer.hxx"
37 #include "ReSamplers625x48.hxx"
38 #include "AudioIfc.hxx"
39 #include "MedianFilter.hxx"
40 
41 #include <queue>
42 #include <boost/thread.hpp>
43 #include <boost/thread/thread.hpp>
44 #include <boost/thread/mutex.hpp>
45 #include <boost/thread/condition.hpp>
46 #include <fstream>
47 #include <string>
48 
49 namespace SoDa {
75  class BaseBandRX : public SoDaThread {
76  public:
85  BaseBandRX(Params * params,
86  DatMBox * rx_stream,
89 
93  void run();
94 
95  private:
100  void execGetCommand(Command * cmd);
105  void execSetCommand(Command * cmd);
110  void execRepCommand(Command * cmd);
111 
119  void demodulateSSB(std::complex<float> * drxbuf,
121 
128  void demodulateAM(std::complex<float> * drxbuf);
129 
138  void demodulateNBFM(std::complex<float> * drxbuf,
140  float af_gain);
141 
153  void demodulateWBFM(SoDaBuf * rxbuf,
155  float af_gain);
156 
157 
164  void demodulate(SoDaBuf * rxbuf);
165 
170  void repAFFilterShape();
171 
172  // parameters
173  unsigned int audio_buffer_size;
174  unsigned int rf_buffer_size;
176  double rf_sample_rate;
180 
182 
185  unsigned int rx_subs;
186  unsigned int cmd_subs;
187 
189 
190  // buffer pool management
191 
198  void pendAudioBuffer(float * b);
199 
205  float * getNextAudioBuffer();
209  void flushAudioBuffers();
215  void freeAudioBuffer(float * b);
222  float * getFreeAudioBuffer();
223 
227  int readyAudioBuffers();
228 
229 
230  // flow timing management
231  bool in_catchup;
232  bool in_fallback;
233  unsigned int catchup_rand_mask;
234 
235  std::queue<float *> free_buffers;
236  std::queue<float *> ready_buffers;
237 
238  boost::mutex free_lock;
239  boost::mutex ready_lock;
240 
242 
243  // resampler -- downsample from 625K samples / sec to 48K samples/sec
245  // a second resampler for wideband fm
247 
251  void buildFilterMap();
252 
259 
260 
261 
262  std::map<SoDa::Command::AudioFilterBW, SoDa::OSFilter *> filter_map;
263 
264  // hilbert transformer
266 
267  // audio gain
268  float af_gain;
270  float *cur_af_gain;
271 
272  // support for NBFM/WBFM demodulator
274 
275  // median filter for FM demods
277 
278  // debug helper
279  unsigned int dbg_ctr;
280  std::ofstream dbg_out;
281 
282  // audio output file
284  std::ofstream audio_file;
285  std::ofstream audio_file2;
286 
287  };
288 }
289 
290 
291 #endif
The Baseclass for all SoDa objects, and useful commonly used classes.
The Thread baseclass for all SoDa thread objects.
Definition: SoDaBase.hxx:284
This is an overlap-and-save frequency domain implementation of a general FIR filter widget...
unsigned int rf_buffer_size
size of input RF buffer chunk
Definition: BaseBandRX.hxx:174
void demodulateSSB(std::complex< float > *drxbuf, SoDa::Command::ModulationType mod)
demodulate the input stream as an SSB signal place the resulting audio buffer on the audio output que...
Definition: BaseBandRX.cxx:201
SoDa::OSFilter * am_audio_filter
After AM demod, we do a second filter.
Definition: BaseBandRX.hxx:258
bool in_fallback
when true, the audio server has gotten ahead...
Definition: BaseBandRX.hxx:232
float af_gain
audio gain setting for RX mode
Definition: BaseBandRX.hxx:268
float * getNextAudioBuffer()
return the next queued audio buffer to pass to the audio output device
Definition: BaseBandRX.cxx:593
void demodulateAM(std::complex< float > *drxbuf)
demodulate the input stream as an amplitude modulated signal place the resulting audio buffer on the ...
Definition: BaseBandRX.cxx:220
Resampler for 625KHz to 48KHz data stream, built on rational ReSampler class.
BaseBandRX(Params *params, DatMBox *rx_stream, CmdMBox *cmd_stream, AudioIfc *audio_ifc)
the constructor
Definition: BaseBandRX.cxx:37
bool audio_rx_stream_enabled
if true, send pending audio buffers to output
Definition: BaseBandRX.hxx:177
This class handles command line parameters and built-ins.
Definition: Params.hxx:42
std::ofstream dbg_out
Definition: BaseBandRX.hxx:280
In several places we have a real valued signal x(t) that needs to be converted to an analytic signal ...
void flushAudioBuffers()
empty the queue of pending audio buffers, we&#39;re going into TX mode.
Definition: BaseBandRX.cxx:603
void demodulateWBFM(SoDaBuf *rxbuf, SoDa::Command::ModulationType mod, float af_gain)
demodulate the input stream as a wideband frequency modulated signal place the resulting audio buffer...
Definition: BaseBandRX.cxx:123
SoDa::ReSample625to48 * wbfm_resampler
downsample the RF input to 48KS/s for WBFM unit
Definition: BaseBandRX.hxx:246
void demodulate(SoDaBuf *rxbuf)
apply the currently selected demodulation scheme to the input RX buffer place the resulting audio buf...
Definition: BaseBandRX.cxx:246
The Buffer Class.
Definition: SoDaBase.hxx:72
bool sidetone_stream_enabled
if true, send CW sidetone to audio output
Definition: BaseBandRX.hxx:179
std::queue< float * > free_buffers
a pool of free audio buffers
Definition: BaseBandRX.hxx:235
SoDa::OSFilter * am_pre_filter
Before AM demod, we do some (6KHz) prefilter.
Definition: BaseBandRX.hxx:256
double audio_sample_rate
sample rate of audio output – assumed 48KHz
Definition: BaseBandRX.hxx:175
SoDa::Command::AudioFilterBW af_filter_selection
currently audio filter selector
Definition: BaseBandRX.hxx:253
This is a list of all the commands that can "do something" to one or more components in the SoDa radi...
Definition: Command.hxx:47
This is a simple median filter widget.
MedianFilter3< float > fmMedianFilter
simple 3 point median filter for FM units
Definition: BaseBandRX.hxx:276
boost::mutex free_lock
lock for the free_buffers pool
Definition: BaseBandRX.hxx:238
DatMBox * rx_stream
mailbox producing rx sample stream from USRP
Definition: BaseBandRX.hxx:183
CmdMBox * cmd_stream
mailbox producing command stream from user
Definition: BaseBandRX.hxx:184
AudioFilterBW
these are the possible audio filter bandwidths
Definition: Command.hxx:483
ModulationType
modulation selector targets take one of these values
Definition: Command.hxx:478
SoDa::OSFilter * fm_audio_filter
audio filter for FM (wider passband)
Definition: BaseBandRX.hxx:255
SoDa::Command::ModulationType rx_modulation
current receive modulation mode (USB,LSB,CW_U,CW_L,NBFM,WBFM,AM,...)
Definition: BaseBandRX.hxx:181
unsigned int audio_buffer_size
size of output audio buffer chunk
Definition: BaseBandRX.hxx:173
SoDa::HilbertTransformer * hilbert
hilbert transform object for SSB/CW widgets
Definition: BaseBandRX.hxx:265
void freeAudioBuffer(float *b)
add an audio buffer to the free list, we&#39;ve dispatched it.
Definition: BaseBandRX.cxx:558
unsigned int dbg_ctr
debug counter, used to support one-time or infrequent bulletins
Definition: BaseBandRX.hxx:279
SoDa::OSFilter * nbfm_pre_filter
Before NBFM demod, we do some (15KHz) prefilter – rf rate.
Definition: BaseBandRX.hxx:257
void demodulateNBFM(std::complex< float > *drxbuf, SoDa::Command::ModulationType mod, float af_gain)
demodulate the input stream as a narrowband frequency modulated signal place the resulting audio buff...
Definition: BaseBandRX.cxx:160
void buildFilterMap()
build the audio filter map for selected bandwidths
Definition: BaseBandRX.cxx:614
boost::mutex ready_lock
lock for the ready_buffers_pool
Definition: BaseBandRX.hxx:239
unsigned int cmd_subs
mailbox subscription ID for command stream
Definition: BaseBandRX.hxx:186
double rf_sample_rate
sample rate of RF input from USRP – assumed 625KHz
Definition: BaseBandRX.hxx:176
void execGetCommand(Command *cmd)
execute GET commands from the command channel
Definition: BaseBandRX.cxx:397
int readyAudioBuffers()
return number audio buffers available
Definition: BaseBandRX.cxx:576
BaseBandRX – this is the audio processing chain for the recieve path.
Definition: BaseBandRX.hxx:75
Overlap-and-save filter class.
Definition: OSFilter.hxx:50
SoDa::OSFilter * cur_audio_filter
currently selected audio filter
Definition: BaseBandRX.hxx:254
std::map< SoDa::Command::AudioFilterBW, SoDa::OSFilter * > filter_map
map filter selectors to the filter objects
Definition: BaseBandRX.hxx:262
AudioIfc * audio_ifc
pointer to the audio interface (output) object
Definition: BaseBandRX.hxx:188
std::ofstream audio_file
Definition: BaseBandRX.hxx:284
void execSetCommand(Command *cmd)
handle SET commands from the command channel
Definition: BaseBandRX.cxx:321
SoDa::ReSample625to48 * rf_resampler
downsample the RF input to 48KS/s
Definition: BaseBandRX.hxx:244
void pendAudioBuffer(float *b)
put an audio buffer on the "pending for output" list
Definition: BaseBandRX.cxx:582
Generic Audio Interface Class.
Definition: AudioIfc.hxx:44
std::ofstream audio_file2
Definition: BaseBandRX.hxx:285
float af_sidetone_gain
audio gain setting for TX/CW mode
Definition: BaseBandRX.hxx:269
void repAFFilterShape()
send a report of the lower and upper edges of the IF passband based on the current filter and modulat...
Definition: BaseBandRX.cxx:297
bool in_catchup
when true, the audio server has fallen behind...
Definition: BaseBandRX.hxx:231
float * getFreeAudioBuffer()
remove a buffer from the free list, or allocate one if the free list is empty.
Definition: BaseBandRX.cxx:563
float * cur_af_gain
pointer to the gain setting for this mode
Definition: BaseBandRX.hxx:270
float last_phase_samp
history value used to calculate dPhase/dt in FM atan based discriminator.
Definition: BaseBandRX.hxx:273
unsigned int catchup_rand_mask
a mask to use for fast selection of a random index into an audio buffer.
Definition: BaseBandRX.hxx:233
std::queue< float * > ready_buffers
a list of audio buffers ready to send to the output
Definition: BaseBandRX.hxx:236
unsigned int rx_subs
mailbox subscription ID for rx data stream
Definition: BaseBandRX.hxx:185
void run()
the run method – does the work of the audio receiver process
Definition: BaseBandRX.cxx:426
bool audio_rx_stream_needs_start
if true, the audio output device needs a wakeup
Definition: BaseBandRX.hxx:178
void execRepCommand(Command *cmd)
handle Report commands from the command channel
Definition: BaseBandRX.cxx:421
float * sidetone_silence
a sequence of zero samples to stuff silence into the audio
Definition: BaseBandRX.hxx:241