From c2a9ac34a28cda07e3a5d08c3616af33fd863035 Mon Sep 17 00:00:00 2001 From: boblark Date: Tue, 14 Jul 2020 20:48:29 -0700 Subject: [PATCH] Repair audio mixer_F32 --- AudioMixer_F32.cpp | 109 +++++++++++++---------- examples/ReceiverPart2/ReceiverPart2.ino | 46 +++++----- 2 files changed, 86 insertions(+), 69 deletions(-) diff --git a/AudioMixer_F32.cpp b/AudioMixer_F32.cpp index 5c644f8..b9135dc 100644 --- a/AudioMixer_F32.cpp +++ b/AudioMixer_F32.cpp @@ -1,63 +1,76 @@ -// Fix 1 to n problem Bob Larkin June 2020 -// Need to convert to TYmpan routine?? +/* Fix 1 to n problem Bob Larkin June 2020 + * Adapted to Chip Audette's Tympan routine. Allows random channels. + * Class name does not have "_OA" to be backward compatible. + * + * MIT License. use at your own risk. +*/ #include "AudioMixer_F32.h" void AudioMixer4_F32::update(void) { audio_block_f32_t *in, *out=NULL; - - out = receiveWritable_f32(0); - if (!out) return; - - arm_scale_f32(out->data, multiplier[0], out->data, out->length); - - for (int channel=0; channel < 4; channel++) { // Was 1 to 3 RSL June 2020 - in = receiveReadOnly_f32(channel); - if (!in) { - continue; - } - - audio_block_f32_t *tmp = allocate_f32(); - - arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); - arm_add_f32(out->data, tmp->data, out->data, tmp->length); - - AudioStream_F32::release(tmp); - AudioStream_F32::release(in); + int channel = 0; + + //get the first available channel + while (channel < 4) { + out = receiveWritable_f32(channel); + if (out) break; + channel++; } - - if (out) { - AudioStream_F32::transmit(out); - AudioStream_F32::release(out); + if (!out) return; //there was no data output array available, so exit. + arm_scale_f32(out->data, multiplier[channel], out->data, out->length); + + //add in the remaining channels, as available + channel++; + while (channel < 4) { + in = receiveReadOnly_f32(channel); + if (in) { + audio_block_f32_t *tmp = allocate_f32(); + + arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); + arm_add_f32(out->data, tmp->data, out->data, tmp->length); + + AudioStream_F32::release(tmp); + AudioStream_F32::release(in); + } else { + //do nothing, this vector is empty + } + channel++; } + AudioStream_F32::transmit(out); + AudioStream_F32::release(out); } void AudioMixer8_F32::update(void) { audio_block_f32_t *in, *out=NULL; - out = receiveWritable_f32(0); //try to get the first input channel - if (!out) return; //if it's not there, return immediately - - arm_scale_f32(out->data, multiplier[0], out->data, out->length); //scale the first input channel - - //load and process the rest of the channels - for (int channel=0; channel < 8; channel++) { // Was 1 to 7 RSL June 2020 - in = receiveReadOnly_f32(channel); - if (!in) { - continue; - } - - audio_block_f32_t *tmp = allocate_f32(); - - arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); - arm_add_f32(out->data, tmp->data, out->data, tmp->length); - - AudioStream_F32::release(tmp); - AudioStream_F32::release(in); + //get the first available channel + int channel = 0; + while (channel < 8) { + out = receiveWritable_f32(channel); + if (out) break; + channel++; } - - if (out) { - AudioStream_F32::transmit(out); - AudioStream_F32::release(out); + if (!out) return; //there was no data output array. so exit. + arm_scale_f32(out->data, multiplier[channel], out->data, out->length); + + //add in the remaining channels, as available + channel++; + while (channel < 8) { + in = receiveReadOnly_f32(channel); + if (in) { + audio_block_f32_t *tmp = allocate_f32(); + + arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); + arm_add_f32(out->data, tmp->data, out->data, tmp->length); + + AudioStream_F32::release(tmp); + AudioStream_F32::release(in); + } else { + //do nothing, this vector is empty + } + channel++; } + AudioStream_F32::transmit(out); + AudioStream_F32::release(out); } diff --git a/examples/ReceiverPart2/ReceiverPart2.ino b/examples/ReceiverPart2/ReceiverPart2.ino index 4f4d60f..db6586f 100644 --- a/examples/ReceiverPart2/ReceiverPart2.ino +++ b/examples/ReceiverPart2/ReceiverPart2.ino @@ -1,5 +1,5 @@ /* ReceiverPart2.ino Bob Larkin 29 April 2020 - * This is a simple SP radio design. It can receive 2 modes, + * This is a simple DSP radio design. It can receive 2 modes, * Single Sideband (SSB) and Narrow Band FM (NBFM). SSB * breaks into Lower Sidband (LSB) and Upper Sideband (USB). * It gets even better in that AM can be received on either @@ -32,11 +32,14 @@ * At LPF FIR Out 2.0 * * FM Det gives 0.50 out for about 5.6 kHz p-p deviation + * + * With a 14 kHz input sine wave, 0.5 Vp-p the LSB output is 0.738 p-p + * With 15kHz, 1000Hz FM modulation, 2 kHz deviation, NBFM output is 0.173 p-p * - * T3.6 Processor load, measured: 16% for NBFM - * 30% for LSB or USB 29 tap LPF + * T3.6 Processor load, measured: 17% for NBFM + * 31% for LSB or USB, 29 tap LPF * T4.0 Processor load, measured: 4.3% for NBFM - * 6.5% for LSB or USB 29 tap LPF + * 6.5% for LSB or USB, 29 tap LPF */ #include "Audio.h" @@ -68,8 +71,8 @@ RadioFMDetector_F32 fmdet1; // NBFM from 10 to 20 kHz AudioMixer4_F32 sum2; // SSB and NBFM rejoin here AudioConvert_F32toI16 cnvrt2; // Left AudioConvert_F32toI16 cnvrt3; // Right -AudioOutputI2S i2sOut; AudioAnalyzePeak_F32 peak1; +AudioOutputI2S i2sOut; AudioControlSGTL5000 sgtl5000_1; AudioConnection conI16_1(i2sIn, 0, cnvrt1, 0); // ADC @@ -81,8 +84,8 @@ AudioConnection_F32 connect4(iqmixer1, 0, hilbert1, 0); // Broadband 90 deg AudioConnection_F32 connect5(iqmixer1, 1, hilbert1, 1); AudioConnection_F32 connect6(hilbert1, 0, sum1, 0); // Sideband select AudioConnection_F32 connect7(hilbert1, 1, sum1, 1); -AudioConnection_F32 connect8(sum1, 0, fir1, 0); // Limit audio BW -AudioConnection_F32 connect9(fir1, 0, sum2, 0); // Output of SSB +AudioConnection_F32 connect8(sum1, 0, fir1, 0); // Limit audio SSB BW +AudioConnection_F32 connect9(fir1, 0, sum2, 0); // Output of SSB <<