34 #include <sys/types.h> 74 for(j = 0; j < 6; j++) {
114 debugMsg(
"audio_rx_stream_enabled = true\n");
143 float phase = arg(dbuf[i]);
145 if(dphase < -M_PI) dphase += 2.0 * M_PI;
146 if(dphase > M_PI) dphase -= 2.0 * M_PI;
147 demod_out[i] = af_gain * dphase;
148 last_phase_samp = phase;
178 float phase = arg(dbuf[i]);
180 if(dphase < -M_PI) dphase += 2.0 * M_PI;
181 if(dphase > M_PI) dphase -= 2.0 * M_PI;
182 demod_out[i] = af_gain * dphase;
183 last_phase_samp = phase;
189 audio_file2.write((
char*) demod_out, audio_buffer_size *
sizeof(std::complex<float>));
192 audio_buffer[i] = demod_out[i].real();
214 audio_buffer[i] = (float) (dbuf[i].real() + sbmul * dbuf[i].imag());
229 float v = 0.5 * abs(dbuf[i]);
230 if(v > maxval) maxval = v;
234 sumsq = sqrt(sumsq / ((
float) audio_buffer_size));
303 fshape.first, fshape.second));
308 -fshape.first, -fshape.second));
312 -fshape.second, fshape.second));
351 debugMsg(
"audio_rx_stream_enabled = false\n");
359 debugMsg(
"audio_rx_stream_enabled = true\n");
428 bool exitflag =
false;
438 int null_audio_buf_count = 0;
440 int catchup_count = 0;
442 int restart_count = 0;
444 bool did_work =
false;
445 bool did_audio_work =
false;
495 did_audio_work =
true;
522 null_audio_buf_count++;
534 if(rxbuf == NULL)
break;
544 if(!did_audio_work && !did_work) {
559 boost::mutex::scoped_lock lock(
free_lock);
565 boost::mutex::scoped_lock lock(
free_lock);
The Thread baseclass for all SoDa thread objects.
This is an overlap-and-save frequency domain implementation of a general FIR filter widget...
void debugMsg(const std::string &msg, unsigned int threshold=1)
turn transmitter on and off.
UnitSelector
a selector to identify a particular unit for debug reports
T * get(unsigned int subscriber_id)
unsigned int rf_buffer_size
size of input RF buffer chunk
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...
std::string & getObjName()
get the name of this object
SoDa::OSFilter * am_audio_filter
After AM demod, we do a second filter.
bool in_fallback
when true, the audio server has gotten ahead...
float af_gain
audio gain setting for RX mode
Set the modulation mode for the receive chain.
float * getNextAudioBuffer()
return the next queued audio buffer to pass to the audio output device
void demodulateAM(std::complex< float > *drxbuf)
demodulate the input stream as an amplitude modulated signal place the resulting audio buffer on the ...
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
int iparms[4]
integer parameters
double getAudioSampleRate() const
bool audio_rx_stream_enabled
if true, send pending audio buffers to output
Set the modulation mode for the transmit chain.
virtual int send(void *buf, unsigned int len)=0
send – send a buffer to the audio output
This class handles command line parameters and built-ins.
The SoDa Exception class.
void flushAudioBuffers()
empty the queue of pending audio buffers, we're going into TX mode.
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...
CmdTarget target
the thing we're touching
SoDa::ReSample625to48 * wbfm_resampler
downsample the RF input to 48KS/s for WBFM unit
void demodulate(SoDaBuf *rxbuf)
apply the currently selected demodulation scheme to the input RX buffer place the resulting audio buf...
double getRXRate() const
Sample rates and all that other stuff are fixed.
void apply(std::complex< float > *in, std::complex< float > *out)
Perform the resampling on a complex float buffer.
bool sidetone_stream_enabled
if true, send CW sidetone to audio output
virtual std::string currentPlaybackState()
unsigned int getRFBufferSize() const
std::queue< float * > free_buffers
a pool of free audio buffers
On receipt of a STOP command, all threads should exit their run loop.
SoDa::OSFilter * am_pre_filter
Before AM demod, we do some (6KHz) prefilter.
double audio_sample_rate
sample rate of audio output – assumed 48KHz
std::complex< float > * getComplexBuf()
Return a pointer to the storage buffer of complex floats.
SoDa::Command::AudioFilterBW af_filter_selection
currently audio filter selector
This is a list of all the commands that can "do something" to one or more components in the SoDa radi...
virtual bool sendBufferReady(unsigned int len)=0
sendBufferReady – is there enough space in the audio device send buffer for a call from send...
boost::mutex free_lock
lock for the free_buffers pool
unsigned int getAFBufferSize() const
DatMBox * rx_stream
mailbox producing rx sample stream from USRP
CmdMBox * cmd_stream
mailbox producing command stream from user
AudioFilterBW
these are the possible audio filter bandwidths
ModulationType
modulation selector targets take one of these values
SoDa::OSFilter * fm_audio_filter
audio filter for FM (wider passband)
SoDa::Command::ModulationType rx_modulation
current receive modulation mode (USB,LSB,CW_U,CW_L,NBFM,WBFM,AM,...)
unsigned int audio_buffer_size
size of output audio buffer chunk
SoDa::HilbertTransformer * hilbert
hilbert transform object for SSB/CW widgets
void freeAudioBuffer(float *b)
add an audio buffer to the free list, we've dispatched it.
unsigned int dbg_ctr
debug counter, used to support one-time or infrequent bulletins
SoDa::OSFilter * nbfm_pre_filter
Before NBFM demod, we do some (15KHz) prefilter – rf rate.
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...
void buildFilterMap()
build the audio filter map for selected bandwidths
boost::mutex ready_lock
lock for the ready_buffers_pool
unsigned int cmd_subs
mailbox subscription ID for command stream
double rf_sample_rate
sample rate of RF input from USRP – assumed 625KHz
void execGetCommand(Command *cmd)
execute GET commands from the command channel
int readyAudioBuffers()
return number audio buffers available
double dparms[4]
double float parameters
Overlap-and-save filter class.
SoDa::OSFilter * cur_audio_filter
currently selected audio filter
virtual void sleepOut()=0
stop the output stream so that we don't encounter a buffer underflow while the reciever is muted...
virtual void wakeOut()=0
start the output stream
std::map< SoDa::Command::AudioFilterBW, SoDa::OSFilter * > filter_map
map filter selectors to the filter objects
AudioIfc * audio_ifc
pointer to the audio interface (output) object
void execSetCommand(Command *cmd)
handle SET commands from the command channel
SoDa::ReSample625to48 * rf_resampler
downsample the RF input to 48KS/s
void pendAudioBuffer(float *b)
put an audio buffer on the "pending for output" list
Generic Audio Interface Class.
std::ofstream audio_file2
RX audio gain for sidetone (CW) monitor.
unsigned int apply(std::complex< float > *inbuf, std::complex< float > *outbuf, float outgain=1.0)
run the filter on a complex input stream
float af_sidetone_gain
audio gain setting for TX/CW mode
void repAFFilterShape()
send a report of the lower and upper edges of the IF passband based on the current filter and modulat...
std::pair< double, double > getFilterEdges()
bool in_catchup
when true, the audio server has fallen behind...
float * getFreeAudioBuffer()
remove a buffer from the free list, or allocate one if the free list is empty.
float * cur_af_gain
pointer to the gain setting for this mode
float last_phase_samp
history value used to calculate dPhase/dt in FM atan based discriminator.
unsigned int catchup_rand_mask
a mask to use for fast selection of a random index into an audio buffer.
std::queue< float * > ready_buffers
a list of audio buffers ready to send to the output
unsigned int rx_subs
mailbox subscription ID for rx data stream
void execCommand(Command *cmd)
Execute (dispatch) a message removed from the command stream to one of the basic Command handler func...
void run()
the run method – does the work of the audio receiver process
bool audio_rx_stream_needs_start
if true, the audio output device needs a wakeup
void execRepCommand(Command *cmd)
handle Report commands from the command channel
float * sidetone_silence
a sequence of zero samples to stuff silence into the audio