The trigger signal fluctuate about 16ms around the trigger threshold, when I play the identical sound with an audio interface to the teensy audio shield. I think the reason is the queue where a pointer to a 128 sample array of 16 bit integers is returned. With a sample rate of 8kHz the audiodata is held in the queue for 128samples/8kHz = 16ms.
Do you have any idea to fix this problem, to get a higher precision? thanks
Code:
#include <Audio.h>
#include <Wire.h> //serielle communication mit arduino
#include <SPI.h>
#include <SerialFlash.h>
#include "fir_filter.h"
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=210.182 receive 16bit audio
AudioFilterFIR fir1; //xy=639.128
AudioRecordQueue queue1; //xy=996.147
AudioOutputI2S i2s2; //xy=1036.76
AudioConnection patchCord1(i2s1, 0, fir1, 0);
AudioConnection patchCord2(fir1, 0, i2s2, 0);
AudioConnection patchCord3(fir1, 0, i2s2, 1);
AudioConnection patchCord4(fir1, queue1);
AudioControlSGTL5000 AudioShield; //xy=437.392
// GUItool: end automatically generated code
const int Trigger_Out = 30;
const int myInput = AUDIO_INPUT_MIC;
int16_t Signal;
void setup() {
Serial.begin(256000);
// Audio connections require memory, and the record queue
// uses this memory to buffer incoming audio.
AudioMemory(60);
// Enable the audio shield, select input, and enable output
AudioShield.enable();
AudioShield.inputSelect(myInput);
AudioShield.volume(0.7);
pinMode(Trigger_Out, OUTPUT);
checkMicgain.begin(controlMicGain, 200000); // function called every 200us
fir1.begin(filterCoeffs, 200);
queue1.begin();
}
void loop() {
if (queue1.available() >= 1) // check if a package is available;
{
Signal = *queue1.readBuffer();
queue1.freeBuffer();
}
if(Signal> treshold)
{
digitalWrite(Trigger_Out,HIGH);
delay(10);
digitalWrite(Trigger_Out,LOW);
}
}