Repair audio mixer_F32

pull/11/head
boblark 4 years ago
parent 03c774f77f
commit c2a9ac34a2
  1. 67
      AudioMixer_F32.cpp
  2. 46
      examples/ReceiverPart2/ReceiverPart2.ino

@ -1,22 +1,30 @@
// Fix 1 to n problem Bob Larkin June 2020 /* Fix 1 to n problem Bob Larkin June 2020
// Need to convert to TYmpan routine?? * 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" #include "AudioMixer_F32.h"
void AudioMixer4_F32::update(void) { void AudioMixer4_F32::update(void) {
audio_block_f32_t *in, *out=NULL; audio_block_f32_t *in, *out=NULL;
int channel = 0;
out = receiveWritable_f32(0); //get the first available channel
if (!out) return; while (channel < 4) {
out = receiveWritable_f32(channel);
arm_scale_f32(out->data, multiplier[0], out->data, out->length); if (out) break;
channel++;
for (int channel=0; channel < 4; channel++) { // Was 1 to 3 RSL June 2020
in = receiveReadOnly_f32(channel);
if (!in) {
continue;
} }
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(); audio_block_f32_t *tmp = allocate_f32();
arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length);
@ -24,29 +32,33 @@ void AudioMixer4_F32::update(void) {
AudioStream_F32::release(tmp); AudioStream_F32::release(tmp);
AudioStream_F32::release(in); AudioStream_F32::release(in);
} else {
//do nothing, this vector is empty
}
channel++;
} }
if (out) {
AudioStream_F32::transmit(out); AudioStream_F32::transmit(out);
AudioStream_F32::release(out); AudioStream_F32::release(out);
}
} }
void AudioMixer8_F32::update(void) { void AudioMixer8_F32::update(void) {
audio_block_f32_t *in, *out=NULL; audio_block_f32_t *in, *out=NULL;
out = receiveWritable_f32(0); //try to get the first input channel //get the first available channel
if (!out) return; //if it's not there, return immediately int channel = 0;
while (channel < 8) {
arm_scale_f32(out->data, multiplier[0], out->data, out->length); //scale the first input channel out = receiveWritable_f32(channel);
if (out) break;
//load and process the rest of the channels channel++;
for (int channel=0; channel < 8; channel++) { // Was 1 to 7 RSL June 2020
in = receiveReadOnly_f32(channel);
if (!in) {
continue;
} }
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(); audio_block_f32_t *tmp = allocate_f32();
arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length); arm_scale_f32(in->data, multiplier[channel], tmp->data, tmp->length);
@ -54,10 +66,11 @@ void AudioMixer8_F32::update(void) {
AudioStream_F32::release(tmp); AudioStream_F32::release(tmp);
AudioStream_F32::release(in); AudioStream_F32::release(in);
} else {
//do nothing, this vector is empty
}
channel++;
} }
if (out) {
AudioStream_F32::transmit(out); AudioStream_F32::transmit(out);
AudioStream_F32::release(out); AudioStream_F32::release(out);
}
} }

@ -1,5 +1,5 @@
/* ReceiverPart2.ino Bob Larkin 29 April 2020 /* 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 * Single Sideband (SSB) and Narrow Band FM (NBFM). SSB
* breaks into Lower Sidband (LSB) and Upper Sideband (USB). * breaks into Lower Sidband (LSB) and Upper Sideband (USB).
* It gets even better in that AM can be received on either * It gets even better in that AM can be received on either
@ -33,10 +33,13 @@
* *
* FM Det gives 0.50 out for about 5.6 kHz p-p deviation * FM Det gives 0.50 out for about 5.6 kHz p-p deviation
* *
* T3.6 Processor load, measured: 16% for NBFM * With a 14 kHz input sine wave, 0.5 Vp-p the LSB output is 0.738 p-p
* 30% for LSB or USB 29 tap LPF * With 15kHz, 1000Hz FM modulation, 2 kHz deviation, NBFM output is 0.173 p-p
*
* 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 * 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" #include "Audio.h"
@ -68,8 +71,8 @@ RadioFMDetector_F32 fmdet1; // NBFM from 10 to 20 kHz
AudioMixer4_F32 sum2; // SSB and NBFM rejoin here AudioMixer4_F32 sum2; // SSB and NBFM rejoin here
AudioConvert_F32toI16 cnvrt2; // Left AudioConvert_F32toI16 cnvrt2; // Left
AudioConvert_F32toI16 cnvrt3; // Right AudioConvert_F32toI16 cnvrt3; // Right
AudioOutputI2S i2sOut;
AudioAnalyzePeak_F32 peak1; AudioAnalyzePeak_F32 peak1;
AudioOutputI2S i2sOut;
AudioControlSGTL5000 sgtl5000_1; AudioControlSGTL5000 sgtl5000_1;
AudioConnection conI16_1(i2sIn, 0, cnvrt1, 0); // ADC 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 connect5(iqmixer1, 1, hilbert1, 1);
AudioConnection_F32 connect6(hilbert1, 0, sum1, 0); // Sideband select AudioConnection_F32 connect6(hilbert1, 0, sum1, 0); // Sideband select
AudioConnection_F32 connect7(hilbert1, 1, sum1, 1); AudioConnection_F32 connect7(hilbert1, 1, sum1, 1);
AudioConnection_F32 connect8(sum1, 0, fir1, 0); // Limit audio BW AudioConnection_F32 connect8(sum1, 0, fir1, 0); // Limit audio SSB BW
AudioConnection_F32 connect9(fir1, 0, sum2, 0); // Output of SSB AudioConnection_F32 connect9(fir1, 0, sum2, 0); // Output of SSB <<<THESE GOT REVERSED
AudioConnection_F32 connectA(fmdet1, 0, sum2, 1); // Output of FM AudioConnection_F32 connectA(fmdet1, 0, sum2, 1); // Output of FM
AudioConnection_F32 connectC(sum2, 0, cnvrt2, 0); // Out to the CODEC left AudioConnection_F32 connectC(sum2, 0, cnvrt2, 0); // Out to the CODEC left
AudioConnection_F32 connectD(sum2, 0, cnvrt3, 0); // and right AudioConnection_F32 connectD(sum2, 0, cnvrt3, 0); // and right
@ -133,6 +136,10 @@ void setup(void) {
Serial.print("FM Initialization errors: "); Serial.print("FM Initialization errors: ");
Serial.println( fmdet1.returnInitializeFMError() ); Serial.println( fmdet1.returnInitializeFMError() );
// The following enables error checking inside of the "ubdate()"
// Output goes to the Serial (USB) Monitor. Normally, this is quiet.
if (mode == NBFM) fmdet1.showError(1);
// See RadioFMDetector_F32.h for information on functions for modifying the // See RadioFMDetector_F32.h for information on functions for modifying the
// FM Detector. Default values are used here, starting with a 15 kHz center frequency. // FM Detector. Default values are used here, starting with a 15 kHz center frequency.
@ -141,8 +148,8 @@ void setup(void) {
// The gainControlDB goes in 1 dB steps. Convert here to a voltage ratio // The gainControlDB goes in 1 dB steps. Convert here to a voltage ratio
vGain = powf(10.0f, ((float32_t)gainControlDB)/20.0 ); vGain = powf(10.0f, ((float32_t)gainControlDB)/20.0 );
// And apply that ratio to the output summing block. Gain here for SSB only // And apply that ratio to the output summing block. Gain here for SSB only
sum2.gain(0, vGain); Serial.print("vGain = "); Serial.println(vGain, 4); sum2.gain(0, vGain); Serial.print("SSB vGain = "); Serial.println(vGain, 4);
sum2.gain(1, 1.0f); // FM gain sum2.gain(2, 1.0f); // FM gain
// The following enable error checking inside of the blocks indicated. // The following enable error checking inside of the blocks indicated.
// Output goes to the Serial (USB) Monitor. Use for debug. // Output goes to the Serial (USB) Monitor. Use for debug.
@ -151,27 +158,24 @@ void setup(void) {
} }
void loop(void) { void loop(void) {
// Here is where the adjustment of the volume control could go. if (peak1.available() ) {
// And anything else that needs regular attention, other Serial.print("P-P =");
// than the audio stream. Serial.println(peak1.readPeakToPeak(), 6);
}
if (peak1.available() ) {Serial.print("P-P ="); Serial.println(peak1.readPeakToPeak(), 6);} else
else Serial.println("Peak-Peak not available"); Serial.println("Peak-Peak not available");
Serial.print("CPU: Percent Usage, Max: "); Serial.print("CPU: Percent Usage, Max: ");
Serial.print(AudioProcessorUsage()); Serial.print(AudioProcessorUsage());
Serial.print(", "); Serial.print(", ");
Serial.print(AudioProcessorUsageMax()); Serial.println(AudioProcessorUsageMax());
Serial.print(" ");
Serial.print("Int16 Memory: "); Serial.print("Int16 Memory: ");
Serial.print(AudioMemoryUsage()); Serial.print(AudioMemoryUsage());
Serial.print(", "); Serial.print(", ");
Serial.print(AudioMemoryUsageMax()); Serial.println(AudioMemoryUsageMax());
Serial.print(" "); Serial.print("Float 32 Memory: ");
Serial.print("Float Memory: ");
Serial.print(AudioMemoryUsage_F32()); Serial.print(AudioMemoryUsage_F32());
Serial.print(", "); Serial.print(", ");
Serial.println(AudioMemoryUsageMax_F32()); Serial.println(AudioMemoryUsageMax_F32());
Serial.println();
delay(1000); delay(1000);
} }

Loading…
Cancel
Save