The 'tone' filter examples are both using calcBiquad(..); but one uses AudioFilterBiquad and other uses SGTL5000 PEQ filters. Had included code for volume level control optionally and decided to drop it from both.dds
// Tone example using AudioFilterBiquad object and calcBiquad filter calculator routine. | |||||
#include <Audio.h> | |||||
#include <Wire.h> | |||||
#include <SD.h> | |||||
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 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); | |||||
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); | |||||
// Create an object to control the audio shield. | |||||
// | |||||
AudioControlSGTL5000 audioShield; | |||||
void setup() { | |||||
// Audio connections require memory to work. For more | |||||
// detailed information, see the MemoryAndCpuUsage example | |||||
AudioMemory(12); | |||||
// Enable the audio shield, select the input and set the output volume. | |||||
audioShield.enable(); | |||||
audioShield.inputSelect(myInput); | |||||
audioShield.volume(75); | |||||
audioShield.unmuteLineout(); | |||||
calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter); | |||||
filterBass_L.updateCoefs(updateFilter); | |||||
filterBass_R.updateCoefs(updateFilter); | |||||
calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter); | |||||
filterTreb_L.updateCoefs(updateFilter); | |||||
filterTreb_R.updateCoefs(updateFilter); | |||||
} | |||||
elapsedMillis chgMsec=0; | |||||
float tone1=0; | |||||
void loop() { | |||||
// every 10 ms, check for adjustment the tone & vol | |||||
if (chgMsec > 10) { // more regular updates for actual changes seems better. | |||||
float tone2=analogRead(15); | |||||
tone2=floor(((tone2-512)/512)*70)/10; | |||||
if(tone2!=tone1) | |||||
{ | |||||
// 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); | |||||
calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,2147483648,44100,updateFilter); | |||||
filterTreb_L.updateCoefs(updateFilter); | |||||
filterTreb_R.updateCoefs(updateFilter); | |||||
tone1=tone2; | |||||
} | |||||
chgMsec = 0; | |||||
} | |||||
} | |||||
// Tone example using SGTL5000 DAP PEQ filters and calcBiquad filter calculator routine. | |||||
#include <Audio.h> | |||||
#include <Wire.h> | |||||
#include <SD.h> | |||||
const int myInput = AUDIO_INPUT_LINEIN; | |||||
// const int myInput = AUDIO_INPUT_MIC; | |||||
int updateFilter[5]; | |||||
AudioInputI2S audioInput; // audio shield: mic or line-in | |||||
AudioOutputI2S audioOutput; // audio shield: headphones & line-out | |||||
// Create Audio connections between the components | |||||
// | |||||
AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through | |||||
AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through | |||||
// Create an object to control the audio shield. | |||||
// | |||||
AudioControlSGTL5000 audioShield; | |||||
void setup() { | |||||
// Audio connections require memory to work. For more | |||||
// detailed information, see the MemoryAndCpuUsage example | |||||
AudioMemory(4); | |||||
// Enable the audio shield, select the input and set the output volume. | |||||
audioShield.enable(); | |||||
audioShield.inputSelect(myInput); | |||||
audioShield.volume(75); | |||||
audioShield.unmuteLineout(); | |||||
audioShield.dap_enable(); // enable the DAP block in SGTL5000 | |||||
audioShield.dap_audio_eq(1); // using PEQ Biquad filters | |||||
audioShield.dap_peqs(2); // enable filter 0 & filter 1 | |||||
calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter); | |||||
audioShield.load_peq(0,updateFilter); | |||||
calcBiquad(FILTER_PARAEQ,4400,0,0.167,524288,44100,updateFilter); | |||||
audioShield.load_peq(1,updateFilter); | |||||
} | |||||
elapsedMillis chgMsec=0; | |||||
float tone1=0; | |||||
void loop() { | |||||
// every 10 ms, check for adjustment the tone & vol | |||||
if (chgMsec > 10) { // more regular updates for actual changes seems better. | |||||
float tone2=analogRead(15); | |||||
tone2=floor(((tone2-512)/512)*70)/10; | |||||
if(tone2!=tone1) | |||||
{ | |||||
// calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*); | |||||
calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,524288,44100,updateFilter); | |||||
audioShield.load_peq(0,updateFilter); | |||||
calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,524288,44100,updateFilter); | |||||
audioShield.load_peq(1,updateFilter); | |||||
tone1=tone2; | |||||
} | |||||
chgMsec = 0; | |||||
} | |||||
} | |||||
#include <Wire.h> | #include <Wire.h> | ||||
#include <SD.h> | #include <SD.h> | ||||
#define PIN_VOLUME 0 | |||||
#define PIN_BALANCE 15 | |||||
const int myInput = AUDIO_INPUT_LINEIN; | const int myInput = AUDIO_INPUT_LINEIN; | ||||
// const int myInput = AUDIO_INPUT_MIC; | // const int myInput = AUDIO_INPUT_MIC; | ||||
AudioInputI2S audioInput; // audio shield: mic or line-in | AudioInputI2S audioInput; // audio shield: mic or line-in | ||||
AudioOutputI2S audioOutput; // audio shield: headphones & line-out | AudioOutputI2S audioOutput; // audio shield: headphones & line-out | ||||
// Create Audio connections between the components | // Create Audio connections between the components | ||||
// | // | ||||
AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through | AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through | ||||
void setup() { | void setup() { | ||||
// Audio connections require memory to work. For more | // Audio connections require memory to work. For more | ||||
// detailed information, see the MemoryAndCpuUsage example | // detailed information, see the MemoryAndCpuUsage example | ||||
AudioMemory(6); | |||||
AudioMemory(4); | |||||
// Enable the audio shield and set the output volume. | // Enable the audio shield and set the output volume. | ||||
audioShield.enable(); | audioShield.enable(); | ||||
audioShield.inputSelect(myInput); | audioShield.inputSelect(myInput); | ||||
audioShield.volume(90); | |||||
audioShield.volume(75); | |||||
audioShield.unmuteLineout(); | audioShield.unmuteLineout(); | ||||
} | } | ||||
elapsedMillis chgMsec=0; | elapsedMillis chgMsec=0; | ||||
float lastVol=1024; | |||||
float lastBal=1024; | float lastBal=1024; | ||||
void loop() { | void loop() { | ||||
// every 10 ms, check for adjustment the balance & vol | // every 10 ms, check for adjustment the balance & vol | ||||
if (chgMsec > 10) { // more regular updates for actual changes seems better. | if (chgMsec > 10) { // more regular updates for actual changes seems better. | ||||
#if PIN_BALANCE | |||||
float bal1=analogRead(PIN_BALANCE); | |||||
#else | |||||
float bal1=0; // middle will be default if analog pin is not supplied | |||||
#endif | |||||
float bal1=analogRead(15); | |||||
bal1=((bal1-512)/512)*100; | bal1=((bal1-512)/512)*100; | ||||
bal1=(int)bal1; | bal1=(int)bal1; | ||||
if(lastBal!=bal1) | if(lastBal!=bal1) | ||||
} | } | ||||
lastBal=bal1; | lastBal=bal1; | ||||
} | } | ||||
#if PIN_VOLUME | |||||
float vol1=analogRead(PIN_VOLUME)/10.23; // 0 - 100 | |||||
#else | |||||
float vol1=70; // 70% output will be default if analog pin is not supplied. | |||||
#endif | |||||
vol1=(int)vol1; | |||||
if(lastVol!=vol1) | |||||
{ | |||||
audioShield.volume(vol1); | |||||
lastVol=vol1; | |||||
} | |||||
chgMsec = 0; | chgMsec = 0; | ||||
} | } | ||||
} | } |
// HP balance example: Will influence both HP & LO outputs. | |||||
// HP balance example: Will influence only HP output. | |||||
#include <Audio.h> | #include <Audio.h> | ||||
#include <Wire.h> | #include <Wire.h> | ||||
#include <SD.h> | #include <SD.h> | ||||
#define PIN_VOLUME 0 | |||||
#define PIN_BALANCE 15 | |||||
const int myInput = AUDIO_INPUT_LINEIN; | const int myInput = AUDIO_INPUT_LINEIN; | ||||
// const int myInput = AUDIO_INPUT_MIC; | // const int myInput = AUDIO_INPUT_MIC; | ||||
AudioInputI2S audioInput; // audio shield: mic or line-in | AudioInputI2S audioInput; // audio shield: mic or line-in | ||||
AudioOutputI2S audioOutput; // audio shield: headphones & line-out | AudioOutputI2S audioOutput; // audio shield: headphones & line-out | ||||
// Create Audio connections between the components | // Create Audio connections between the components | ||||
// Just connecting in to out | // Just connecting in to out | ||||
void setup() { | void setup() { | ||||
// Audio connections require memory to work. For more | // Audio connections require memory to work. For more | ||||
// detailed information, see the MemoryAndCpuUsage example | // detailed information, see the MemoryAndCpuUsage example | ||||
AudioMemory(12); | |||||
AudioMemory(4); | |||||
// Enable the audio shield and set the output volume. | // Enable the audio shield and set the output volume. | ||||
audioShield.enable(); | audioShield.enable(); | ||||
audioShield.inputSelect(myInput); | audioShield.inputSelect(myInput); | ||||
elapsedMillis chgMsec=0; | elapsedMillis chgMsec=0; | ||||
float lastVol=1024; | |||||
float lastBal=1024; | float lastBal=1024; | ||||
float vol1=75; | |||||
void loop() { | void loop() { | ||||
// every 10 ms, check for adjustment the balance & vol | // every 10 ms, check for adjustment the balance & vol | ||||
if (chgMsec > 10) { // more regular updates for actual changes seems better. | if (chgMsec > 10) { // more regular updates for actual changes seems better. | ||||
#if PIN_VOLUME | |||||
float vol1=analogRead(PIN_VOLUME)/10.23; // 0 - 1000 | |||||
#else | |||||
float vol1=70; // 70% output will be default if analog pin is not supplied. | |||||
#endif | |||||
vol1=(int)vol1; | |||||
#if PIN_BALANCE | |||||
float bal1=analogRead(PIN_BALANCE); | |||||
#else | |||||
float bal1=0; // middle will be default if analog pin is not supplied | |||||
#endif | |||||
float bal1=analogRead(15); | |||||
bal1=((bal1-512)/512)*100; | bal1=((bal1-512)/512)*100; | ||||
bal1=(int)bal1; | bal1=(int)bal1; | ||||
if((lastVol!=vol1)||(lastBal!=bal1)) | |||||
if(lastBal!=bal1) | |||||
{ | { | ||||
if(bal1<0) | if(bal1<0) | ||||
{ | { | ||||
} else { | } else { | ||||
audioShield.volume((vol1/100)*(100-bal1),vol1); | audioShield.volume((vol1/100)*(100-bal1),vol1); | ||||
} | } | ||||
lastVol=vol1; | |||||
lastBal=bal1; | lastBal=bal1; | ||||
} | } | ||||
chgMsec = 0; | chgMsec = 0; |