I2S.read() question

I've looked at several of the examples posted to try to understand the I2S.read() class but I'm still confused on the operation of this. The I2S library lists write (and others) in its classes but not read.
Is there a reference doc to describe how to use this class?

I've seen this used as:

int size = I2S.available();
byte data;
I2S.read(data, size);


int sample = I2S.read();

In the project that I'm doing (using the MKR ZERO) I want to capture a 2 channel 48kHz I2S stream and write it to a wav file on an SD card. The input stream is using the I2S standard in that the signaling is using 32 bits per channel with 24 bit data words aligned as per the I2S standard. I'll be reducing this to 16 bit data that will be used to store as a wav file on an SD card.

In things that I've read on other projects and posts the first example above is implemented as an interrupt (callback) routine. I didn't see anything in the setup code to control the size of the input buffer. Is it possible using this class to buffer some number of multiple input sample pairs and then trigger the interrupt to read the buffer? The first example reads data as bytes. Can this be a 32 bit int? The way this is written looks like the buffer size can be different on every callback. Is that a correct observation?

Last, I've seen some discussion on difficulties of the SD write keeping up with the incoming stream. I would appreciate any comments on what technique has worked best for this from anyone who has implemented something like this.


1 Like