Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Simplify audio muting.
Browse files Browse the repository at this point in the history
Zero out the audio buffer instead of muting the codec. The HPF (and other downstream signal processing) can continue running, not produce discontinuities from being effectively halted during mute.
  • Loading branch information
jboone committed Jul 21, 2015
1 parent 9a8552e commit ae62405
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions firmware/baseband/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,6 @@ class BasebandProcessor {
feed_audio_stats(audio);
}

void mute_audio_buffer() {
auto audio_buffer = audio::dma::tx_empty_buffer();;
for(size_t i=0; i<audio_buffer.count; i++) {
audio_buffer.p[i].left = audio_buffer.p[i].right = 0;
}
i2s::i2s0::tx_unmute();

// TODO: No hard-coded audio sampling rate!
mute_audio_stats(audio_buffer.count, 48000);
}

private:
BlockDecimator<256> channel_spectrum_decimator { 4 };

Expand Down Expand Up @@ -474,16 +463,6 @@ class BasebandProcessor {
);
}

void mute_audio_stats(const size_t count, const size_t sampling_rate) {
audio_stats.mute(
count,
sampling_rate,
[this](const AudioStatistics statistics) {
this->post_audio_stats_message(statistics);
}
);
}

void post_audio_stats_message(const AudioStatistics statistics) {
if( audio_stats_message.is_free() ) {
audio_stats_message.statistics = statistics;
Expand Down Expand Up @@ -572,15 +551,19 @@ class NarrowbandFMAudio : public BasebandProcessor {
auto audio = demod.execute(channel, work_audio_buffer);

static uint64_t audio_present_history = 0;
const auto audio_present = squelch.execute(audio);
audio_present_history = (audio_present_history << 1) | (audio_present ? 1 : 0);

if( audio_present_history ) {
audio_hpf.execute_in_place(audio);
fill_audio_buffer(audio);
} else {
mute_audio_buffer();
const auto audio_present_now = squelch.execute(audio);
audio_present_history = (audio_present_history << 1) | (audio_present_now ? 1 : 0);
const bool audio_present = (audio_present_history != 0);

if( !audio_present ) {
// Zero audio buffer.
for(size_t i=0; i<audio.count; i++) {
audio.p[i] = 0;
}
}

audio_hpf.execute_in_place(audio);
fill_audio_buffer(audio);
}

private:
Expand Down Expand Up @@ -727,7 +710,7 @@ class FSKProcessor : public BasebandProcessor {

auto demodulated = demod.execute(channel, work_demod_buffer);

mute_audio_buffer();
i2s::i2s0::tx_mute();

for(size_t i=0; i<demodulated.count; i++) {
clock_recovery.execute(demodulated.p[i], symbol_handler_fn);
Expand Down

0 comments on commit ae62405

Please sign in to comment.