Skip to content

Commit

Permalink
an update of ESP8266Audio library for Core 3.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jun 7, 2024
1 parent 28e4fec commit 07d048c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool
}
if ((size > 0) && (pos >= size)) return 0;

#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient *stream = http.getStreamPtr();
#else
WiFiClient *stream = http.getStreamPtr();
#endif

// Can't read past EOF...
if ( (size > 0) && (len > (uint32_t)(pos - size)) ) len = pos - size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#include <Arduino.h>
#ifdef ESP32
#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR >= 5
#include <WiFi.h>
#endif /* ESP_IDF_VERSION_MAJOR */
#include <HTTPClient.h>
#else
#include <ESP8266HTTPClient.h>
Expand Down Expand Up @@ -56,7 +53,11 @@ class AudioFileSourceHTTPStream : public AudioFileSource

private:
virtual uint32_t readInternal(void *data, uint32_t len, bool nonBlock);
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient client;
#else
WiFiClient client;
#endif
HTTPClient http;
int pos;
int size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
}
if ((size > 0) && (pos >= size)) return 0;

#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient *stream = http.getStreamPtr();
#else
WiFiClient *stream = http.getStreamPtr();
#endif

// Can't read past EOF...
if ( (size > 0) && (len > (uint32_t)(pos - size)) ) len = pos - size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@

#include "AudioGeneratorMIDI.h"

#if (__GNUC__ == 8) && (__XTENSA__)
// Do not build, GCC8 has a compiler bug
#if defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__)
// Do not build, Espressif's GCC8+ has a compiler bug
#else // __GNUC__ == 8

#pragma GCC optimize ("O3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#ifndef _AUDIOGENERATORMIDI_H
#define _AUDIOGENERATORMIDI_H

#if (__GNUC__ == 8) && (__XTENSA__)
// Do not build, GCC8 has a compiler bug
#if defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__)
// Do not build, Espressif's GCC8+ has a compiler bug
#else // __GNUC__ == 8

#include "AudioGenerator.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ bool AudioOutputI2S::begin(bool txDAC)
{
// don't use audio pll on buggy rev0 chips
use_apll = APLL_DISABLE;
esp_chip_info_t out_info;
esp_chip_info(&out_info);
if (out_info.revision > 0)
//esp_chip_info_t out_info;
//esp_chip_info(&out_info);
//if (out_info.revision > 0)
{
use_apll = APLL_ENABLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ AudioOutputSPDIF::AudioOutputSPDIF(int dout_pin, int port, int dma_buf_count)
.use_apll = true, // Audio PLL is needed for low clock jitter
.tx_desc_auto_clear = true, // Silence on underflow
.fixed_mclk = 0, // Unused
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
.mclk_multiple = I2S_MCLK_MULTIPLE_256, // Unused
#else
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
.mclk_multiple = I2S_MCLK_MULTIPLE_512, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
//#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR>=5
// .mclk_multiple = I2S_MCLK_MULTIPLE_256, // Unused
//#else
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, // Unused
#endif /* ESP_IDF_VERSION_MAJOR */
//#endif /* ESP_IDF_VERSION_MAJOR */
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
#endif
};
Expand Down Expand Up @@ -187,14 +190,14 @@ bool AudioOutputSPDIF::SetRate(int hz)
int adjustedHz = AdjustI2SRate(hz);
#if defined(ESP32)
if (i2s_set_sample_rates((i2s_port_t)portNo, adjustedHz) == ESP_OK) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#if defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR < 3)
if (adjustedHz == 88200) {
// Manually fix the APLL rate for 44100.
// See: https://github.com/espressif/esp-idf/issues/2634
// sdm0 = 28, sdm1 = 8, sdm2 = 5, odir = 0 -> 88199.977
rtc_clk_apll_enable(1, 28, 8, 5, 0);
}
#endif /* CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 */
#endif /* ESP_ARDUINO_VERSION_MAJOR */
} else {
audioLogger->println("ERROR changing S/PDIF sample rate");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CMpaDecObj
// return.
// pPCM pointer to a buffer to decode into
// pulPCMSize size of the PCM buffer. It will contain the
// number of PCM bytes prodced upon return.
// number of PCM bytes produced upon return.
///////////////////////////////////////////////////////////////////////////
void DecodeFrame_v(unsigned char *pSource,
unsigned long *pulSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
*/

// ESP32 as of 3.x has a compiler bug in this section, with the G++ generated assembly
// being illegal. There's nothing wrong with the code here, it just looks like an
// Xtensa backend issue. Until that's fixed, no MIDI for you!
///home/earle/Arduino/libraries/ESP8266Audio/src/libtinysoundfont/tsf.h: In function 'void tsf_channel_midi_control(tsf*, int, int, int)':
// /home/earle/Arduino/libraries/ESP8266Audio/src/libtinysoundfont/tsf.h:2101:1: error: insn does not satisfy its constraints:
// 2101 | }
// | ^

#if !defined(ESP32)

#ifndef TSF_INCLUDE_TSF_INL
#define TSF_INCLUDE_TSF_INL

Expand Down Expand Up @@ -2145,3 +2155,5 @@ TSFDEF float tsf_channel_get_tuning(tsf* f, int channel)
#endif

#endif //TSF_IMPLEMENTATION

#endif // ! ESP32

0 comments on commit 07d048c

Please sign in to comment.