Hello all,
I am trying to copy audio inputs from a mic into a buffer that I can use to play the same set of audio over and over. The way I have the code now is to rewrite the audio once it is played back but once I get it working I will write to the buffer only when instructed to.
in addition, If someone could add some insight as to how the timing works to play the audio at the right pace
and why the most efficient size to copy is 256,
and where this code and the "delay" effect stores its recording, id be grateful
I was able to read and play from a small buffer with this technique, but the more I added, the more choppy the output was and then the output and eventually was incomprehensible.
The delay effect is able to play back most of a seconds worth of audio and that is all I will need in the end, so I am wondering where the library differs from my code. I realize it uses a head and tail setup but it seems similar in the sense of writing the same amount of data.
I am trying to copy audio inputs from a mic into a buffer that I can use to play the same set of audio over and over. The way I have the code now is to rewrite the audio once it is played back but once I get it working I will write to the buffer only when instructed to.
in addition, If someone could add some insight as to how the timing works to play the audio at the right pace
and why the most efficient size to copy is 256,
and where this code and the "delay" effect stores its recording, id be grateful
I was able to read and play from a small buffer with this technique, but the more I added, the more choppy the output was and then the output and eventually was incomprehensible.
The delay effect is able to play back most of a seconds worth of audio and that is all I will need in the end, so I am wondering where the library differs from my code. I realize it uses a head and tail setup but it seems similar in the sense of writing the same amount of data.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=77,57
AudioRecordQueue queue2; //xy=208,57
AudioPlayQueue queue1; //xy=327,55
AudioOutputI2S i2s2; //xy=459,52
AudioConnection patchCord1(i2s1, 0, queue2, 0);
AudioConnection patchCord2(queue1, 0, i2s2, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=446,103
// GUItool: end automatically generated code
//uint16_t buffer[512];
uint8_t Counter = 0;
uint8_t Counter2 = 0;
uint16_t buff[20000];
void setup(){
AudioMemory(64);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
sgtl5000_1.volume(0.7);
sgtl5000_1.lineInLevel(0);
sgtl5000_1.lineOutLevel(13);
queue2.begin();
}
void loop(){
//delay(1000);
if(queue2.available() >= 2){ //input buffer
if(Counter <=78) //read packets into buffer
{
memcpy(buff + Counter, queue2.readBuffer(), 256);
queue2.freeBuffer();
Counter++;
}
else //copy all packets to output buff
{
if(Counter2 <=78)
{
memcpy(queue2.readBuffer(), queue2.readBuffer(), 256);
queue2.freeBuffer();
int16_t *outBuf = queue1.getBuffer();
memcpy(outBuf, buff + Counter2, 256);
queue1.playBuffer();
Counter2++;
}
else
{
Counter2 = 0;
Counter = 0;
}
}
}}