diff --git a/keywords.txt b/keywords.txt
index 251f431..75b1113 100644
--- a/keywords.txt
+++ b/keywords.txt
@@ -22,6 +22,7 @@ AudioGeneratorWAV KEYWORD1
AudioOutput KEYWORD1
AudioOutputI2S KEYWORD1
AudioOutputI2SNoDAC KEYWORD1
+AudioOutputI2SClass KEYWORD1
AudioOutputNull KEYWORD1
AudioOutputBuffer KEYWORD1
AudioOutputSerialWAV KEYWORD1
diff --git a/library.json b/library.json
index c351e32..c6c2e35 100644
--- a/library.json
+++ b/library.json
@@ -1,6 +1,6 @@
{
"name": "ESP8266Audio",
- "description": "Audio file format and I2S DAC library",
+ "description": "Audio file format and I2S DAC library for ESP8266, ESP32, and Raspberry Pi Pico RP2040",
"keywords": "ESP8266, ESP32, MP3, AAC, WAV, MOD, FLAC, RTTTL, MIDI, I2S, DAC, Delta-Sigma, TTS",
"authors": [
{
@@ -14,14 +14,8 @@
"type": "git",
"url": "https://github.com/earlephilhower/ESP8266Audio"
},
- "version": "1.8.1",
+ "version": "1.9.0",
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
- "dependencies": {
- "SPI": "1.0",
- "SPIFFS": "1.0",
- "HTTPClient": "1.0",
- "WiFiClientSecure": "1.0"
- },
"frameworks": "Arduino",
"examples": [
"examples/*/*.ino"
diff --git a/library.properties b/library.properties
index 72da8a8..0560012 100644
--- a/library.properties
+++ b/library.properties
@@ -1,9 +1,9 @@
name=ESP8266Audio
-version=1.8.1
+version=1.9.0
author=Earle F. Philhower, III
maintainer=Earle F. Philhower, III
-sentence=Audio file and I2S sound playing routines.
-paragraph=Decode compressed MP3, AAC, FLAC, Screamtracker MOD, MIDI, RTTL, TI Talkie, and WAV and play on an I2S DAC or a software-driven delta-sigma DAC and 1-transistor amplifier.
+sentence=Audio file and I2S sound playing routines for ESP8266, ESP32, and Raspberry Pi Pico RP2040
+.paragraph=Decode compressed MP3, AAC, FLAC, Screamtracker MOD, MIDI, RTTL, TI Talkie, 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,esp32
+architectures=esp8266,esp32,rp2040
diff --git a/src/AudioFileSourceHTTPStream.cpp b/src/AudioFileSourceHTTPStream.cpp
index 2917fbc..c5d0b83 100644
--- a/src/AudioFileSourceHTTPStream.cpp
+++ b/src/AudioFileSourceHTTPStream.cpp
@@ -18,6 +18,8 @@
along with this program. If not, see .
*/
+#if defined(ESP32) || defined(ESP8266)
+
#include "AudioFileSourceHTTPStream.h"
AudioFileSourceHTTPStream::AudioFileSourceHTTPStream()
@@ -152,3 +154,5 @@ uint32_t AudioFileSourceHTTPStream::getPos()
{
return pos;
}
+
+#endif
diff --git a/src/AudioFileSourceHTTPStream.h b/src/AudioFileSourceHTTPStream.h
index bb5014d..34e5466 100644
--- a/src/AudioFileSourceHTTPStream.h
+++ b/src/AudioFileSourceHTTPStream.h
@@ -18,8 +18,8 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOFILESOURCEHTTPSTREAM_H
-#define _AUDIOFILESOURCEHTTPSTREAM_H
+#if defined(ESP32) || defined(ESP8266)
+#pragma once
#include
#ifdef ESP32
diff --git a/src/AudioFileSourceICYStream.cpp b/src/AudioFileSourceICYStream.cpp
index 522db40..63c84f3 100644
--- a/src/AudioFileSourceICYStream.cpp
+++ b/src/AudioFileSourceICYStream.cpp
@@ -17,6 +17,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+
+#if defined(ESP32) || defined(ESP8266)
+
#define _GNU_SOURCE
#include "AudioFileSourceICYStream.h"
@@ -215,3 +218,5 @@ retry:
icyByteCount += ret;
return read;
}
+
+#endif
diff --git a/src/AudioFileSourceICYStream.h b/src/AudioFileSourceICYStream.h
index 479c16b..97688a5 100644
--- a/src/AudioFileSourceICYStream.h
+++ b/src/AudioFileSourceICYStream.h
@@ -18,8 +18,8 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOFILESOURCEICYSTREAM_H
-#define _AUDIOFILESOURCEICYSTREAM_H
+#if defined(ESP32) || defined(ESP8266)
+#pragma once
#include
#ifdef ESP32
@@ -45,6 +45,4 @@ class AudioFileSourceICYStream : public AudioFileSourceHTTPStream
int icyByteCount;
};
-
#endif
-
diff --git a/src/AudioFileSourceSPIRAMBuffer.cpp b/src/AudioFileSourceSPIRAMBuffer.cpp
index fafadce..2c9eb3b 100644
--- a/src/AudioFileSourceSPIRAMBuffer.cpp
+++ b/src/AudioFileSourceSPIRAMBuffer.cpp
@@ -22,6 +22,8 @@
along with this program. If not, see .
*/
+#if defined(ESP32) || defined(ESP8266)
+
#include
#include "AudioFileSourceSPIRAMBuffer.h"
@@ -165,3 +167,5 @@ bool AudioFileSourceSPIRAMBuffer::loop()
}
return true;
}
+
+#endif
diff --git a/src/AudioFileSourceSPIRAMBuffer.h b/src/AudioFileSourceSPIRAMBuffer.h
index 19d915f..d8c0554 100644
--- a/src/AudioFileSourceSPIRAMBuffer.h
+++ b/src/AudioFileSourceSPIRAMBuffer.h
@@ -19,8 +19,8 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOFILESOURCESPIRAMBUFFER_H
-#define _AUDIOFILESOURCESPIRAMBUFFER_H
+#if defined(ESP32) || defined(ESP8266)
+#pragma once
#include "AudioFileSource.h"
#include
diff --git a/src/AudioGeneratorFLAC.cpp b/src/AudioGeneratorFLAC.cpp
index 1af00ce..bd6e801 100644
--- a/src/AudioGeneratorFLAC.cpp
+++ b/src/AudioGeneratorFLAC.cpp
@@ -177,9 +177,9 @@ FLAC__StreamDecoderWriteStatus AudioGeneratorFLAC::write_cb(const FLAC__StreamDe
// Hackish warning here. FLAC sends the buffer but doesn't free it until the next call to decode_frame, so we stash
// the pointers here and use it in our loop() instead of memcpy()'ing into yet another buffer.
buffLen = frame->header.blocksize;
- buff[0] = buffer[0];
- if (frame->header.channels>1) buff[1] = buffer[1];
- else buff[1] = buffer[0];
+ buff[0] = (const int *)buffer[0];
+ if (frame->header.channels>1) buff[1] = (const int *)buffer[1];
+ else buff[1] = (const int *)buffer[0];
buffPtr = 0;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
diff --git a/src/AudioOutputI2S.cpp b/src/AudioOutputI2S.cpp
index 6d0762d..496c2d1 100644
--- a/src/AudioOutputI2S.cpp
+++ b/src/AudioOutputI2S.cpp
@@ -21,11 +21,14 @@
#include
#ifdef ESP32
#include "driver/i2s.h"
-#else
+#elif defined(ESP8266)
#include
+#elif defined(ARDUINO_ARCH_RP2040)
+ #include
#endif
#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;
@@ -48,31 +51,6 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
SetGain(1.0);
}
-AudioOutputI2S::~AudioOutputI2S()
-{
- #ifdef ESP32
- if (i2sOn) {
- audioLogger->printf("UNINSTALL I2S\n");
- i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
- }
- #else
- if (i2sOn)
- i2s_end();
- #endif
- i2sOn = false;
-}
-
-bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
-{
- bclkPin = bclk;
- wclkPin = wclk;
- doutPin = dout;
- if (i2sOn)
- return SetPinout();
-
- return true;
-}
-
bool AudioOutputI2S::SetPinout()
{
#ifdef ESP32
@@ -94,6 +72,45 @@ bool AudioOutputI2S::SetPinout()
#endif
}
+bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
+{
+ bclkPin = bclk;
+ wclkPin = wclk;
+ doutPin = dout;
+ if (i2sOn)
+ return SetPinout();
+
+ return true;
+}
+#elif defined(ARDUINO_ARCH_RP2040)
+AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) {
+ i2sOn = false;
+ mono = false;
+ bps = 16;
+ channels = 2;
+ hertz = sampleRate;
+ bclkPin = sck;
+ doutPin = data;
+ SetGain(1.0);
+}
+#endif
+
+AudioOutputI2S::~AudioOutputI2S()
+{
+ #ifdef ESP32
+ if (i2sOn) {
+ audioLogger->printf("UNINSTALL I2S\n");
+ i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
+ }
+ #elif defined(ESP8266)
+ if (i2sOn)
+ i2s_end();
+ #elif defined(ARDUINO_ARCH_RP2040)
+ stop();
+ #endif
+ i2sOn = false;
+}
+
bool AudioOutputI2S::SetRate(int hz)
{
// TODO - have a list of allowable rates from constructor, check them
@@ -102,8 +119,10 @@ bool AudioOutputI2S::SetRate(int hz)
{
#ifdef ESP32
i2s_set_sample_rates((i2s_port_t)portNo, AdjustI2SRate(hz));
- #else
+ #elif defined(ESP8266)
i2s_set_rate(AdjustI2SRate(hz));
+ #elif defined(ARDUINO_ARCH_RP2040)
+ I2S.setFrequency(hz);
#endif
}
return true;
@@ -189,7 +208,7 @@ bool AudioOutputI2S::begin(bool txDAC)
}
i2s_zero_dma_buffer((i2s_port_t)portNo);
}
- #else
+ #elif defined(ESP8266)
(void)dma_buf_count;
(void)use_apll;
if (!i2sOn)
@@ -209,6 +228,11 @@ bool AudioOutputI2S::begin(bool txDAC)
}
#endif
}
+ #elif defined(ARDUINO_ARCH_RP2040)
+ (void)txDAC;
+ if (!i2sOn) {
+ I2S.begin(hertz, bclkPin, doutPin);
+ }
#endif
i2sOn = true;
SetRate(hertz); // Default
@@ -246,9 +270,11 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
}
return i2s_write_bytes((i2s_port_t)portNo, (const char *)&s32, sizeof(uint32_t), 0);
- #else
+ #elif defined(ESP8266)
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
+ #elif defined(ARDUINO_ARCH_RP2040)
+ return !!I2S.write((void*)ms, 4);
#endif
}
@@ -265,6 +291,8 @@ void AudioOutputI2S::flush()
delay(10);
}
}
+ #elif defined(ARDUINO_ARCH_RP2040)
+ I2S.flush();
#endif
}
@@ -275,6 +303,9 @@ bool AudioOutputI2S::stop()
#ifdef ESP32
i2s_zero_dma_buffer((i2s_port_t)portNo);
+ #elif defined(ARDUINO_ARCH_RP2040)
+ I2S.end();
#endif
+ i2sOn = false;
return true;
}
diff --git a/src/AudioOutputI2S.h b/src/AudioOutputI2S.h
index f221d2e..90370dc 100644
--- a/src/AudioOutputI2S.h
+++ b/src/AudioOutputI2S.h
@@ -18,17 +18,22 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOOUTPUTI2S_H
-#define _AUDIOOUTPUTI2S_H
+#pragma once
#include "AudioOutput.h"
class AudioOutputI2S : public AudioOutput
{
public:
+#if defined(ESP32) || defined(ESP8266)
AudioOutputI2S(int port=0, int output_mode=EXTERNAL_I2S, int dma_buf_count = 8, int use_apll=APLL_DISABLE);
- virtual ~AudioOutputI2S() override;
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
+ enum : int { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
+ enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
+#elif defined(ARDUINO_ARCH_RP2040)
+ AudioOutputI2S(long sampleRate = 44100, pin_size_t sck = 26, pin_size_t data = 28);
+#endif
+ virtual ~AudioOutputI2S() override;
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
virtual bool SetChannels(int channels) override;
@@ -37,12 +42,9 @@ class AudioOutputI2S : public AudioOutput
virtual void flush() override;
virtual bool stop() override;
- bool begin (bool txDAC);
+ bool begin(bool txDAC);
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
- enum : int { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
- enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
-
protected:
bool SetPinout();
virtual int AdjustI2SRate(int hz) { return hz; }
@@ -60,6 +62,3 @@ class AudioOutputI2S : public AudioOutput
uint8_t wclkPin;
uint8_t doutPin;
};
-
-#endif
-
diff --git a/src/AudioOutputI2SNoDAC.cpp b/src/AudioOutputI2SNoDAC.cpp
index cb36e13..b8040e3 100644
--- a/src/AudioOutputI2SNoDAC.cpp
+++ b/src/AudioOutputI2SNoDAC.cpp
@@ -21,8 +21,10 @@
#include
#ifdef ESP32
#include "driver/i2s.h"
-#else
+#elif defined(ESP8266)
#include
+#elif defined(ARDUINO_ARCH_RP2040)
+ #include
#endif
#include "AudioOutputI2SNoDAC.h"
@@ -32,7 +34,7 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
SetOversampling(32);
lastSamp = 0;
cumErr = 0;
-#ifndef ESP32
+#ifdef ESP8266
WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, orig_bck);
WRITE_PERI_REG(PERIPHS_IO_MUX_GPIO2_U, orig_ws);
#endif
@@ -97,12 +99,17 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
#ifdef ESP32
if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
return false;
-#else
+#elif defined(ESP8266)
if (!i2s_write_sample_nb(dsBuff[0])) return false; // No room at the inn
// At this point we've sent in first of possibly 8 32-bits, need to send
// remaining ones even if they block.
for (int i = 32; i < oversample; i+=32)
i2s_write_sample( dsBuff[i / 32]);
+#elif defined(ARDUINO_ARCH_RP2040)
+ int16_t *p = (int16_t *) dsBuff;
+ for (int i = 0; i < oversample / 16; i++) {
+ I2S.write(*(p++));
+ }
#endif
return true;
}
diff --git a/src/AudioOutputI2SNoDAC.h b/src/AudioOutputI2SNoDAC.h
index d1738d1..2a63225 100644
--- a/src/AudioOutputI2SNoDAC.h
+++ b/src/AudioOutputI2SNoDAC.h
@@ -18,8 +18,7 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOOUTPUTI2SNODAC_H
-#define _AUDIOOUTPUTI2SNODAC_H
+#pragma once
#include "AudioOutputI2S.h"
@@ -42,6 +41,3 @@ class AudioOutputI2SNoDAC : public AudioOutputI2S
fixed24p8_t lastSamp; // Last sample value
fixed24p8_t cumErr; // Running cumulative error since time began
};
-
-#endif
-
diff --git a/src/AudioOutputSPDIF.cpp b/src/AudioOutputSPDIF.cpp
index 8c993c5..53483d4 100644
--- a/src/AudioOutputSPDIF.cpp
+++ b/src/AudioOutputSPDIF.cpp
@@ -37,6 +37,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#if defined(ESP32) || defined(ESP8266)
#include
#if defined(ESP32)
@@ -286,3 +287,5 @@ bool AudioOutputSPDIF::stop()
frame_num = 0;
return true;
}
+
+#endif
diff --git a/src/AudioOutputSPDIF.h b/src/AudioOutputSPDIF.h
index 92a4e46..5da160b 100644
--- a/src/AudioOutputSPDIF.h
+++ b/src/AudioOutputSPDIF.h
@@ -30,8 +30,8 @@
along with this program. If not, see .
*/
-#ifndef _AUDIOOUTPUTSPDIF_H
-#define _AUDIOOUTPUTSPDIF_H
+#if defined(ESP32) || defined(ESP8266)
+#pragma once
#include "AudioOutput.h"
diff --git a/src/libflac/cpu.c b/src/libflac/cpu.c
index efed11b..cd650a0 100644
--- a/src/libflac/cpu.c
+++ b/src/libflac/cpu.c
@@ -31,7 +31,7 @@
*/
//#ifdef HAVE_CONFIG_H
-# include
+# include "config.h"
//#endif
#include "private/cpu.h"
diff --git a/src/libhelix-aac/assembly.h b/src/libhelix-aac/assembly.h
index fc4d767..595a8fc 100644
--- a/src/libhelix-aac/assembly.h
+++ b/src/libhelix-aac/assembly.h
@@ -223,7 +223,7 @@ Word64 MADD64(Word64 sum64, int x, int y);
/* toolchain: ARM ADS or RealView
* target architecture: ARM v.4 and above (requires 'M' type processor for 32x32->64 multiplier)
*/
-#elif defined (__arm) && defined (__ARMCC_VERSION)
+#elif defined (XXX__arm) && defined (__ARMCC_VERSION)
static __inline int MULSHIFT32(int x, int y)
{
@@ -336,7 +336,7 @@ static __inline Word64 MADD64(Word64 sum64, int x, int y)
/* toolchain: ARM gcc
* target architecture: ARM v.4 and above (requires 'M' type processor for 32x32->64 multiplier)
*/
-#elif defined(__GNUC__) && defined(__arm__)
+#elif defined(__GNUC__) && defined(XXXX__arm__)
static inline int MULSHIFT32(int x, int y)
{
diff --git a/src/libhelix-aac/sbr.c b/src/libhelix-aac/sbr.c
index ec04672..e463915 100644
--- a/src/libhelix-aac/sbr.c
+++ b/src/libhelix-aac/sbr.c
@@ -44,6 +44,7 @@
**************************************************************************************/
#if defined(USE_DEFAULT_STDLIB) || defined(ARDUINO)
+#include
#include
#else
#include "hlxclib/stdlib.h"
diff --git a/src/libhelix-aac/sbrhfgen.c b/src/libhelix-aac/sbrhfgen.c
index 7ebc047..e5f27eb 100644
--- a/src/libhelix-aac/sbrhfgen.c
+++ b/src/libhelix-aac/sbrhfgen.c
@@ -76,7 +76,7 @@ static const int newBWTab[4][4] PROGMEM = {
* Notes: this is carefully written to be efficient on ARM
* use the assembly code version in sbrcov.s when building for ARM!
**************************************************************************************/
-#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
+#if (defined (XXXX__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(XXXX__arm__))
#ifdef __cplusplus
extern "C"
#endif
@@ -237,7 +237,7 @@ static int CalcCovariance1(int *XBuf, int *p01reN, int *p01imN, int *p12reN, int
* Notes: this is carefully written to be efficient on ARM
* use the assembly code version in sbrcov.s when building for ARM!
**************************************************************************************/
-#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
+#if (defined (XXXX__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(XXXX__arm__))
#ifdef __cplusplus
extern "C"
#endif
diff --git a/src/libhelix-mp3/assembly.h b/src/libhelix-mp3/assembly.h
index 9c10c4d..b9e46c5 100644
--- a/src/libhelix-mp3/assembly.h
+++ b/src/libhelix-mp3/assembly.h
@@ -217,7 +217,7 @@ static __inline int CLZ(int x)
return numZeros;
}
-#elif defined ARM_ADS
+#elif defined XXXARM_ADS
static __inline int MULSHIFT32(int x, int y)
{
@@ -267,7 +267,7 @@ static __inline int CLZ(int x)
return numZeros;
}
-#elif defined(__GNUC__) && defined(__thumb__)
+#elif defined(__GNUC__) && defined(XXXX__thumb__)
static __inline int MULSHIFT32(int x, int y)