Skip to content

Commit

Permalink
Merge pull request #1255 from gqrx-sdr/wav-file-attenuation
Browse files Browse the repository at this point in the history
Add 6 dB attentuation to WAV file recordings
  • Loading branch information
argilo authored Jun 18, 2023
2 parents f857267 + 4258dc1 commit a9725de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions resources/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
IMPROVED: Plot can be zoomed & resized while DSP is stopped.
IMPROVED: FFT window setting is stored as a string.
IMPROVED: Waterfall span setting is stored in milliseconds.
IMPROVED: Added 6 dB attenuation to WAV file recordings to prevent clipping.
CHANGED: Default narrow FM deviation increased to 5 kHz.
FIXED: Time on waterfall is calculated correctly.
FIXED: Frequency is correctly rounded in I/Q filenames.
Expand Down
24 changes: 18 additions & 6 deletions src/applications/gqrx/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#endif

#define DEFAULT_AUDIO_GAIN -6.0
#define WAV_FILE_GAIN 0.5
#define TARGET_QUAD_RATE 1e6

/**
Expand Down Expand Up @@ -1020,6 +1021,9 @@ receiver::status receiver::start_audio_recording(const std::string filename)
return STATUS_ERROR;
}

wav_gain0 = gr::blocks::multiply_const_ff::make(WAV_FILE_GAIN);
wav_gain1 = gr::blocks::multiply_const_ff::make(WAV_FILE_GAIN);

// if this fails, we don't want to go and crash now, do we
try {
#if GNURADIO_VERSION < 0x030900
Expand All @@ -1038,8 +1042,10 @@ receiver::status receiver::start_audio_recording(const std::string filename)
}

tb->lock();
tb->connect(rx, 0, wav_sink, 0);
tb->connect(rx, 1, wav_sink, 1);
tb->connect(rx, 0, wav_gain0, 0);
tb->connect(rx, 1, wav_gain1, 0);
tb->connect(wav_gain0, 0, wav_sink, 0);
tb->connect(wav_gain1, 0, wav_sink, 1);
tb->unlock();
d_recording_wav = true;

Expand Down Expand Up @@ -1068,15 +1074,19 @@ receiver::status receiver::stop_audio_recording()
// not strictly necessary to lock but I think it is safer
tb->lock();
wav_sink->close();
tb->disconnect(rx, 0, wav_sink, 0);
tb->disconnect(rx, 1, wav_sink, 1);
tb->disconnect(rx, 0, wav_gain0, 0);
tb->disconnect(rx, 1, wav_gain1, 0);
tb->disconnect(wav_gain0, 0, wav_sink, 0);
tb->disconnect(wav_gain1, 0, wav_sink, 1);

// Temporary workaround for https://github.com/gnuradio/gnuradio/issues/5436
tb->disconnect(ddc, 0, rx, 0);
tb->connect(ddc, 0, rx, 0);
// End temporary workaronud

tb->unlock();
wav_gain0.reset();
wav_gain1.reset();
wav_sink.reset();
d_recording_wav = false;

Expand Down Expand Up @@ -1395,8 +1405,10 @@ void receiver::connect_all(rx_chain type)
// Recorders and sniffers
if (d_recording_wav)
{
tb->connect(rx, 0, wav_sink, 0);
tb->connect(rx, 1, wav_sink, 1);
tb->connect(rx, 0, wav_gain0, 0);
tb->connect(rx, 1, wav_gain1, 0);
tb->connect(wav_gain0, 0, wav_sink, 0);
tb->connect(wav_gain1, 0, wav_sink, 1);
}

if (d_sniffer_active)
Expand Down
2 changes: 2 additions & 0 deletions src/applications/gqrx/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ class receiver

gr::blocks::multiply_const_ff::sptr audio_gain0; /*!< Audio gain block. */
gr::blocks::multiply_const_ff::sptr audio_gain1; /*!< Audio gain block. */
gr::blocks::multiply_const_ff::sptr wav_gain0; /*!< WAV file gain block. */
gr::blocks::multiply_const_ff::sptr wav_gain1; /*!< WAV file gain block. */

gr::blocks::file_sink::sptr iq_sink; /*!< I/Q file sink. */

Expand Down

0 comments on commit a9725de

Please sign in to comment.