Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10d929ac01 | ||
|
|
74fc1f09bb | ||
|
|
05f2fb0045 | ||
|
|
70defdb6c6 | ||
|
|
3450935a2a | ||
|
|
94c68ecbaa | ||
|
|
cd98586a2c | ||
|
|
89c60ad19b |
No files matched your search
@@ -26,7 +26,8 @@ If you have a neat use for this library, [I'd love to hear about it](mailto:earl
|
||||
* A neat MQTT-driven ESP8266 light-and-sound device (alarm? toy? who can say!) was built by @CosmicMac, available at https://github.com/CosmicMac/ESParkle
|
||||
* A very interesting "linear clock" with a stepper motor, NTP time keeping, and configurable recorded chimes with schematics, 3D printer plans, and source code, is now available https://janderogee.com/projects/linear_clock/linear_clock.htm
|
||||
* Source and instructions for a gorgeous wooden MP3-playing clock, FM radio and a walkie-talkie using the ESP8266 and AVR microcontrollers is available https://github.com/zduka/mp3-player
|
||||
|
||||
* Automate your negativity with a speaking, automatic rejection project at https://www.hackster.io/abouhatab/getting-rejected-by-wemos-d1-mini-f8be9c
|
||||
|
||||
## Prerequisites
|
||||
First, make sure you are running the 2.6.3/later or GIT head version of the Arduino libraries for ESP8266, or the latest ESP32 SDK from Espressif.
|
||||
|
||||
@@ -51,6 +52,23 @@ Create an AudioInputXXX source pointing to your input file, an AudioOutputXXX si
|
||||
|
||||
After creation, you need to call the AudioGeneratorXXX::loop() routine from inside your own main loop() one or more times. This will automatically read as much of the file as needed and fill up the I2S buffers and immediately return. Since this is not interrupt driven, if you have large delay()s in your code, you may end up with hiccups in playback. Either break large delays into very small ones with calls to AudioGenerator::loop(), or reduce the sampling rate to require fewer samples per second.
|
||||
|
||||
## ESP32 and Platform.IO
|
||||
|
||||
It seems that Espressif discontinued official Platform.IO integration of their Arduino several
|
||||
releases ago. The `platformio/framework-arduinoespressif32` package available is much older
|
||||
than the latest Espressif Arduino core and at IDF 4.x. This library needs IDF 5.x and the new
|
||||
I2S APIs to function, so if you attempt to build using ``platformio/framework-arduinoespressif32``
|
||||
you will get errors like, `cannot open source file "driver/i2s_std.h"`.
|
||||
|
||||
The solution is to move to @Jason2866's community
|
||||
[pioarduino](https://github.com/pioarduino/platform-espressif32) core which is built from the
|
||||
current Espressif Arduino with IDF 5.x. Simply change `platform` in your `platform.ini` as below:
|
||||
|
||||
```ini
|
||||
; Pioarduino Arduino-ESP32 Latest
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
|
||||
```
|
||||
|
||||
## Example
|
||||
See the examples directory for some simple examples, but the following snippet can play an MP3 file over the simulated I2S DAC:
|
||||
```cpp
|
||||
|
||||
@@ -31,7 +31,7 @@ AudioGeneratorAAC::AudioGeneratorAAC() {
|
||||
output = NULL;
|
||||
|
||||
buff = (uint8_t*)malloc(buffLen);
|
||||
outSample = (int16_t*)malloc(1024 * 2 * sizeof(uint16_t));
|
||||
outSample = (int16_t*)malloc(outSampleLen * sizeof(uint16_t));
|
||||
if (!buff || !outSample) {
|
||||
audioLogger->printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
Serial.flush();
|
||||
@@ -63,7 +63,7 @@ AudioGeneratorAAC::AudioGeneratorAAC(void *preallocateData, int preallocateSz) {
|
||||
buff = (uint8_t*) p;
|
||||
p += (buffLen + 7) & ~7;
|
||||
outSample = (int16_t*) p;
|
||||
p += (1024 * 2 * sizeof(int16_t) + 7) & ~7;
|
||||
p += (outSampleLen * sizeof(int16_t) + 7) & ~7;
|
||||
int used = p - (uint8_t*)preallocateSpace;
|
||||
int availSpace = preallocateSize - used;
|
||||
if (availSpace < 0) {
|
||||
@@ -212,7 +212,7 @@ bool AudioGeneratorAAC::begin(AudioFileSource *source, AudioOutput *output) {
|
||||
output->begin();
|
||||
|
||||
memset(buff, 0, buffLen);
|
||||
memset(outSample, 0, 1024 * 2 * sizeof(int16_t));
|
||||
memset(outSample, 0, outSampleLen * sizeof(int16_t));
|
||||
|
||||
|
||||
running = true;
|
||||
|
||||
@@ -49,7 +49,12 @@ protected:
|
||||
bool FillBufferWithValidFrame(); // Read until we get a valid syncword and min(feof, 2048) butes in the buffer
|
||||
|
||||
// Output buffering
|
||||
int16_t *outSample; //[1024 * 2]; // Interleaved L/R
|
||||
#ifdef ESP8266
|
||||
const int outSampleLen = 1024 * 2; // SBR disabled
|
||||
#else
|
||||
const int outSampleLen = 2048 * 2; // SBR enabled
|
||||
#endif
|
||||
int16_t *outSample; //[1024 * 2] or [2048 * 2]; // Interleaved L/R
|
||||
int16_t validSamples;
|
||||
int16_t curSample;
|
||||
|
||||
|
||||
@@ -87,22 +87,21 @@ bool AudioGeneratorWAV::loop() {
|
||||
// Try and stuff the buffer one sample at a time
|
||||
do {
|
||||
if (bitsPerSample == 8) {
|
||||
uint8_t l, r;
|
||||
if (!GetBufferedData(1, &l)) {
|
||||
uint8_t u8s; // For read u8 sample
|
||||
if (!GetBufferedData(1, &u8s)) {
|
||||
stop();
|
||||
}
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::LEFTCHANNEL] = ((int16_t)u8s - 128) << 8;
|
||||
if (channels == 2) {
|
||||
if (!GetBufferedData(1, &r)) {
|
||||
if (!GetBufferedData(1, &u8s)) {
|
||||
stop();
|
||||
}
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = ((int16_t)u8s - 128) << 8;
|
||||
} else {
|
||||
r = 0;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = lastSample[AudioOutput::LEFTCHANNEL];
|
||||
}
|
||||
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::LEFTCHANNEL] = (((int16_t)(lastSample[AudioOutput::LEFTCHANNEL] & 0xff)) - 128) << 8;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = (((int16_t)(lastSample[AudioOutput::RIGHTCHANNEL] & 0xff)) - 128) << 8;
|
||||
|
||||
} else if (bitsPerSample == 16) {
|
||||
if (!GetBufferedData(2, &lastSample[AudioOutput::LEFTCHANNEL])) {
|
||||
stop();
|
||||
@@ -112,7 +111,7 @@ bool AudioGeneratorWAV::loop() {
|
||||
stop();
|
||||
}
|
||||
} else {
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = 0;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = lastSample[AudioOutput::LEFTCHANNEL];
|
||||
}
|
||||
}
|
||||
} while (running && output->ConsumeSample(lastSample));
|
||||
|
||||
@@ -61,7 +61,7 @@ bool AudioOutputPDM::begin() {
|
||||
assert(ESP_OK == i2s_new_channel(&chan_cfg, &_tx_handle, nullptr));
|
||||
|
||||
i2s_pdm_tx_config_t pdm_cfg = {
|
||||
.clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(AdjustI2SRate(hertz)),
|
||||
.clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG((uint32_t)AdjustI2SRate(hertz)),
|
||||
.slot_cfg = I2S_PDM_TX_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
|
||||
.gpio_cfg = {
|
||||
.clk = I2S_GPIO_UNUSED,
|
||||
|
||||
@@ -148,6 +148,7 @@ bool AudioOutputSPDIF::begin() {
|
||||
std_cfg.clk_cfg.clk_src = i2s_clock_src_t::I2S_CLK_SRC_APLL;
|
||||
#endif
|
||||
assert(ESP_OK == i2s_channel_init_std_mode(_tx_handle, &std_cfg));
|
||||
assert(ESP_OK == i2s_channel_enable(_tx_handle));
|
||||
#else
|
||||
if (!I2SDriver.begin(_buffers, _bufferWords)) {
|
||||
audioLogger->println(F("ERROR: Unable to start I2S driver"));
|
||||
|
||||
@@ -276,6 +276,7 @@ int PNS(AACDecInfo *aacDecInfo, int ch) {
|
||||
const /*short*/ int *sfbTab;
|
||||
unsigned char *sfbCodeBook;
|
||||
short *scaleFactors;
|
||||
(void) scaleFactors;
|
||||
int msMaskOffset, checkCorr, genNew;
|
||||
unsigned char msMask;
|
||||
unsigned char *msMaskPtr;
|
||||
|
||||
+2
-2
@@ -873,7 +873,7 @@ enum mad_flow mad_synth_frame(struct mad_synth *synth, struct mad_frame const *f
|
||||
//void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
|
||||
{
|
||||
unsigned int nch, ns;
|
||||
enum mad_flow(*synth_frame)(struct mad_synth *, struct mad_frame const *, unsigned int, unsigned int, unsigned int, enum mad_flow(*output_func)(), void *);
|
||||
enum mad_flow(*synth_frame)(struct mad_synth *, struct mad_frame const *, unsigned int, unsigned int, unsigned int, enum mad_flow(*output_func)(void *, const struct mad_header *, struct mad_pcm *), void *);
|
||||
|
||||
nch = MAD_NCHANNELS(&frame->header);
|
||||
ns = MAD_NSBSAMPLES(&frame->header);
|
||||
@@ -902,7 +902,7 @@ enum mad_flow mad_synth_frame(struct mad_synth *synth, struct mad_frame const *f
|
||||
// Up to caller to increment synth->phase, only call proper # of ns
|
||||
enum mad_flow mad_synth_frame_onens(struct mad_synth *synth, struct mad_frame const *frame, unsigned int ns) {
|
||||
unsigned int nch; //, ns;
|
||||
enum mad_flow(*synth_frame)(struct mad_synth *, struct mad_frame const *, unsigned int, unsigned int, unsigned int, enum mad_flow(*output_func)(), void *);
|
||||
enum mad_flow(*synth_frame)(struct mad_synth *, struct mad_frame const *, unsigned int, unsigned int, unsigned int, enum mad_flow(*output_func)(void *, const struct mad_header *, struct mad_pcm *), void *);
|
||||
|
||||
nch = MAD_NCHANNELS(&frame->header);
|
||||
// ns = MAD_NSBSAMPLES(&frame->header);
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ while [ $(echo $sketches | wc -w) -gt 0 ]; do
|
||||
echo "::group::Compiling $(basename $sketch) for $fqbn into $outdir"
|
||||
if [ 0"$werror" -gt 0 ]; then
|
||||
./arduino-cli compile -b "$fqbn" -v --warnings all \
|
||||
--build-property "compiler.c.extra_flags=-Wall -Wextra -Werror -Wno-ignored-qualifiers" \
|
||||
--build-property "compiler.cpp.extra_flags=-Wall -Wextra -Werror -Wno-ignored-qualifiers -Wno-overloaded-virtual" \
|
||||
--build-property "compiler.c.extra_flags=-Wall -Wextra -Werror -Wno-ignored-qualifiers -Wno-unused-parameter" \
|
||||
--build-property "compiler.cpp.extra_flags=-Wall -Wextra -Werror -Wno-ignored-qualifiers -Wno-overloaded-virtual -Wno-unused-parameter" \
|
||||
--build-path "$outdir" "$sketch" || exit 255
|
||||
else
|
||||
./arduino-cli compile -b "$fqbn" -v --warnings all --build-path "$outdir" "$sketch" || exit 255
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ int main(int argc, char **argv)
|
||||
AudioFileSourceSTDIO *in = new AudioFileSourceSTDIO(AAC);
|
||||
AudioOutputSTDIO *out = new AudioOutputSTDIO();
|
||||
out->SetFilename("out.aac.wav");
|
||||
void *space = malloc(28000+60000);
|
||||
AudioGeneratorAAC *aac = new AudioGeneratorAAC(space, 28000+60000);
|
||||
void *space = malloc(28000+60000+2048);
|
||||
AudioGeneratorAAC *aac = new AudioGeneratorAAC(space, 28000+60000+2048);
|
||||
|
||||
aac->begin(in, out);
|
||||
while (aac->loop()) { /*noop*/ }
|
||||
|
||||
Reference in new issue
Block a user