Porting for ESP-32 (#33)
* support ESP-32 * make compile with ESP-32/arduino platform * fixed: use libmad on ESP8266 as original
This commit is contained in:
1 parent
0c002cd014
commit
03aa2467f0
22 files changed
+199
-42
No files matched your search
@@ -39,7 +39,11 @@ After creation, you need to call the AudioGeneratorXXX::loop() routine from insi
|
||||
See the examples directory for some simple examples, but the following snippet can play an MP3 file over the simulated I2S DAC:
|
||||
````
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <AudioOutputNull.h>
|
||||
#include <AudioOutputI2SDAC.h>
|
||||
@@ -17,7 +22,7 @@ void setup()
|
||||
const char *soundfont = "1mgm.sf2";
|
||||
const char *midifile = "furelise.mid";
|
||||
|
||||
WiFi.forceSleepBegin();
|
||||
WiFi.mode(WIFI_OFF);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting up...\n");
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorMOD.h"
|
||||
#include "AudioOutputI2SDAC.h"
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
// enigma.mod sample from the mod archive: https://modarchive.org/index.php?request=view_by_moduleid&query=42146
|
||||
#include "enigma.h"
|
||||
@@ -13,7 +17,7 @@ AudioOutputI2SDAC *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.forceSleepBegin();
|
||||
WiFi.mode(WIFI_OFF); //WiFi.forceSleepBegin();
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
file = new AudioFileSourcePROGMEM( enigma_mod, sizeof(enigma_mod) );
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include "SPIFFS.h"
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, and include a SPIFFS of 512KB or greater.
|
||||
// Use the "Tools->ESP8266 Sketch Data Upload" menu to write the MP3 to SPIFFS
|
||||
// Use the "Tools->ESP8266/ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS
|
||||
// Then upload the sketch normally.
|
||||
|
||||
// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
||||
@@ -41,7 +46,7 @@ void MDCallback(void *cbData, const char *type, bool isUnicode, const char *stri
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.forceSleepBegin();
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
SPIFFS.begin();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorWAV.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
@@ -13,9 +18,10 @@ AudioOutputI2SNoDAC *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.forceSleepBegin();
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.printf("WAV start\n");
|
||||
file = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
wav = new AudioGeneratorWAV();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceSPIRAMBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "web.h"
|
||||
|
||||
void WebPrintError(WiFiClient *client, int code)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ESP8266Audio",
|
||||
"description": "Audio file format and I2S DAC library",
|
||||
"keywords": "ESP8266, MP3, WAV, MOD, FLAC, I2S, DAC, Delta-Sigma",
|
||||
"keywords": "ESP8266, ESP32, MP3, WAV, MOD, FLAC, I2S, DAC, Delta-Sigma",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Earle F. Philhower, III",
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ sentence=Audio file and I2S sound playing routines.
|
||||
paragraph=Decode compressed MP3, FLAC, Screamtracker MOD, and WAV and play on an I2S DAC or a software-driven delta-sigma DAC and 1-transistor amplifier.
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/earlephilhower/ESP8266Audio
|
||||
architectures=esp8266
|
||||
architectures=esp8266,esp32
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
#define _AUDIOFILESOURCEHTTPSTREAM_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
|
||||
#ifdef ESP32
|
||||
#include <HTTPClient.h>
|
||||
#else
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#endif
|
||||
#include "AudioFileSource.h"
|
||||
|
||||
class AudioFileSourceHTTPStream : public AudioFileSource
|
||||
|
||||
@@ -22,7 +22,11 @@
|
||||
#define _AUDIOFILESOURCEICYSTREAM_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#ifdef ESP32
|
||||
#include <HTTPClient.h>
|
||||
#else
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#endif
|
||||
|
||||
#include "AudioFileSourceHTTPStream.h"
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#ifdef ESP32
|
||||
#include "SPIFFS.h"
|
||||
#endif
|
||||
|
||||
AudioFileSourceSPIFFS::AudioFileSourceSPIFFS()
|
||||
{
|
||||
|
||||
@@ -231,6 +231,16 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
||||
|
||||
#undef stack
|
||||
extern "C" {
|
||||
#ifdef ESP32
|
||||
//TOTO - add ESP32 checks
|
||||
void stack(const char *s, const char *t, int i)
|
||||
{
|
||||
}
|
||||
int stackfree()
|
||||
{
|
||||
return 8192;
|
||||
}
|
||||
#else
|
||||
#include <cont.h>
|
||||
extern cont_t g_cont;
|
||||
|
||||
@@ -264,5 +274,6 @@ extern "C" {
|
||||
int freestack = 4 * (sp - g_cont.stack);
|
||||
return freestack;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -19,14 +19,48 @@
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <i2s.h>
|
||||
#ifdef ESP32
|
||||
#include "driver/i2s.h"
|
||||
#else
|
||||
#include <i2s.h>
|
||||
#endif
|
||||
#include "AudioOutputI2SDAC.h"
|
||||
|
||||
bool AudioOutputI2SDAC::i2sOn = false;
|
||||
|
||||
#ifdef ESP32
|
||||
//i2s configuration
|
||||
int i2s_num = 0; // i2s port number
|
||||
i2s_config_t i2s_config_dac = {
|
||||
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
|
||||
.sample_rate = 36000,
|
||||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
|
||||
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
|
||||
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
|
||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // high interrupt priority
|
||||
.dma_buf_count = 8,
|
||||
.dma_buf_len = 64 //Interrupt level 1
|
||||
};
|
||||
|
||||
i2s_pin_config_t pin_config_dac = {
|
||||
.bck_io_num = 26, //this is BCK pin
|
||||
.ws_io_num = 25, // this is LRCK pin
|
||||
.data_out_num = 22, // this is DATA output pin
|
||||
.data_in_num = -1 //Not used
|
||||
};
|
||||
#endif
|
||||
|
||||
AudioOutputI2SDAC::AudioOutputI2SDAC()
|
||||
{
|
||||
#ifdef ESP32
|
||||
if (!i2sOn) {
|
||||
//initialize i2s with configurations above
|
||||
i2s_driver_install((i2s_port_t)i2s_num, &i2s_config_dac, 0, NULL);
|
||||
i2s_set_pin((i2s_port_t)i2s_num, &pin_config_dac);
|
||||
}
|
||||
#else
|
||||
if (!i2sOn) i2s_begin();
|
||||
#endif
|
||||
i2sOn = true;
|
||||
mono = false;
|
||||
SetGain(1.0);
|
||||
@@ -34,7 +68,13 @@ AudioOutputI2SDAC::AudioOutputI2SDAC()
|
||||
|
||||
AudioOutputI2SDAC::~AudioOutputI2SDAC()
|
||||
{
|
||||
#ifdef ESP32
|
||||
if (!i2sOn) {
|
||||
i2s_driver_uninstall((i2s_port_t)i2s_num); //stop & destroy i2s driver
|
||||
}
|
||||
#else
|
||||
if (i2sOn) i2s_end();
|
||||
#endif
|
||||
i2sOn = false;
|
||||
}
|
||||
|
||||
@@ -42,7 +82,11 @@ bool AudioOutputI2SDAC::SetRate(int hz)
|
||||
{
|
||||
// TODO - have a list of allowable rates from constructor, check them
|
||||
this->hertz = hz;
|
||||
#ifdef ESP32
|
||||
i2s_set_sample_rates((i2s_port_t)i2s_num, hz);
|
||||
#else
|
||||
i2s_set_rate(hz);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,7 +126,11 @@ bool AudioOutputI2SDAC::ConsumeSample(int16_t sample[2])
|
||||
sample[LEFTCHANNEL] = sample[RIGHTCHANNEL] = (ttl>>1) & 0xffff;
|
||||
}
|
||||
uint32_t s32 = ((Amplify(sample[RIGHTCHANNEL]))<<16) | (Amplify(sample[LEFTCHANNEL]) & 0xffff);
|
||||
#ifdef ESP32
|
||||
return i2s_write_bytes((i2s_port_t)i2s_num, (const char *)&s32, sizeof(uint32_t), 100);
|
||||
#else
|
||||
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AudioOutputI2SDAC::stop()
|
||||
|
||||
@@ -19,14 +19,49 @@
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <i2s.h>
|
||||
#ifdef ESP32
|
||||
#include "driver/i2s.h"
|
||||
#else
|
||||
#include <i2s.h>
|
||||
#endif
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
i2s_config_t i2s_config = {
|
||||
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
|
||||
.sample_rate = 44100,
|
||||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, /* the DAC module will only take the 8bits from MSB */
|
||||
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
|
||||
.communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_I2S_MSB,
|
||||
.intr_alloc_flags = 0, // default interrupt priority
|
||||
.dma_buf_count = 8,
|
||||
.dma_buf_len = 64,
|
||||
.use_apll = 0
|
||||
};
|
||||
|
||||
i2s_pin_config_t pin_config = {
|
||||
.bck_io_num = 26, //this is BCK pin
|
||||
.ws_io_num = 25, // this is LRCK pin
|
||||
.data_out_num = 22, // this is DATA output pin
|
||||
.data_in_num = -1 //Not used
|
||||
};
|
||||
#endif
|
||||
|
||||
bool AudioOutputI2SNoDAC::i2sOn = false;
|
||||
|
||||
AudioOutputI2SNoDAC::AudioOutputI2SNoDAC()
|
||||
{
|
||||
#ifdef ESP32
|
||||
if (!i2sOn) {
|
||||
//initialize i2s with configurations above
|
||||
|
||||
i2s_driver_install((i2s_port_t)0, &i2s_config, 0, NULL);
|
||||
i2s_set_pin((i2s_port_t)0, &pin_config);
|
||||
}
|
||||
#else
|
||||
if (!i2sOn) i2s_begin();
|
||||
#endif
|
||||
i2sOn = true;
|
||||
hertz = 44100;
|
||||
oversample = 32;
|
||||
@@ -37,7 +72,13 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC()
|
||||
|
||||
AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC()
|
||||
{
|
||||
#ifdef ESP32
|
||||
if (!i2sOn) {
|
||||
i2s_driver_uninstall((i2s_port_t)0); //stop & destroy i2s driver
|
||||
}
|
||||
#else
|
||||
if (i2sOn) i2s_end();
|
||||
#endif
|
||||
i2sOn = false;
|
||||
}
|
||||
|
||||
@@ -45,7 +86,11 @@ bool AudioOutputI2SNoDAC::SetRate(int hz)
|
||||
{
|
||||
// TODO - what is the max hz we can request on I2S?
|
||||
this->hertz = hz;
|
||||
#ifdef ESP32
|
||||
i2s_set_sample_rates((i2s_port_t)0, hz * (oversample / 32));
|
||||
#else
|
||||
i2s_set_rate(hz * (oversample / 32));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,6 +155,19 @@ void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[4])
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
/* write sample data to I2S */
|
||||
int i2s_write_sample_nb(uint8_t sample){
|
||||
return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(uint8_t), 100);
|
||||
}
|
||||
|
||||
// how to do this blocking??
|
||||
int i2s_write_sample(uint8_t sample){
|
||||
return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(uint8_t), 100);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
|
||||
{
|
||||
MakeSampleStereo16( sample );
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FS.h>
|
||||
#ifdef ESP32
|
||||
#include "SPIFFS.h"
|
||||
#endif
|
||||
|
||||
#include "AudioOutputSPIFFSWAV.h"
|
||||
|
||||
|
||||
@@ -532,8 +532,8 @@ static FLAC__StreamDecoderInitStatus init_FILE_internal_(
|
||||
* must assign the FILE pointer before any further error can occur in
|
||||
* this routine.
|
||||
*/
|
||||
if(file == stdin)
|
||||
file = get_binary_stdin_(); /* just to be safe */
|
||||
// if(file == stdin)
|
||||
// file = get_binary_stdin_(); /* just to be safe */
|
||||
|
||||
decoder->private_->file = file;
|
||||
|
||||
@@ -1274,26 +1274,7 @@ void set_defaults_(FLAC__StreamDecoder *decoder)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* This will forcibly set stdin to binary mode (for OSes that require it)
|
||||
*/
|
||||
FILE *get_binary_stdin_(void)
|
||||
{
|
||||
/* if something breaks here it is probably due to the presence or
|
||||
* absence of an underscore before the identifiers 'setmode',
|
||||
* 'fileno', and/or 'O_BINARY'; check your system header files.
|
||||
*/
|
||||
#if defined _MSC_VER || defined __MINGW32__
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
#elif defined __CYGWIN__
|
||||
/* almost certainly not needed for any modern Cygwin, but let's be safe... */
|
||||
setmode(_fileno(stdin), _O_BINARY);
|
||||
#elif defined __EMX__
|
||||
setmode(fileno(stdin), O_BINARY);
|
||||
#endif
|
||||
|
||||
return stdin;
|
||||
}
|
||||
|
||||
FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <stdint.h>
|
||||
|
||||
# ifdef HAVE_ASSERT_H
|
||||
# include <assert.h>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#pragma GCC optimize ("O3")
|
||||
|
||||
#include <stddef.h>
|
||||
#include <pgmspace.h>
|
||||
# include "config.h"
|
||||
|
||||
|
||||
@@ -1257,7 +1257,11 @@ static void tsf_voice_render(tsf* f, struct tsf_voice* v, float* outputBuffer, i
|
||||
|
||||
|
||||
void DumpF32P32(char *name, long long x) {
|
||||
#ifdef ESP32
|
||||
printf("%s = %08x.%08x\n", name, (int)((x>>32)&0xffffffff), (int)(x&0xffffffff));
|
||||
#else
|
||||
printf("%s = %08x.%08x\n", name, (int32)((x>>32)&0xffffffff), (int32)(x&0xffffffff));
|
||||
#endif
|
||||
}
|
||||
static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuffer, int numSamples)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user