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_
