TeensyPhonon
Active member
I have a code for Teensy 4.1 that is working well with one SPH0645 microphone (mono). But now, I need to make it stereo, which is why I am here...
The strangest part is that even the output queue stops working (seems to struggle at "sp_L = Q_out_L.getBuffer();").
AudioInputI2SNoBegin and AudioOutputI2SNoBegin are two custom objects that are identical to the original I2S objects but do not call "begin()" (which I call later) when created. The problem is the same with the original I2S objects.
If you comment out the line "AudioConnection patchCord_in_R(i2s_in, 1, Q_in_R, 0);" (or Q_in_R.begin()), it works! Note that the two channels are working separately (by changing "patchCord_in(i2s_in, 0, Q_in_L, 0);" to "patchCord_in(i2s_in, 1, Q_in_L, 0);"). I also made a test code... which works:
I really don't see where the problem is...
The strangest part is that even the output queue stops working (seems to struggle at "sp_L = Q_out_L.getBuffer();").
C:
#include <Audio.h>
#include <arm_const_structs.h>
#include <utility/imxrt_hw.h>
#include <SD.h>
#include <SPI.h>
#include "input_i2s_nobegin.h"
#include "output_i2s_nobegin.h"
File dataFile;
const int chipSelect = BUILTIN_SDCARD;
extern "C" uint32_t set_arm_clock(uint32_t frequency);
const float32_t PROGMEM audio_gain = 0.05;
const int Npartitions = 500;
const double PROGMEM SAMPLE_RATE = AUDIO_SAMPLE_RATE_EXACT;
const int PROGMEM partitionsize = AUDIO_BLOCK_SAMPLES;
const float32_t T = Npartitions*partitionsize/SAMPLE_RATE;
const int nc = T*SAMPLE_RATE;
const int N_memory = 10;
float32_t mem_delay = N_memory*partitionsize/SAMPLE_RATE;
int16_t *sp_L;
uint8_t first_block = 1;
const int PROGMEM nfor = nc / partitionsize;
float32_t DMAMEM float_buffer_L[nc];
char buffer[4];
float32_t chirp[nc];
AudioInputI2SNoBegin i2s_in;
AudioRecordQueue Q_in_L;
AudioRecordQueue Q_in_R;
AudioPlayQueue Q_out_L;
AudioOutputI2SNoBegin i2s_out;
AudioConnection patchCord_in(i2s_in, 0, Q_in_L, 0);
AudioConnection patchCord_in_R(i2s_in, 1, Q_in_R, 0);
AudioConnection patchCord_out(Q_out_L, 0, i2s_out, 0);
String command;
void setup() {
SD.begin(chipSelect);
AudioMemory(N_memory);
delay(100);
Q_in_L.begin();
Q_in_R.begin();
pinMode(0,INPUT_PULLDOWN);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(LED_BUILTIN,OUTPUT);
setI2SFreq(SAMPLE_RATE);
digitalWrite(1,HIGH);
digitalWrite(LED_BUILTIN,HIGH);
Serial.begin(115200);
while(!Serial);
Serial.println(SAMPLE_RATE);
Serial.println(partitionsize);
Serial.println(Npartitions);
}
void loop() {
//stuff
}
AudioInputI2SNoBegin and AudioOutputI2SNoBegin are two custom objects that are identical to the original I2S objects but do not call "begin()" (which I call later) when created. The problem is the same with the original I2S objects.
If you comment out the line "AudioConnection patchCord_in_R(i2s_in, 1, Q_in_R, 0);" (or Q_in_R.begin()), it works! Note that the two channels are working separately (by changing "patchCord_in(i2s_in, 0, Q_in_L, 0);" to "patchCord_in(i2s_in, 1, Q_in_L, 0);"). I also made a test code... which works:
C:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=204,228
AudioRecordQueue queue2; //xy=438,297
AudioRecordQueue queue1; //xy=440,162
AudioConnection patchCord1(i2s1, 0, queue1, 0);
AudioConnection patchCord2(i2s1, 1, queue2, 0);
// GUItool: end automatically generated code
void setup() {
AudioMemory(10);
delay(100);
queue1.begin();
queue2.begin();
}
void loop() {
if(queue1.available()){
Serial.println("left channel OK");
queue1.freeBuffer();
}
if(queue2.available()){
Serial.println("right channel OK");
queue2.freeBuffer();
}
}
I really don't see where the problem is...
Last edited: