9 Replies Latest reply on Mar 11, 2015 1:07 PM by Petter0007

    I2S library for Edison

    onehorse

      I put together a small pcb that has two Invensense INMP441 digital MEMS microphones each with an ASIC embedded in the phones that outputs serial data that conforms to the I2S protocol. The board takes power, GND, I2S CLK, and I2S Word Select as inputs and outputs I2S serial data. I think I know how to hook up the small microphone board to the Edison via our custom Edison-module adapter board with the four signals of the I2S port broken out to logic-level-converted (from 1V8 to 3V3) edge pins. We wont use the I2S TX from the Edison; no need.

       

      What would be very useful though would be an Arduino I2S library that could make reading the data as easy as using the Wire.h library to read I2C data from sensor registers. The I2S serial data in this case is 64 bit words (32-bits per stereo output) and the clock needs to run at ~3 MHz. I think this protocol is literally standard I2S but I haven't run across any examples of an easy to use Arduino-like I2S library. Does anyone know of such a library?

        • 1. Re: I2S library for Edison
          JPMontero_Intel

          Hi onehorse,

           

          I’ve never used an I2S library for Arduino, but I’ve found one this one https://github.com/delsauce/ArduinoDueHiFi. The problem is that is written for the ARM processor. I think this might be a problem for most of I2S libraries since this is a hardware configuration and probably won’t work. I’d suggest you try to configure I2S on Linux side, but unfortunately for the moment there is no documentation on it nor has been validated.

           

          Regards,
            JPMontero_Intel 

          • 2. Re: I2S library for Edison
            onehorse


            I mispoke about the word length for these microphones. The I2S serial output is 24-bit each for left and right output but it is read out over 32 clock cycles.

             

            I have asked a friend to make an I2S Arduino library so we can read I2S data as simply as we now read I2C data. Once we have this working on a 3V3 Pro Mini and a Teensy 3.1, I will try it out on the Edison using it's Arduino IDE. If this works (and why shouldn't it), I will post the GitHub link to the I2S library.

            • 3. Re: I2S library for Edison
              JPMontero_Intel

              Sounds good, please let us know your results with this library.

               

              Regards,
                JPMontero_Intel

              • 4. Re: I2S library for Edison
                WavelengthAudio

                Hey I develop embedded I2S applications all day. I am interested also in whatever you come up with here and the best way to implement them.

                 

                I will receive my modules and stuff next week.

                 

                It looks like the Edison modules can do I2S master and slave. In most cases the best results for MEMs or other what I would call I2S inputs is to setup the Edison as a slave. That is if your mems is capable of being the master. That would have the best results and the lowest jitter error.

                 

                I take it that Intel is probably considering some kind ALSA compliant implementation of the I2S so that any application can access external devices.

                 

                Thanks,

                Gordon

                • 5. Re: I2S library for Edison
                  onehorse

                  The INMP441 MEMS microphones on the board I designed take BCLK and WS as inputs from the Edison and return SD (I2S data) to the Edison. This sounds rather like the Edison is in master mode to me. But I am no expert on I2S.

                   

                  The library I have in mind will just read the serial data and store it in memory for later processing. I hope to take advantage of existing libraries for FFT and other manipulations of the audio data.

                   

                  I am trying to understand how the audio data is encoded in the I2S signal. It is apparently like a PWM output with the frequency encoded as pulse density in the data word and amplitude encoded as, well, amplitude of the pulse. Or is this just all wrong. Anyway, I am looking for a cogent explanation of how to convert a stream of 24-bit I2S serial data into amplitude and frequency of the sound recorded by the microphones. Can you explain this?

                  • 6. Re: I2S library for Edison
                    WavelengthAudio

                    Ok,

                     

                    Basic I2S stuff, correct the edison would be the master. You have to set the L/R on the mems and this will determine were in the I2S stream the data will reside. All I2S feeds are stereo and the Word Clock WS determines if the data is for the LEFT channel or the RIGHT channel. I bet the edison can be configured for mono or stereo. But I would imagine any libraries here are going to assume stereo data.

                     

                    All the data will be PCM format:

                     

                    Pulse-code modulation - Wikipedia, the free encyclopedia

                     

                    The data buffer if setup for stereo will be L, R, L, R... so forth. If you can set the edison up for mono then it will ask which channel L or R. If so then the data will just a linear table of 3 byte samples (24 bits). I have not looked into the edison yet here I just received mine this morning. But some controllers like to use 32 bit words for samples at that point you would see 4 bytes with the 24 bits packed in I2S format i.e. MSB, bottom 8 bits = 0. Since PCM is a signed number a 3 byte sample and a 4 byte sample will be the same value in this type of format.

                     

                    All I2S stuff is usually done with DMA as the stream is pretty fast. There are tons of ways to handle this. For input there is usually some kind of que with buffers = some length. I usually program an array of pointers to the buffers in some multiple of 2. Like 2,4,8, 16 etc... and then just push and pull the samples for processing.

                     

                    The bit clock BCLK in your mems is going to determine the sample rate. You will have to set that up and then the Word Clock will be that divided by 64. There are 64 bits per Word Clock, 32 for left, 32 for right. To sample at say 44.1K you would want to set the bit clock to 2.8224Mhz (44.1E3 * 64).

                     

                    I went through the yocko you tube thing yesterday. Tell me if you find any libraries up there for the edison board and we can look at the code.

                     

                    Thanks,

                    Gordon

                    • 7. Re: I2S library for Edison
                      onehorse

                      Wow! This is great Gordon. Thanks for the tutorial. Now I think I understand enough to get a simple program together to read and parse the data. When I have it working I'll post it here or at least the link to GitHub. I will assemble the first few microphone boards this week and get to work! Thanks again. Kris

                      • 8. Re: I2S library for Edison
                        WavelengthAudio

                        Kris,

                         

                        Great, really if you need any help, just ask. I am primarily looking to do work as an output device for audio. To probably a DAC and maybe an SPDIF transmitter.

                         

                        Thanks,

                        Gordon

                        • 9. Re: I2S library for Edison
                          Petter0007

                          Did you get the mic to work?

                          I plan to use the same microphone in my project, and would be greatful for any confirmation on the functionality.

                           

                          I'm new ti I2S so i don't really have any experience with ant digital sound other than PWM modulation's from different atmel's....

                          In my project i want to have a microphone and a small mono speaker...is it possible to have one I2S channel (ex,left) as inbound data from microphone like the INMP441 and the other (ex.right) channel as outgoing data for a monoamp like the tfa9879 ,or do i have to switch mode from incoming data to outgoing to switch between microphone to amplifyer?

                          In my project i don't need the mic while using the amplifyer, so switching is possible, but if it's configurable as inbound and outbound simultanius it would be great.

                           

                          Thank's for any reply's