Hi all,
For a school project I'm working on, I need to be able to generate a waveform with the Teensy 4.0 and copy to AudioRecordQueue to do some manipulations of the array before outputting sound (white noise, sine, etc., it doesn't matter at this point what type).
I've had success in the past using AudioRecordQueue with mic inputs (i2s input). I'd like to do the same thing, but I'm not getting results as I would expect.
My code is below. I'm just generating white noise, sending it to an AudioRecordQueue object, copying the values from the record queue object to the play queue object, and repeating.
What I get is maybe 200ms of noise and then silence. I also added in some Serial.print lines to debug where it's hanging up, but I'm not getting consistent outputs with this.
Am I misunderstanding how AudioSynthNoiseWhite works by assuming I can use it with AudioRecordQueue the same as the i2s mic input?
For a school project I'm working on, I need to be able to generate a waveform with the Teensy 4.0 and copy to AudioRecordQueue to do some manipulations of the array before outputting sound (white noise, sine, etc., it doesn't matter at this point what type).
I've had success in the past using AudioRecordQueue with mic inputs (i2s input). I'd like to do the same thing, but I'm not getting results as I would expect.
My code is below. I'm just generating white noise, sending it to an AudioRecordQueue object, copying the values from the record queue object to the play queue object, and repeating.
What I get is maybe 200ms of noise and then silence. I also added in some Serial.print lines to debug where it's hanging up, but I'm not getting consistent outputs with this.
Am I misunderstanding how AudioSynthNoiseWhite works by assuming I can use it with AudioRecordQueue the same as the i2s mic input?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
AudioSynthNoiseWhite noise; //white noise source
AudioRecordQueue Q_1_rec_noise; //object for recording white noise source to array
AudioPlayQueue Q_1_play; //object to write array to for output
AudioOutputI2S i2s_out; //Audio output
AudioConnection patchcord0(noise,0,Q_1_rec_noise,0);
AudioConnection patchcord1(Q_1_play,0,i2s_out,0);
AudioConnection patchcord2(Q_1_play,0,i2s_out,1);
AudioControlSGTL5000 sgtl5000;
const uint32_t blockSize=AUDIO_BLOCK_SAMPLES;
int16_t * ptr_in_noise;
int16_t * ptr_out;
void setup() {
Serial.begin(115200);
AudioMemory(10);
sgtl5000.enable();
sgtl5000.volume(0.2);
noise.amplitude(0.3);
Q_1_rec_noise.begin();
}
void loop() {
Serial.println(Q_1_rec_noise.available());
if(Q_1_rec_noise.available()){
Serial.print("loop \n");
int knob2 = analogRead(A2); //Setting volume of output with potentiometer
float vol = knob2 / 1023.0;
sgtl5000.volume(vol);
ptr_in_noise = Q_1_rec_noise.readBuffer();
ptr_out = Q_1_play.getBuffer();
for(uint8_t i=0;i<blockSize;i++){ //Copy input buffer to output buffer
ptr_out[i] = ptr_in_noise[i];
}
Q_1_rec_noise.freeBuffer();
Q_1_play.playBuffer();
Serial.print("end loop \n");
}
}
Last edited: