Ver código fonte

Added filter 'tone' examples and trimmed fat in balance examples

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
robsoles 10 anos atrás
pai
commit
1498a6e60a
4 arquivos alterados com 150 adições e 47 exclusões
  1. +78
    -0
      examples/CalcBiquadToneControl/CalcBiquadToneControl.ino
  2. +64
    -0
      examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino
  3. +3
    -24
      examples/SGTL5000_Specific/balanceDAC/balanceDAC.ino
  4. +5
    -23
      examples/SGTL5000_Specific/balanceHP/balanceHP.ino

+ 78
- 0
examples/CalcBiquadToneControl/CalcBiquadToneControl.ino Ver arquivo

@@ -0,0 +1,78 @@
// 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;
}
}


+ 64
- 0
examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino Ver arquivo

@@ -0,0 +1,64 @@
// 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;
}
}


+ 3
- 24
examples/SGTL5000_Specific/balanceDAC/balanceDAC.ino Ver arquivo

@@ -4,8 +4,6 @@
#include <Wire.h>
#include <SD.h>

#define PIN_VOLUME 0
#define PIN_BALANCE 15

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;
@@ -17,8 +15,6 @@ const int myInput = AUDIO_INPUT_LINEIN;
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
@@ -31,26 +27,21 @@ AudioControlSGTL5000 audioShield;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(6);
AudioMemory(4);
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(90);
audioShield.volume(75);
audioShield.unmuteLineout();
}

elapsedMillis chgMsec=0;
float lastVol=1024;
float lastBal=1024;

void loop() {
// every 10 ms, check for adjustment the balance & vol
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=(int)bal1;
if(lastBal!=bal1)
@@ -65,18 +56,6 @@ void loop() {
}
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;
}
}

+ 5
- 23
examples/SGTL5000_Specific/balanceHP/balanceHP.ino Ver arquivo

@@ -1,12 +1,9 @@
// HP balance example: Will influence both HP & LO outputs.
// HP balance example: Will influence only HP output.

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

#define PIN_VOLUME 0
#define PIN_BALANCE 15

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

@@ -17,8 +14,6 @@ const int myInput = AUDIO_INPUT_LINEIN;
AudioInputI2S audioInput; // audio shield: mic or line-in
AudioOutputI2S audioOutput; // audio shield: headphones & line-out



// Create Audio connections between the components

// Just connecting in to out
@@ -32,7 +27,7 @@ AudioControlSGTL5000 audioShield;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);
AudioMemory(4);
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
@@ -42,28 +37,16 @@ void setup() {

elapsedMillis chgMsec=0;

float lastVol=1024;
float lastBal=1024;
float vol1=75;

void loop() {
// every 10 ms, check for adjustment the balance & vol
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=(int)bal1;
if((lastVol!=vol1)||(lastBal!=bal1))
if(lastBal!=bal1)
{
if(bal1<0)
{
@@ -71,7 +54,6 @@ void loop() {
} else {
audioShield.volume((vol1/100)*(100-bal1),vol1);
}
lastVol=vol1;
lastBal=bal1;
}
chgMsec = 0;

Carregando…
Cancelar
Salvar