Errors Using Fir Filter

Status
Not open for further replies.

lownote

Active member
Hi-

I recently completed the Audio tutorial, and I'm really enjoying it. I want to use it (eventually) in a project involving comb filters, so I wanted to get to know how to use the fir filter. I don't have a mic connected to the set up, so I was attempting to make a sketch from scratch, utilizing the buttons to play a song and turn the filter on/off. I was able to get the sketch to run when the filter was in passthrough mode, but as soon as I tried to attach an array to it, I got a very long list of error messages. I created the array using TFilter, if that's important.

I'm pretty new to coding, so I'm not really even sure how to parse the language in the error message. Below is my code:

Code:
// Advanced Microcontroller-based Audio Workshop
//
// https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

#include <Bounce.h>

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

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=241,415
AudioFilterFIR           fir1;           //xy=393,485
AudioFilterFIR           fir2;           //xy=399,524
AudioMixer4              mixer1;         //xy=580,434
AudioOutputI2S           i2s1;           //xy=764,438
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 0, fir1, 0);
AudioConnection          patchCord3(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord4(playSdWav1, 1, fir2, 0);
AudioConnection          patchCord5(fir1, 0, mixer1, 2);
AudioConnection          patchCord6(fir2, 0, mixer1, 3);
AudioConnection          patchCord7(mixer1, 0, i2s1, 0);
AudioConnection          patchCord8(mixer1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=535,208
// GUItool: end automatically generated code



Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);  // 15 ms debounce time
Bounce button2 = Bounce(2, 15);

const int filterArray[16]= {
641177394499741,
-912565366389671,
-277830563849637,
1168842801724910,
-586425339303592,
-464669631669128,
715631940112409,
-284161235123925,
-284161235123925,
715631940112409,
-464669631669128,
-586425339303592,
1168842801724910,
-277830563849637,
-912565366389671,
641177394499741,
};

void setup() {
  Serial.begin(9600);
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
}

void loop() {

  fir1.begin(filterArray, 16);
  fir2.begin(filterArray, 16);
  button0.update();
  button1.update();
  button2.update();

  if (button0.fallingEdge()) {
    playSdWav1.play("SDTEST1.WAV");
    delay (10);
    Serial.println("Play song 1");
  }
  if (button1.fallingEdge()) {
  mixer1.gain(0, 0.4);
  mixer1.gain(1, 0.4);
  mixer1.gain(2, 0.0);
  mixer1.gain(3, 0.0);
 
  }
  if (button2.fallingEdge()) {
  mixer1.gain(0, 0.0);
  mixer1.gain(1, 0.0);
  mixer1.gain(2, 0.4);
  mixer1.gain(3, 0.4);
   
  }

  /*int knob = analogRead(A3);  // knob = 0 to 1023
  float gain1 = (float)knob / 1023.0 * 0.4;
  mixer1.gain(0, gain1);
  mixer1.gain(1, gain1);
*/
   

}

The error messages are as follows:

Code:
Arduino: 1.6.11 (Windows 10), TD: 1.30, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimize speed (overclock), US English"

NewFilterTest:59: warning: narrowing conversion of '641177394499741ll' from 'long long int' to 'const int' inside { } 
 };

 ^

NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-912565366389671ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-277830563849637ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '1168842801724910ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-586425339303592ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-464669631669128ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '715631940112409ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-284161235123925ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-284161235123925ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '715631940112409ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-464669631669128ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-586425339303592ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '1168842801724910ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-277830563849637ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '-912565366389671ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest:59: warning: narrowing conversion of '641177394499741ll' from 'long long int' to 'const int' inside { } 
NewFilterTest:59: warning: overflow in implicit constant conversion 
NewFilterTest: In function 'void loop()':
NewFilterTest:82: error: no matching function for call to 'AudioFilterFIR::begin(const int [16], int)'
   fir1.begin(filterArray, 16);

                             ^

C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:82:29: note: candidate is:

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:82:0,

                 from C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:13:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note: void AudioFilterFIR::begin(const short int*, int)

  void begin(const short *cp, int n_coeffs) {

       ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note:   no known conversion for argument 1 from 'const int [16]' to 'const short int*'

NewFilterTest:83: error: no matching function for call to 'AudioFilterFIR::begin(const int [16], int)'
   fir2.begin(filterArray, 16);

                             ^

C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:83:29: note: candidate is:

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:82:0,

                 from C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:13:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note: void AudioFilterFIR::begin(const short int*, int)

  void begin(const short *cp, int n_coeffs) {

       ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note:   no known conversion for argument 1 from 'const int [16]' to 'const short int*'

Multiple libraries were found for "SD.h"
 Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Program Files (x86)\Arduino\libraries\SD
no matching function for call to 'AudioFilterFIR::begin(const int [16], int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thanks in advance!
 
The problem is that the array is declared to be 16-bit integer (as it should be) but you are initializing it with integers that require a lot more than 16 bits to represent. The first number, for example, is 50 bits.
I've just looked at tfilter and it seems that its options for output are either "double" or "int". It appears that in the case of the "int" output it gives 16-bit integers. How did you get such large integers?

Pete
 
That's what I thought too, but those are definitely the numbers trigger punched out when I chose int. I figured I was confusing how I counted bit sizes.

I'll mess with the tfilter site some more, though, and see if I can get it to give me numbers in a friendlier size.

Thanks for pointing me in that direction!
 
Well, I don't have the exact settings saved because I typed in a new setting and it cleared, but here is the current setting, which give similar sized numbers:

from to gain ripple/att act rpl
0 400 1 5db 12.19db
500 1000 0 -40db -31.81db

and the output set to plain text and int 16 bits:
-56408830787309030
-180649324315713000
-83586708051206640
232887621300175170
351013286662953700
96846242914128160
-163256762359958530
-196845525363017180
-196845525363017180
-163256762359958530
96846242914128160
351013286662953700
232887621300175170
-83586708051206640
-180649324315713000
-56408830787309030
 
I presume that you also selected a sampling rate of 44100Hz. I think that, as specified, tfilter can't come up with a design. If you specify a sampling rate of 44100, you have to specify pass/stop bands up to 22050. Change the 1000 to 22050 and try again (and wait - it takes several seconds).
It gave me a filter with 445 coefficients.

Pete
 
Hi Pete-

We managed to make one error go away! Thanks. Now I have a new error, related to being unable to call a function. I'll post the code below. It appears that the example for the fir filter in the library is built much differently than I had interpreted the gui notes on the fir filter. I'm out for the rest of the night, but I wanted to thank you for solving my first problem, and I'll be tackling this new one later in the week.

Code:
// Advanced Microcontroller-based Audio Workshop
//
// https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

#include <Bounce.h>

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

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=241,415
AudioFilterFIR           fir1;           //xy=393,485
AudioFilterFIR           fir2;           //xy=399,524
AudioMixer4              mixer1;         //xy=580,434
AudioOutputI2S           i2s1;           //xy=764,438
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 0, fir1, 0);
AudioConnection          patchCord3(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord4(playSdWav1, 1, fir2, 0);
AudioConnection          patchCord5(fir1, 0, mixer1, 2);
AudioConnection          patchCord6(fir2, 0, mixer1, 3);
AudioConnection          patchCord7(mixer1, 0, i2s1, 0);
AudioConnection          patchCord8(mixer1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=535,208
// GUItool: end automatically generated code



Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);  // 15 ms debounce time
Bounce button2 = Bounce(2, 15);

const int filterArray[160]= {
  -955,
  118,
  114,
  112,
  112,
  114,
  117,
  122,
  128,
  135,
  144,
  153,
  164,
  176,
  188,
  201,
  216,
  231,
  246,
  263,
  280,
  298,
  316,
  335,
  355,
  375,
  396,
  417,
  439,
  461,
  483,
  507,
  529,
  554,
  578,
  601,
  625,
  650,
  674,
  700,
  725,
  750,
  774,
  799,
  824,
  848,
  873,
  897,
  921,
  945,
  969,
  992,
  1015,
  1037,
  1059,
  1081,
  1102,
  1122,
  1142,
  1161,
  1179,
  1197,
  1214,
  1230,
  1245,
  1260,
  1274,
  1287,
  1299,
  1310,
  1320,
  1329,
  1337,
  1344,
  1350,
  1356,
  1360,
  1363,
  1365,
  1366,
  1366,
  1365,
  1363,
  1360,
  1356,
  1350,
  1344,
  1337,
  1329,
  1320,
  1310,
  1299,
  1287,
  1274,
  1260,
  1245,
  1230,
  1214,
  1197,
  1179,
  1161,
  1142,
  1122,
  1102,
  1081,
  1059,
  1037,
  1015,
  992,
  969,
  945,
  921,
  897,
  873,
  848,
  824,
  799,
  774,
  750,
  725,
  700,
  674,
  650,
  625,
  601,
  578,
  554,
  529,
  507,
  483,
  461,
  439,
  417,
  396,
  375,
  355,
  335,
  316,
  298,
  280,
  263,
  246,
  231,
  216,
  201,
  188,
  176,
  164,
  153,
  144,
  135,
  128,
  122,
  117,
  114,
  112,
  112,
  114,
  118,
  -955
};

void setup() {
  Serial.begin(9600);
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
}

void loop() {

  fir1.begin(filterArray, 16);
  fir2.begin(filterArray, 16);
  button0.update();
  button1.update();
  button2.update();

  if (button0.fallingEdge()) {
    playSdWav1.play("SDTEST1.WAV");
    delay (10);
    Serial.println("Play song 1");
  }
  if (button1.fallingEdge()) {
  mixer1.gain(0, 0.4);
  mixer1.gain(1, 0.4);
  mixer1.gain(2, 0.0);
  mixer1.gain(3, 0.0);
 
  }
  if (button2.fallingEdge()) {
  mixer1.gain(0, 0.0);
  mixer1.gain(1, 0.0);
  mixer1.gain(2, 0.4);
  mixer1.gain(3, 0.4);
   
  }

  /*int knob = analogRead(A3);  // knob = 0 to 1023
  float gain1 = (float)knob / 1023.0 * 0.4;
  mixer1.gain(0, gain1);
  mixer1.gain(1, gain1);
*/
   

}

The resulting error is:

Code:
Arduino: 1.6.11 (Windows 10), TD: 1.30, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimize speed (overclock), US English"

NewFilterTest: In function 'void loop()':
NewFilterTest:226: error: no matching function for call to 'AudioFilterFIR::begin(const int [160], int)'
   fir1.begin(filterArray, 16);

                             ^

C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:226:29: note: candidate is:

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:82:0,

                 from C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:13:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note: void AudioFilterFIR::begin(const short int*, int)

  void begin(const short *cp, int n_coeffs) {

       ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note:   no known conversion for argument 1 from 'const int [160]' to 'const short int*'

NewFilterTest:227: error: no matching function for call to 'AudioFilterFIR::begin(const int [160], int)'
   fir2.begin(filterArray, 16);

                             ^

C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:227:29: note: candidate is:

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:82:0,

                 from C:\Users\Doug\Documents\Arduino\NewFilterTest\NewFilterTest.ino:13:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note: void AudioFilterFIR::begin(const short int*, int)

  void begin(const short *cp, int n_coeffs) {

       ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/filter_fir.h:41:7: note:   no known conversion for argument 1 from 'const int [160]' to 'const short int*'

Multiple libraries were found for "SD.h"
 Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Program Files (x86)\Arduino\libraries\SD
no matching function for call to 'AudioFilterFIR::begin(const int [160], int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Again, thanks! I appreciate your help, and I'll be back if/when I figure this new one out.
 
Code:
const int filterArray[160]= {
The audio samples and coefficients for the FIR array must be 16-bit integers which on a Teensy 3.x must be declared as "short" rather than "int" because T3.x are 32-bit beasties.
Code:
const short filterArray[160]= {

Pete
 
(I saw the note about changing it to short in the gui notes, but I had inverted it to needing to change it from short to int. This is probably a mistake only I'll make, but I figure I should mention it here just in case anyone else stumbles on this thread in the future.
 
Last edited:
Can anyone explain how the integer coefficients work in a formula?

The float coefs from the calculator make sense as they are all small fractional values ( |c| < 1) and are multiplied by the tap values but how do integer coefficients work?

Edit ...sorry this is pretty off topic ...I just don't get how multiply works with integers. Somehow the products have to scale to less than the multiplcands... some kind of bit shift I presume.....by half the bit rez??
 
Last edited:
Status
Not open for further replies.
Back
Top