Skip to content

Commit f77f292

Browse files
committed
Initial import
1 parent e409964 commit f77f292

25 files changed

+1947
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
This example reads audio data from an Invensense's ICS43432 I2S microphone
3+
breakout board, and prints out the amplitude to the Serial console. The
4+
Serial Plotter built into the Arduino IDE can be used to plot the audio
5+
amplitude data (Tools -> Serial Plotter)
6+
7+
Circuit:
8+
* Arduino/Genuino Zero or MKR1000 board
9+
* ICS43432:
10+
* GND connected GND
11+
* 3.3V connected 3.3V
12+
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
13+
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
14+
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)
15+
16+
created 23 November 2016
17+
by Sandeep Mistry
18+
*/
19+
20+
#include <ArduinoSound.h>
21+
22+
// create an amplitude analyzer to be used with the I2S input
23+
AmplitudeAnalyzer amplitudeAnalyzer;
24+
25+
void setup() {
26+
// Open serial communications and wait for port to open:
27+
// A baud rate of 115200 is used instead of 9600 for a faster data rate
28+
// on non-native USB ports
29+
Serial.begin(115200);
30+
while (!Serial) {
31+
; // wait for serial port to connect. Needed for native USB port only
32+
}
33+
34+
// setup the I2S audio input for 44.1 kHz with 32-bits per sample
35+
if (AudioInI2S.begin(44100, 32)) {
36+
Serial.println("Failed to initialize I2S input!");
37+
while (1); // do nothing
38+
}
39+
40+
// configure the I2S input as the input for the amplitude analyzer
41+
if (amplitudeAnalyzer.input(AudioInI2S)) {
42+
Serial.println("Failed to set amplitude analyzer input!");
43+
while (1); // do nothing
44+
}
45+
}
46+
47+
void loop() {
48+
// check if a new analysis is available
49+
if (amplitudeAnalyzer.available()) {
50+
// read the new amplitude
51+
int amplitude = amplitudeAnalyzer.read();
52+
53+
// print out the amplititude to the serial monitor
54+
Serial.println(amplitude);
55+
}
56+
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
This example reads audio data from an Invensense's ICS43432 I2S microphone
3+
breakout board, and uses the input to detect clapping sounds. An LED is
4+
togggled when a clapp is detected.
5+
6+
Circuit:
7+
* Arduino/Genuino Zero or MKR1000 board
8+
* ICS43432:
9+
* GND connected GND
10+
* 3.3V connected 3.3V
11+
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
12+
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
13+
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)
14+
15+
created 18 November 2016
16+
by Sandeep Mistry
17+
*/
18+
19+
#include <ArduinoSound.h>
20+
21+
// the LED pin to use as output
22+
const int ledPin = LED_BUILTIN;
23+
24+
// the amplitude threshold for a clap to be detected
25+
const int amplitudeDeltaThreshold = 100000000;
26+
27+
// create an amplitude analyzer to be used with the I2S input
28+
AmplitudeAnalyzer amplitudeAnalyzer;
29+
30+
// variable to keep track of last amplitude
31+
int lastAmplitude = 0;
32+
33+
void setup() {
34+
// setup the serial
35+
Serial.begin(9600);
36+
37+
// configure the LED pin as an output
38+
pinMode(ledPin, OUTPUT);
39+
40+
// setup the I2S audio input for 44.1 kHz with 32-bits per sample
41+
if (AudioInI2S.begin(44100, 32)) {
42+
Serial.println("Failed to initialize I2S input!");
43+
while (1); // do nothing
44+
}
45+
46+
// configure the I2S input as the input for the amplitude analyzer
47+
if (amplitudeAnalyzer.input(AudioInI2S)) {
48+
Serial.println("Failed to set amplitude analyzer input!");
49+
while (1); // do nothing
50+
}
51+
}
52+
53+
void loop() {
54+
// check if a new analysis is available
55+
if (amplitudeAnalyzer.available()) {
56+
// read the new amplitude
57+
int amplitude = amplitudeAnalyzer.read();
58+
59+
// find the difference between the new amplitude and the last
60+
int delta = amplitude - lastAmplitude;
61+
62+
// check if the difference is larger than the threshold
63+
if (delta > amplitudeDeltaThreshold) {
64+
// a clap was detected
65+
Serial.println("clap detected");
66+
67+
// toggle the LED
68+
digitalWrite(ledPin, !digitalRead(ledPin));
69+
70+
// delay a bit to debounce
71+
delay(100);
72+
}
73+
74+
// update the last amplitude with the new amplitude
75+
lastAmplitude = amplitude;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
This example reads audio data from an Invensense's ICS43432 I2S microphone
3+
breakout board, and prints out the spectrum to the Serial console. The
4+
Serial Plotter built into the Arduino IDE can be used to plot the audio
5+
amplitude data (Tools -> Serial Plotter)
6+
7+
Circuit:
8+
* Arduino/Genuino Zero or MKR1000 board
9+
* ICS43432:
10+
* GND connected GND
11+
* 3.3V connected 3.3V
12+
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
13+
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
14+
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)
15+
16+
created 21 November 2016
17+
by Sandeep Mistry
18+
*/
19+
20+
#include <ArduinoSound.h>
21+
22+
// sample rate for the input
23+
const int sampleRate = 8000;
24+
25+
// size of the FFT to compute
26+
const int fftSize = 128;
27+
28+
// size of the spectrum output, half of FFT size
29+
const int spectrumSize = fftSize / 2;
30+
31+
// array to store spectrum output
32+
int spectrum[spectrumSize];
33+
34+
// create an FFT analyzer to be used with the I2S input
35+
FFTAnalyzer fftAnalyzer(fftSize);
36+
37+
void setup() {
38+
// Open serial communications and wait for port to open:
39+
// A baud rate of 115200 is used instead of 9600 for a faster data rate
40+
// on non-native USB ports
41+
Serial.begin(115200);
42+
while (!Serial) {
43+
; // wait for serial port to connect. Needed for native USB port only
44+
}
45+
46+
// setup the I2S audio input for the sample rate with 32-bits per sample
47+
if (AudioInI2S.begin(sampleRate, 32)) {
48+
Serial.println("Failed to initialize I2S input!");
49+
while (1); // do nothing
50+
}
51+
52+
// configure the I2S input as the input for the FFT analyzer
53+
if (fftAnalyzer.input(AudioInI2S)) {
54+
Serial.println("Failed to set FFT analyzer input!");
55+
while (1); // do nothing
56+
}
57+
}
58+
59+
void loop() {
60+
// check if a new analysis is available
61+
if (fftAnalyzer.available()) {
62+
// read the new spectrum
63+
fftAnalyzer.read(spectrum, spectrumSize);
64+
65+
// print out the spectrum
66+
for (int i = 0; i < spectrumSize; i++) {
67+
Serial.print((i * sampleRate) / fftSize); // the starting frequency
68+
Serial.print("\t"); //
69+
Serial.println(spectrum[i]); // the spectrum value
70+
}
71+
}
72+
}
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
This reads a wave file from an SD card and plays it using the I2S interface to
3+
a MAX08357 I2S Amp Breakout board.
4+
5+
Circuit:
6+
* Arduino/Genuino Zero or MKR1000 board
7+
* SD breakout or shield connected
8+
* MAX08357:
9+
* GND connected GND
10+
* VIN connected 5V
11+
* LRC connected to pin 0 (Zero) or pin 3 (MKR1000)
12+
* BCLK connected to pin 1 (Zero) or pin 2 (MKR1000)
13+
* DIN connected to pin 9 (Zero) or pin A6 (MKR1000)
14+
15+
created 15 November 2016
16+
by Sandeep Mistry
17+
*/
18+
19+
#include <SD.h>
20+
#include <ArduinoSound.h>
21+
22+
// filename of wave file to play
23+
const char filename[] = "MUSIC.WAV";
24+
25+
// variable representing the Wave File
26+
SDWaveFile waveFile;
27+
28+
void setup() {
29+
// Open serial communications and wait for port to open:
30+
Serial.begin(9600);
31+
while (!Serial) {
32+
; // wait for serial port to connect. Needed for native USB port only
33+
}
34+
35+
// setup the SD card, depending on your shield of breakout board
36+
// you may need to pass a pin number in begin for SS
37+
Serial.print("Initializing SD card...");
38+
if (!SD.begin()) {
39+
Serial.println("initialization failed!");
40+
return;
41+
}
42+
Serial.println("initialization done.");
43+
44+
// create a SDWaveFile
45+
waveFile = SDWaveFile(filename);
46+
47+
// check if the WaveFile is valid
48+
if (!waveFile) {
49+
Serial.println("wave file is invalid!");
50+
while (1); // do nothing
51+
}
52+
53+
// print out some info. about the wave file
54+
Serial.print("Bits per sample = ");
55+
Serial.println(waveFile.bitsPerSample());
56+
57+
long channels = waveFile.channels();
58+
Serial.print("Channels = ");
59+
Serial.println(channels);
60+
61+
long sampleRate = waveFile.sampleRate();
62+
Serial.print("Sample rate = ");
63+
Serial.print(sampleRate);
64+
Serial.println(" Hz");
65+
66+
long duration = waveFile.duration();
67+
Serial.print("Duration = ");
68+
Serial.print(duration);
69+
Serial.println(" seconds");
70+
71+
// adjust the playback volume
72+
AudioOutI2S.volume(5);
73+
74+
// check if the I2S output can play the wave file
75+
if (!AudioOutI2S.canPlay(waveFile)) {
76+
Serial.println("unable to play wave file using I2S!");
77+
while (1); // do nothing
78+
}
79+
80+
// start playback
81+
Serial.println("starting playback");
82+
AudioOutI2S.play(waveFile);
83+
}
84+
85+
void loop() {
86+
// check if playback is still going on
87+
if (!AudioOutI2S.isPlaying()) {
88+
// playback has stopped
89+
90+
Serial.println("playback stopped");
91+
while (1); // do nothing
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
This example reads audio data from an Invensense's ICS43432 I2S microphone
3+
breakout board, and uses the input to detect whistling sounds at a particular
4+
frequency. When a whistle is detected, it's level is used to control the
5+
brightness of an LED
6+
7+
Circuit:
8+
* Arduino/Genuino Zero or MKR1000 board
9+
* ICS43432:
10+
* GND connected GND
11+
* 3.3V connected 3.3V
12+
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
13+
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
14+
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)
15+
16+
created 30 November 2016
17+
by Sandeep Mistry
18+
*/
19+
20+
#include <ArduinoSound.h>
21+
22+
// the LED pin to use as output
23+
const int ledPin = LED_BUILTIN;
24+
25+
// sample rate for the input
26+
const int sampleRate = 8000;
27+
28+
// size of the FFT to compute
29+
const int fftSize = 128;
30+
31+
// size of the spectrum output, half of FFT size
32+
const int spectrumSize = fftSize / 2;
33+
34+
// frequency of whistle to detect
35+
const int whistleFrequency = 1250;
36+
37+
// map whistle frequency to FFT bin
38+
const int whistleBin = (whistleFrequency * fftSize / sampleRate);
39+
40+
// array to store spectrum output
41+
int spectrum[spectrumSize];
42+
43+
// create an FFT analyzer to be used with the I2S input
44+
FFTAnalyzer fftAnalyzer(fftSize);
45+
46+
void setup() {
47+
// setup the serial
48+
Serial.begin(9600);
49+
50+
// configure the pin for output mode
51+
pinMode(ledPin, OUTPUT);
52+
53+
// setup the I2S audio input for the sample rate with 32-bits per sample
54+
if (AudioInI2S.begin(sampleRate, 32)) {
55+
Serial.println("Failed to initialize I2S input!");
56+
while (1); // do nothing
57+
}
58+
59+
// configure the I2S input as the input for the FFT analyzer
60+
if (fftAnalyzer.input(AudioInI2S)) {
61+
Serial.println("Failed to set FFT analyzer input!");
62+
while (1); // do nothing
63+
}
64+
}
65+
66+
void loop() {
67+
if (fftAnalyzer.available()) {
68+
// analysis available, read in the spectrum
69+
fftAnalyzer.read(spectrum, spectrumSize);
70+
71+
// map the value of the whistle bin magnitude between 0 and 255
72+
int ledValue = map(spectrum[whistleBin], 50000, 60000, 0, 255);
73+
74+
// cap the values
75+
if (ledValue < 0) {
76+
ledValue = 0;
77+
} else if (ledValue > 255) {
78+
ledValue = 255;
79+
}
80+
81+
// set LED brightness based on whistle bin magnitude
82+
analogWrite(ledPin, ledValue);
83+
}
84+
}

0 commit comments

Comments
 (0)