How edit I2S library?

Good morning!
I have a project and I must edit I2S.h library. This function used only one microphone but I have to use more than 2 microphones by this function. So I have to change function I2S read in I2S.h library. Could you tell me how can I do it?

#include <I2S.h> //I can't find this library !!!

Here I paste you the code of my programme:

void setup() {
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

digitalWrite(4, LOW);
digitalWrite(5, HIGH);

digitalWrite(4, HIGH);
// Open serial communications and wait for port to open:
// A baud rate of 115200 is used instead of 9600 for a faster data rate
// on non-native USB ports

Serial1.begin(9600);
while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}

// start I2S at 16 kHz with 32-bits per sample
if (!I2S.begin(I2S_PHILIPS_MODE, 16000, 32)) {
Serial1.println("Failed to initialize I2S!");
while (1); // do nothing
}
}

#define SAMPLES 128 // make it a power of two for best DMA performance

void loop() {
// read a bunch of samples:
int samples[SAMPLES];
float minsample[4];
float meanval[4];
float maxsample[4];
int mikrofon_nr = 0;

mikrofon_nr = 0;

while(mikrofon_nr < 4 )
{
for (int i=0; i<SAMPLES; i++)
{
int sample = 0;
while ((sample == 0) || (sample == -1) )
{
sample = I2S.read();
}
// convert to 18 bit signed
sample >>= 14;
samples = sample;

  • }*

  • // ok we hvae the samples, get the mean (avg)*

  • meanval[mikrofon_nr] = 0;*

  • for (int i=0; i<SAMPLES; i++) {*
    meanval[mikrofon_nr] += samples*;
    _
    }_
    meanval[mikrofon_nr] /= SAMPLES;
    //Serial.print("# average: " ); Serial.println(meanval[mikrofon_nr]);*

* // subtract it from all sapmles to get a 'normalized' output*
* for (int i=0; i<SAMPLES; i++) {*
samples -= meanval[mikrofon_nr];
_ //Serial.println(samples*);
}*_

* // find the 'peak to peak' max*
* float maxsample[mikrofon_nr], minsample[mikrofon_nr];
maxsample[mikrofon_nr] = -100000;
minsample[mikrofon_nr] = 100000;
_ for (int i=0; i<SAMPLES; i++) {_
minsample[mikrofon_nr] = min(minsample[mikrofon_nr], samples);
maxsample[mikrofon_nr] = max(maxsample[mikrofon_nr], samples);
_ }*_

_ /_
if(mikrofon_nr == 0)
_ {
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
else*

* {
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
}
/

* delay(10);*_

* mikrofon_nr++;
_ }*_

* String ramka_danych = "AT+#";*

* mikrofon_nr = 0;
while(mikrofon_nr < 4 )
_ {_
ramka_danych += minsample[mikrofon_nr];
ramka_danych += "#";
ramka_danych += meanval[mikrofon_nr];
ramka_danych += "#";
ramka_danych += maxsample[mikrofon_nr];
ramka_danych += "#";
mikrofon_nr++;
_ }*_

* ramka_danych += "koniec#";
Serial1.println(ramka_danych);
_ delay(10000);
}*

And that's all
Thank you in advance_

Here's the easiest way to find most libraries:

  • Select one of the library's examples from the File > Examples menu
  • Sketch > Show Sketch Folder

That will open the folder of the library's example sketch, which is inside the library folder. You can then navigate up a couple of folder levels to the library root folder. You will find the source code there or else in the src subfolder (as is the case with the I2S library).

In the case of the I2S library, this is especially helpful because that library is bundled with the Arduino SAMD Boards hardware package, which is under a folder that may be hidden by your operating system.

This system doesn't work for libraries which don't have examples. In that case, the way to find the library is:

  • File > Preferences
  • Check the box next to "Show verbose output during: compilation".
  • Click "OK".
  • Compile a sketch that an #include directive for the library.
  • After compilation finishes, examine the contents of the black console window at the bottom of the Arduino IDE window (you will need to scroll up to see it all). Somewhere near the top, you will find a compiler command that has -I flags for all the library dependencies of the code you compiled. In that command, you will find the path to the library's source code.

When you modify the library, you might be better off to save it to the libraries subfolder of your sketchbook folder (shown at File > Preferences > Sketchbook location). If you don't do that, your modifications to the library will be lost every time you update to a new version of Arduino SAMD Boards via Boards Manager. If you do save it to the sketchbook folder, you might want to check from time to time whether improvements have been made to the standard I2S library that you're missing out on by using your outdated modified version, and updating your version. Note that the I2S library will not necessarily be updated with every release of Arduino SAMD Boards. You can check the version in the text file library.properties that's in the root of the I2S folder. The version number should be updated every time Arduino updates the library.

Thank you very much for your answer. I have got another question to you: how can I change function I2S read () to read the signal from first and second microphone separately?From first microphone and then for second one. What I have to do to change it?
I add for you a part of my documentation of my microphone and a part of my programme :

while ((sample == 0) || (sample == -1) ) 
      {
        sample = I2S.read();
      }
      // convert to 18 bit signed
      sample >>= 14; 
      samples[i] = sample;
    }

In system conection.png I add very important thing. It show you why I have to change the I2S library.

OP's picture:

Did you look to see if the library already has a method for selecting which channel to read from (Left or Right) at any given time?

I know it (that is why I have add this picture with divison to first and second microphone)but I checked and I2S library doesn't have a method for selecting wchich channel to read from. That is why I have a problem with it and I wrote this question. Do you have other idea how I can do it? Maybe somebody could show me a place in code programme ( I add I2S.H library in first post) where I can do it.

Post a GitHub link to the EXACT library you're using. Also, specify which processor you're using.

Okay, I posted my question also on this forum. But if anyone could help me with this problem here, please do it.

gfvalvo:
Post a GitHub link to the EXACT library you're using. Also, specify which processor you're using.

Which part of this request is unclear?

Hi,

The Tri-state Control (gray) uses the state of the WS and SELECT inputs to determine if the DATA pin is driven
or tri-stated. This allows 2 microphones to operate on
a single I2S port. When SELECT =HIGH the DATA pin drives the SDIN bus when WS=HIGH otherwise DATA= tri-state. When SELECT =LOW the DATA pin drives the SDIN bus when WS=LOW otherwise DATA= tri-state

Tie SELECT pin of each mic to a Digital pin and set High to read mic and Low to disable. Simples

G

gfvalvo:
Which part of this request is unclear?

He doesn't know how to find this information because the library was delivered by the boards manager. I thought that part had already been resolved.

Mateusz1978, what do you have selected from the Tools > Board menu in the Arduino IDE?

Assuming it's a SAMD board (which is the only I2S library I know of), the library is here:

Yes, I found that on The Google. It doesn't really seem that flexible. I only gave it a quick look, but there doesn't seem to be a way to access both left and right channels.

I think Adafuit has an I2S library. I don't know if it works with any SAMD board or just theirs.

Also, the Teensy 3.x processors have I2S interfaces and the PRJC Audio Library is very powerful.

If OP wants more than 2 mics, then TDM interface should work. But it will require external multiplexing hardware. TDM is available on Teensy, I don't know about SAMD.