Hello again,
I changes the code and now I'm trying to detect the pitch of a 5sec and 100Hz sine, I stored as a wav file on the SD card. I only use the detect-button to check if a note frequency is available.
This is my code
and thats my serial output:
Can anyone help me to fix it? I don't know why there is no note frequency available....
Thanks a lot!
I changes the code and now I'm trying to detect the pitch of a 5sec and 100Hz sine, I stored as a wav file on the SD card. I only use the detect-button to check if a note frequency is available.
This is my code
Code:
#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioInputI2S LineIn;
AudioOutputI2S LineOut;
AudioRecordQueue queue1;
//AudioPlaySdRaw playRaw;
AudioPlaySdWav playWav;
AudioAnalyzeNoteFrequency notefreq;
AudioConnection patchCord1(LineIn,0,queue1,0);
//AudioConnection patchCord2(playRaw, notefreq);
//AudioConnection patchCord3(playRaw, 0, LineOut, 0);
//AudioConnection patchCord4(playRaw, 0, LineOut, 1);
AudioConnection patchCord2(playWav, notefreq);
AudioConnection patchCord3(playWav, 0, LineOut, 0);
AudioConnection patchCord4(playWav, 0, LineOut, 1);
AudioControlSGTL5000 sgtl5000_1;
Bounce buttonRecord = Bounce(0,8);
Bounce buttonDetect = Bounce(1,8);
Bounce buttonStop = Bounce(2,8);
const int myInput = AUDIO_INPUT_MIC;
int mode = 0; // 0=Stop, 1=Recording, 2=Detecting
File frec;
void setup()
{
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
AudioMemory(60);
notefreq.begin(.15);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(0.9);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10)))
{
while(1)
{
Serial.println("Unable to access the SC card");
delay(500);
}
}
}
void loop()
{
buttonRecord.update();
buttonDetect.update();
buttonStop.update();
if (buttonRecord.fallingEdge())
{
Serial.println("Record Button Press");
if (mode == 0) startRecording();
}
if (buttonDetect.fallingEdge())
{
Serial.println("Detect Button Press");
if (mode == 0) Detecting();
}
if (buttonStop.fallingEdge())
{
Serial.println("Stop Button Press");
if (mode == 1) stopRecording();
if (mode == 2) mode = 0;
}
if (mode == 1)
{
Serial.println("continue Recording");
continueRecording();
}
if (mode == 2)
{
Serial.println("continue Detecting");
continueDetecting();
}
}
void startRecording()
{
Serial.println("startRecording");
if (SD.exists("RECORD.RAW"))
{
SD.remove("RECORD.RAW");
}
frec = SD.open("RECORD.RAW", FILE_WRITE);
if (frec)
{
queue1.begin();
mode = 1;
}
}
void continueRecording()
{
if(queue1.available() >= 2)
{
byte buffer[512];
memcpy(buffer,queue1.readBuffer(),256);
queue1.freeBuffer();
memcpy(buffer+256,queue1.readBuffer(),256);
queue1.freeBuffer();
elapsedMicros usec = 0;
frec.write(buffer,512);
}
}
void stopRecording()
{
Serial.println("stopRecording");
queue1.end();
if (mode == 1)
{
while (queue1.available() > 0)
{
frec.write((byte*)queue1.readBuffer(), 256);
queue1.freeBuffer();
}
frec.close();
}
mode = 0;
}
void Detecting()
{
Serial.println("Detecting");
playWav.play("100Hz.WAV");
if (notefreq.available())
{
Serial.println("test");
}
if(!playWav.isPlaying())
{
playWav.stop();
}
mode = 2;
}
void continueDetecting()
{
playWav.play("100Hz.WAV");
if (notefreq.available())
{
Serial.println("test");
}
if(!playWav.isPlaying())
{
playWav.stop();
mode = 0;
}
}
and thats my serial output:
Code:
Detect Button Press
Detecting
continue Detecting
Can anyone help me to fix it? I don't know why there is no note frequency available....
Thanks a lot!