Skip to content

Commit d4b20ba

Browse files
sound working with audio-tools
1 parent 4101b1e commit d4b20ba

File tree

11 files changed

+9522
-2835
lines changed

11 files changed

+9522
-2835
lines changed

include/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "rtos_tasks.h"
66
#include "user_interface.h"
77
#include "sound.h"
8+
#include "serial_helpers.h"
89

910
lv_point_t g_touchCoordinate;
1011

include/serial_helpers.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef SERIAL_HELPERS_H
2+
#define SERIAL_HELPERS_H
3+
4+
#include <Arduino.h>
5+
#include <string>
6+
7+
using std::string;
8+
9+
#define DEFAULT_BAUD_RATE 115200
10+
11+
12+
namespace SerialHelpers
13+
{
14+
void setupSerial();
15+
void logHeapInfo(string context);
16+
}
17+
18+
#endif

include/sound.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#ifndef SOUND_H
22
#define SOUND_H
33

4-
#include "AudioGeneratorAAC.h"
5-
#include "AudioOutputI2S.h"
6-
#include "AudioFileSourcePROGMEM.h"
7-
8-
#include "sounds/sampleaac.h"
4+
#include "AudioTools.h"
95

106
#define I2S_DOUT 37
117
#define I2S_BCLK 36
128
#define I2S_LRC 35
139

10+
// How to create audio memory streams
11+
// https://github.com/pschatzmann/arduino-audio-tools/wiki/MemoryStream:-Converting-a-File-to-Flash-Memory
12+
// In Audacity:
13+
// - export WAV, Mono, 22050 Hz, Signed 16-bit PCM
14+
1415
namespace Sound
1516
{
1617
void setup();

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ build_flags =
2626
lib_deps =
2727
lovyan03/LovyanGFX@^1.1.5
2828
lvgl/lvgl@^8.3.7
29-
earlephilhower/ESP8266Audio@^1.9.7
29+
https://github.com/pschatzmann/arduino-audio-tools
3030
monitor_speed = 115200
3131
monitor_filters =
3232
esp32_exception_decoder

src/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
void setup()
44
{
5-
Serial.begin(115200);
6-
delay(1000); // allow serial to start
5+
SerialHelpers::setupSerial();
76

87
ESP_LOGI("", "setup");
8+
SerialHelpers::logHeapInfo("Startup");
99

10-
// setting up hardware systems
10+
// setting up graphics systems
1111
Graphics::lovyanGFX_init();
1212
Graphics::LVGL_init();
13+
SerialHelpers::logHeapInfo("after Graphics::setup()");
1314

1415
// setup support libraries
1516
UserInterface::setup();
17+
SerialHelpers::logHeapInfo("after UserInterface::setup()");
1618

1719
// setup audio play
1820
Sound::setup();
21+
SerialHelpers::logHeapInfo("after Sound::setup()");
1922

2023
// setup scheduled tasks
2124
RTOSTasks::setup();
25+
SerialHelpers::logHeapInfo("after RTOSTasks::setup()");
2226
}
2327

2428
void loop()

src/serial_helpers.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "serial_helpers.h"
2+
#include "user_interface.h"
3+
4+
char *stack_start;
5+
6+
bool isSerialAvailable = false;
7+
8+
void SerialHelpers::setupSerial()
9+
{
10+
Serial.begin(DEFAULT_BAUD_RATE);
11+
12+
while (!Serial)
13+
{
14+
; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
15+
}
16+
17+
delay(1000); // allow serial to start
18+
19+
ESP_LOGI("-----", "Program Start");
20+
21+
isSerialAvailable = true;
22+
}
23+
24+
void SerialHelpers::logHeapInfo(string context)
25+
{
26+
ESP_LOGI("HEAP/PSRAM", "%s: %d / %d", context.c_str(), ESP.getFreeHeap(), ESP.getFreePsram());
27+
}

src/sound.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
#include "sound.h"
22

3-
AudioFileSourcePROGMEM *in;
4-
AudioGeneratorAAC *aac;
5-
AudioOutputI2S *out;
3+
#include "sounds/beep1.h"
4+
#include "sounds/beep2.h"
5+
6+
uint8_t channels = 2;
7+
uint16_t sample_rate = 22050;
8+
9+
I2SConfig config;
10+
MemoryStream sound1(beep1_wav, sizeof(beep1_wav));
11+
MemoryStream sound2(beep2_wav, sizeof(beep2_wav));
12+
I2SStream out; // Output to I2S
13+
StreamCopy copier;
14+
15+
bool even = false;
616

717
void Sound::setup()
818
{
919
ESP_LOGI("", "Sound::setup()");
1020

11-
aac = new AudioGeneratorAAC();
12-
out = new AudioOutputI2S();
13-
out->SetPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
21+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
22+
23+
config = out.defaultConfig(TX_MODE);
24+
config.sample_rate = sample_rate;
25+
config.channels = channels;
26+
config.bits_per_sample = 16;
27+
config.pin_bck = I2S_BCLK;
28+
config.pin_data = I2S_DOUT;
29+
config.pin_ws = I2S_LRC;
30+
out.begin(config);
1431
}
1532

1633
void Sound::play()
1734
{
1835
ESP_LOGI("", "Sound::play()");
1936

20-
in = new AudioFileSourcePROGMEM(sampleaac, sizeof(sampleaac));
21-
aac->begin(in, out);
37+
if (even)
38+
{
39+
sound1.begin();
40+
copier.begin(out, sound1);
41+
}
42+
else
43+
{
44+
sound2.begin();
45+
copier.begin(out, sound2);
46+
}
47+
even = !even;
2248
}
2349

2450
void Sound::loop()
2551
{
26-
// ESP_LOGW("IsPlaying", "%d", aac->isRunning());
27-
28-
if (aac->isRunning())
29-
{
30-
aac->loop();
31-
}
52+
copier.copy();
3253
}

src/sounds/beep1.h

Lines changed: 5033 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)