Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=218,105
AudioFilterFIR fir1; //xy=379,110
AudioOutputI2S i2s2; //xy=545,112
AudioConnection patchCord1(i2s1, 0, fir1, 0);
AudioConnection patchCord2(fir1, 0, i2s2, 0);
AudioConnection patchCord3(fir1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=359,183
// GUItool: end automatically generated code
const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;
// Huge 384 tap filter from:
// https://forum.pjrc.com/threads/41114-FIR-taps-and-use-of-CMSIS-arm_fir_q15
const int16_t BigFilterResponse[384] = {
17525, 15233, -8989, 157, 2735, 987, 5595, -1294, 313, 3421,
-68, -2135, 783, 1939, -447, -870, -227, -1084, -878, 425,
227, -363, -122, -415, -700, 186, 577, -242, -540, -149,
-129, -137, 266, 651, 787, 556, 107, 164, 655, 730,
474, 312, 43, -84, 245, 288, -166, -169, 203, 61,
-228, -8, 185, -43, -127, 191, 403, 163, -137, 65,
503, 487, 244, 382, 495, 130, -81, 215, 368, 126,
-58, -54, -25, 24, 83, 122, 144, 75, -14, 76,
197, 122, 55, 139, 157, 90, 113, 139, 61, -13,
-36, -41, -17, -16, -67, -89, -106, -172, -167, -80,
-106, -229, -264, -219, -189, -171, -176, -197, -185, -174,
-175, -110, -44, -89, -130, -62, -5, -16, -5, 21,
16, 19, 41, 55, 54, 21, -29, -32, -19, -50,
-66, -44, -70, -120, -99, -63, -85, -114, -119, -124,
-121, -111, -112, -102, -87, -92, -86, -63, -75, -102,
-96, -99, -124, -118, -88, -83, -91, -94, -95, -79,
-55, -59, -63, -37, -23, -25, -5, 14, 12, 18,
35, 44, 51, 56, 52, 61, 71, 60, 59, 85,
86, 61, 59, 68, 61, 57, 63, 63, 63, 68,
71, 80, 85, 72, 69, 91, 97, 84, 85, 90,
80, 75, 78, 73, 70, 66, 52, 47, 53, 49,
45, 52, 49, 37, 39, 43, 33, 23, 21, 22,
29, 29, 16, 13, 18, 5, -9, 1, 8, -1,
1, 8, 4, 0, 2, 0, -3, -6, -10, -6,
-1, -9, -13, -2, -4, -18, -16, -8, -15, -22,
-22, -26, -31, -31, -29, -23, -17, -21, -20, -6,
0, -1, 9, 17, 15, 21, 33, 36, 39, 47,
46, 41, 44, 46, 46, 49, 49, 46, 46, 43,
35, 38, 41, 30, 23, 30, 29, 21, 20, 22,
21, 22, 18, 12, 18, 22, 10, 5, 12, 9,
-2, -3, 1, -4, -13, -18, -16, -17, -27, -32,
-27, -31, -44, -42, -32, -37, -42, -36, -38, -44,
-39, -36, -43, -43, -40, -43, -46, -49, -53, -50,
-48, -54, -52, -41, -41, -44, -34, -29, -35, -30,
-23, -29, -26, -18, -25, -26, -15, -20, -30, -17,
-10, -25, -25, -11, -17, -26, -14, -9, -20, -20,
-10, -13, -21, -23, -19, -15, -20, -27, -18, -6,
-16, -24, -9, -3, -14, -13, -2, -6, -10, -4,
-3, -8, -4, -5};
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);
// Enable the audio shield, select input, and enable output
sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(0.5);
// Start the FIR filter
fir1.begin(BigFilterResponse, 384);
}
elapsedMillis msec=0;
void loop() {
if (msec > 2000) {
msec = 0;
Serial.print("CPU = ");
Serial.print(AudioProcessorUsage());
Serial.print(" (");
Serial.print(AudioProcessorUsageMax());
Serial.println(" max)");
}
}
When running on Teensy 3.6 at 180 MHz, it prints this: