Skip to content

Commit 489eddd

Browse files
committed
I2S RXTX_MODE support
1 parent 21e61f9 commit 489eddd

File tree

11 files changed

+257
-71
lines changed

11 files changed

+257
-71
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
3+
#include <FS.h>
4+
#include <SD_MMC.h>
5+
#include <WiFi.h>
6+
#include "AudioTools.h"
7+
8+
/**
9+
* @brief Some examples are using files. Here is an example sketch for the ESP32 which creates
10+
* the files by copying the data from a URL.
11+
*
12+
* @author pschatzmann
13+
*/
14+
15+
const char* ssid = "ssid";
16+
const char* password = "password";
17+
StreamCopy copier; // copy kit to csvStream
18+
URLStream url(ssid,password);
19+
20+
void downloadFile(const char *c_url, const char *path){
21+
Serial.print("processing ");
22+
Serial.println(path);
23+
24+
auto file = SD_MMC.open(path, FILE_WRITE);
25+
url.begin(c_url);
26+
copier.begin(file, url);
27+
copier.copyAll();
28+
copier.end();
29+
url.end();
30+
file.flush();
31+
file.close();
32+
}
33+
34+
void createDirectory() {
35+
// Create directory
36+
File root = SD_MMC.open("/");
37+
if (!root){
38+
if(SD_MMC.mkdir("/Maximilian")){
39+
Serial.println("Dir created");
40+
} else {
41+
Serial.println("mkdir failed");
42+
}
43+
}
44+
root.close();
45+
}
46+
47+
void setup(){
48+
Serial.begin(115200);
49+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
50+
51+
// setup SD
52+
if(!SD_MMC.begin()){
53+
Serial.println("Card Mount Failed");
54+
return;
55+
}
56+
57+
createDirectory();
58+
59+
downloadFile("https://pschatzmann.github.io/Maximilian/doc/resources/beat2.wav","/Maximilian/beat2.wav");
60+
downloadFile("https://pschatzmann.github.io/Maximilian/doc/resources/snare.wav","/Maximilian/snare.wav");
61+
downloadFile("https://pschatzmann.github.io/Maximilian/doc/resources/blip.wav","/Maximilian/blip.wav");
62+
downloadFile("https://pschatzmann.github.io/Maximilian/doc/resources/crebit2.wav","/Maximilian/crebit2.wav");
63+
downloadFile("https://pschatzmann.github.io/Maximilian/doc/resources/crebit2.ogg","/Maximilian/crebit2.ogg");
64+
65+
Serial.println("The END");
66+
}
67+
68+
void loop(){}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "AudioTools.h"
2+
#include "AudioLibs/MaximilianDSP.h"
3+
#include "AudioLibs/AudioKit.h"
4+
#include "maximilian.h"
5+
#include <FS.h>
6+
#include <SD_MMC.h>
7+
8+
9+
// Define Arduino output
10+
AudioKitStream out;
11+
Maximilian maximilian(out);
12+
13+
// MAXIMILIAN
14+
maxiSample beats; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names.
15+
16+
void setup() {//some inits
17+
// setup logging
18+
Serial.begin(115200);
19+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
20+
21+
// setup audio output
22+
auto cfg = out.defaultConfig(TX_MODE);
23+
out.begin(cfg);
24+
maximilian.begin(cfg);
25+
26+
// setup SD to allow file operations
27+
if(!SD_MMC.begin()){
28+
Serial.println("Card Mount Failed");
29+
return;
30+
}
31+
32+
//load in your samples: beat2.wav is too big - but snare.wav will work
33+
//beats.load("/sdcard/Maximilian/beat2.wav");
34+
beats.load("/sdcard/Maximilian/snare.wav");
35+
//get info on samples if you like.
36+
Serial.println(beats.getSummary().c_str());
37+
38+
}
39+
40+
//this is where the magic happens. Very slow magic.
41+
void play(double *output) {
42+
//output[0]=beats.play();//just play the file. Looping is default for all play functions.
43+
output[0]=beats.playAtSpeed(0.68);//play the file with a speed setting. 1. is normal speed.
44+
//output[0]=beats.playAtSpeedBetweenPoints(0.5,0,13300);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
45+
//output[0]=beats.play4(0.5,0,13300);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
46+
47+
output[1]=output[0];
48+
}
49+
50+
// Arduino loop
51+
void loop() {
52+
maximilian.copy();
53+
}

examples/examples-maximilian/Unsupported/16-Replicant.ino renamed to examples/examples-maximilian/16-Replicant/16-Replicant.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
// WARNNG: This sketch is too big to fit on an ESP32 !
3+
24
//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
35

46
#include "AudioTools.h"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
#include "AudioTools.h"
3+
#include "AudioLibs/MaximilianDSP.h"
4+
#include <FS.h>
5+
#include <SD_MMC.h>
6+
7+
8+
// Arduino output
9+
I2SStream out;
10+
Maximilian maximilian(out);
11+
12+
// Maximilian
13+
maxiSample beats; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names.
14+
maxiDyn compressor; //this is a compressor
15+
float fout;
16+
17+
void setup() {//some inits
18+
// setup logging
19+
Serial.begin(115200);
20+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
21+
22+
// setup audio output
23+
auto cfg = out.defaultConfig(TX_MODE);
24+
out.begin(cfg);
25+
maximilian.begin(cfg);
26+
27+
// setup SD to allow file operations
28+
if(!SD_MMC.begin()){
29+
Serial.println("Card Mount Failed");
30+
return;
31+
}
32+
33+
//load in your samples. Provide the full path to a wav file: beat2 is too big
34+
//beats.load("/sdcard/Maximilian/beat2.wav");
35+
beats.load("/sdcard/Maximilian/snare.wav");
36+
Serial.println(beats.getSummary().c_str());//get info on samples if you like.
37+
38+
compressor.setAttack(100);
39+
compressor.setRelease(300);
40+
compressor.setThreshold(0.25);
41+
compressor.setRatio(5);
42+
43+
//you can set these any time you like.
44+
45+
}
46+
47+
void play(double *output) {//this is where the magic happens. Very slow magic.
48+
//here, we're just compressing the file in real-time
49+
//arguments are input,ratio,threshold,attack,release
50+
fout=compressor.compress(beats.play());
51+
52+
output[0]=fout;
53+
output[1]=fout;
54+
}
55+
56+
// Arduino loop
57+
void loop() {
58+
maximilian.copy();
59+
}

examples/examples-maximilian/Unsupported/18.DrumMachine.cpp renamed to examples/examples-maximilian/18-DrumMachine/18-DrumMachine.ino

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
#include "maximilian.h"
1+
#include "AudioTools.h"
2+
#include "AudioLibs/MaximilianDSP.h"
3+
#include <FS.h>
4+
#include <SD_MMC.h>
25

3-
maxiSample kick,snare; //we've got two sampleplayers
6+
// Arduino output
7+
I2SStream out;
8+
Maximilian maximilian(out);
49

10+
// Maximilian def
11+
maxiSample kick,snare; //we've got two sampleplayers
512
maxiOsc timer; //and a timer
613

714
int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}; //This is the sequence for the kick
@@ -12,11 +19,24 @@ int kicktrigger,snaretrigger;
1219
double sampleOut;
1320

1421
void setup() {//some inits
22+
// setup logging
23+
Serial.begin(115200);
24+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
25+
26+
// setup audio output
27+
auto cfg = out.defaultConfig(TX_MODE);
28+
out.begin(cfg);
29+
maximilian.begin(cfg);
30+
31+
// setup SD to allow file operations
32+
if(!SD_MMC.begin()){
33+
Serial.println("Card Mount Failed");
34+
return;
35+
}
1536

16-
//YOU HAVE TO PROVIDE THE SAMPLES....
17-
18-
kick.load("/Users/yourusername/somewhere/kick.wav");//load in your samples. Provide the full path to a wav file.
19-
snare.load("/Users/yourusername/somewhere/snare.wav");//load in your samples. Provide the full path to a wav file.
37+
//YOU HAVE TO PROVIDE THE SAMPLES....
38+
kick.load("/sdcard/Maximilian/kick.wav");//load in your samples. Provide the full path to a wav file.
39+
snare.load("/sdcard/Maximilian/snare.wav");
2040

2141

2242
printf("Summary:\n%s", kick.getSummary());//get info on samples if you like.

examples/examples-maximilian/Unsupported/20-FFT.ino renamed to examples/examples-maximilian/20-FFT/20-FFT.ino

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
// WARNNG: This sketch is too big to fit on an ESP32 !
3+
4+
25
#include "AudioTools.h"
36
#include "AudioLibs/MaximilianDSP.h"
47
#include "libs/maxim.h"
@@ -11,8 +14,6 @@ Maximilian maximilian(out);
1114
maxiOsc mySine, myPhasor; // This is the oscillator we will use to generate the test tone
1215
maxiFFT myFFT;
1316

14-
15-
1617
void setup() {
1718
// setup logging
1819
Serial.begin(115200);
@@ -28,21 +29,17 @@ void setup() {
2829

2930
}
3031

31-
void play(double *output) {
32-
33-
32+
void play(double *output) {
3433
float myOut=mySine.sinewave(myPhasor.phasorBetween(0.2,100,5000));
3534
//output[0] is the left output. output[1] is the right output
3635

3736
if (myFFT.process(myOut)) {
38-
3937
//if you want you can mess with FFT frame values in here
4038

4139
}
4240

4341
output[0]=myOut;//simple as that!
4442
output[1]=output[0];
45-
4643
}
4744

4845

examples/examples-maximilian/Unsupported/12.SamplePlayer.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/examples-maximilian/Unsupported/17.Compressor.cpp

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/AudioI2S/I2SConfig.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ class I2SConfig : public AudioBaseInfo {
4040
channels = DEFAULT_CHANNELS;
4141
sample_rate = DEFAULT_SAMPLE_RATE;
4242
bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
43-
this->rx_tx_mode = mode;
43+
rx_tx_mode = mode;
44+
switch(mode){
45+
case RX_MODE:
46+
pin_data = PIN_I2S_DATA_IN;
47+
break;
48+
case TX_MODE:
49+
pin_data = PIN_I2S_DATA_OUT;
50+
break;
51+
default:
52+
pin_data = PIN_I2S_DATA_OUT;
53+
pin_data_rx = PIN_I2S_DATA_IN;
54+
break;
55+
}
4456
pin_data = rx_tx_mode == TX_MODE ? PIN_I2S_DATA_OUT : PIN_I2S_DATA_IN;
4557
}
4658

@@ -50,7 +62,8 @@ class I2SConfig : public AudioBaseInfo {
5062
int port_no = 0; // processor dependent port
5163
int pin_ws = PIN_I2S_WS;
5264
int pin_bck = PIN_I2S_BCK;
53-
int pin_data = PIN_I2S_DATA_OUT;
65+
int pin_data; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
66+
int pin_data_rx; // rx pin for RXTX_MODE
5467
I2SFormat i2s_format = I2S_STD_FORMAT;
5568

5669
#ifdef ESP32
@@ -80,6 +93,9 @@ class I2SConfig : public AudioBaseInfo {
8093
LOGI("pin_bck: %d", pin_bck);
8194
LOGI("pin_ws: %d", pin_ws);
8295
LOGI("pin_data: %d", pin_data);
96+
if (rx_tx_mode==RXTX_MODE){
97+
LOGI("pin_data_rx: %d", pin_data_rx);
98+
}
8399
}
84100

85101
};

0 commit comments

Comments
 (0)