massahwahl
Active member
I am using a modified version of Paul's example code for recording and playing back audio using teensy 4.0 and audio shield. Everything looks good except I am getting errors on all of the subroutine calls based on what the button does:
if (buttonRecord.fallingEdge()) {
Serial.println("Record Button Press");
if (mode == 2) stopPlaying();
if (mode == 0) startRecording();
}
Error: "message": "'stopPlaying' was not declared in this scope"
I am using PlatformIO in vsCode if that makes a difference.
Full code:
if (buttonRecord.fallingEdge()) {
Serial.println("Record Button Press");
if (mode == 2) stopPlaying();
if (mode == 0) startRecording();
}
Error: "message": "'stopPlaying' was not declared in this scope"
I am using PlatformIO in vsCode if that makes a difference.
Full code:
Code:
#include <Arduino.h>
#include <korg_syro_volcasample.h>
// Three pushbuttons need to be connected:
// Record Button: pin 0 to GND
// Stop Button: pin 1 to GND
// Play Button: pin 2 to GND
// Syro Button: pin 3 to GND
// This example code is in the public domain.
#include <SPI.h>
#include <SD.h>
#include <SD_t3.h>
#include <SerialFlash.h>
#include <Audio.h>
#include <Bounce.h>
#include <Wire.h>
//write wav
unsigned long ChunkSize = 0L;
unsigned long Subchunk1Size = 16;
unsigned int AudioFormat = 1;
unsigned int numChannels = 1;
unsigned long sampleRate = 44100;
unsigned int bitsPerSample = 16;
unsigned long byteRate = sampleRate*numChannels*(bitsPerSample/8);// samplerate x channels x (bitspersample / 8)
unsigned int blockAlign = numChannels*bitsPerSample/8;
unsigned long Subchunk2Size = 0L;
unsigned long recByteSaved = 0L;
unsigned long NumSamples = 0L;
byte byte1, byte2, byte3, byte4;
// which input on the audio shield will be used?
const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;
AudioPlaySdWav audioSD;
AudioInputI2S audioInput;
AudioOutputI2S audioOutput;
AudioRecordQueue queue1;
//recod from mic
AudioConnection patchCord1(audioInput, 0, queue1, 0);
AudioConnection patchCord2(audioSD, 0, audioOutput, 0);
AudioConnection patchCord3(audioSD, 0, audioOutput, 1);
AudioControlSGTL5000 audioShield;
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
// Remember which mode we're doing
int mode = 0; // 0=stopped, 1=recording, 2=playing
elapsedMillis msecs;
// Bounce objects to easily and reliably read the buttons
Bounce buttonRecord = Bounce(0, 8);
Bounce buttonStop = Bounce(1, 8); // 8 = 8 ms debounce time
Bounce buttonPlay = Bounce(2, 8);
Bounce buttonSyro = Bounce(3, 8);
//////Korg Required Variables/////////////
uint8_t *pData; // pointer which specifies the data to be converted.
uint32_t Number; // the sample (0-99) or sequence pattern (0-9) number.
uint32_t Size; // size of data to be converted (in bytes).
// set it to sizeof(VolcaSample_Pattern_Data) when converting sequence data.
uint32_t Quality; // The conversion bit depth. It can be set to 8-16. **By default this is set to 16.
Endian SampleEndian; //set to LittleEndian or BigEndian to suite your sample data.
int NumOfData; //The number of files we are sending to be converted by the syro converter process. When not specified, this is set to 1 by default.
uint32_t Flags; //This is always set to 0
uint32_t *pNumOfSyroFrame; // the pointer of the value which stores the size of the SyroData after conversion. Units in frames (an LR pair is one unit)
/////References for Syro Stuff/////
SyroDataType DataType;
//specifies any of the following data type to be converted.
//DataType_Sample_Compress //: convert single audio sample
//DataType_Sample_Erase //: delete single sample slot on volca sample
//DataType_Sample_AllCompress //: convert all sample data
//DataType_Pattern
// The file where data is recorded
File frec;
void setup() {
///Korg Syro variables setup
// Quality = 16;
// Size = 512;
// SampleEndian = BigEndian;
// DataType = DataType_Sample_Compress;
// NumOfData = 1; //for testing, this is being set to 1
// Number = 1;
// Configure the pushbutton pins
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
// 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.micGain(40); //0-63
audioShield.volume(0.5); //0-1
// Initialize the SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// stop here if no SD card, but print a message
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop() {
// First, read the buttons
buttonRecord.update();
buttonStop.update();
buttonPlay.update();
buttonSyro.update();
// Respond to button presses
if (buttonRecord.fallingEdge()) {
Serial.println("Record Button Press");
if (mode == 2) stopPlaying();
if (mode == 0) startRecording();
}
if (buttonStop.fallingEdge()) {
Serial.println("Stop Button Press");
if (mode == 1) stopRecording();
if (mode == 2) stopPlaying();
}
if (buttonPlay.fallingEdge()) {
Serial.println("Play Button Press");
if (mode == 1) stopRecording();
if (mode == 0) startPlaying();
}
if (buttonSyro.fallingEdge()) {
Serial.println("Syro Button Press");
if (mode == 1) stopRecording();
if (mode == 0) SyroStatus SyroVolcaSample_Start(
SyroHandle *pHandle,
SyroData *pData,
int NumOfData,
uint32_t Flags,
uint32_t *pNumOfSyroFrame
);
}
// If we're playing or recording, carry on...
if (mode == 1) {
continueRecording();
}
if (mode == 2) {
continuePlaying();
}
// when using a microphone, continuously adjust gain
// if (myInput == AUDIO_INPUT_MIC) adjustMicLevel();
}
void startRecording() {
Serial.println("startRecording");
if (SD.exists("RECORD.WAV")) {
SD.remove("RECORD.WAV");
}
frec = SD.open("RECORD.WAV", FILE_WRITE);
if (frec) {
queue1.begin();
mode = 1;
recByteSaved = 0L;
}
}
void continueRecording() {
if (queue1.available() >= 2) {
byte buffer[512];
memcpy(buffer, queue1.readBuffer(), 256);
queue1.freeBuffer();
memcpy(buffer + 256, queue1.readBuffer(), 256);
queue1.freeBuffer();
// write all 512 bytes to the SD card
frec.write(buffer, 512);
recByteSaved += 512;
// elapsedMicros usec = 0;
// Serial.print("SD write, us=");
// Serial.println(usec);
}
}
void stopRecording() {
Serial.println("stopRecording");
queue1.end();
if (mode == 1) {
while (queue1.available() > 0) {
frec.write((byte*)queue1.readBuffer(), 256);
queue1.freeBuffer();
recByteSaved += 256;
}
writeOutHeader();
frec.close();
}
mode = 0;
}
void startPlaying() {
Serial.println("startPlaying");
audioSD.play("RECORD.WAV");
mode = 2;
}
void stopPlaying() {
Serial.println("stopPlaying");
if (mode == 2) audioSD.stop();
mode = 0;
}
void writeOutHeader() { // update WAV header with final filesize/datasize
// NumSamples = (recByteSaved*8)/bitsPerSample/numChannels;
// Subchunk2Size = NumSamples*numChannels*bitsPerSample/8; // number of samples x number of channels x number of bytes per sample
Subchunk2Size = recByteSaved;
ChunkSize = Subchunk2Size + 36;
frec.seek(0);
frec.write("RIFF");
byte1 = ChunkSize & 0xff;
byte2 = (ChunkSize >> 8) & 0xff;
byte3 = (ChunkSize >> 16) & 0xff;
byte4 = (ChunkSize >> 24) & 0xff;
frec.write(byte1); frec.write(byte2); frec.write(byte3); frec.write(byte4);
frec.write("WAVE");
frec.write("fmt ");
byte1 = Subchunk1Size & 0xff;
byte2 = (Subchunk1Size >> 8) & 0xff;
byte3 = (Subchunk1Size >> 16) & 0xff;
byte4 = (Subchunk1Size >> 24) & 0xff;
frec.write(byte1); frec.write(byte2); frec.write(byte3); frec.write(byte4);
byte1 = AudioFormat & 0xff;
byte2 = (AudioFormat >> 8) & 0xff;
frec.write(byte1); frec.write(byte2);
byte1 = numChannels & 0xff;
byte2 = (numChannels >> 8) & 0xff;
frec.write(byte1); frec.write(byte2);
byte1 = sampleRate & 0xff;
byte2 = (sampleRate >> 8) & 0xff;
byte3 = (sampleRate >> 16) & 0xff;
byte4 = (sampleRate >> 24) & 0xff;
frec.write(byte1); frec.write(byte2); frec.write(byte3); frec.write(byte4);
byte1 = byteRate & 0xff;
byte2 = (byteRate >> 8) & 0xff;
byte3 = (byteRate >> 16) & 0xff;
byte4 = (byteRate >> 24) & 0xff;
frec.write(byte1); frec.write(byte2); frec.write(byte3); frec.write(byte4);
byte1 = blockAlign & 0xff;
byte2 = (blockAlign >> 8) & 0xff;
frec.write(byte1); frec.write(byte2);
byte1 = bitsPerSample & 0xff;
byte2 = (bitsPerSample >> 8) & 0xff;
frec.write(byte1); frec.write(byte2);
frec.write("data");
byte1 = Subchunk2Size & 0xff;
byte2 = (Subchunk2Size >> 8) & 0xff;
byte3 = (Subchunk2Size >> 16) & 0xff;
byte4 = (Subchunk2Size >> 24) & 0xff;
frec.write(byte1); frec.write(byte2); frec.write(byte3); frec.write(byte4);
frec.close();
Serial.println("header written");
Serial.print("Subchunk2: ");
Serial.println(Subchunk2Size);
}
Last edited: