In the following sketch I try to copy audio data from a record-queue to a play-queue in the c-main function.
(Later I will do a lot of signalprocessing between input and output).
The code works. I try to measure execution times of the parts using Leds with a scope attached also to
the Led lines. I find that playQueue.playBuffer(); takes more than 2ms. The other times are rather short (as expected).
I don't understand why playBuffer() takes so long. Perhaps I do something
wrong in my way of copying. Is there a way to get the number of free buffers?
I am a total Teensy noob, but I am learning a lot in the 5 dyas since I own a Teensy.
(Later I will do a lot of signalprocessing between input and output).
The code works. I try to measure execution times of the parts using Leds with a scope attached also to
the Led lines. I find that playQueue.playBuffer(); takes more than 2ms. The other times are rather short (as expected).
I don't understand why playBuffer() takes so long. Perhaps I do something
wrong in my way of copying. Is there a way to get the number of free buffers?
I am a total Teensy noob, but I am learning a lot in the 5 dyas since I own a Teensy.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "ossi1.h"
// GUItool: begin automatically generated code
AudioInputI2S i2s2; //xy=136,152
AudioPlayQueue playQueue; //xy=306,234
AudioRecordQueue recordQueue; //xy=309,190
AudioOutputI2S i2s1; //xy=499,152
AudioConnection patchCord1(i2s2, 0, i2s1, 0);
AudioConnection patchCord2(i2s2, 1, recordQueue, 0);
AudioConnection patchCord3(playQueue, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=141,54
// GUItool: end automatically generated code
int led33 = 33;
int led34 = 34;
int led35 = 35;
void setup() {
pinMode(led33, OUTPUT);
pinMode(led34, OUTPUT);
pinMode(led35, OUTPUT);
sgtl5000_1.enable();
sgtl5000_1.volume(0.9);
AudioMemory(128) ;
recordQueue.begin();
delay(2000) ;
}
int16_t *input_L ;
int16_t *output_L ;
void doBuffers(int imax){
for (int i = 0; i < imax; i++) {
digitalWrite(led35, HIGH);
input_L = recordQueue.readBuffer();
output_L = playQueue.getBuffer();
recordQueue.freeBuffer();
digitalWrite(led35, LOW);
digitalWrite(led33, HIGH);
for(int k=0 ; k<128 ; k++){ output_L[k]=input_L[k] ; }
delay(1) ;
digitalWrite(led33, LOW);
digitalWrite(led34, HIGH);
playQueue.playBuffer();
digitalWrite(led34, LOW);
}
}
void loop() {
while (recordQueue.available() > 1 ) {
doBuffers(1) ;
}
}