From d92596397da83c7f8d1b6c568dfdbfb5208e5474 Mon Sep 17 00:00:00 2001 From: Chip Audette Date: Fri, 15 Oct 2021 15:02:28 -0400 Subject: [PATCH] Examples: Delete some deprecated FullSystems --- .../Deprecated/WDRC_8BandFIR/GHA_Alternates.h | 38 -- .../Deprecated/WDRC_8BandFIR/SerialManager.h | 173 ------ .../WDRC_8BandFIR/WDRC_8BandFIR.ino | 442 ---------------- .../WDRC_8BandIIR_wBT/GHA_Alternates.h | 38 -- .../WDRC_8BandIIR_wBT/GHA_Constants.h | 42 -- .../WDRC_8BandIIR_wBT/SerialManager.h | 178 ------- .../WDRC_8BandIIR_wBT/WDRC_8BandIIR_wBT.ino | 499 ------------------ .../WDRC_8BandIIR_wBT/filter_coeff_sos.h | 132 ----- .../WDRC_8BandIIR_wBT/makeIIRfilterbank.m | 78 --- 9 files changed, 1620 deletions(-) delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandFIR/GHA_Alternates.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandFIR/SerialManager.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandFIR/WDRC_8BandFIR.ino delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/GHA_Alternates.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/GHA_Constants.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/SerialManager.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/WDRC_8BandIIR_wBT.ino delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/filter_coeff_sos.h delete mode 100644 examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/makeIIRfilterbank.m diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/GHA_Alternates.h b/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/GHA_Alternates.h deleted file mode 100644 index 0d259e32..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/GHA_Alternates.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Here is an alternate configuration for the algorithms. The intention - * is that these settings would be for the "full-on gain" condition for ANSI - * testing. These values shown are place-holders until values can be - * tested and improved experimentally -*/ - -// these values should be probably adjusted experimentally until the gains run right up to -// the point of the output sounding bad. The only thing to adjust is the compression-start gain. - -//per-band processing parameters...all compression/expansion is defeated. Just gain is left. -BTNRH_WDRC::CHA_DSL dsl_fullon = {5, // attack (ms) - 300, // release (ms) - 115, //maxdB. calibration at 1kHz? dB SPL for input signal at 0 dBFS. Needs to be tailored to mic, spkrs, and mic gain. - 0, // 0=left, 1=right...ignored - 8, //num channels...ignored. 8 is always assumed - {317.1666, 502.9734, 797.6319, 1264.9, 2005.9, 3181.1, 5044.7}, // cross frequencies (Hz) - {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, // compression ratio for low-SPL region (ie, the expander..values should be < 1.0) - {45.0, 45.0, 33.0, 32.0, 36.0, 34.0, 36.0, 40.0}, // expansion-end kneepoint. not relevant when there is no expansion or compression. - {40.0, 40.0, 40.0, 40.0, 40.0, 40.0, 40.0, 40.0}, // compression-start gain. Tweak these values up until it sounds bad! - {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, // compression ratio. Set to 1.0 to defeat. - {50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0}, // compression-start kneepoint (input dB SPL). not relevant when there is no compression - {200.0,200.0,200.0,200.0,200.0,200.0,200.0,200.0} // output limiting threshold (comp ratio 10). set to large value to defeat. -}; - -// Here is the broadband limiter for the full-on gain condition. Only the "bolt" (last value) needs to be iterated. -BTNRH_WDRC::CHA_WDRC gha_fullon = {5.f, // attack time (ms) - 300.f, // release time (ms) - 24000.f, // sampling rate (Hz)...ignored. Set globally in the main program. - 115.f, // maxdB. calibration. dB SPL for signal at 0dBFS. Needs to be tailored to mic, spkrs, and mic gain. - 1.0, // compression ratio for lowest-SPL region (ie, the expansion region) (should be < 1.0. set to 1.0 for linear) - 0.0, // kneepoint of end of expansion region (set very low to defeat the expansion) - 0.f, // compression-start gain....set to zero for pure limitter - 130.f, // compression-start kneepoint...set to some high value to make it not relevant - 1.f, // compression ratio...set to 1.0 to make linear (to defeat) - 104.0 // output limiting threshold...hardwired to compression ratio of 10.0 -}; - diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/SerialManager.h b/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/SerialManager.h deleted file mode 100644 index b4f5a28d..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/SerialManager.h +++ /dev/null @@ -1,173 +0,0 @@ - -#ifndef _SerialManager_h -#define _SerialManager_h - -#include - -//add in the algorithm whose gains we wish to set via this SerialManager...change this if your gain algorithms class changes names! -#include "AudioEffectCompWDRC_F32.h" //change this if you change the name of the algorithm's source code filename -typedef AudioEffectCompWDRC_F32 GainAlgorithm_t; //change this if you change the algorithm's class name - -//now, define the Serial Manager class -class SerialManager { - public: - SerialManager(int n, GainAlgorithm_t *gain_algs, - AudioControlTestAmpSweep_F32 &_ampSweepTester, - AudioControlTestFreqSweep_F32 &_freqSweepTester, - AudioControlTestFreqSweep_F32 &_freqSweepTester_FIR) - : N_CHAN(n), - gain_algorithms(gain_algs), - ampSweepTester(_ampSweepTester), - freqSweepTester(_freqSweepTester), - freqSweepTester_FIR(_freqSweepTester_FIR) {}; - - void respondToByte(char c); - void printHelp(void); - void incrementChannelGain(int chan, float change_dB); - void decreaseChannelGain(int chan); - - float channelGainIncrement_dB = 2.5f; - int N_CHAN; - private: - GainAlgorithm_t *gain_algorithms; //point to first element in array of expanders - AudioControlTestAmpSweep_F32 &SweepTester; - AudioControlTestFreqSweep_F32 &freqSweepTester; - AudioControlTestFreqSweep_F32 &freqSweepTester_FIR; -}; - -void SerialManager::printHelp(void) { - Serial.println(); - Serial.println("SerialManager Help: Available Commands:"); - Serial.println(" h: Print this help"); - Serial.println(" g: Print the gain settings of the device."); - Serial.println(" C: Toggle printing of CPU and Memory usage"); - Serial.println(" l: Toggle printing of pre-gain per-channel signal levels (dBFS)"); - Serial.println(" L: Toggle printing of pre-gain per-channel signal levels (dBSPL, per DSL 'maxdB')"); - Serial.println(" A: Self-Generated Test: Amplitude sweep. End-to-End Measurement."); - Serial.println(" F: Self-Generated Test: Frequency sweep. End-to-End Measurement."); - Serial.println(" f: Self-Generated Test: Frequency sweep. Measure filterbank."); - Serial.print(" k: Increase the gain of all channels (ie, knob gain) by "); Serial.print(channelGainIncrement_dB); Serial.println(" dB"); - Serial.print(" K: Decrease the gain of all channels (ie, knob gain) by "); Serial.print(channelGainIncrement_dB); Serial.println(" dB"); - Serial.print(" 1,2,3,4,5,6,7,8: Increase linear gain of given channel (1-8) by "); Serial.print(channelGainIncrement_dB); Serial.println(" dB"); - Serial.print(" !,@,#,$,%,^,&,*: Decrease linear gain of given channel (1-8) by "); Serial.print(channelGainIncrement_dB); Serial.println(" dB"); - Serial.println(" D: Toggle between DSL configurations: NORMAL vs FULL-ON"); - Serial.println(); -} - -//functions in the main sketch that I want to call from here -extern void incrementKnobGain(float); -extern void printGainSettings(void); -extern void togglePrintMemoryAndCPU(void); -extern void togglePrintAveSignalLevels(bool); -extern void incrementDSLConfiguration(Stream *); - -//switch yard to determine the desired action -void SerialManager::respondToByte(char c) { - switch (c) { - case 'h': case '?': - printHelp(); break; - case 'g': case 'G': - printGainSettings(); break; - case 'k': - incrementKnobGain(channelGainIncrement_dB); break; - case 'K': //which is "shift k" - incrementKnobGain(-channelGainIncrement_dB); break; - case '1': - incrementChannelGain(1-1, channelGainIncrement_dB); break; - case '2': - incrementChannelGain(2-1, channelGainIncrement_dB); break; - case '3': - incrementChannelGain(3-1, channelGainIncrement_dB); break; - case '4': - incrementChannelGain(4-1, channelGainIncrement_dB); break; - case '5': - incrementChannelGain(5-1, channelGainIncrement_dB); break; - case '6': - incrementChannelGain(6-1, channelGainIncrement_dB); break; - case '7': - incrementChannelGain(7-1, channelGainIncrement_dB); break; - case '8': - incrementChannelGain(8-1, channelGainIncrement_dB); break; - case '!': //which is "shift 1" - incrementChannelGain(1-1, -channelGainIncrement_dB); break; - case '@': //which is "shift 2" - incrementChannelGain(2-1, -channelGainIncrement_dB); break; - case '#': //which is "shift 3" - incrementChannelGain(3-1, -channelGainIncrement_dB); break; - case '$': //which is "shift 4" - incrementChannelGain(4-1, -channelGainIncrement_dB); break; - case '%': //which is "shift 5" - incrementChannelGain(5-1, -channelGainIncrement_dB); break; - case '^': //which is "shift 6" - incrementChannelGain(6-1, -channelGainIncrement_dB); break; - case '&': //which is "shift 7" - incrementChannelGain(7-1, -channelGainIncrement_dB); break; - case '*': //which is "shift 8" - incrementChannelGain(8-1, -channelGainIncrement_dB); break; - case 'A': - //amplitude sweep test - { //limit the scope of any variables that I create here - ampSweepTester.setSignalFrequency_Hz(1000.f); - float start_amp_dB = -100.0f, end_amp_dB = 0.0f, step_amp_dB = 5.0f; - ampSweepTester.setStepPattern(start_amp_dB, end_amp_dB, step_amp_dB); - ampSweepTester.setTargetDurPerStep_sec(1.0); - } - Serial.println("Command Received: starting test using amplitude sweep..."); - ampSweepTester.begin(); - while (!ampSweepTester.available()) {delay(100);}; - Serial.println("Press 'h' for help..."); - break; - case 'C': case 'c': - Serial.println("Command Received: toggle printing of memory and CPU usage."); - togglePrintMemoryAndCPU(); break; - case 'D': - Serial.println("Command Received: changing DSL configuration...you will lose any custom gain values..."); - incrementDSLConfiguration(&Serial); - break; - case 'F': - //frequency sweep test...end-to-end - { //limit the scope of any variables that I create here - freqSweepTester.setSignalAmplitude_dBFS(-70.f); - float start_freq_Hz = 125.0f, end_freq_Hz = 12000.f, step_octave = powf(2.0,1.0/2.0); //pow(2.0,0.5) is 2 steps per octave - freqSweepTester.setStepPattern(start_freq_Hz, end_freq_Hz, step_octave); - freqSweepTester.setTargetDurPerStep_sec(1.0); - } - Serial.println("Command Received: starting test using frequency sweep, end-to-end assessment..."); - freqSweepTester.begin(); - while (!freqSweepTester.available()) {delay(100);}; - Serial.println("Press 'h' for help..."); - break; - case 'f': - //frequency sweep test - { //limit the scope of any variables that I create here - freqSweepTester_FIR.setSignalAmplitude_dBFS(-30.f); - float start_freq_Hz = 125.0f, end_freq_Hz = 16000.f, step_octave = powf(2.0,1.0/6.0); //pow(2.0,0.5) is 2 steps per octave - freqSweepTester_FIR.setStepPattern(start_freq_Hz, end_freq_Hz, step_octave); - freqSweepTester_FIR.setTargetDurPerStep_sec(0.5); - } - Serial.println("Command Received: starting test using frequency sweep. Filterbank assessment..."); - freqSweepTester_FIR.begin(); - while (!freqSweepTester_FIR.available()) {delay(100);}; - Serial.println("Press 'h' for help..."); - break; - case 'l': - Serial.println("Command Received: toggle printing of per-band ave signal levels."); - { bool as_dBSPL = false; togglePrintAveSignalLevels(as_dBSPL); } - break; - case 'L': - Serial.println("Command Received: toggle printing of per-band ave signal levels."); - { bool as_dBSPL = true; togglePrintAveSignalLevels(as_dBSPL); } - break; - } -} - -void SerialManager::incrementChannelGain(int chan, float change_dB) { - if (chan < N_CHAN) { - gain_algorithms[chan].incrementGain_dB(change_dB); - //Serial.print("Incrementing gain on channel ");Serial.print(chan); - //Serial.print(" by "); Serial.print(change_dB); Serial.println(" dB"); - printGainSettings(); //in main sketch file - } -} - -#endif diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/WDRC_8BandFIR.ino b/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/WDRC_8BandFIR.ino deleted file mode 100644 index 460ea587..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandFIR/WDRC_8BandFIR.ino +++ /dev/null @@ -1,442 +0,0 @@ -/* - WDRC_8BandFIR - - Created: Chip Audette (OpenAudio), Feb 2017 - Primarly built upon CHAPRO "Generic Hearing Aid" from - Boys Town National Research Hospital (BTNRH): https://github.com/BTNRH/chapro - - Purpose: Implements 8-band WDRC compressor. The BTNRH version was implemented the - filters in the frequency-domain, whereas I implemented them as FIR filters - in the time-domain. I've also added an expansion stage to manage noise at very - low SPL. - - User Controls: - Potentiometer on Tympan controls the algorithm gain - - MIT License. use at your own risk. -*/ - - -// Include the of the needed libraries -#include -#include "SerialManager.h" - -// Define the overall setup -String overall_name = String("Tympan: WDRC Expander-Compressor-Limiter with Overall Limiter"); -const int N_CHAN = 8; //number of frequency bands (channels) -const float input_gain_dB = 15.0f; //gain on the microphone -float vol_knob_gain_dB = 0.0; //will be overridden by volume knob - -int USE_VOLUME_KNOB = 1; //set to 1 to use volume knob to override the default vol_knob_gain_dB set a few lines below - -const float sample_rate_Hz = 24000.0f ; //24000 or 44117.64706f (or other frequencies in the table in AudioOutputI2S_F32 -const int audio_block_samples = 16; //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128) -AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples); - -// /////////// Define audio objects...they are configured later - -//create audio library objects for handling the audio -Tympan audioHardware(TympanRev::D); //do TympanRev::C or TympanRev::D -AudioInputI2S_F32 i2s_in(audio_settings); //Digital audio input from the ADC -AudioTestSignalGenerator_F32 audioTestGenerator(audio_settings); //move this to be *after* the creation of the i2s_in object - -//create audio objects for the algorithm -AudioFilterFIR_F32 firFilt[N_CHAN]; //here are the filters to break up the audio into multipel bands -AudioEffectCompWDRC_F32 expCompLim[N_CHAN]; //here are the per-band compressors -AudioMixer8_F32 mixer1; //mixer to reconstruct the broadband audio -AudioEffectCompWDRC_F32 compBroadband; //broad band compressor -AudioOutputI2S_F32 i2s_out(audio_settings); //Digital audio output to the DAC. Should be last. - -//complete the creation of the tester objects -AudioTestSignalMeasurement_F32 audioTestMeasurement(audio_settings); -AudioTestSignalMeasurementMulti_F32 audioTestMeasurement_FIR(audio_settings); -AudioControlTestAmpSweep_F32 ampSweepTester(audio_settings,audioTestGenerator,audioTestMeasurement); -AudioControlTestFreqSweep_F32 freqSweepTester(audio_settings,audioTestGenerator,audioTestMeasurement); -AudioControlTestFreqSweep_F32 freqSweepTester_FIR(audio_settings,audioTestGenerator,audioTestMeasurement_FIR); - -//make the audio connections -#define N_MAX_CONNECTIONS 100 //some large number greater than the number of connections that we'll make -AudioConnection_F32 *patchCord[N_MAX_CONNECTIONS]; -int makeAudioConnections(void) { //call this in setup() or somewhere like that - int count=0; - - //connect input - patchCord[count++] = new AudioConnection_F32(i2s_in, 0, audioTestGenerator, 0); //#8 wants left, #3 wants right. //connect the Left input to the Left Int->Float converter - - //make the connection for the audio test measurements - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement, 0); - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement_FIR, 0); - - //make per-channel connections - for (int i = 0; i < N_CHAN; i++) { - //audio connections - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, firFilt[i], 0); //connect to FIR filter - patchCord[count++] = new AudioConnection_F32(firFilt[i], 0, expCompLim[i], 0); //connect filter to compressor - patchCord[count++] = new AudioConnection_F32(expCompLim[i], 0, mixer1, i); //connect to mixer - - //make the connection for the audio test measurements - patchCord[count++] = new AudioConnection_F32(firFilt[i], 0, audioTestMeasurement_FIR, 1+i); - } - - //connect the output of the mixers to the final broadband compressor - patchCord[count++] = new AudioConnection_F32(mixer1, 0, compBroadband, 0); //connect to final limiter - - //send the audio out - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, i2s_out, 0); //left output - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, i2s_out, 1); //right output - //make the connections for the audio test measurements - - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement, 0); - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, audioTestMeasurement, 1); - - return count; -} - -//Bluetooth parameters...if used -//define USE_BT_SERIAL 0 //set to zero to disable bluetooth -#define BT_SERIAL Serial1 - -//control display and serial interaction -bool enable_printCPUandMemory = false; -void togglePrintMemoryAndCPU(void) { enable_printCPUandMemory = !enable_printCPUandMemory; }; //"extern" let's be it accessible outside -bool enable_printAveSignalLevels = false, printAveSignalLevels_as_dBSPL = false; -void togglePrintAveSignalLevels(bool as_dBSPL) { enable_printAveSignalLevels = !enable_printAveSignalLevels; printAveSignalLevels_as_dBSPL = as_dBSPL;}; -SerialManager serialManager(N_CHAN,expCompLim,ampSweepTester,freqSweepTester,freqSweepTester_FIR); - -//routine to setup the hardware -#define POT_PIN A20 //potentiometer is tied to this pin -void setupTympanHardware(void) { - Serial.println("Setting up Tympan Audio Board..."); - audioHardware.enable(); // activate AIC - - //choose input - switch (1) { - case 1: - //choose on-board mics - audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones - break; - case 2: - //choose external input, as a line in - audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN); // - break; - case 3: - //choose external mic plus the desired bias level - audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - int myBiasLevel = TYMPAN_MIC_BIAS_2_5; //choices: TYMPAN_MIC_BIAS_2_5, TYMPAN_MIC_BIAS_1_7, TYMPAN_MIC_BIAS_1_25, TYMPAN_MIC_BIAS_VSUPPLY - audioHardware.setMicBias(myBiasLevel); // set mic bias to 2.5 // default - break; - } - - //set volumes - audioHardware.volume_dB(0.f); // -63.6 to +24 dB in 0.5dB steps. uses signed 8-bit - audioHardware.setInputGain_dB(input_gain_dB); // set MICPGA volume, 0-47.5dB in 0.5dB setps - - //setup pin for potentiometer - pinMode(POT_PIN, INPUT); //set the potentiometer's input pin as an INPUT -} - - -// /////////// setup the audio processing -//define functions to setup the audio processing parameters -#include "GHA_Constants.h" //this sets dsl and gha settings, which will be the defaults -#include "GHA_Alternates.h" //this sets alternate dsl and gha, which can be switched in via commands -#define DSL_NORMAL 0 -#define DSL_FULLON 1 -int current_dsl_config = DSL_NORMAL; //used to select one of the configurations above for startup -float overall_cal_dBSPL_at0dBFS; //will be set later - -//define the filterbank size -#define N_FIR 96 -float firCoeff[N_CHAN][N_FIR]; - -void setupAudioProcessing(void) { - //make all of the audio connections - makeAudioConnections(); - - //setup processing based on the DSL and GHA prescriptions - if (current_dsl_config == DSL_NORMAL) { - setupFromDSLandGHA(dsl, gha, N_CHAN, N_FIR, audio_settings); - } else if (current_dsl_config == DSL_FULLON) { - setupFromDSLandGHA(dsl_fullon, gha_fullon, N_CHAN, N_FIR, audio_settings); - } -} - -void setupFromDSLandGHA(const BTNRH_WDRC::CHA_DSL &this_dsl, const BTNRH_WDRC::CHA_WDRC &this_gha, - const int n_chan_max, const int n_fir, const AudioSettings_F32 &settings) -{ - int n_chan = n_chan_max; //maybe change this to be the value in the DSL itself. other logic would need to change, too. - - //compute the per-channel filter coefficients - AudioConfigFIRFilterBank_F32 makeFIRcoeffs(n_chan, n_fir, settings.sample_rate_Hz, (float *)this_dsl.cross_freq, (float *)firCoeff); - - //set the coefficients (if we lower n_chan, we should be sure to clean out the ones that aren't set) - for (int i=0; i< n_chan; i++) firFilt[i].begin(firCoeff[i], n_fir, settings.audio_block_samples); - - //setup all of the per-channel compressors - configurePerBandWDRCs(n_chan, settings.sample_rate_Hz, this_dsl, this_gha, expCompLim); - - //setup the broad band compressor (limiter) - configureBroadbandWDRCs(settings.sample_rate_Hz, this_gha, vol_knob_gain_dB, compBroadband); - - //overwrite the one-point calibration based on the dsl data structure - overall_cal_dBSPL_at0dBFS = this_dsl.maxdB; - -} - -void incrementDSLConfiguration(Stream *s) { - current_dsl_config++; - if (current_dsl_config==2) current_dsl_config=0; - switch (current_dsl_config) { - case (DSL_NORMAL): - if (s) s->println("incrementDSLConfiguration: changing to NORMAL dsl configuration"); - setupFromDSLandGHA(dsl, gha, N_CHAN, N_FIR, audio_settings); break; - case (DSL_FULLON): - if (s) s->println("incrementDSLConfiguration: changing to FULL-ON dsl configuration"); - setupFromDSLandGHA(dsl_fullon, gha_fullon, N_CHAN, N_FIR, audio_settings); break; - } -} - -void configureBroadbandWDRCs(float fs_Hz, const BTNRH_WDRC::CHA_WDRC &this_gha, - float vol_knob_gain_dB, AudioEffectCompWDRC_F32 &WDRC) -{ - //assume all broadband compressors are the same - //for (int i=0; i< ncompressors; i++) { - //logic and values are extracted from from CHAPRO repo agc_prepare.c...the part setting CHA_DVAR - - //extract the parameters - float atk = (float)this_gha.attack; //milliseconds! - float rel = (float)this_gha.release; //milliseconds! - //float fs = this_gha.fs; - float fs = (float)fs_Hz; // WEA override...not taken from gha - float maxdB = (float) this_gha.maxdB; - float exp_cr = (float) this_gha.exp_cr; - float exp_end_knee = (float) this_gha.exp_end_knee; - float tk = (float) this_gha.tk; - float comp_ratio = (float) this_gha.cr; - float tkgain = (float) this_gha.tkgain; - float bolt = (float) this_gha.bolt; - - //set the compressor's parameters - //WDRCs[i].setSampleRate_Hz(fs); - //WDRCs[i].setParams(atk, rel, maxdB, exp_cr, exp_end_knee, tkgain, comp_ratio, tk, bolt); - WDRC.setSampleRate_Hz(fs); - WDRC.setParams(atk, rel, maxdB, exp_cr, exp_end_knee, tkgain + vol_knob_gain_dB, comp_ratio, tk, bolt); - // } -} - -void configurePerBandWDRCs(int nchan, float fs_Hz, - const BTNRH_WDRC::CHA_DSL &this_dsl, const BTNRH_WDRC::CHA_WDRC &this_gha, - AudioEffectCompWDRC_F32 *WDRCs) -{ - if (nchan > this_dsl.nchannel) { - Serial.println(F("configureWDRC.configure: *** ERROR ***: nchan > dsl.nchannel")); - Serial.print(F(" : nchan = ")); Serial.println(nchan); - Serial.print(F(" : dsl.nchannel = ")); Serial.println(dsl.nchannel); - } - - //now, loop over each channel - for (int i=0; i < nchan; i++) { - - //logic and values are extracted from from CHAPRO repo agc_prepare.c - float atk = (float)this_dsl.attack; //milliseconds! - float rel = (float)this_dsl.release; //milliseconds! - //float fs = gha->fs; - float fs = (float)fs_Hz; // WEA override - float maxdB = (float) this_dsl.maxdB; - float exp_cr = (float)this_dsl.exp_cr[i]; - float exp_end_knee = (float)this_dsl.exp_end_knee[i]; - float tk = (float) this_dsl.tk[i]; - float comp_ratio = (float) this_dsl.cr[i]; - float tkgain = (float) this_dsl.tkgain[i]; - float bolt = (float) this_dsl.bolt[i]; - - // adjust BOLT - float cltk = (float)this_gha.tk; - if (bolt > cltk) bolt = cltk; - if (tkgain < 0) bolt = bolt + tkgain; - - //set the compressor's parameters - WDRCs[i].setSampleRate_Hz(fs); - WDRCs[i].setParams(atk,rel,maxdB,exp_cr,exp_end_knee,tkgain,comp_ratio,tk,bolt); - } -} - -// ///////////////// Main setup() and loop() as required for all Arduino programs - -// define the setup() function, the function that is called once when the device is booting -void setup() { - Serial.begin(115200); //Open USB Serial link...for debugging - //if (USE_BT_SERIAL) BT_SERIAL.begin(115200); //Open BT link - delay(500); - - Serial.print(overall_name);Serial.println(": setup():..."); - Serial.print("Sample Rate (Hz): "); Serial.println(audio_settings.sample_rate_Hz); - Serial.print("Audio Block Size (samples): "); Serial.println(audio_settings.audio_block_samples); - //if (USE_BT_SERIAL) BT_SERIAL.print(overall_name);BT_SERIAL.println(": setup():..."); - - // Audio connections require memory - AudioMemory(10); //allocate Int16 audio data blocks (need a few for under-the-hood stuff) - AudioMemory_F32_wSettings(40,audio_settings); //allocate Float32 audio data blocks (primary memory used for audio processing) - - // Enable the audio shield, select input, and enable output - setupTympanHardware(); - - //setup filters and mixers - setupAudioProcessing(); - - //update the potentiometer settings - if (USE_VOLUME_KNOB) servicePotentiometer(millis()); - - //End of setup - printGainSettings(); - Serial.println("Setup complete."); - serialManager.printHelp(); -} //end setup() - - -// define the loop() function, the function that is repeated over and over for the life of the device -void loop() { - //choose to sleep ("wait for interrupt") instead of spinning our wheels doing nothing but consuming power - asm(" WFI"); //ARM-specific. Will wake on next interrupt. The audio library issues tons of interrupts, so we wake up often. - - //respond to Serial commands - while (Serial.available()) { - serialManager.respondToByte((char)Serial.read()); - } - - //service the potentiometer...if enough time has passed - if (USE_VOLUME_KNOB) servicePotentiometer(millis()); - - //update the memory and CPU usage...if enough time has passed - if (enable_printCPUandMemory) printCPUandMemory(millis()); - - //print info about the signal processing - updateAveSignalLevels(millis()); - if (enable_printAveSignalLevels) printAveSignalLevels(millis(),printAveSignalLevels_as_dBSPL); - -} //end loop() - - -// ///////////////// Servicing routines - -//servicePotentiometer: listens to the blue potentiometer and sends the new pot value -// to the audio processing algorithm as a control parameter -void servicePotentiometer(unsigned long curTime_millis) { - static unsigned long updatePeriod_millis = 100; //how many milliseconds between updating the potentiometer reading? - static unsigned long lastUpdate_millis = 0; - static float prev_val = -1.0; - - //has enough time passed to update everything? - if (curTime_millis < lastUpdate_millis) lastUpdate_millis = 0; //handle wrap-around of the clock - if ((curTime_millis - lastUpdate_millis) > updatePeriod_millis) { //is it time to update the user interface? - - //read potentiometer - float val = float(analogRead(POT_PIN)) / 1024.0; //0.0 to 1.0 - val = (1.0/9.0) * (float)((int)(9.0 * val + 0.5)); //quantize so that it doesn't chatter...0 to 1.0 - - //send the potentiometer value to your algorithm as a control parameter - //float scaled_val = val / 3.0; scaled_val = scaled_val * scaled_val; - if (abs(val - prev_val) > 0.05) { //is it different than befor? - prev_val = val; //save the value for comparison for the next time around - - setVolKnobGain_dB(val*45.0f - 10.0f - input_gain_dB); - } - lastUpdate_millis = curTime_millis; - } // end if -} //end servicePotentiometer(); - - -extern void printGainSettings(void) { //"extern" to make it available to other files, such as SerialManager.h - Serial.print("Gain (dB): "); - Serial.print("Vol Knob = "); Serial.print(vol_knob_gain_dB,1); - Serial.print(", Input PGA = "); Serial.print(input_gain_dB,1); - Serial.print(", Per-Channel = "); - for (int i=0; i updatePeriod_millis) { //is it time to update the user interface? - Serial.print("CPU Cur/Peak: "); - Serial.print(audio_settings.processorUsage()); - //Serial.print(AudioProcessorUsage()); - Serial.print("%/"); - Serial.print(audio_settings.processorUsageMax()); - //Serial.print(AudioProcessorUsageMax()); - Serial.print("%, "); - Serial.print("Dyn MEM Int16 Cur/Peak: "); - Serial.print(AudioMemoryUsage()); - Serial.print("/"); - Serial.print(AudioMemoryUsageMax()); - Serial.print(", "); - Serial.print("Dyn MEM Float32 Cur/Peak: "); - Serial.print(AudioMemoryUsage_F32()); - Serial.print("/"); - Serial.print(AudioMemoryUsageMax_F32()); - Serial.println(); - - lastUpdate_millis = curTime_millis; //we will use this value the next time around. - } -} - -float aveSignalLevels_dBFS[N_CHAN]; -void updateAveSignalLevels(unsigned long curTime_millis) { - static unsigned long updatePeriod_millis = 100; //how often to perform the averaging - static unsigned long lastUpdate_millis = 0; - float update_coeff = 0.2; - - //is it time to update the calculations - if (curTime_millis < lastUpdate_millis) lastUpdate_millis = 0; //handle wrap-around of the clock - if ((curTime_millis - lastUpdate_millis) > updatePeriod_millis) { //is it time to update the user interface? - for (int i=0; i updatePeriod_millis) { //is it time to update the user interface? - Serial.print("Ave Input Level (");Serial.print(units_txt); Serial.print("), Per-Band = "); - for (int i=0; i //for CHA_DSL and CHA_WDRC data types - -// Here is the per-band prescription that is the default behavior of the multi-band -// processing. This sounded decent to WEA's ears but YMMV. -BTNRH_WDRC::CHA_DSL dsl = {5, // attack (ms) - 300, // release (ms) - 115, //maxdB. calibration. dB SPL for input signal at 0 dBFS. Needs to be tailored to mic, spkrs, and mic gain. - 0, // 0=left, 1=right...ignored - 8, //num channels...ignored. 8 is always assumed - {317.1666, 502.9734, 797.6319, 1264.9, 2005.9, 3181.1, 5044.7}, // cross frequencies (Hz)...FOR IIR FILTERING, THESE VALUES ARE IGNORED!!! - {0.57, 0.57, 0.57, 0.57, 0.57, 0.57, 0.57, 0.57}, // compression ratio for low-SPL region (ie, the expander..values should be < 1.0) - {45.0, 45.0, 33.0, 32.0, 36.0, 34.0, 36.0, 40.0}, // expansion-end kneepoint - {20.f, 20.f, 25.f, 30.f, 30.f, 30.f, 30.f, 30.f}, // compression-start gain - {1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f}, // compression ratio - {50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0}, // compression-start kneepoint (input dB SPL) - {90.f, 90.f, 90.f, 90.f, 90.f, 91.f, 92.f, 93.f} // output limiting threshold (comp ratio 10) -}; - -// Here are the settings for the broadband limiter at the end. -// Again, it sounds OK to WEA, but YMMV. -//from GHA_Demo.c from "amplify()" Used for broad-band limiter. -BTNRH_WDRC::CHA_WDRC gha = {5.f, // attack time (ms) - 300.f, // release time (ms) - 24000.f, // sampling rate (Hz)...ignored. Set globally in the main program. - 115.f, // maxdB. calibration. dB SPL for signal at 0dBFS. Needs to be tailored to mic, spkrs, and mic gain. - 1.0, // compression ratio for lowest-SPL region (ie, the expansion region) (should be < 1.0. set to 1.0 for linear) - 0.0, // kneepoint of end of expansion region (set very low to defeat the expansion) - 0.f, // compression-start gain....set to zero for pure limitter - 115.f, // compression-start kneepoint...set to some high value to make it not relevant - 1.f, // compression ratio...set to 1.0 to make linear (to defeat) - 98.0 // output limiting threshold...hardwired to compression ratio of 10.0 -}; - - - - diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/SerialManager.h b/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/SerialManager.h deleted file mode 100644 index bb36cf06..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/SerialManager.h +++ /dev/null @@ -1,178 +0,0 @@ - -#ifndef _SerialManager_h -#define _SerialManager_h - -#include - -//add in the algorithm whose gains we wish to set via this SerialManager...change this if your gain algorithms class changes names! -#include "AudioEffectCompWDRC_F32.h" //change this if you change the name of the algorithm's source code filename -typedef AudioEffectCompWDRC_F32 GainAlgorithm_t; //change this if you change the algorithm's class name - -//now, define the Serial Manager class -class SerialManager { - public: - SerialManager(Stream *_s, int n, GainAlgorithm_t *gain_algs, - AudioControlTestAmpSweep_F32 &_ampSweepTester, - AudioControlTestFreqSweep_F32 &_freqSweepTester, - AudioControlTestFreqSweep_F32 &_freqSweepTester_filterbank) - : gain_algorithms(gain_algs), - ampSweepTester(_ampSweepTester), - freqSweepTester(_freqSweepTester), - freqSweepTester_filterbank(_freqSweepTester_filterbank) - { - s = _s; - N_CHAN = n; - }; - - void respondToByte(char c); - void printHelp(void); - void incrementChannelGain(int chan, float change_dB); - void decreaseChannelGain(int chan); - - float channelGainIncrement_dB = 2.5f; - int N_CHAN; - private: - Stream *s; - GainAlgorithm_t *gain_algorithms; //point to first element in array of expanders - AudioControlTestAmpSweep_F32 &SweepTester; - AudioControlTestFreqSweep_F32 &freqSweepTester; - AudioControlTestFreqSweep_F32 &freqSweepTester_filterbank; -}; - -void SerialManager::printHelp(void) { - s->println(); - s->println("SerialManager Help: Available Commands:"); - s->println(" h: Print this help"); - s->println(" g: Print the gain settings of the device."); - s->println(" C: Toggle printing of CPU and Memory usage"); - s->println(" l: Toggle printing of pre-gain per-channel signal levels (dBFS)"); - s->println(" L: Toggle printing of pre-gain per-channel signal levels (dBSPL, per DSL 'maxdB')"); - s->println(" A: Self-Generated Test: Amplitude sweep. End-to-End Measurement."); - s->println(" F: Self-Generated Test: Frequency sweep. End-to-End Measurement."); - s->println(" f: Self-Generated Test: Frequency sweep. Measure filterbank."); - s->print(" k: Increase the gain of all channels (ie, knob gain) by "); s->print(channelGainIncrement_dB); s->println(" dB"); - s->print(" K: Decrease the gain of all channels (ie, knob gain) by "); s->print(channelGainIncrement_dB); s->println(" dB"); - s->print(" 1,2,3,4,5,6,7,8: Increase linear gain of given channel (1-8) by "); s->print(channelGainIncrement_dB); s->println(" dB"); - s->print(" !,@,#,$,%,^,&,*: Decrease linear gain of given channel (1-8) by "); s->print(channelGainIncrement_dB); s->println(" dB"); - s->println(" D: Toggle between DSL configurations: NORMAL vs FULL-ON"); - s->println(); -} - -//functions in the main sketch that I want to call from here -extern void incrementKnobGain(float); -extern void printGainSettings(void); -extern void printGainSettings(Stream *); -extern void togglePrintMemoryAndCPU(void); -extern void togglePrintAveSignalLevels(bool); -extern void incrementDSLConfiguration(Stream *); - -//switch yard to determine the desired action -void SerialManager::respondToByte(char c) { - switch (c) { - case 'h': case '?': - printHelp(); break; - case 'g': case 'G': - printGainSettings(); break; - case 'k': - incrementKnobGain(channelGainIncrement_dB); break; - case 'K': //which is "shift k" - incrementKnobGain(-channelGainIncrement_dB); break; - case '1': - incrementChannelGain(1-1, channelGainIncrement_dB); break; - case '2': - incrementChannelGain(2-1, channelGainIncrement_dB); break; - case '3': - incrementChannelGain(3-1, channelGainIncrement_dB); break; - case '4': - incrementChannelGain(4-1, channelGainIncrement_dB); break; - case '5': - incrementChannelGain(5-1, channelGainIncrement_dB); break; - case '6': - incrementChannelGain(6-1, channelGainIncrement_dB); break; - case '7': - incrementChannelGain(7-1, channelGainIncrement_dB); break; - case '8': - incrementChannelGain(8-1, channelGainIncrement_dB); break; - case '!': //which is "shift 1" - incrementChannelGain(1-1, -channelGainIncrement_dB); break; - case '@': //which is "shift 2" - incrementChannelGain(2-1, -channelGainIncrement_dB); break; - case '#': //which is "shift 3" - incrementChannelGain(3-1, -channelGainIncrement_dB); break; - case '$': //which is "shift 4" - incrementChannelGain(4-1, -channelGainIncrement_dB); break; - case '%': //which is "shift 5" - incrementChannelGain(5-1, -channelGainIncrement_dB); break; - case '^': //which is "shift 6" - incrementChannelGain(6-1, -channelGainIncrement_dB); break; - case '&': //which is "shift 7" - incrementChannelGain(7-1, -channelGainIncrement_dB); break; - case '*': //which is "shift 8" - incrementChannelGain(8-1, -channelGainIncrement_dB); break; - case 'A': - //amplitude sweep test - { //limit the scope of any variables that I create here - ampSweepTester.setSignalFrequency_Hz(1000.f); - float start_amp_dB = -100.0f, end_amp_dB = 0.0f, step_amp_dB = 5.0f; - ampSweepTester.setStepPattern(start_amp_dB, end_amp_dB, step_amp_dB); - ampSweepTester.setTargetDurPerStep_sec(1.0); - } - s->println("Command Received: starting test using amplitude sweep..."); - ampSweepTester.begin(); - while (!ampSweepTester.available()) {delay(100);}; - s->println("Press 'h' for help..."); - break; - case 'C': case 'c': - s->println("Command Received: toggle printing of memory and CPU usage."); - togglePrintMemoryAndCPU(); break; - case 'D': - s->println("Command Received: changing DSL configuration...you will lose any custom gain values..."); - incrementDSLConfiguration(s); - break; - case 'F': - //frequency sweep test...end-to-end - { //limit the scope of any variables that I create here - freqSweepTester.setSignalAmplitude_dBFS(-70.f); - float start_freq_Hz = 125.0f, end_freq_Hz = 12000.f, step_octave = powf(2.0,1.0/6.0); //pow(2.0,1.0/3.0) is 3 steps per octave - freqSweepTester.setStepPattern(start_freq_Hz, end_freq_Hz, step_octave); - freqSweepTester.setTargetDurPerStep_sec(1.0); - } - s->println("Command Received: starting test using frequency sweep, end-to-end assessment..."); - freqSweepTester.begin(); - while (!freqSweepTester.available()) {delay(100);}; - s->println("Press 'h' for help..."); - break; - case 'f': - //frequency sweep test - { //limit the scope of any variables that I create here - freqSweepTester_filterbank.setSignalAmplitude_dBFS(-30.f); - float start_freq_Hz = 125.0f, end_freq_Hz = 12000.f, step_octave = powf(2.0,1.0/6.0); //pow(2.0,1.0/3.0) is 3 steps per octave - freqSweepTester_filterbank.setStepPattern(start_freq_Hz, end_freq_Hz, step_octave); - freqSweepTester_filterbank.setTargetDurPerStep_sec(0.5); - } - s->println("Command Received: starting test using frequency sweep. Filterbank assessment..."); - freqSweepTester_filterbank.begin(); - while (!freqSweepTester_filterbank.available()) {delay(100);}; - s->println("Press 'h' for help..."); - break; - case 'l': - s->println("Command Received: toggle printing of per-band ave signal levels."); - { bool as_dBSPL = false; togglePrintAveSignalLevels(as_dBSPL); } - break; - case 'L': - s->println("Command Received: toggle printing of per-band ave signal levels."); - { bool as_dBSPL = true; togglePrintAveSignalLevels(as_dBSPL); } - break; - } -} - -void SerialManager::incrementChannelGain(int chan, float change_dB) { - if (chan < N_CHAN) { - gain_algorithms[chan].incrementGain_dB(change_dB); - //s->print("Incrementing gain on channel ");s->print(chan); - //s->print(" by "); s->print(change_dB); s->println(" dB"); - printGainSettings(); //in main sketch file - } -} - -#endif diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/WDRC_8BandIIR_wBT.ino b/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/WDRC_8BandIIR_wBT.ino deleted file mode 100644 index c4494d0f..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/WDRC_8BandIIR_wBT.ino +++ /dev/null @@ -1,499 +0,0 @@ -/* - WDRC_8BandIIR_wBT - - Created: Chip Audette (OpenAudio), Feb 2017 - Primarly built upon CHAPRO "Generic Hearing Aid" from - Boys Town National Research Hospital (BTNRH): https://github.com/BTNRH/chapro - - Purpose: Implements 8-band WDRC compressor based on the work of BTNRH. - Filters: The BTNRH filterbank was implemented in the frequency-domain, whereas - I implemented them in the time-domain via IIR filters. Furthermore, I delay - the individual IIR filters to try to line up their impulse response so that - the overall frequency response is smoother because the phases are better aligned - in the cross-over region between neighboring filters. - Compressor: The BTNRH WDRC compresssor did not include an expansion stage at low SPL. - I added an expansion stage to better manage noise. - Communicates via USB Serial and via Bluetooth Serial - - This version uses IIR filters instead of FIR or FFT filters for the 8-band - filterbank. - - User Controls: - Potentiometer on Tympan controls the algorithm gain - - MIT License. use at your own risk. -*/ - - -// Include all the of the needed libraries -#include - -//local files -#include "SerialManager.h" - -//Bluetooth parameters...if used -#define USE_BT_SERIAL 1 //set to zero to disable bluetooth -#define BT_SERIAL Serial1 - -// Define the overall setup -String overall_name = String("Tympan: WDRC Expander-Compressor-Limiter with Overall Limiter"); -const int N_CHAN = 8; //number of frequency bands (channels) -const float input_gain_dB = 15.0f; //gain on the microphone -float vol_knob_gain_dB = 0.0; //will be overridden by volume knob - -int USE_VOLUME_KNOB = 1; //set to 1 to use volume knob to override the default vol_knob_gain_dB set a few lines below - -const float sample_rate_Hz = 24000.0f ; //24000 or 44117.64706f (or other frequencies in the table in AudioOutputI2S_F32 -const int audio_block_samples = 16; //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128) -AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples); - -// /////////// Define audio objects...they are configured later - -//create audio library objects for handling the audio -Tympan audioHardware(TympanRev::D); //do TympanRev::C or TympanRev::D -AudioInputI2S_F32 i2s_in(audio_settings); //Digital audio input from the ADC -AudioTestSignalGenerator_F32 audioTestGenerator(audio_settings); //keep this to be *after* the creation of the i2s_in object - -//create audio objects for the algorithm -AudioFilterBiquad_F32 bpFilt[N_CHAN]; //filters to break up the audio into multiple bands -AudioEffectDelay_F32 postFiltDelay[N_CHAN]; //delay modules that we'll use to time-align the output of the filters -AudioEffectCompWDRC_F32 expCompLim[N_CHAN]; //per-band compressors -AudioMixer8_F32 mixer1; //mixer to reconstruct the broadband audio -AudioEffectCompWDRC_F32 compBroadband; //broadband compressor (for output limitting) -AudioOutputI2S_F32 i2s_out(audio_settings); //Digital audio output to the DAC. Should be last. - -//complete the creation of the tester objects -AudioTestSignalMeasurement_F32 audioTestMeasurement(audio_settings); -AudioTestSignalMeasurementMulti_F32 audioTestMeasurement_filterbank(audio_settings); -AudioControlTestAmpSweep_F32 ampSweepTester(audio_settings,audioTestGenerator,audioTestMeasurement); -AudioControlTestFreqSweep_F32 freqSweepTester(audio_settings,audioTestGenerator,audioTestMeasurement); -AudioControlTestFreqSweep_F32 freqSweepTester_FIR(audio_settings,audioTestGenerator,audioTestMeasurement_filterbank); - -//make the audio connections -#define N_MAX_CONNECTIONS 110 //some large number greater than the number of connections that we'll make -AudioConnection_F32 *patchCord[N_MAX_CONNECTIONS]; -int makeAudioConnections(void) { //call this in setup() or somewhere like that - int count=0; - - //connect input - patchCord[count++] = new AudioConnection_F32(i2s_in, 0, audioTestGenerator, 0); //#8 wants left, #3 wants right. //connect the Left input to the Left Int->Float converter - - //make the connection for the audio test measurements - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement, 0); - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement_filterbank, 0); - - //make per-channel connections - for (int i = 0; i < N_CHAN; i++) { - //audio connections - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, bpFilt[i], 0); //connect to FIR filter - patchCord[count++] = new AudioConnection_F32(bpFilt[i], 0, postFiltDelay[i], 0); //connect to delay - patchCord[count++] = new AudioConnection_F32(postFiltDelay[i], 0, expCompLim[i], 0); //connect to compressor - patchCord[count++] = new AudioConnection_F32(expCompLim[i], 0, mixer1, i); //connect to mixer - - //make the connection for the audio test measurements - patchCord[count++] = new AudioConnection_F32(bpFilt[i], 0, audioTestMeasurement_filterbank, 1+i); - } - - //connect the output of the mixers to the final broadband compressor - patchCord[count++] = new AudioConnection_F32(mixer1, 0, compBroadband, 0); //connect to final limiter - - //send the audio out - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, i2s_out, 0); //left output - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, i2s_out, 1); //right output - //make the connections for the audio test measurements - - patchCord[count++] = new AudioConnection_F32(audioTestGenerator, 0, audioTestMeasurement, 0); - patchCord[count++] = new AudioConnection_F32(compBroadband, 0, audioTestMeasurement, 1); - - return count; -} - - - -//control display and serial interaction -bool enable_printCPUandMemory = false; -void togglePrintMemoryAndCPU(void) { enable_printCPUandMemory = !enable_printCPUandMemory; }; //"extern" let's be it accessible outside -bool enable_printAveSignalLevels = false, printAveSignalLevels_as_dBSPL = false; -void togglePrintAveSignalLevels(bool as_dBSPL) { enable_printAveSignalLevels = !enable_printAveSignalLevels; printAveSignalLevels_as_dBSPL = as_dBSPL;}; -SerialManager serialManager_USB(&Serial,N_CHAN,expCompLim,ampSweepTester,freqSweepTester,freqSweepTester_FIR); -#if (USE_BT_SERIAL) - SerialManager serialManager_BT(&BT_SERIAL,N_CHAN,expCompLim,ampSweepTester,freqSweepTester,freqSweepTester_FIR); //this instance will handle the Bluetooth Serial link -#endif - -//routine to setup the hardware -#define POT_PIN A20 //potentiometer is tied to this pin -void setupTympanHardware(void) { - Serial.println("Setting up Tympan Audio Board..."); - #if (USE_BT_SERIAL) - BT_SERIAL.println("Setting up Tympan Audio Board..."); - #endif - audioHardware.enable(); // activate AIC - - //choose input - switch (1) { - case 1: - //choose on-board mics - audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones - break; - case 2: - //choose external input, as a line in - audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN); // - break; - case 3: - //choose external mic plus the desired bias level - audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - int myBiasLevel = TYMPAN_MIC_BIAS_2_5; //choices: TYMPAN_MIC_BIAS_2_5, TYMPAN_MIC_BIAS_1_7, TYMPAN_MIC_BIAS_1_25, TYMPAN_MIC_BIAS_VSUPPLY - audioHardware.setMicBias(myBiasLevel); // set mic bias to 2.5 // default - break; - } - - //set volumes - audioHardware.volume_dB(0.f); // -63.6 to +24 dB in 0.5dB steps. uses signed 8-bit - audioHardware.setInputGain_dB(input_gain_dB); // set MICPGA volume, 0-47.5dB in 0.5dB setps - - //setup pin for potentiometer - pinMode(POT_PIN, INPUT); //set the potentiometer's input pin as an INPUT -} - - -// /////////// setup the audio processing -//define functions to setup the audio processing parameters -#include "GHA_Constants.h" //this sets dsl and gha settings, which will be the defaults -#include "GHA_Alternates.h" //this sets alternate dsl and gha, which can be switched in via commands -#include "filter_coeff_sos.h" //IIR filter coefficients for our filterbank -#define DSL_NORMAL 0 -#define DSL_FULLON 1 -int current_dsl_config = DSL_NORMAL; //used to select one of the configurations above for startup -float overall_cal_dBSPL_at0dBFS; //will be set later - -//define the filterbank FIR size -#define N_FIR 96 //I need to remove some legacy dependencies on N_FIR. The actual value shouldn't matter -//float firCoeff[N_CHAN][N_FIR]; - -void setupAudioProcessing(void) { - //make all of the audio connections - makeAudioConnections(); - - //setup processing based on the DSL and GHA prescriptions - if (current_dsl_config == DSL_NORMAL) { - setupFromDSLandGHA(dsl, gha, N_CHAN, N_FIR, audio_settings); - } else if (current_dsl_config == DSL_FULLON) { - setupFromDSLandGHA(dsl_fullon, gha_fullon, N_CHAN, N_FIR, audio_settings); - } -} - -void setupFromDSLandGHA(const BTNRH_WDRC::CHA_DSL &this_dsl, const BTNRH_WDRC::CHA_WDRC &this_gha, - const int n_chan_max, const int n_fir, const AudioSettings_F32 &settings) -{ - int n_chan = n_chan_max; //maybe change this to be the value in the DSL itself. other logic would need to change, too. - - - // //compute the per-channel filter coefficients - //AudioConfigFIRFilterBank_F32 makeFIRcoeffs(n_chan, n_fir, settings.sample_rate_Hz, (float *)this_dsl.cross_freq, (float *)firCoeff); - - // //set the coefficients (if we lower n_chan, we should be sure to clean out the ones that aren't set) - //for (int i=0; i< n_chan; i++) bpFilt[i].begin(firCoeff[i], n_fir, settings.audio_block_samples); - - //give the pre-computed coefficients to the IIR filters - for (int i=0; i< n_chan; i++) { - bpFilt[i].setFilterCoeff_Matlab_sos(&(all_matlab_sos[i][0]),SOS_N_BIQUADS_PER_FILTER); //from filter_coeff_sos.h - } - - //setup the per-channel delays - for (int i=0; iprintln("incrementDSLConfiguration: changing to NORMAL dsl configuration"); - setupFromDSLandGHA(dsl, gha, N_CHAN, N_FIR, audio_settings); break; - case (DSL_FULLON): - if (s) s->println("incrementDSLConfiguration: changing to FULL-ON dsl configuration"); - setupFromDSLandGHA(dsl_fullon, gha_fullon, N_CHAN, N_FIR, audio_settings); break; - } -} - -void configureBroadbandWDRCs(float fs_Hz, const BTNRH_WDRC::CHA_WDRC &this_gha, - float vol_knob_gain_dB, AudioEffectCompWDRC_F32 &WDRC) -{ - //assume all broadband compressors are the same - //for (int i=0; i< ncompressors; i++) { - //logic and values are extracted from from CHAPRO repo agc_prepare.c...the part setting CHA_DVAR - - //extract the parameters - float atk = (float)this_gha.attack; //milliseconds! - float rel = (float)this_gha.release; //milliseconds! - //float fs = this_gha.fs; - float fs = (float)fs_Hz; // WEA override...not taken from gha - float maxdB = (float) this_gha.maxdB; - float exp_cr = (float) this_gha.exp_cr; - float exp_end_knee = (float) this_gha.exp_end_knee; - float tk = (float) this_gha.tk; - float comp_ratio = (float) this_gha.cr; - float tkgain = (float) this_gha.tkgain; - float bolt = (float) this_gha.bolt; - - //set the compressor's parameters - //WDRCs[i].setSampleRate_Hz(fs); - //WDRCs[i].setParams(atk, rel, maxdB, exp_cr, exp_end_knee, tkgain, comp_ratio, tk, bolt); - WDRC.setSampleRate_Hz(fs); - WDRC.setParams(atk, rel, maxdB, exp_cr, exp_end_knee, tkgain + vol_knob_gain_dB, comp_ratio, tk, bolt); - // } -} - -void configurePerBandWDRCs(int nchan, float fs_Hz, - const BTNRH_WDRC::CHA_DSL &this_dsl, const BTNRH_WDRC::CHA_WDRC &this_gha, - AudioEffectCompWDRC_F32 *WDRCs) -{ - if (nchan > this_dsl.nchannel) { - Serial.println(F("configureWDRC.configure: *** ERROR ***: nchan > dsl.nchannel")); - Serial.print(F(" : nchan = ")); Serial.println(nchan); - Serial.print(F(" : dsl.nchannel = ")); Serial.println(dsl.nchannel); - } - - //now, loop over each channel - for (int i=0; i < nchan; i++) { - - //logic and values are extracted from from CHAPRO repo agc_prepare.c - float atk = (float)this_dsl.attack; //milliseconds! - float rel = (float)this_dsl.release; //milliseconds! - //float fs = gha->fs; - float fs = (float)fs_Hz; // WEA override - float maxdB = (float) this_dsl.maxdB; - float exp_cr = (float)this_dsl.exp_cr[i]; - float exp_end_knee = (float)this_dsl.exp_end_knee[i]; - float tk = (float) this_dsl.tk[i]; - float comp_ratio = (float) this_dsl.cr[i]; - float tkgain = (float) this_dsl.tkgain[i]; - float bolt = (float) this_dsl.bolt[i]; - - // adjust BOLT - float cltk = (float)this_gha.tk; - if (bolt > cltk) bolt = cltk; - if (tkgain < 0) bolt = bolt + tkgain; - - //set the compressor's parameters - WDRCs[i].setSampleRate_Hz(fs); - WDRCs[i].setParams(atk,rel,maxdB,exp_cr,exp_end_knee,tkgain,comp_ratio,tk,bolt); - } -} - -// ///////////////// Main setup() and loop() as required for all Arduino programs - -// define the setup() function, the function that is called once when the device is booting -void setup() { - Serial.begin(115200); //Open USB Serial link...for debugging - #if (USE_BT_SERIAL) - BT_SERIAL.begin(115200); //Open BT serial link - #endif - delay(500); - - Serial.print(overall_name);Serial.println(": setup():..."); - Serial.print("Sample Rate (Hz): "); Serial.println(audio_settings.sample_rate_Hz); - Serial.print("Audio Block Size (samples): "); Serial.println(audio_settings.audio_block_samples); - #if (USE_BT_SERIAL) - BT_SERIAL.print(overall_name);BT_SERIAL.println(": setup():..."); - BT_SERIAL.print("Sample Rate (Hz): "); BT_SERIAL.println(audio_settings.sample_rate_Hz); - BT_SERIAL.print("Audio Block Size (samples): "); BT_SERIAL.println(audio_settings.audio_block_samples); - #endif - - // Audio connections require memory - AudioMemory(10); //allocate Int16 audio data blocks (need a few for under-the-hood stuff) - AudioMemory_F32_wSettings(200,audio_settings); //allocate Float32 audio data blocks (primary memory used for audio processing) - - // Enable the audio shield, select input, and enable output - setupTympanHardware(); - - //setup filters and mixers - setupAudioProcessing(); - - //update the potentiometer settings - if (USE_VOLUME_KNOB) servicePotentiometer(millis()); - - //End of setup - printGainSettings(&Serial);Serial.println("Setup complete.");serialManager_USB.printHelp(); - #if (USE_BT_SERIAL) - printGainSettings(&BT_SERIAL); BT_SERIAL.println("Setup complete."); serialManager_BT.printHelp(); - #endif - -} //end setup() - - -// define the loop() function, the function that is repeated over and over for the life of the device -void loop() { - //choose to sleep ("wait for interrupt") instead of spinning our wheels doing nothing but consuming power - asm(" WFI"); //ARM-specific. Will wake on next interrupt. The audio library issues tons of interrupts, so we wake up often. - - //respond to Serial commands - while (Serial.available()) serialManager_USB.respondToByte((char)Serial.read()); - #if (USE_BT_SERIAL) - while (BT_SERIAL.available()) serialManager_BT.respondToByte((char)BT_SERIAL.read()); - #endif - - //service the potentiometer...if enough time has passed - if (USE_VOLUME_KNOB) servicePotentiometer(millis()); - - //update the memory and CPU usage...if enough time has passed - if (enable_printCPUandMemory) printCPUandMemory(millis()); - - //print info about the signal processing - updateAveSignalLevels(millis()); - if (enable_printAveSignalLevels) printAveSignalLevels(millis(),printAveSignalLevels_as_dBSPL); - -} //end loop() - - -// ///////////////// Servicing routines - -//servicePotentiometer: listens to the blue potentiometer and sends the new pot value -// to the audio processing algorithm as a control parameter -void servicePotentiometer(unsigned long curTime_millis) { - static unsigned long updatePeriod_millis = 100; //how many milliseconds between updating the potentiometer reading? - static unsigned long lastUpdate_millis = 0; - static float prev_val = -1.0; - - //has enough time passed to update everything? - if (curTime_millis < lastUpdate_millis) lastUpdate_millis = 0; //handle wrap-around of the clock - if ((curTime_millis - lastUpdate_millis) > updatePeriod_millis) { //is it time to update the user interface? - - //read potentiometer - float val = float(analogRead(POT_PIN)) / 1024.0; //0.0 to 1.0 - val = (1.0/9.0) * (float)((int)(9.0 * val + 0.5)); //quantize so that it doesn't chatter...0 to 1.0 - - //send the potentiometer value to your algorithm as a control parameter - //float scaled_val = val / 3.0; scaled_val = scaled_val * scaled_val; - if (abs(val - prev_val) > 0.05) { //is it different than befor? - prev_val = val; //save the value for comparison for the next time around - - setVolKnobGain_dB(val*45.0f - 10.0f - input_gain_dB); - } - lastUpdate_millis = curTime_millis; - } // end if -} //end servicePotentiometer(); - - -void printGainSettings(void) { - printGainSettings(&Serial); - #if (USE_BT_SERIAL) - printGainSettings(&BT_SERIAL); - #endif -} -void printGainSettings(Stream *s) { - s->print("Gain (dB): "); - s->print("Vol Knob = "); s->print(vol_knob_gain_dB,1); - s->print(", Input PGA = "); s->print(input_gain_dB,1); - s->print(", Per-Channel = "); - for (int i=0; iprint(expCompLim[i].getGain_dB()-vol_knob_gain_dB,1); - s->print(", "); - } - s->println(); -} - -extern void incrementKnobGain(float increment_dB) { //"extern" to make it available to other files, such as SerialManager.h - setVolKnobGain_dB(vol_knob_gain_dB+increment_dB); -} - -void setVolKnobGain_dB(float gain_dB) { - float prev_vol_knob_gain_dB = vol_knob_gain_dB; - vol_knob_gain_dB = gain_dB; - float linear_gain_dB; - for (int i=0; i updatePeriod_millis) { //is it time to update the user interface? - printCPUandMemoryMessage(&Serial); //USB Serial - #if (USE_BT_SERIAL) - printCPUandMemoryMessage(&BT_SERIAL); //Bluetooth Serial - #endif - lastUpdate_millis = curTime_millis; //we will use this value the next time around. - } -} -void printCPUandMemoryMessage(Stream *s) { - s->print("CPU Cur/Peak: "); - s->print(audio_settings.processorUsage()); - //s->print(AudioProcessorUsage()); - s->print("%/"); - s->print(audio_settings.processorUsageMax()); - //s->print(AudioProcessorUsageMax()); - s->print("%, "); - s->print("Dyn MEM Int16 Cur/Peak: "); - s->print(AudioMemoryUsage()); - s->print("/"); - s->print(AudioMemoryUsageMax()); - s->print(", "); - s->print("Dyn MEM Float32 Cur/Peak: "); - s->print(AudioMemoryUsage_F32()); - s->print("/"); - s->print(AudioMemoryUsageMax_F32()); - s->println(); -} - -float aveSignalLevels_dBFS[N_CHAN]; -void updateAveSignalLevels(unsigned long curTime_millis) { - static unsigned long updatePeriod_millis = 100; //how often to perform the averaging - static unsigned long lastUpdate_millis = 0; - float update_coeff = 0.2; - - //is it time to update the calculations - if (curTime_millis < lastUpdate_millis) lastUpdate_millis = 0; //handle wrap-around of the clock - if ((curTime_millis - lastUpdate_millis) > updatePeriod_millis) { //is it time to update the user interface? - for (int i=0; i updatePeriod_millis) { //is it time to update the user interface? - printAveSignalLevelsMessage(&Serial,as_dBSPL); - #if (USE_BT_SERIAL) - printAveSignalLevelsMessage(&BT_SERIAL,as_dBSPL); - #endif - lastUpdate_millis = curTime_millis; //we will use this value the next time around. - } -} -void printAveSignalLevelsMessage(Stream *s, bool as_dBSPL) { - float offset_dB = 0.0f; - String units_txt = String("dBFS"); - if (as_dBSPL) { - offset_dB = overall_cal_dBSPL_at0dBFS; - units_txt = String("dBSPL, approx"); - } - s->print("Ave Input Level (");s->print(units_txt); s->print("), Per-Band = "); - for (int i=0; iprint(aveSignalLevels_dBFS[i]+offset_dB,1); s->print(", "); } - s->println(); -} diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/filter_coeff_sos.h b/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/filter_coeff_sos.h deleted file mode 100644 index d0480e8f..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/filter_coeff_sos.h +++ /dev/null @@ -1,132 +0,0 @@ -//These filter coefficients were written by the Matlab code shown at the bottom of this file. -//Filter order: 3 -//Cutoff Frequencies: 317.2 503 797.6 1265 2006 3181 5045 - -#define SOS_ASSUMED_SAMPLE_RATE_HZ 24000 -#define SOS_N_FILTERS 8 -#define SOS_N_BIQUADS_PER_FILTER 3 -float32_t all_matlab_sos_delay_msec[SOS_N_FILTERS] = {1.597, 0.000, 1.492, 2.435, 3.028, 3.402, 3.638, 3.924}; -float32_t all_matlab_sos[SOS_N_FILTERS][SOS_N_BIQUADS_PER_FILTER*6] = { - { - -4.3795680416e-09, -8.7850244775e-09, -4.4055075790e-09, 1.0000000000e+00, -1.8452635209e+00, 8.5164441591e-01, \ - 1.0000000000e+00, 1.9999692783e+00, 9.9998086545e-01, 1.0000000000e+00, -1.8826835085e+00, 8.8919380158e-01, \ - 1.0000000000e+00, 1.9941195464e+00, 9.9413104295e-01, 1.0000000000e+00, -1.9512184122e+00, 9.5796569798e-01, \ - }, - { - 1.3711430905e-05, -2.0283434308e-12, -1.3711292683e-05, 1.0000000000e+00, -1.9418353062e+00, 9.5250347954e-01, \ - 1.0000000000e+00, 2.0000051143e+00, 1.0000051144e+00, 1.0000000000e+00, -1.9551862528e+00, 9.7128925105e-01, \ - 1.0000000000e+00, -2.0000049664e+00, 1.0000049664e+00, 1.0000000000e+00, -1.9734517945e+00, 9.8068716426e-01, \ - }, - { - 5.3168748143e-05, -8.5375722505e-12, -5.3169374853e-05, 1.0000000000e+00, -1.8992739065e+00, 9.2570221606e-01, \ - 1.0000000000e+00, 1.9999941867e+00, 9.9999418674e-01, 1.0000000000e+00, -1.9148395554e+00, 9.5491393840e-01, \ - 1.0000000000e+00, -1.9999940261e+00, 9.9999402617e-01, 1.0000000000e+00, -1.9514448920e+00, 9.6952041083e-01, \ - }, - { - 2.0339178407e-04, -3.2659637706e-11, -2.0339418149e-04, 1.0000000000e+00, -1.8196863574e+00, 8.8455414845e-01, \ - 1.0000000000e+00, 1.9999941867e+00, 9.9999418674e-01, 1.0000000000e+00, -1.8306128212e+00, 9.2961901298e-01, \ - 1.0000000000e+00, -1.9999940261e+00, 9.9999402617e-01, 1.0000000000e+00, -1.9070155806e+00, 9.5196087823e-01, \ - }, - { - 7.5854625794e-04, -1.9682884939e-11, -7.5855594361e-04, 1.0000000000e+00, -1.6659447209e+00, 8.2265226162e-01, \ - 1.0000000000e+00, 1.9999936286e+00, 9.9999362867e-01, 1.0000000000e+00, -1.6505023005e+00, 8.9153468326e-01, \ - 1.0000000000e+00, -1.9999936027e+00, 9.9999360272e-01, 1.0000000000e+00, -1.8135981551e+00, 9.2443891372e-01, \ - }, - { - 2.7360776473e-03, -4.3934569484e-10, -2.7361098980e-03, 1.0000000000e+00, -1.3636204554e+00, 7.3155438551e-01, \ - 1.0000000000e+00, 1.9999941867e+00, 9.9999418674e-01, 1.0000000000e+00, -1.2663835045e+00, 8.3658805261e-01, \ - 1.0000000000e+00, -1.9999940261e+00, 9.9999402617e-01, 1.0000000000e+00, -1.6123585489e+00, 8.8099099491e-01, \ - }, - { - 9.4242118217e-03, -1.5132929050e-09, -9.4243229068e-03, 1.0000000000e+00, -7.8247426193e-01, 6.0133580902e-01, \ - 1.0000000000e+00, 1.9999941867e+00, 9.9999418674e-01, 1.0000000000e+00, -4.9363941852e-01, 7.6537275441e-01, \ - 1.0000000000e+00, -1.9999940261e+00, 9.9999402617e-01, 1.0000000000e+00, -1.1829125763e+00, 8.1030351433e-01, \ - }, - { - -5.9464718481e-02, 1.1933825484e-01, -5.9874474602e-02, 1.0000000000e+00, -2.5561514545e-01, 3.3114880357e-02, \ - 1.0000000000e+00, -1.9999799335e+00, 9.9999564253e-01, 1.0000000000e+00, -2.9365458597e-01, 1.8685816495e-01, \ - 1.0000000000e+00, -1.9931451012e+00, 9.9316074160e-01, 1.0000000000e+00, -3.9563060245e-01, 5.9901269467e-01, \ - } - }; - -/* The matlab code that created this file is below - -function makeIIRFilterbank() - -fs_Hz = 24000; %assumed sample rate -N_IIR=3; %desired filter order -cutoff_Hz=[317.2,503.0,797.6,1265,2006,3181,5045]; % crossover frequencies -use_delays = 1; %1 = use delays to better align individual filters, 0 = defeat. - -%compute all of the filter coefficients -all_sos={}; -all_gd_msec = zeros(length(cutoff_Hz)+1,1); -N_gd = 100; -for I=1:length(cutoff_Hz)+1 - if I==1 - [b,a] = butter(2*N_IIR,cutoff_Hz(1)/(fs_Hz/2)); % low-pass - f_Hz = [0:1/N_gd:1]*(cutoff_Hz(1)-50) + 50; - elseif I==length(cutoff_Hz)+1 - [b,a] = butter(2*N_IIR,cutoff_Hz(end)/(fs_Hz/2),'high'); %high-pass - f_Hz = [0:1/N_gd:1]*(0.9*(fs_Hz/2)-cutoff_Hz(end)) + cutoff_Hz(end); - else - bp_Hz = [cutoff_Hz(I-1) cutoff_Hz(I)]; - [b,a] = butter(N_IIR,bp_Hz/(fs_Hz/2)); %band-pass - f_Hz = [0:1/N_gd:1]*(cutoff_Hz(I)-cutoff_Hz(I-1))+cutoff_Hz(I-1); - end - - if (use_delays==1); - %flip the phase of the low-pass and high-pass filters, but not the BP filters in the middle - if ((I==1) || (I==(length(cutoff_Hz)+1))); b = -b; end - - %calculate the mean delay of this filter - all_gd_msec(I) = 1000*(mean(grpdelay(b,a,f_Hz,fs_Hz))/fs_Hz); - end; - - %use matlab's conversion to second-order sections, no gain term - sos=tf2sos(b,a); - - %accumulate the sos representations - all_sos{I} = sos; -end - -%align all of the filter delays to the one with the longest delay -all_gd_msec = max(all_gd_msec) - all_gd_msec; - -%% print text to screen for copying into C++ -diary off -!del filter_coeff_sos.h -diary('filter_coeff_sos.h') -disp(['//These filter coefficients were written by the Matlab code shown at the bottom of this file.']); -disp(['//Filter order: ' num2str(N_IIR)]); -disp(['//Cutoff Frequencies: ' num2str(cutoff_Hz)]); -disp([' ']); -disp(['#define SOS_ASSUMED_SAMPLE_RATE_HZ ' num2str(fs_Hz)]); -disp(['#define SOS_N_FILTERS ' num2str(length(all_sos))]); -disp(['#define SOS_N_BIQUADS_PER_FILTER ' num2str(size(all_sos{1},1))]); -foo=sprintf('%5.3f, ', all_gd_msec); foo = foo(1:end-2); -disp(['float32_t all_matlab_sos_delay_msec[SOS_N_FILTERS] = {' foo '};']); -disp(['float32_t all_matlab_sos[SOS_N_FILTERS][SOS_N_BIQUADS_PER_FILTER*6] = { ']); -for Ifilt=1:length(all_sos) - sos = all_sos{Ifilt}; - disp([' { ']); - for I=1:size(sos,1) - disp(sprintf(' %.10e, %.10e, %.10e, %.10e, %.10e, %.10e, \\',sos(I,:))); - end - - if Ifilt < length(all_sos) - disp([' }, ']); - else - disp([' } ']); - end -end -disp([' };']); -disp([' ']); -disp(['/' '*' ' The matlab code that created this file is below']); -eval(['type ' mfilename]); -disp(['*' '/']); -diary off - -return - -*/ diff --git a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/makeIIRfilterbank.m b/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/makeIIRfilterbank.m deleted file mode 100644 index 9c05d00d..00000000 --- a/examples/05-FullSystems/Deprecated/WDRC_8BandIIR_wBT/makeIIRfilterbank.m +++ /dev/null @@ -1,78 +0,0 @@ -function makeIIRFilterbank() - -fs_Hz = 24000; %assumed sample rate -N_IIR=3; %desired filter order -cutoff_Hz=[317.2,503.0,797.6,1265,2006,3181,5045]; % crossover frequencies -use_delays = 0; %1 = use delays to better align individual filters, 0 = defeat. - -%compute all of the filter coefficients -all_sos={}; -all_gd_msec = zeros(length(cutoff_Hz)+1,1); -N_gd = 100; -for I=1:length(cutoff_Hz)+1 - if I==1 - [b,a] = butter(2*N_IIR,cutoff_Hz(1)/(fs_Hz/2)); % low-pass - f_Hz = [0:1/N_gd:1]*(cutoff_Hz(1)-50) + 50; - elseif I==length(cutoff_Hz)+1 - [b,a] = butter(2*N_IIR,cutoff_Hz(end)/(fs_Hz/2),'high'); %high-pass - f_Hz = [0:1/N_gd:1]*(0.9*(fs_Hz/2)-cutoff_Hz(end)) + cutoff_Hz(end); - else - bp_Hz = [cutoff_Hz(I-1) cutoff_Hz(I)]; - [b,a] = butter(N_IIR,bp_Hz/(fs_Hz/2)); %band-pass - f_Hz = [0:1/N_gd:1]*(cutoff_Hz(I)-cutoff_Hz(I-1))+cutoff_Hz(I-1); - end - - if (use_delays==1); - %flip the phase of the low-pass and high-pass filters, but not the BP filters in the middle - if ((I==1) || (I==(length(cutoff_Hz)+1))); b = -b; end - - %calculate the mean delay of this filter - all_gd_msec(I) = 1000*(mean(grpdelay(b,a,f_Hz,fs_Hz))/fs_Hz); - end; - - %use matlab's conversion to second-order sections, no gain term - sos=tf2sos(b,a); - - %accumulate the sos representations - all_sos{I} = sos; -end - -%align all of the filter delays to the one with the longest delay -all_gd_msec = max(all_gd_msec) - all_gd_msec; - -%% print text to screen for copying into C++ -diary off -!del filter_coeff_sos.h -diary('filter_coeff_sos.h') -disp(['//These filter coefficients were written by the Matlab code shown at the bottom of this file.']); -disp(['//Filter order: ' num2str(N_IIR)]); -disp(['//Cutoff Frequencies: ' num2str(cutoff_Hz)]); -disp([' ']); -disp(['#define SOS_ASSUMED_SAMPLE_RATE_HZ ' num2str(fs_Hz)]); -disp(['#define SOS_N_FILTERS ' num2str(length(all_sos))]); -disp(['#define SOS_N_BIQUADS_PER_FILTER ' num2str(size(all_sos{1},1))]); -foo=sprintf('%5.3f, ', all_gd_msec); foo = foo(1:end-2); -disp(['float32_t all_matlab_sos_delay_msec[SOS_N_FILTERS] = {' foo '};']); -disp(['float32_t all_matlab_sos[SOS_N_FILTERS][SOS_N_BIQUADS_PER_FILTER*6] = { ']); -for Ifilt=1:length(all_sos) - sos = all_sos{Ifilt}; - disp([' { ']); - for I=1:size(sos,1) - disp(sprintf(' %.10e, %.10e, %.10e, %.10e, %.10e, %.10e, \\',sos(I,:))); - end - - if Ifilt < length(all_sos) - disp([' }, ']); - else - disp([' } ']); - end -end -disp([' };']); -disp([' ']); -disp(['/' '*' ' The matlab code that created this file is below']); -eval(['type ' mfilename]); -disp(['*' '/']); -diary off - -return -