I2S sound recording from Teensy Audio Board using I2S.h library

Status
Not open for further replies.

Mr.Pedro

Active member
Hi folks,

I do want to directly record raw audio data from AUDIO_INPUT_MIC (16 bit, 44.1 kHz sample rate) using I2S.h library as shown in the following example for the ICS43432 I2S Microphone which I'll be using later in my project: https://github.com/arduino-libraries/ArduinoSound/issues/2

Is there a way of doing this without using the Audio System Design Tool for Teensy Audio Board?
Is there any example available?

- I do need to store the last 1 second of sound in an array which is constatly updated so that I can perform different analysis on it (That's 88.2KB out of 256KB of SDRAM for Teensy 3.6).
- Eventually, I'll need to store the array in the SD card for later analysis and comparison

Thank you,
Pedro
 
That is Arduino's I2S library.

Is there a way of doing this without using the Audio System Design Tool for Teensy Audio Board?

Teensy's audio library has much more capability and runs much more efficiently.

The Teensy audio library works with much more than only the audio shield. It can use these types of I2S mics. Certainly the audio shield is the default hardware used in most of the examples, but the library is not tied to only that hardware.

You don't necessarily have to use the design tool, but it's much simpler to create the object instances code that way. If you're *really* good at C++ and following the finer details, you could just type the code. But I don't recommend it. The design tool avoid all sorts of common human errors.

Is there any example available?

Yes. With Teensy selected in the Tools > Boards menu, click File > Examples > Audio > Recorder.

This example is designed for the audio shield, but it's easy to adapt to other I2S devices, where Teensy is the I2S master and the device devices the I2S clocks. Just delete the SGTL5000 stuff, since you won't have that chip. These mics don't have any configurable stuff like more advanced codec chips, so you don't need any of that.

- Eventually, I'll need to store the array in the SD card for later analysis and comparison

Good news for you. The example does exactly what you want. :)

It records only mono audio to the file. For stereo, look at this recent thread:

https://forum.pjrc.com/threads/46150?p=158388&viewfull=1#post158388

- I do need to store the last 1 second of sound in an array which is constatly updated so that I can perform different analysis on it (That's 88.2KB out of 256KB of SDRAM for Teensy 3.6).

What type of analysis are you going to do?
 
Thank you Paul,

I can use Audio System Design Tool to create the object instances for the SGTL5000 codec chip to configure the microphone and the Audio Board I2S output, then I'd like to use I2S Arduino library to read the raw audio output.

Would the following Canvas be correct or do I need to connect the output of the i2s input object?

Capture.JPG

Recorder example is great but I'm not *really* good at C++ so I cannot follow the finer details to get the recorded data not only into my ssd but into the mentioned array.

What type of analysis are you going to do?

I'll be performing a real time spectogram of the last 1 second of sound using my own STFT and Wavelet transform implementations.
 
Would the following Canvas be correct or do I need to connect the output of the i2s input object?

The design tool can import. Just copy the list of objects from the Recorder example, click Import in the design tool, and paste the code. Then it will give you the design that was originally made, which you click to place onto the design tool canvas. Then you can click on each object to see its documentation.

That particular example both records and plays audio back, so it has objects for both functions. It also has an unused peak object.

Hopefully you'll actually use the design tool and read the docs. But to directly answer your question, to make this work you really only need the i2s input object (which brings the I2S data into Teensy) and the record queue object (which gives you access to the raw data).

Perhaps you may be feeling like this audio library stuff is an extra later that adds more burden for you to learn, but I can assure you it is worth your effort. Unlike Arduino's I2S, the Teensy audio library provides those queue objects which automatically queue up data if you are not able to process it all at the full incoming audio speed. This is an essential feature for recording to a SD card, or probably also for your wavelet analysis, because they digest large chunks of data at once. Without the audio library queues, you would need to build rather complex timing critical code to buffer the data while doing the SD card writes or wavelet analysis. This happens automatically with the Teensy audio library. It really is worth learning and using, because this feature will make everything so much easier.

Recorder example is great but I'm not *really* good at C++ so I cannot follow the finer details to get the recorded data not only into my ssd but into the mentioned array.

You're going to have to work with arrays and basic C++ programming, regardless of whether you use Teensy or Arduino. You'll probably have much less to do with Teensy, since we already have an example that does all the array stuff needed for getting blocks efficiently into the SD library.

Probably the most effective way to learn would be to buy the audio shield. Then you could use the already-working example as-is and experience how it really works. That would give you a solid starting point for learning how to adapt it to your needs.

The harder way would involve just deleting the SGTL5000 stuff. The PT2811 page has some info about adapting the examples from the audio shield. Follow the parts about deleting the SGTL5000, but obviously changing from I2S to PT2811 doesn't apply. The rest of the code ought to "just work", if you get the I2S mic wired up properly. But if it doesn't work, you're going to have a steep learning curve because you're not starting from already-working hardware. That's your choice. If you get stuck and need a way to figure things out from a working starting point, at least the audio shield is available to buy.

Make sure you are using the latest 1.40 version of Teensyduino, since the I2S code was recently changed to improve compatibility with those mics.

I'll be performing a real time spectogram of the last 1 second of sound using my own STFT and Wavelet transform implementations.

Sounds like you're going to have quite a lot of work to do on the coding side!
 
Thank you again Paul,

I know it's probably boring for you to answer this basic stuff but it helps a lot on early stages of a project where you are lost among indecent amounts of documentation. I appreciate it a lot, thanks.

I already have the audio shield and I'll just start testing the different examples so I can adapt then to my needs as shown:

Capture.JPG

Sounds like you're going to have quite a lot of work to do on the coding side!

Yes I am! Actually, I'm using Python for the analysis by now, Teensy is going to be used as a rapid prototyping tool to get samples from a custom microphone and everything will lately be ported/implemented into a custom embedded system.

Best,
Pedro
 
Status
Not open for further replies.
Back
Top