Compare commits
8 Commits
c22af696cb
...
8bacf85af0
Author | SHA1 | Date |
---|---|---|
tobozo | 8bacf85af0 | |
ChuckMash | b837e7d36a | |
Infinity | 51a584c2b7 | |
tobozo | c46f3d3e12 | |
tobozo | 06a45d2757 | |
tobozo | 377862b0f8 | |
tobozo | c10efdd8ee | |
tobozo | 582ae8d486 |
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
AudioGeneratorMP3
|
||||
Wrap libmad MP3 library to play audio
|
||||
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -62,7 +62,7 @@ AudioGeneratorMP3::~AudioGeneratorMP3()
|
|||
free(synth);
|
||||
free(frame);
|
||||
free(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,7 +182,7 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
|
|||
output->SetChannels(synth->pcm.channels);
|
||||
lastChannels = synth->pcm.channels;
|
||||
}
|
||||
|
||||
|
||||
// If we're here, we have one decoded frame and sent 0 or more samples out
|
||||
if (samplePtr < synth->pcm.length) {
|
||||
sample[AudioOutput::LEFTCHANNEL ] = synth->pcm.samples[0][samplePtr];
|
||||
|
@ -190,7 +190,7 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
|
|||
samplePtr++;
|
||||
} else {
|
||||
samplePtr = 0;
|
||||
|
||||
|
||||
switch ( mad_synth_frame_onens(synth, frame, nsCount++) ) {
|
||||
case MAD_FLOW_STOP:
|
||||
case MAD_FLOW_BREAK: audioLogger->printf_P(PSTR("msf1ns failed\n"));
|
||||
|
@ -302,6 +302,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
|||
synth = reinterpret_cast<struct mad_synth *>(preallocateSynthSpace);
|
||||
}
|
||||
else {
|
||||
output->stop();
|
||||
audioLogger->printf_P("OOM error in MP3: Want %d/%d/%d/%d bytes, have %d/%d/%d/%d bytes preallocated.\n",
|
||||
preAllocBuffSize(), preAllocStreamSize(), preAllocFrameSize(), preAllocSynthSize(),
|
||||
preallocateSize, preallocateStreamSize, preallocateFrameSize, preallocateSynthSize);
|
||||
|
@ -319,6 +320,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
|||
p += preAllocSynthSize();
|
||||
int neededBytes = p - reinterpret_cast<uint8_t *>(preallocateSpace);
|
||||
if (neededBytes > preallocateSize) {
|
||||
output->stop();
|
||||
audioLogger->printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
|
||||
return false;
|
||||
}
|
||||
|
@ -336,17 +338,20 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
|||
stream = NULL;
|
||||
frame = NULL;
|
||||
synth = NULL;
|
||||
|
||||
output->stop();
|
||||
audioLogger->printf_P("OOM error in MP3\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mad_stream_init(stream);
|
||||
mad_frame_init(frame);
|
||||
mad_synth_init(synth);
|
||||
synth->pcm.length = 0;
|
||||
mad_stream_options(stream, 0); // TODO - add options support
|
||||
madInitted = true;
|
||||
|
||||
|
||||
running = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -413,4 +418,3 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -236,13 +236,13 @@ bool AudioGeneratorRTTTL::GetNextNote()
|
|||
ptr++;
|
||||
note++;
|
||||
}
|
||||
if (!ReadInt(&scale)) {
|
||||
scale = defaultOctave;
|
||||
}
|
||||
if ((ptr < len) && (buff[ptr] == '.')) {
|
||||
ptr++;
|
||||
dur += dur / 2;
|
||||
}
|
||||
if (!ReadInt(&scale)) {
|
||||
scale = defaultOctave;
|
||||
}
|
||||
// Eat any trailing whitespace and comma
|
||||
SkipWhitespace();
|
||||
if ((ptr < len) && (buff[ptr]==',')) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
AudioOutputI2S
|
||||
Base class for I2S interface port
|
||||
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -20,7 +20,40 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
|
||||
#include "driver/i2s.h"
|
||||
|
||||
#define I2S_FLAVOUR_1_x_x 0 // Initial I2S macros flavour (before esp-idf 4.2.0)
|
||||
#define I2S_FLAVOUR_2_x_x 1 // Revision 1 of I2S macros flavour
|
||||
|
||||
// handle I2S migration across SDK versions
|
||||
#ifdef ESP_ARDUINO_VERSION_VAL
|
||||
#if defined ESP_ARDUINO_VERSION && ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
// 2.0.0 and upstream esp-idf versions start at4.4
|
||||
#define I2S_FLAVOUR I2S_FLAVOUR_2_x_x
|
||||
#else
|
||||
// 1.0.6 and previous versions use esp-idf up to version 3.1
|
||||
#define I2S_FLAVOUR I2S_FLAVOUR_1_x_x
|
||||
#endif
|
||||
#else
|
||||
// custom build of Arduino, check esp-idf version instead
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
#define I2S_FLAVOUR I2S_FLAVOUR_2_x_x
|
||||
#else
|
||||
#define I2S_FLAVOUR I2S_FLAVOUR_1_x_x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if I2S_FLAVOUR==I2S_FLAVOUR_2_x_x
|
||||
#define _COMM_FORMAT_DEFAULT I2S_COMM_FORMAT_STAND_I2S
|
||||
#define _COMM_FORMAT_MSB I2S_COMM_FORMAT_STAND_MSB
|
||||
#define _COMM_FORMAT_LSB I2S_COMM_FORMAT_STAND_I2S
|
||||
#elif I2S_FLAVOUR==I2S_FLAVOUR_1_x_x
|
||||
#define _COMM_FORMAT_DEFAULT I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB
|
||||
#define _COMM_FORMAT_MSB I2S_COMM_FORMAT_I2S_MSB
|
||||
#define _COMM_FORMAT_LSB I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB
|
||||
#endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) || ARDUINO_ESP8266_MAJOR >= 3
|
||||
#include <I2S.h>
|
||||
#elif ARDUINO_ESP8266_MAJOR < 3
|
||||
|
@ -29,6 +62,9 @@
|
|||
#include "AudioOutputI2S.h"
|
||||
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
|
||||
|
||||
|
||||
AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int use_apll)
|
||||
{
|
||||
this->portNo = port;
|
||||
|
@ -212,7 +248,7 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
#if CONFIG_IDF_TARGET_ESP32
|
||||
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
else if (output_mode == INTERNAL_PDM)
|
||||
|
@ -220,34 +256,22 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
#if CONFIG_IDF_TARGET_ESP32
|
||||
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
i2s_comm_format_t comm_fmt;
|
||||
if (output_mode == INTERNAL_DAC)
|
||||
{
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
comm_fmt = (i2s_comm_format_t) I2S_COMM_FORMAT_STAND_MSB;
|
||||
#else
|
||||
comm_fmt = (i2s_comm_format_t) I2S_COMM_FORMAT_I2S_MSB;
|
||||
#endif
|
||||
comm_fmt = (i2s_comm_format_t) (_COMM_FORMAT_MSB);
|
||||
}
|
||||
else if (lsb_justified)
|
||||
{
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
comm_fmt = (i2s_comm_format_t) I2S_COMM_FORMAT_STAND_MSB;
|
||||
#else
|
||||
comm_fmt = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB);
|
||||
#endif
|
||||
comm_fmt = (i2s_comm_format_t) (_COMM_FORMAT_LSB);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
comm_fmt = (i2s_comm_format_t) (I2S_COMM_FORMAT_STAND_I2S);
|
||||
#else
|
||||
comm_fmt = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB);
|
||||
#endif
|
||||
comm_fmt = (i2s_comm_format_t) (_COMM_FORMAT_DEFAULT);
|
||||
}
|
||||
|
||||
i2s_config_t i2s_config_dac = {
|
||||
|
|
|
@ -247,6 +247,11 @@ class ESP8266SPIRAM {
|
|||
|
||||
#include <SPI.h>
|
||||
|
||||
#ifndef SPECIAL
|
||||
#define UNDEF_SPECIAL
|
||||
#define SPECIAL 0xf0
|
||||
#endif
|
||||
|
||||
class ESP8266SPIRAM {
|
||||
private:
|
||||
uint8_t csPin;
|
||||
|
@ -361,6 +366,10 @@ class ESP8266SPIRAM {
|
|||
|
||||
};
|
||||
|
||||
#ifdef UNDEF_SPECIAL
|
||||
#undef SPECIAL
|
||||
#endif
|
||||
|
||||
#endif // ESP32
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue