1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
\\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_005\sketch_FIR_005.ino
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#include <filter_fir.h>
//This section has been copied from the Teensy FIR example
// If this pin is grounded the FIR filter is turned off
// which just passes the audio sraight through
// Don't use any of the pins listed above
#define PASSTHRU_PIN 1 //donc si je comprends bien il faut mettre la pin 1 à +3.3V ??
// If this pin goes low the next FIR filter in the list
// is switched in.
#define FILTER_PIN 0 //if I understand correctly, the input of the Filter is pin 0
/*
These lines are followed by two "debounce" instrutions that are unknown to me,
// seem to manage the buttons, that I don't use in my project, so I remove the "bounce" lines
*/
// GUItool: begin automatically generated code
AsyncAudioInputSPDIF3 spdif_async1; //xy=145.3333282470703,121.33333587646484
AudioFilterFIR fir1; //xy=353.25,121.25
AudioOutputI2S i2s1; //xy=569.25,126.25
AudioConnection patchCord1(spdif_async1, 0, fir1, 0);
AudioConnection patchCord2(fir1, 0, i2s1, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=360.25,265.25
// GUItool: end automatically generated code
//LPF Coefficients provided by T-Filter
// I got only 5 coefficients, that is not enough, but I don't know why !?!
const short length = 57; // définition de la longueur du filtre, i.e le nombre de coefficients
// Liste des 57 coefficients bruts donnés par lesite arc.id.au de calcul des fltres
float Coeffs_Bruts[] = { -0.000220, 0.000395, -0.000589, 0.000753, -0.000817, 0.000696, -0.000308,
-0.000416, 0.001510, -0.002950, 0.004644, -0.006416, 0.008012, -0.009109, 0.009343, -0.008340,
0.005765, -0.001367, -0.004979, 0.013234, -0.023175, 0.034397, -0.046329, 0.058275, -0.069471,
0.079153, -0.086631, 0.091355, 0.907029, 0.091355, -0.086631, 0.079153, -0.069471, 0.058275,
-0.046329, 0.034397, -0.023175, 0.013234, -0.004979, -0.001367, 0.005765, -0.008340, 0.009343,
-0.009109, 0.008012, -0.006416, 0.004644, -0.002950, 0.001510, -0.000416, -0.000308, 0.000696,
-0.000817, 0.000753, -0.000589, 0.000395, -0.000220};
// The declaration below seems similar to the "struct" declaration used in the Teensy FIR Filter example
// but the "const" approach has been said to be more optimized than the éstruct" approach
const short fir1_Coeffs[57]; // définition du tableau de constantes que l'on va calculer
// à partir de la liste "Coeffs_Bruts" du dessus
//const int myInput = AUDIO_INPUT_MIC; // remove from the Teensy FIR example
const int myInput = AUDIO_INPUT_LINEIN; // because my correct input is not MIC
// d'autres exemples utilisent myInput = AUDIO_INPUT_LINEIN;
// avec un diagramme AudioDesignTool dans le domaine digital aussi
// par ex le prog "Invert Phase Audio Signal"
unsigned long last_time = millis(); // copied from the Teensy FIR example
void setup()
{
Serial.begin(9600); //copied from the Teensy FIR Filter example
delay(300); //copied from the Teensy FIR Filter example
//transfère les Coeffs_Bruts dans le tableau LPF_Coeffs, sous forme "short"
for (int i=1 ; i<=length ; i++) {
fir1_Coeffs[i] == (short) (32768 * Coeffs_Bruts[i]);
/*
if (i=length){
Serial.println("Tableau fir1_Coeffs initialisé");
Serial.println("Length= ", length);
}
*/
} //fin du remplissage du tableau fir1_Coeffs
pinMode(PASSTHRU_PIN, INPUT_PULLUP); //probably activates the Pull-Up resistor because PASSTHRU_PIN is defined as an input
pinMode(FILTER_PIN, INPUT_PULLUP); //probably activates the Pull-Up resistor because FILTER_PIN is defined as an input
//setup the audio shield
AudioNoInterrupts(); // added to the Teensy FIR example: recommended in the video
// what are the benefit ???
// mentionned at the very beginning
AudioMemory(16); /*
The numberBlocks input specifies how much memory to reserve for audio data.
Each block holds 128 audio samples, or approx 2.9 ms of sound.
*/
// Enable the audio shield. select input. and enable output
sgtl5000_1.enable(); //added: was it missing in the Teensy example
//sgtl5000_1.InputSelect(myInput);
/*
dois-je mettre spdif_async1 ou bien LINEIN comme dans la video ???
Je pense spdif_async1 puisque c'est le nom donné à AsyncAudioInputSPDIF3
qui remplace le AudioInputI2S de la video
Pas sûr car le pgm "Invert Phase Audio Signal" utilise bien
AUDIO_INPUT_LINEIN, donc je laisse myInput défini à
AUDIO_INPUT_LINEIN
*/
sgtl5000_1.lineInLevel(5);
//sgtl5000_1.unmuteheadphone();
sgtl5000_1.volume(0.5); // I have a doubt about the parameter: is it correct ???
fir1.begin(fir1_Coeffs, 5); //initialize the fir filter 'fir1" declared before
AudioInterrupts(); //as recommended in the video
// Warn on the Serial Monitor if the passthru pin is grounded
if(!digitalRead(PASSTHRU_PIN)) {
Serial.print("PASSTHRU_PIN (");
Serial.print(PASSTHRU_PIN);
Serial.println(") is grounded");
}
// Warn if the filter pin is grounded: what for ??
//it is supposed to be the filter input, isn't it ?
if(!digitalRead(FILTER_PIN)) {
Serial.print("FILTER_PIN (");
Serial.print(FILTER_PIN);
Serial.println(") is grounded");
}
//ADDED to the Teensy FIR example (as recommended by the video)
fir1.begin(fir1_Coeffs, 5); //Iniitialize the LPF filter as recommended by the AudioDesignTool
Serial.print("fir1 Filter: begin done"); // displays on the Serial Monitor
Serial.println("setup done");
}
void loop() //la video ne dit pas quoi faire dans cette boucle loop,
//et l'exemple de Teensy pas grand chose !
{
// print information about resource usage
// Proc = 18 (18), Mem = 4 (5)
if (millis() - last_time >= 2500) {
Serial.print("Proc = ");
Serial.print(AudioProcessorUsage());
Serial.print(" (");
Serial.print(AudioProcessorUsageMax());
Serial.print("), Mem = ");
Serial.print(AudioMemoryUsage());
Serial.print(" (");
Serial.print(AudioMemoryUsageMax());
Serial.println(")");
last_time = millis();
}
} |
Partager