Skip to content

Commit 7367d2d

Browse files
committed
I2S
1 parent 8a23236 commit 7367d2d

23 files changed

+111222
-44
lines changed

.DS_Store

0 Bytes
Binary file not shown.

License.txt

+216
Large diffs are not rendered by default.

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
Some basic C++ classes that can be used for Audio Processing privided as Arduino Library
44

5+
- Additinal Stream implementations: MemoryStream, UrlStream [ESP32 only]
56
- a simple I2S class (to read and write to the internal I2S) [ESP32 only]
67
- a simple ADC class (to read analog data with the help of I2S) [ESP32 only]
78
- Converters
8-
- Notes (Frequencies of notes)
9+
- Musical Notes (with Frequencies of notes)
910
- SineWaveGenerator (to generate some sine tone)
1011
- NBuffer (Multi buffer for writing and reading of (sound) data)
1112
- TimerAlarmRepeating (e.g. for sampling sound data using exact times) [ESP32 only]
13+
- A Wav Encoder and Decoder
1214

1315
This functionality provides the glue which makes different sound processing components and libraries work together.
1416
We also provide plenty of examples that demonstrate how to implement the different scenarios.
@@ -41,6 +43,15 @@ Here is the generated [Class documentation](https://pschatzmann.github.io/arduin
4143

4244
## Project Status
4345

44-
This is currently work in progress.
45-
46+
This is currently work in progress:
47+
48+
| Functionality | Status
49+
|-----------------------------------
50+
| Analog input - ADC | tested
51+
| I2S | tested
52+
| Files | open
53+
| Streams | open
54+
| WAV encoding/deconding | open
55+
| AAC encoding/deconding | open
56+
| int24_t | open
4657

examples/adc-a2dp/adc-a2dp.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using namespace sound_tools;
1111
ADC adc;
1212
BluetoothA2DPSource a2dp_source;
1313
// The data has a center of around 26427, so we we need to shift it down to bring the center to 0
14-
FilterScaler<int16_t> scaler(1.0, -26427, 32700 );
14+
<int16_t> scaler(1.0, -26427, 32700 );
1515

1616
// callback used by A2DP to provide the sound data
1717
int32_t get_sound_data(Channels* data, int32_t len) {

examples/i2s-a2dp/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ The INMP441 is a high-performance, low power, digital-output, omnidirectional ME
1414
| --------| ---------------
1515
| VDD | 3.3
1616
| GND | GND
17-
| SD | IN (GPIO23)
17+
| SD | IN (GPIO32)
1818
| L/R | GND
19-
| WS | WS (GPIO25)
20-
| SCK | BCK (GPIO26)
19+
| WS | WS (GPIO15)
20+
| SCK | BCK (GPIO14)
2121

2222

2323
SCK: Serial data clock for I²S interface

examples/i2s-serial/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ The INMP441 is a high-performance, low power, digital-output, omnidirectional ME
1414
| --------| ---------------
1515
| VDD | 3.3
1616
| GND | GND
17-
| SD | IN (GPIO23)
17+
| SD | IN (GPIO32)
1818
| L/R | GND
19-
| WS | WS (GPIO25)
20-
| SCK | BCK (GPIO26)
19+
| WS | WS (GPIO15)
20+
| SCK | BCK (GPIO14)
2121

2222

2323
SCK: Serial data clock for I²S interface

examples/i2s-serial/i2s-serial.ino

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55
using namespace sound_tools;
66

77
/**
8-
* @brief We use a ADS1015 I2S microphone as input and send the data to A2DP
9-
* Unfortunatly the data type from the microphone (int32_t) does not match with the required data type by A2DP (int16_t),
10-
* so we need to convert.
8+
* @brief We use I2S as input and send the data to A2DP
9+
* To test we use a INMP441 microphone.
1110
*/
1211

1312
I2S<int32_t> i2s;
1413
const size_t max_buffer_len = 512;
15-
int16_t buffer[max_buffer_len][2];
14+
int32_t buffer[max_buffer_len][2];
1615

1716
// Arduino Setup
1817
void setup(void) {
1918
Serial.begin(115200);
2019

2120
// start i2s input with default configuration
2221
Serial.println("starting I2S...");
23-
i2s.begin(i2s.defaultConfig(RX_MODE));
22+
I2SConfig<int32_t> config = i2s.defaultConfig(RX_MODE);
23+
config.i2s.sample_rate = 16000;
24+
i2s.begin(config);
2425
}
2526

2627
// Arduino loop - repeated processing
2728
void loop() {
2829
size_t len = i2s.read(buffer, max_buffer_len);
2930

3031
for (int j=0;j<len;j++){
31-
Serial.print(buffer[j][0]);
32+
Serial.print((int32_t)buffer[j][0]);
3233
Serial.print(", ");
33-
Serial.println(buffer[j][1]);
34+
Serial.println((int32_t)buffer[j][1]);
3435
}
3536
}

sandbox/.DS_Store

6 KB
Binary file not shown.

sandbox/wav_decode/wav_decode.ino

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "AudioWAV.h"
2+
#include "AudioTools.h"
3+
#include "AudioToolsESP32.h"
4+
5+
I2S i2s; // I2S output destination
6+
WAVDecoder decoder(i2s);
7+
UrlStream music;
8+
9+
void setup(){
10+
Serial.begin(115200);
11+
// connect to WIFI
12+
WiFi.begin("network name", "password");
13+
while (WiFi.status() != WL_CONNECTED) {
14+
delay(500);
15+
Serial.print(".");
16+
}
17+
18+
music.begin("https://www2.cs.uic.edu/~i101/SoundFiles/BabyElephantWalk60.wav");
19+
i2s.begin();
20+
decoder.begin();
21+
}
22+
23+
void loop(){
24+
static uint8_t buffer[512];
25+
if (music.available()>0){
26+
int len = music.readBytes(buffer, 512);
27+
decoder.write(buffer, len);
28+
}
29+
}

sandbox/wav_encode/StarWars30.h

+110,110
Large diffs are not rendered by default.

sandbox/wav_encode/wav_encode.ino

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file aac_encode.ino
3+
* @author Phil Schatzmann
4+
* @brief Encode pwm data to AAC Stream (SD file)
5+
* @version 0.1
6+
* @date 2021-01-24
7+
*
8+
* @copyright Copyright (c) 2021
9+
*
10+
*/
11+
#include <SPI.h>
12+
#include <SD.h>
13+
#include "WAVEncoder.h"
14+
#include "StarWars30.h"
15+
#include "AudioTools.h"
16+
17+
File dataFile = SD.open("example.wav", FILE_WRITE);
18+
WAVEncoder encoder(dataFile);
19+
MemoryStream music(StarWars30_raw, StarWars30_raw_len);
20+
21+
void setup(){
22+
Serial.begin(115200);
23+
SD.begin();
24+
25+
// setup encoder
26+
encoder.begin();
27+
Serial.println("Creating WAV file...");
28+
}
29+
30+
void loop(){
31+
static uint8_t buffer[512];
32+
if (dataFile){
33+
if (music.available()>0){
34+
int len = music.readBytes(buffer, 512);
35+
encoder.write(buffer, len);
36+
} else {
37+
// no more data -> close file
38+
dataFile.close();
39+
Serial.println("File has been closed");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)