Browse Source

Merge pull request #13 from robsoles/master

Actual fix for multiple filter sets in AudioFilterBiquad
dds
Paul Stoffregen 11 years ago
parent
commit
7b3fbe6dd5
4 changed files with 114 additions and 26 deletions
  1. +20
    -24
      examples/CalcBiquadToneControl/CalcBiquadToneControl.ino
  2. +39
    -0
      examples/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino
  3. +53
    -0
      examples/StereoPeakMeter/StereoPeakMeter.ino
  4. +2
    -2
      filter_biquad.cpp

+ 20
- 24
examples/CalcBiquadToneControl/CalcBiquadToneControl.ino View File

@@ -10,28 +10,22 @@ This example code is in the public domain
const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

int BassFilter_L[]={0,0,0,0,0,0,0,0};
int BassFilter_R[]={0,0,0,0,0,0,0,0};
int TrebFilter_L[]={0,0,0,0,0,0,0,0};
int TrebFilter_R[]={0,0,0,0,0,0,0,0};
int ToneFilter_L[]={0,0,0,0,0,0,0,0x80000000,0,0,0,0,0,0,0,0}; // defines 2 sets of coefficients, not sure max possible in
int ToneFilter_R[]={0,0,0,0,0,0,0,0x80000000,0,0,0,0,0,0,0,0}; // time frame but probably quite a few.

int updateFilter[5];
AudioInputI2S audioInput; // audio shield: mic or line-in
AudioFilterBiquad filterBass_L(BassFilter_L);
AudioFilterBiquad filterBass_R(BassFilter_R);
AudioFilterBiquad filterTreb_L(TrebFilter_L);
AudioFilterBiquad filterTreb_R(TrebFilter_R);
AudioFilterBiquad filterTone_L(ToneFilter_L);
AudioFilterBiquad filterTone_R(ToneFilter_R);
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

// Create Audio connections between the components
//
AudioConnection c1(audioInput,0,filterBass_L,0);
AudioConnection c2(audioInput,1,filterBass_R,0);
AudioConnection c3(filterBass_L,0,filterTreb_L,0);
AudioConnection c4(filterBass_R,0,filterTreb_R,0);
AudioConnection c5(filterTreb_L,0,audioOutput,0);
AudioConnection c6(filterTreb_R,0,audioOutput,1);
//
AudioConnection c1(audioInput,0,filterTone_L,0);
AudioConnection c2(audioInput,1,filterTone_R,0);
AudioConnection c3(filterTone_L,0,audioOutput,0);
AudioConnection c4(filterTone_R,0,audioOutput,1);

// Create an object to control the audio shield.
//
@@ -40,7 +34,7 @@ AudioControlSGTL5000 audioShield;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);
AudioMemory(6);
// Enable the audio shield, select the input and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
@@ -48,11 +42,13 @@ void setup() {
audioShield.unmuteLineout();

calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter);
filterBass_L.updateCoefs(updateFilter);
filterBass_R.updateCoefs(updateFilter);
filterTone_L.updateCoefs(updateFilter); // default set updateCoefs(0,updateFilter);
filterTone_R.updateCoefs(updateFilter);
calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter);
filterTreb_L.updateCoefs(updateFilter);
filterTreb_R.updateCoefs(updateFilter);
filterTone_L.updateCoefs(1,updateFilter);
filterTone_R.updateCoefs(1,updateFilter);
Serial.begin(9600);
}

elapsedMillis chgMsec=0;
@@ -68,11 +64,11 @@ void loop() {
{
// calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,2147483648,44100,updateFilter);
filterBass_L.updateCoefs(updateFilter);
filterBass_R.updateCoefs(updateFilter);
filterTone_L.updateCoefs(updateFilter);
filterTone_R.updateCoefs(updateFilter);
calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,2147483648,44100,updateFilter);
filterTreb_L.updateCoefs(updateFilter);
filterTreb_R.updateCoefs(updateFilter);
filterTone_L.updateCoefs(1,updateFilter);
filterTone_R.updateCoefs(1,updateFilter);
tone1=tone2;
}
chgMsec = 0;

+ 39
- 0
examples/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino View File

@@ -0,0 +1,39 @@
/* Mono peak meter example using Analog objects. Assumes Teensy 3.1

At a minimum DC decouple audio signals to/from Teensy pins with capacitors in the signal paths both in and out, 10uF is often used.
Possibly worthwhile to set up virtual ground at 3v3/2 for both, or if changing DAC REF to 1.2V then 1.2V/2 for output side.

This example code is in the public domain
*/

#include <Audio.h>
#include <Wire.h>
#include <SD.h>

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputAnalog audioInput(A0); // A0 is pin 14, feel free to change.
AudioPeak peak_M;
AudioOutputAnalog audioOutput; // DAC pin.

AudioConnection c1(audioInput,peak_M);
AudioConnection c2(audioInput,audioOutput);

void setup() {
AudioMemory(4);
Serial.begin(Serial.baud());
}

elapsedMillis fps;

void loop() {
if(fps>24) { // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
Serial.println();
fps=0;
uint8_t monoPeak=peak_M.Dpp()/2184.5321;
Serial.print("|");
for(uint8_t cnt=0;cnt<monoPeak;cnt++) Serial.print(">");
peak_M.begin();
}
}

+ 53
- 0
examples/StereoPeakMeter/StereoPeakMeter.ino View File

@@ -0,0 +1,53 @@
/* Stereo peak meter example, assumes Audio adapter but just uses terminal so no more parts required.

This example code is in the public domain
*/

#include <Audio.h>
#include <Wire.h>
#include <SD.h>

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputI2S audioInput; // audio shield: mic or line-in
AudioPeak peak_L;
AudioPeak peak_R;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

AudioConnection c1(audioInput,0,peak_L,0);
AudioConnection c2(audioInput,1,peak_R,0);
AudioConnection c3(audioInput,0,audioOutput,0);
AudioConnection c4(audioInput,1,audioOutput,1);

AudioControlSGTL5000 audioShield;


void setup() {
AudioMemory(6);
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.unmuteLineout();
Serial.begin(Serial.baud());
}

elapsedMillis fps;
uint8_t cnt=0;

void loop() {
if(fps>24) { // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
Serial.println();
fps=0;
uint8_t leftPeak=peak_L.Dpp()/2184.5321; // 65536 / 2184.5321 ~ 30.
for(cnt=0;cnt<30-leftPeak;cnt++) Serial.print(" ");
while(cnt++<30) Serial.print("<");
Serial.print("||");
uint8_t rightPeak=peak_R.Dpp()/2184.5321;
for(cnt=0;cnt<rightPeak;cnt++) Serial.print(">");
while(cnt++<30) Serial.print(" ");
peak_L.begin(); // no need to call .stop if all you want
peak_R.begin(); // is to zero it.
}
}

+ 2
- 2
filter_biquad.cpp View File

@@ -82,9 +82,9 @@ void AudioFilterBiquad::updateCoefs(uint8_t set,int *source, bool doReset)
int32_t *dest=(int32_t *)definition;
while(set)
{
*dest+=7;
dest+=7;
if(!(*dest)&0x80000000) return;
*dest++;
dest++;
set--;
}
__disable_irq();

Loading…
Cancel
Save