Skip to content

Comments

Add I2S Slave Support For Teensy 4.0#38

Draft
bthayer3 wants to merge 2 commits intochipaudette:masterfrom
bthayer3:addI2SslaveInput
Draft

Add I2S Slave Support For Teensy 4.0#38
bthayer3 wants to merge 2 commits intochipaudette:masterfrom
bthayer3:addI2SslaveInput

Conversation

@bthayer3
Copy link

@bthayer3 bthayer3 commented Feb 15, 2026

Looks like the AudioInputI2Sslave_F32 is targeting an older teensy 3 board. Add a new logic section to support Teensy 4.0 board. I compared the logic used in the PJRC audio library and added this logic more so as an educated guess. It my testing it does work with some glitches though, I am probably testing this all wrong though as I don't have an oscilloscope.

Probably would also need the design tool with this i2sslaveinput drag and drop element. Didn't add that code yet as I think this slave code needs more work.

For reference: this is the code I was using in the Arduino sketch when I tested this. I was sending over 16 bit at 48 khz:

#include "OpenAudio_ArduinoLibrary.h"
#include "AudioStream_F32.h"
#include "USB_Audio_F32.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioInputI2Sslave_F32       audioInI2S1;
AudioOutputUSB_F32           audioOutUSB1;
AudioConnection_F32          patchCord1(audioInI2S1, 0, audioOutUSB1, 0);
AudioConnection_F32          patchCord2(audioInI2S1, 1, audioOutUSB1, 1);

void setup() {
  AudioMemory(30);  
  AudioMemory_F32(30);
}

void loop() {
}

@boblark
Copy link
Collaborator

boblark commented Feb 18, 2026

I confess to being unqualified in this area of the code! So some random thoughts.
I think we can get 16-bit code by borrowing from the work of the I16 library. But, that leaves up to 8-bits that may be available and within the dynamic range of floating point. We also have this issue with the non-slave quad input as well. Does this seem right?
Alternatively, we can restrict the slave input to 16-bits resolution?
The need for slave seems less with 4.1 than 3.6 as the I2S clock generation is both more accurate and can do all the frequencies we need, I think. Thoughts?
Bob

@chipaudette
Copy link
Owner

I also am little qualified to comment on any of the I2S_slave code. I (mostly) left it out of my original creation of this library because I had no hardware to test it on. I still have no hardware to test it on. So, I have little basis for recommending anything.

Sorry.

@bthayer3 , what hardware are you using for testing?

@bthayer3
Copy link
Author

I will also admit I am no expert with this stuff. I was using a raspberry pi 4 with a Teensy 4.0 and don't have an oscilloscope either. I was using i2s-master-dac overlay on the pi to send over audio like sine waves using speaker-test command. I think the issues I was running into was the clocks getting out of sync. I recently switched my code over and made the Teensy the master using AudioInputI2S and this seemed to resolve my issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants