27 Commits
Author SHA1 Message Date
Earle F. Philhower, III c2adbdcf88 Enable Werror for ESP32 (#536)
The ESP32 core now builds without warnings, so at Werror back
2022-06-01 02:44:13 -07:00
Earle F. Philhower, III b987ca3540 Update library.properties 2022-05-31 09:37:03 -07:00
Earle F. Philhower, III 19f802923d Update library.json 2022-05-31 09:36:45 -07:00
Earle F. Philhower, III 9a9e030d90 Add more tests to host testing in CI (#534)
Add more tests to host testing in CI
Fix FLAC potential 1st sample output oddity
2022-05-19 17:17:21 -07:00
Earle F. Philhower, III 879fe48b78 Clean up ESP32 I2S interface undefineds (#533) 2022-05-19 13:17:07 -07:00
Earle F. Philhower, III b9666d3652 Get ESP32 CI running again (#532)
Get ESP32 CI running again
ESP32 lacks separable CI stuff
ESP32 has broken GCC 8, don't build MIDI examples
2022-05-19 10:48:24 -07:00
Earle F. Philhower, III a6f1eda9a2 Get ESP8266 CI running again (#531)
Add LWIP to ESP8266 builds
New build step on ESP8266
Fix warnings, quiet get.py
Ack SPIFFS deprecation
Example fix
Clean up overzealous pragmas
Fix server.accept() deprecation
2022-05-18 22:12:33 -07:00
Earle F. Philhower, III 2069060574 Add RP2040 build (#530)
Fix examples to build on RP2040
Clean up generator warnings
No SPDIF on RP2040 (yet)
Add back C sources for AAC on ARM
No WiFi streaming on RP2040
No webradio on RP2040
No talking clock (NTP) on RP2040 either
2022-05-18 21:03:37 -07:00
Earle F. Philhower, III be8b8efbf2 Clean ESP32 build (#529) 2022-05-18 18:43:50 -07:00
Earle F. Philhower, III 9384bb0f3d Update for RP2040 core v2.0 new I2S (#528)
The I2S subsystem was rewritten in the RP2040 core V2.0, so update to
use the new object and calls.

Also clean up some code warnings and remove SPIFFS from the RP2040\
2022-05-18 17:37:34 -07:00
Raphael Rott 76235d0e3f fix typos in readme (#513) 2022-04-25 09:02:45 -07:00
Wouter van der Put c87b662cb6 Fix typo (#504) 2022-03-15 17:59:40 -07:00
Martin-Laclaustra 9ffb8a503a Do not compile AudioGeneratorMIDI if GCC is 8 (compiler bug) (#502) 2022-03-10 09:14:10 -08:00
Maximilian Gerhardt 8b4010bf84 Fix PlatformIO library search mode (#500)
* Set default library mode to "deep"

* Increase version analog to library.json
2022-02-17 20:40:21 -08:00
Earle F. Philhower, III 20943870a9 Fix #define protection macro name 2022-02-09 08:33:23 -08:00
Frank 73a1821aba Flush MOD output after normal end of playback (#482)
small oops in my previous PR - output->flush was not called after normal "end of song".
2022-01-10 14:27:02 -08:00
smischny d5dea4f20c AudioOutputI2SNoDAC not working for RP2040 due to constructor differences with AudioOutputI2S (parent class) (#477)
Updated code to correctly call the parent classes constructor for the RP2040.
Changed the code for the RP2040 to correctly call the parent classes constructor.
2022-01-09 08:57:54 -08:00
Frank 7a82ba2ab3 AudiogeneratorMOD: use full 16bit with slightly better accuracy (#479)
* Fix a tricky bug that causes delays in playback

... this bug was already present in stellaplayer. Obviously "effectNumber" must be checked, because "effectParameterX" just holds the "upper nibble" of effectParameter

* fix for issue #474

- do channel mixing in 32bit, to avoid noise from over/underflow
- write audio output as "signed int" (not unsigned)
- add int16 saturation check ("clipping")

* avoid crash when MOD file has to many CHANNELS

- avoid guru meditation, by logging an error and refusing playback in case MOD.numberOfChannels > CHANNELS
- correct small typo

* internal DAC: avoid possible overflow in conversion int16 -> uint16

* update constants

.. we can do 16bit and 8 channels, so let's do it ;-)

This adds some debugging code to better understand what is going on inside the mixer code (AudioGeneratorMOD::GetSample). And it also prints out some usefull information from the MOD file.

Only active when do_MIXER_DEBUG is defined.

* MOD generator: 12 bits of "real" resolution (instead of 10)

With this change, we gain 2 additional bits of "real resolution" from the sample interpolation step.
Still need some testing to be sure that nothing get "lost" at the same time.

* limit to 4 channels on ESP8266

As discussed in https://github.com/earlephilhower/ESP8266Audio/pull/479#issuecomment-1007708703
2022-01-09 08:39:34 -08:00
Frank c55d240ade Fix for issue #474, and a few other bugs in MODGenerator (#478)
Fixes #474

This bug was already present in stellaplayer. Obviously "effectNumber" must be checked, because "effectParameterX" just holds the "upper nibble" of effectParameter

- do channel mixing in 32bit, to avoid noise from over/underflow
- write audio output as "signed int" (not unsigned)
- add int16 saturation check ("clipping")
* avoid crash when MOD file has to many CHANNELS
- avoid guru meditation, by logging an error and refusing playback in case MOD.numberOfChannels > CHANNELS
2022-01-05 08:25:26 -08:00
FedericoBusero fe7a1f7951 Fix RTTTL stop on ESP32 (#473)
Fixes #327 
Fixes #471
2021-12-27 08:12:33 -08:00
FedericoBusero 4971e5ce68 Increase I2S buffer size (#472)
Increase I2S buffer size from 64 samples/ block to 128 samples/block. 
Thus fixes sound artifacts described in issue https://github.com/earlephilhower/ESP8266Audio/issues/442

Fixes #442
2021-12-26 09:29:09 -08:00
FedericoBusero 29e5e016af AAC playback on RISC-V processor (ESP32C3) (#466)
The library produces white noise when playing AAC streams because of a little/big endian issue.
2021-12-19 14:02:45 -08:00
Earle F. Philhower, III dca33f80c7 Update library.properties 2021-12-17 19:32:45 -08:00
Earle F. Philhower, III faa8b094c9 Update library.json 2021-12-17 19:32:29 -08:00
FedericoBusero 7ac86f015f I2S Fix Builtin DAC&PDM on ESP32 & compiling warning ESP32-C3 (#461)
* Update AudioOutputI2S.cpp

* Update AudioOutputSPDIF.cpp

* Fix PDM & DAC mode ESP32

The code for enabling compatibility with ESP32C3 had broken DAC builtin and PDM mode on ESP32. This should fix it again

* Update AudioOutputI2S.cpp
2021-12-17 19:31:49 -08:00
Earle F. Philhower, III 933439fa3f Update README.md 2021-12-17 11:42:16 -08:00
Wojtek Kaniewski 0d132c1391 Support LSB Justified DACs (e.g. PT8211) (#459) 2021-12-03 18:47:01 -08:00
44 changed files with 445 additions and 245 deletions

No files matched your search

+27 -1
View File
@@ -13,6 +13,29 @@ on:
jobs:
build-rp2040:
name: Build RP2040
runs-on: ubuntu-latest
strategy:
matrix:
chunk: [0, 1, 2, 3, 4]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Build Sketches
env:
TRAVIS_BUILD_DIR: ${{ github.workspace }}
TRAVIS_TAG: ${{ github.ref }}
BUILD_TYPE: build_rp2040
BUILD_MOD: 5
BUILD_REM: ${{ matrix.chunk }}
run: |
bash ./tests/common.sh
build-esp8266:
name: Build ESP8266
runs-on: ubuntu-latest
@@ -36,7 +59,6 @@ jobs:
run: |
bash ./tests/common.sh
build-esp32:
name: Build ESP-32
runs-on: ubuntu-latest
@@ -84,7 +106,11 @@ jobs:
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./mp3
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./aac
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./wav
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./flac
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./mod
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./wav
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./midi
valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./opus
lint:
runs-on: ubuntu-latest
+6 -4
View File
@@ -1,4 +1,4 @@
# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040[![Gitter](https://badges.gitter.im/ESP8266Audio/community.svg)](https://gitter.im/ESP8266Audio/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040 [![Gitter](https://badges.gitter.im/ESP8266Audio/community.svg)](https://gitter.im/ESP8266Audio/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Arduino library for parsing and decoding MOD, WAV, MP3, FLAC, MIDI, AAC, and RTTL files and playing them on an I2S DAC or even using a software-simulated delta-sigma DAC with dynamic 32x-128x oversampling.
ESP8266 is fully supported and most mature, but ESP32 is also mostly there with built-in DAC as well as external ones.
@@ -33,6 +33,8 @@ A neat MQTT-driven ESP8266 light-and-sound device (alarm? toy? who can say!) was
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
## 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.
@@ -179,7 +181,7 @@ I've used several versions of PCM5102 DAC boards purchased from eBay. They've a
### Others
There are many other variants out there, and they should all work reasonably well with this code and the ESP8266. Please be certain you've read the datasheet and are applying proper input voltages, and be sure to tie off any unused inputs to GND or VCC as appropriate. LEaving an input pin floating on any integrated circuit can cause unstable operation as it may pick up noise from the environment (very low input capacitance) and cause havoc with internal IC settings.
There are many other variants out there, and they should all work reasonably well with this code and the ESP8266. Please be certain you've read the datasheet and are applying proper input voltages, and be sure to tie off any unused inputs to GND or VCC as appropriate. Leaving an input pin floating on any integrated circuit can cause unstable operation as it may pick up noise from the environment (very low input capacitance) and cause havoc with internal IC settings.
## Software I2S Delta-Sigma DAC (i.e. playing music with a single transistor and speaker)
For the best fidelity, and stereo to boot, spend the money on a real I2S DAC. Adafruit makes a great mono one with amplifier, and you can find stereo unamplified ones on eBay or elsewhere quite cheaply. However, thanks to the software delta-sigma DAC with 32x oversampling (up to 128x if the audio rate is low enough) you can still have pretty good sound!
@@ -214,7 +216,7 @@ USB-5V -- Speaker + Terminal
*NOTE*: A prior version of this schematic had a direct connection from the ESP8266 to the base of the transistor. While this does provide the maximum amplitude, it also can draw more current from the 8266 than is safe, and can also cause the transistor to overheat.
As of the latest ESP8266Audio release, with the software delta-sigma DAC the LRCLK and BCLK pins *can* be used by an application. Simply use normal `pinMode` and `dicitalWrite` or `digitalRead` as desired.
As of the latest ESP8266Audio release, with the software delta-sigma DAC the LRCLK and BCLK pins *can* be used by an application. Simply use normal `pinMode` and `digitalWrite` or `digitalRead` as desired.
### High pitched buzzing with the 1-T circuit
The 1-T amp can _NOT_ drive any sort of amplified speaker. If there is a power or USB input to the speaker, or it has lights or Bluetooth or a battery, it can _NOT_ be used with this circuit.
@@ -247,7 +249,7 @@ ESP Pin -------|____|--------+
|
Ground ---------------------+
```
For ESP8266 with red LED (~1.9Vf drop) you need minimum 150Ohm resistor (12mA max per pin), and output pin is fixed (GPIO3/RX0).On ESP32 it is confgurable with `AudioOutputSPDIF(gpio_num)`.
For ESP8266 with red LED (~1.9Vf drop) you need minimum 150Ohm resistor (12mA max per pin), and output pin is fixed (GPIO3/RX0).On ESP32 it is configurable with `AudioOutputSPDIF(gpio_num)`.
## Using external SPI RAM to increase buffer
A class allows you to use a 23lc1024 SPI RAM from Microchip as input buffer. This chip connects to ESP8266 HSPI port and provides a large buffer to help avoid hiccus in playback of web streams.
+6 -1
View File
@@ -1,5 +1,10 @@
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
#define WIFI_OFF
class __x { public: __x() {}; void mode() {}; };
__x WiFi;
#elif defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -1,4 +1,8 @@
#include <Arduino.h>
#ifdef ARDUINO_ARCH_RP2040
void setup() {}
void loop() {}
#else
#include "AudioFileSourceSD.h"
#include "AudioOutputSPDIF.h"
#include "AudioGeneratorFLAC.h"
@@ -61,8 +65,10 @@ void loop() {
}
}
} else {
Serial.println(F("Playback form SD card done\n"));
Serial.println(F("Playback from SD card done\n"));
delay(1000);
}
}
}
#endif
@@ -6,7 +6,13 @@
}
void loop() {}
#else
#include <ESP8266WiFi.h>
#if defined(ARDUINO_ARCH_RP2040)
#define WIFI_OFF
class __x { public: __x() {}; void mode() {}; };
__x WiFi;
#else
#include <ESP8266WiFi.h>
#endif
#include <AudioOutputI2S.h>
#include <AudioGeneratorMIDI.h>
#include <AudioFileSourceLittleFS.h>
@@ -42,7 +48,6 @@ void loop()
{
if (midi->isRunning()) {
if (!midi->loop()) {
uint32_t e = millis();
midi->stop();
}
} else {
@@ -1,4 +1,11 @@
#include <Arduino.h>
// Do not build on GCC8, GCC8 has a compiler bug
#if defined(ARDUINO_ARCH_RP2040) || (__GNUC__ == 8)
void setup() {}
void loop() {}
#else
#ifdef ESP32
#include <WiFi.h>
#include "SPIFFS.h"
@@ -44,7 +51,6 @@ void loop()
{
if (midi->isRunning()) {
if (!midi->loop()) {
uint32_t e = millis();
midi->stop();
}
} else {
@@ -53,4 +59,4 @@ void loop()
}
}
#endif
@@ -2,7 +2,11 @@
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorMOD.h"
#include "AudioOutputI2S.h"
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
#define WIFI_OFF
class __x { public: __x() {}; void mode() {}; };
__x WiFi;
#elif defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -1,4 +1,9 @@
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#ifdef ESP32
#include <WiFi.h>
#include "SPIFFS.h"
@@ -70,3 +75,4 @@ void loop()
delay(1000);
}
}
#endif
@@ -1,4 +1,8 @@
#include <Arduino.h>
#ifdef ARDUINO_ARCH_RP2040
void setup() {}
void loop() {}
#else
#ifdef ESP32
#include "SPIFFS.h"
#endif
@@ -97,3 +101,4 @@ void loop()
delay(1000);
}
}
#endif
@@ -1,4 +1,8 @@
#include <Arduino.h>
#ifdef ARDUINO_ARCH_RP2040
void setup() {}
void loop() {}
#else
#ifdef ESP32
#include <WiFi.h>
#include "SPIFFS.h"
@@ -39,3 +43,5 @@ void loop()
delay(1000);
}
}
#endif
@@ -1,6 +1,11 @@
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -104,4 +109,4 @@ void loop()
delay(1000);
}
}
#endif
@@ -1,6 +1,10 @@
#include <Arduino.h>
#ifdef ARDUINO_ARCH_RP2040
void setup() {}
void loop() {}
#else
#ifdef ESP32
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -140,3 +144,5 @@ void loop()
ESP.restart();
}
}
#endif
@@ -1,5 +1,9 @@
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -101,4 +105,4 @@ void loop()
delay(1000);
}
}
#endif
@@ -30,6 +30,7 @@ class AudioOutputNullSlow : public AudioOutput
~AudioOutputNullSlow() {};
virtual bool begin() { samples = 0; startms = millis(); return true; }
virtual bool ConsumeSample(int16_t sample[2]) {
(void) sample;
// return false (= output buffer full)
// sometimes to let the main loop running
constexpr int everylog2 = 10;
+8 -4
View File
@@ -1,6 +1,10 @@
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -9,10 +13,10 @@
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#if AUDIO
#pragma message("Outputting audio")
// #pragma message("Outputting audio")
#include "AudioOutputLinuxDSP.h"
#else
#pragma message("No audio")
// #pragma message("No audio")
#include "AudioOutputNullSlow.h"
#endif
@@ -115,4 +119,4 @@ void loop()
delay(1000);
}
}
#endif
+9 -1
View File
@@ -2,7 +2,14 @@
// https://github.com/going-digital/Talkie/blob/master/Talkie/examples/Vocab_US_Clock/Vocab_US_Clock.ino
// Released under GPL v2
#ifdef ESP32
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -183,3 +190,4 @@ void loop()
sayTime(tmstruct.tm_hour, tmstruct.tm_min, talkie);
delay(1000);
}
#endif
+10 -1
View File
@@ -19,7 +19,15 @@
*/
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
// ESP8266 server.available() is now server.accept()
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -439,3 +447,4 @@ void loop()
}
}
#endif
+4 -4
View File
@@ -19,6 +19,9 @@
*/
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
// Nothing here
#else
#ifdef ESP32
#include <WiFi.h>
#else
@@ -308,7 +311,4 @@ void Read4Int(char *str, byte *p)
str += ParseInt(str, &i); p[2] = i; if (*str) str++;
str += ParseInt(str, &i); p[3] = i;
}
#endif
+5 -2
View File
@@ -14,10 +14,13 @@
"type": "git",
"url": "https://github.com/earlephilhower/ESP8266Audio"
},
"version": "1.9.4",
"version": "1.9.7",
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
"frameworks": "Arduino",
"examples": [
"examples/*/*.ino"
]
],
"build": {
"libLDFMode": "deep"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
name=ESP8266Audio
version=1.9.4
version=1.9.7
author=Earle F. Philhower, III
maintainer=Earle F. Philhower, III
sentence=Audio file and I2S sound playing routines for ESP8266, ESP32, and Raspberry Pi Pico RP2040
+4 -4
View File
@@ -25,14 +25,14 @@ AudioFileSourceFunction::AudioFileSourceFunction(float sec, uint16_t channels, u
uint32_t len = uint32_t(sec * (float)bytes_per_sec);
// RIFF chunk
strncpy(wav_header.riff.chunk_id, "RIFF", 4);
memcpy(wav_header.riff.chunk_id, "RIFF", 4);
wav_header.riff.chunk_size = 4 // size of riff chunk w/o chunk_id and chunk_size
+ 8 + 16 // size of format chunk
+ 8 + len; // size of data chunk
strncpy(wav_header.riff.format, "WAVE", 4);
memcpy(wav_header.riff.format, "WAVE", 4);
// format chunk
strncpy(wav_header.format.chunk_id, "fmt ", 4);
memcpy(wav_header.format.chunk_id, "fmt ", 4);
wav_header.format.chunk_size = 16;
wav_header.format.format_tag = 0x0001; // PCM
wav_header.format.channels = channels;
@@ -42,7 +42,7 @@ AudioFileSourceFunction::AudioFileSourceFunction(float sec, uint16_t channels, u
wav_header.format.bits_per_sample = bits_per_sample;
// data chunk
strncpy(wav_header.data.chunk_id, "data", 4);
memcpy(wav_header.data.chunk_id, "data", 4);
wav_header.data.chunk_size = len;
funcs.reserve(channels);
+3
View File
@@ -20,6 +20,9 @@
#if defined(ESP32) || defined(ESP8266)
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
#define _GNU_SOURCE
#include "AudioFileSourceICYStream.h"
+2 -2
View File
@@ -18,8 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCESPIFFS_H
#define _AUDIOFILESOURCESPIFFS_H
#ifndef _AUDIOFILESOURCELITTLEFS_H
#define _AUDIOFILESOURCELITTLEFS_H
#include <Arduino.h>
#include <LittleFS.h>
+3
View File
@@ -27,6 +27,9 @@
#include "AudioFileSource.h"
#include "AudioFileSourceFS.h"
// Yes, I know SPIFFS is deprecated
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
class AudioFileSourceSPIFFS : public AudioFileSourceFS
{
public:
+4 -1
View File
@@ -62,6 +62,9 @@ bool AudioGeneratorFLAC::begin(AudioFileSource *source, AudioOutput *output)
output->begin();
running = true;
lastSample[0] = 0;
lastSample[1] = 0;
channels = 0;
return true;
}
@@ -71,7 +74,7 @@ bool AudioGeneratorFLAC::loop()
if (!running) goto done;
if (!output->ConsumeSample(lastSample)) goto done; // Try and send last buffered sample
if (channels && !output->ConsumeSample(lastSample)) goto done; // Try and send last buffered sample
do {
if (buffPtr == buffLen) {
+6
View File
@@ -58,6 +58,10 @@
#include "AudioGeneratorMIDI.h"
#if __GNUC__ == 8
// Do not build, GCC8 has a compiler bug
#else // __GNUC__ == 8
#pragma GCC optimize ("O3")
#define TSF_NO_STDIO
@@ -637,3 +641,5 @@ void AudioGeneratorMIDI::MakeStreamFromAFS(AudioFileSource *src, tsf_stream *afs
afs->size = &afs_size;
}
#endif //__GNUC__ == 8
+5
View File
@@ -21,6 +21,10 @@
#ifndef _AUDIOGENERATORMIDI_H
#define _AUDIOGENERATORMIDI_H
#if __GNUC__ == 8
// Do not build, GCC8 has a compiler bug
#else // __GNUC__ == 8
#include "AudioGenerator.h"
#define TSF_NO_STDIO
@@ -176,6 +180,7 @@ class AudioGeneratorMIDI : public AudioGenerator
short samplesRendered[256];
};
#endif //__GNUC__ == 8
#endif
+56 -20
View File
@@ -69,6 +69,11 @@ bool AudioGeneratorMOD::stop()
free(FatBuffer.channels[i]);
FatBuffer.channels[i] = NULL;
}
if(running || ((file != NULL) && (file->isOpen() == true))) {
output->flush(); //flush I2S output buffer, if the player was actually running before.
}
if (file) file->close();
running = false;
output->stop();
@@ -232,6 +237,11 @@ bool AudioGeneratorMOD::LoadHeader()
Mod.numberOfChannels = (temp[0] - '0') * 10 + temp[1] - '0';
else
Mod.numberOfChannels = 4;
if (Mod.numberOfChannels > CHANNELS) {
audioLogger->printf("\nAudioGeneratorMOD::LoadHeader abort - too many channels (configured: %d, needed: %d)\n", CHANNELS, Mod.numberOfChannels);
return(false);
}
return true;
}
@@ -417,7 +427,7 @@ bool AudioGeneratorMOD::ProcessRow()
if (sampleNumber) {
Player.lastSampleNumber[channel] = sampleNumber - 1;
if (!(effectParameter == 0xE && effectParameterX == NOTEDELAY))
if (!(effectNumber == 0xE && effectParameterX == NOTEDELAY))
Player.volume[channel] = Mod.samples[Player.lastSampleNumber[channel]].volume;
}
@@ -735,13 +745,14 @@ bool AudioGeneratorMOD::RunPlayer()
void AudioGeneratorMOD::GetSample(int16_t sample[2])
{
int16_t sumL;
int16_t sumR;
int32_t sumL;
int32_t sumR;
uint8_t channel;
uint32_t samplePointer;
int8_t current;
int8_t next;
int16_t out;
int32_t out32;
if (!running) return;
@@ -779,8 +790,8 @@ void AudioGeneratorMOD::GetSample(int16_t sample[2])
samplePointer >= FatBuffer.samplePointer[channel] + fatBufferSize - 1 ||
Mixer.channelSampleNumber[channel] != FatBuffer.channelSampleNumber[channel]) {
uint16_t toRead = Mixer.sampleEnd[Mixer.channelSampleNumber[channel]] - samplePointer + 1;
if (toRead > fatBufferSize) toRead = fatBufferSize;
uint32_t toRead = Mixer.sampleEnd[Mixer.channelSampleNumber[channel]] - samplePointer + 1;
if (toRead > (uint32_t)fatBufferSize) toRead = fatBufferSize;
if (!file->seek(samplePointer, SEEK_SET)) {
stop();
@@ -797,30 +808,55 @@ void AudioGeneratorMOD::GetSample(int16_t sample[2])
current = FatBuffer.channels[channel][(samplePointer - FatBuffer.samplePointer[channel]) /*& (FATBUFFERSIZE - 1)*/];
next = FatBuffer.channels[channel][(samplePointer + 1 - FatBuffer.samplePointer[channel]) /*& (FATBUFFERSIZE - 1)*/];
// preserve a few more bits from sample interpolation, by upscaling input values.
// This does (slightly) reduce quantization noise in higher frequencies, typically above 8kHz.
// Actually we could could even gain more bits, I was just not sure if more bits would cause overflows in other conputations.
int16_t current16 = (int16_t) current << 2;
int16_t next16 = (int16_t) next << 2;
out = current16;
out = current;
// Integer linear interpolation - only works correctly in 16bit
out += (next16 - current16) * (Mixer.channelSampleOffset[channel] & ((1 << FIXED_DIVIDER) - 1)) >> FIXED_DIVIDER;
// Integer linear interpolation
out += (next - current) * (Mixer.channelSampleOffset[channel] & ((1 << FIXED_DIVIDER) - 1)) >> FIXED_DIVIDER;
// Upscale to BITDEPTH
out <<= BITDEPTH - 8;
// Upscale to BITDEPTH, considering the we already gained two bits in the previous step
out32 = (int32_t)out << (BITDEPTH - 10);
// Channel volume
out = out * Mixer.channelVolume[channel] >> 6;
out32 = out32 * Mixer.channelVolume[channel] >> 6;
// Channel panning
sumL += out * min(128 - Mixer.channelPanning[channel], 64) >> 6;
sumR += out * min(Mixer.channelPanning[channel], 64) >> 6;
sumL += out32 * min(128 - Mixer.channelPanning[channel], 64) >> 6;
sumR += out32 * min(Mixer.channelPanning[channel], 64) >> 6;
}
// Downscale to BITDEPTH
sumL /= Mod.numberOfChannels;
sumR /= Mod.numberOfChannels;
// Downscale to BITDEPTH - a bit faster because the compiler can replaced division by constants with proper "right shift" + correct handling of sign bit
if (Mod.numberOfChannels <= 4) {
// up to 4 channels
sumL /= 4;
sumR /= 4;
} else {
if (Mod.numberOfChannels <= 6) {
// 5 or 6 channels - pre-multiply be 1.5, then divide by 8 -> same as division by 6
sumL = (sumL + (sumL/2)) / 8;
sumR = (sumR + (sumR/2)) / 8;
} else {
// 7,8, or more channels
sumL /= 8;
sumR /= 8;
}
}
// Fill the sound buffer with unsigned values
sample[AudioOutput::LEFTCHANNEL] = sumL + (1 << (BITDEPTH - 1));
sample[AudioOutput::RIGHTCHANNEL] = sumR + (1 << (BITDEPTH - 1));
// clip samples to 16bit (with saturation in case of overflow)
if(sumL <= INT16_MIN) sumL = INT16_MIN;
else if (sumL >= INT16_MAX) sumL = INT16_MAX;
if(sumR <= INT16_MIN) sumR = INT16_MIN;
else if (sumR >= INT16_MAX) sumR = INT16_MAX;
// Fill the sound buffer with signed values
sample[AudioOutput::LEFTCHANNEL] = sumL;
sample[AudioOutput::RIGHTCHANNEL] = sumR;
}
bool AudioGeneratorMOD::LoadMOD()
+8 -2
View File
@@ -53,7 +53,7 @@ class AudioGeneratorMOD : public AudioGenerator
protected:
int mixerTick;
enum {BITDEPTH = 15};
enum {BITDEPTH = 16};
int sampleRate;
int fatBufferSize; //(6*1024) // File system buffers per-CHANNEL (i.e. total mem required is 4 * FATBUFFERSIZE)
enum {FIXED_DIVIDER = 10}; // Fixed-point mantissa used for integer arithmetic
@@ -64,8 +64,14 @@ class AudioGeneratorMOD : public AudioGenerator
// Hz = 7159091 / (amigaPeriod * 2) for NTSC
int AMIGA;
void UpdateAmiga() { AMIGA = ((usePAL?7159091:7093789) / 2 / sampleRate << FIXED_DIVIDER); }
#ifdef ESP8266 // Not sure if C3/C2 have RAM constraints, maybe add them here?
// support max 4 channels
enum {ROWS = 64, SAMPLES = 31, CHANNELS = 4, NONOTE = 0xFFFF, NONOTE8 = 0xff };
#else
// support max 8 channels
enum {ROWS = 64, SAMPLES = 31, CHANNELS = 8, NONOTE = 0xFFFF, NONOTE8 = 0xff };
#endif
typedef struct Sample {
uint16_t length;
+4 -1
View File
@@ -41,7 +41,10 @@ AudioGeneratorRTTTL::~AudioGeneratorRTTTL()
bool AudioGeneratorRTTTL::stop()
{
if (!running) return true;
if (!file || !output)
{
return false;
}
running = false;
output->stop();
return file->close();
+81 -48
View File
@@ -42,6 +42,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
//set defaults
mono = false;
lsb_justified = false;
bps = 16;
channels = 2;
hertz = 44100;
@@ -51,37 +52,6 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
SetGain(1.0);
}
bool AudioOutputI2S::SetPinout()
{
#ifdef ESP32
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
return false; // Not allowed
i2s_pin_config_t pins = {
.bck_io_num = bclkPin,
.ws_io_num = wclkPin,
.data_out_num = doutPin,
.data_in_num = I2S_PIN_NO_CHANGE};
i2s_set_pin((i2s_port_t)portNo, &pins);
return true;
#else
(void)bclkPin;
(void)wclkPin;
(void)doutPin;
return false;
#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;
@@ -111,6 +81,38 @@ AudioOutputI2S::~AudioOutputI2S()
i2sOn = false;
}
bool AudioOutputI2S::SetPinout()
{
#ifdef ESP32
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
return false; // Not allowed
i2s_pin_config_t pins = {
.mck_io_num = 0, // Unused
.bck_io_num = bclkPin,
.ws_io_num = wclkPin,
.data_out_num = doutPin,
.data_in_num = I2S_PIN_NO_CHANGE};
i2s_set_pin((i2s_port_t)portNo, &pins);
return true;
#else
(void)bclkPin;
(void)wclkPin;
(void)doutPin;
return false;
#endif
}
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
{
bclkPin = bclk;
wclkPin = wclk;
doutPin = dout;
if (i2sOn)
return SetPinout();
return true;
}
bool AudioOutputI2S::SetRate(int hz)
{
// TODO - have a list of allowable rates from constructor, check them
@@ -122,7 +124,7 @@ bool AudioOutputI2S::SetRate(int hz)
#elif defined(ESP8266)
i2s_set_rate(AdjustI2SRate(hz));
#elif defined(ARDUINO_ARCH_RP2040)
I2S.setFrequency(hz);
i2s.setFrequency(hz);
#endif
}
return true;
@@ -148,6 +150,12 @@ bool AudioOutputI2S::SetOutputModeMono(bool mono)
return true;
}
bool AudioOutputI2S::SetLsbJustified(bool lsbJustified)
{
this->lsb_justified = lsbJustified;
return true;
}
bool AudioOutputI2S::begin(bool txDAC)
{
#ifdef ESP32
@@ -168,25 +176,45 @@ bool AudioOutputI2S::begin(bool txDAC)
i2s_mode_t mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
if (output_mode == INTERNAL_DAC)
{
#ifdef I2S_MODE_DAC_BUILT_IN
#if CONFIG_IDF_TARGET_ESP32
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
#else
return false;
#endif
}
if (output_mode == INTERNAL_PDM)
else if (output_mode == INTERNAL_PDM)
{
#ifdef I2S_MODE_PDM
#if CONFIG_IDF_TARGET_ESP32
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
#else
return false;
#endif
}
i2s_comm_format_t comm_fmt = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB);
i2s_comm_format_t comm_fmt;
if (output_mode == INTERNAL_DAC)
{
comm_fmt = (i2s_comm_format_t)I2S_COMM_FORMAT_I2S_MSB;
#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
}
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
}
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
}
i2s_config_t i2s_config_dac = {
@@ -197,8 +225,12 @@ bool AudioOutputI2S::begin(bool txDAC)
.communication_format = comm_fmt,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
.dma_buf_count = dma_buf_count,
.dma_buf_len = 64,
.use_apll = use_apll // Use audio PLL
.dma_buf_len = 128,
.use_apll = use_apll, // Use audio PLL
.tx_desc_auto_clear = true, // Silence on underflow
.fixed_mclk = 0, // Unused
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
};
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK)
@@ -207,7 +239,7 @@ bool AudioOutputI2S::begin(bool txDAC)
}
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
{
#ifdef I2S_DAC_CHANNEL_BOTH_EN
#if CONFIG_IDF_TARGET_ESP32
i2s_set_pin((i2s_port_t)portNo, NULL);
i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
#else
@@ -243,9 +275,9 @@ bool AudioOutputI2S::begin(bool txDAC)
#elif defined(ARDUINO_ARCH_RP2040)
(void)txDAC;
if (!i2sOn) {
I2S.setBCLK(bclkPin);
I2S.setDOUT(doutPin);
I2S.begin(hertz);
i2s.setBCLK(bclkPin);
i2s.setDATA(doutPin);
i2s.begin(hertz);
}
#endif
i2sOn = true;
@@ -277,7 +309,7 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
{
int16_t l = Amplify(ms[LEFTCHANNEL]) + 0x8000;
int16_t r = Amplify(ms[RIGHTCHANNEL]) + 0x8000;
s32 = (r << 16) | (l & 0xffff);
s32 = ((r & 0xffff) << 16) | (l & 0xffff);
}
else
{
@@ -293,7 +325,8 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
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);
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return !!i2s.write((int32_t)s32, false);
#endif
}
@@ -301,7 +334,7 @@ void AudioOutputI2S::flush()
{
#ifdef ESP32
// makes sure that all stored DMA samples are consumed / played
int buffersize = 64 * this->dma_buf_count;
int buffersize = 128 * this->dma_buf_count;
int16_t samples[2] = {0x0, 0x0};
for (int i = 0; i < buffersize; i++)
{
@@ -311,7 +344,7 @@ void AudioOutputI2S::flush()
}
}
#elif defined(ARDUINO_ARCH_RP2040)
I2S.flush();
i2s.flush();
#endif
}
@@ -323,7 +356,7 @@ bool AudioOutputI2S::stop()
#ifdef ESP32
i2s_zero_dma_buffer((i2s_port_t)portNo);
#elif defined(ARDUINO_ARCH_RP2040)
I2S.end();
i2s.end();
#endif
i2sOn = false;
return true;
+12 -1
View File
@@ -22,17 +22,22 @@
#include "AudioOutput.h"
#if defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include <I2S.h>
#endif
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);
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
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
virtual ~AudioOutputI2S() override;
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
@@ -44,6 +49,7 @@ class AudioOutputI2S : public AudioOutput
bool begin(bool txDAC);
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
protected:
bool SetPinout();
@@ -51,6 +57,7 @@ class AudioOutputI2S : public AudioOutput
uint8_t portNo;
int output_mode;
bool mono;
int lsb_justified;
bool i2sOn;
int dma_buf_count;
int use_apll;
@@ -61,4 +68,8 @@ class AudioOutputI2S : public AudioOutput
uint8_t bclkPin;
uint8_t wclkPin;
uint8_t doutPin;
#if defined(ARDUINO_ARCH_RP2040)
I2S i2s;
#endif
};
+24 -6
View File
@@ -29,6 +29,25 @@
#include "AudioOutputI2SNoDAC.h"
#if defined(ARDUINO_ARCH_RP2040)
//
// Create an alternate constructor for the RP2040. The AudioOutputI2S has an alternate
// constructor for the RP2040, so the code was passing port to the sampleRate and false to sck.
//
// AudioOutputI2S(long sampleRate = 44100, pin_size_t sck = 26, pin_size_t data = 28);
//
// So this new constructor adds the ability to pass both port and sck to the underlying class, but
// uses the same defaults in the AudioOutputI2S constructor.
//
AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port, int sck) : AudioOutputI2S(44100, sck, port)
{
SetOversampling(32);
lastSamp = 0;
cumErr = 0;
}
#else
AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
{
SetOversampling(32);
@@ -38,7 +57,10 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, orig_bck);
WRITE_PERI_REG(PERIPHS_IO_MUX_GPIO2_U, orig_ws);
#endif
}
#endif
AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC()
{
@@ -97,9 +119,6 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
// Either send complete pulse stream or nothing
#ifdef ESP32
//"i2s_write_bytes" has been removed in the ESP32 Arduino 2.0.0, use "i2s_write" instead.
// if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
size_t i2s_bytes_written;
i2s_write((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), &i2s_bytes_written, 0);
if (!i2s_bytes_written){
@@ -112,9 +131,8 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
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++));
for (int i = 0; i < oversample / 32; i++) {
i2s.write((int32_t)dsBuff[i], true);
}
#endif
return true;
+9
View File
@@ -25,7 +25,16 @@
class AudioOutputI2SNoDAC : public AudioOutputI2S
{
public:
//
// Define a different constructor for the RP2040, as this class calls the constructor
// of the AudioOutputI2S which has an alternate constructor for the RP2040
//
#if defined(ARDUINO_ARCH_RP2040)
AudioOutputI2SNoDAC(int port = 28,int sck = 26);
#else
AudioOutputI2SNoDAC(int port = 0);
#endif
virtual ~AudioOutputI2SNoDAC() override;
virtual bool begin() override { return AudioOutputI2S::begin(false); }
virtual bool ConsumeSample(int16_t sample[2]) override;
+11 -2
View File
@@ -94,11 +94,19 @@ AudioOutputSPDIF::AudioOutputSPDIF(int dout_pin, int port, int dma_buf_count)
.sample_rate = 88200, // 2 x sampling_rate
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // 32bit words
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // Right than left
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
#else
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
#endif
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
.dma_buf_count = dma_buf_count,
.dma_buf_len = DMA_BUF_SIZE_DEFAULT, // bigger buffers, reduces interrupts
.use_apll = true // Audio PLL is needed for low clock jitter
.use_apll = true, // Audio PLL is needed for low clock jitter
.tx_desc_auto_clear = true, // Silence on underflow
.fixed_mclk = 0, // Unused
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
};
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_spdif, 0, NULL) != ESP_OK) {
audioLogger->println(F("ERROR: Unable to install I2S drivers"));
@@ -143,6 +151,7 @@ bool AudioOutputSPDIF::SetPinout(int bclk, int wclk, int dout)
{
#if defined(ESP32)
i2s_pin_config_t pins = {
.mck_io_num = 0, // unused
.bck_io_num = bclk,
.ws_io_num = wclk,
.data_out_num = dout,
+9 -1
View File
@@ -18,12 +18,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include <FS.h>
#ifdef ESP32
#include "SPIFFS.h"
#endif
// Yes, I know SPIFFS is deprecated
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include "AudioOutputSPIFFSWAV.h"
static const uint8_t wavHeaderTemplate[] PROGMEM = { // Hardcoded simple WAV header with 0xffffffff lengths all around
@@ -110,4 +116,6 @@ bool AudioOutputSPIFFSWAV::stop()
f.close();
return true;
}
#endif
+3
View File
@@ -21,6 +21,8 @@
#ifndef _AUDIOOUTPUTSPIFFSWAV_H
#define _AUDIOOUTPUTSPIFFSWAV_H
#if !defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include <FS.h>
@@ -43,3 +45,4 @@ class AudioOutputSPIFFSWAV : public AudioOutput
#endif
#endif
+2 -2
View File
@@ -2783,7 +2783,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_
if(rice_parameter < pesc) {
partitioned_rice_contents->raw_bits[partition] = 0;
u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
if(!FLAC__bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter))
if(!FLAC__bitreader_read_rice_signed_block(decoder->private_->input, (int *)(residual + sample), u, rice_parameter))
return false; /* read_callback_ sets the state for us */
sample += u;
}
@@ -2792,7 +2792,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_
return false; /* read_callback_ sets the state for us */
partitioned_rice_contents->raw_bits[partition] = rice_parameter;
for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i, rice_parameter))
if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32 *)&i, rice_parameter))
return false; /* read_callback_ sets the state for us */
residual[sample] = i;
}
+1 -1
View File
@@ -558,7 +558,7 @@ static __inline int CLZ(int x)
typedef union _U64 {
Word64 w64;
struct {
#ifdef __XTENSA__
#if defined(__XTENSA__) || defined (__riscv)
unsigned int lo32;
signed int hi32;
#else
+3 -2
View File
@@ -222,7 +222,8 @@ static void PostMultiply64(int *fft1, int nSampsOut)
* Notes: this is carefully written to be efficient on ARM
* use the assembly code version in sbrqmfak.s when building for ARM!
**************************************************************************************/
#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
//TODO - ADD IN .S SOURCES SOMEHOW
#if 0 //(defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
#ifdef __cplusplus
extern "C"
#endif
@@ -395,7 +396,7 @@ int QMFAnalysis(int *inbuf, int *delay, int *XBuf, int fBitsIn, int *delayIdx, i
* Notes: this is carefully written to be efficient on ARM
* use the assembly code version in sbrqmfsk.s when building for ARM!
**************************************************************************************/
#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
#if 0 //(defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__))
#ifdef __cplusplus
extern "C"
#endif
+1
View File
@@ -20,6 +20,7 @@
*/
#pragma GCC optimize ("O3")
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#include <pgmspace.h>
# include "config.h"
+1 -1
View File
@@ -1422,7 +1422,7 @@ static int op_open_seekable2_impl(OggOpusFile *_of){
_of->end=sr[0].offset+sr[0].size;
if(OP_UNLIKELY(_of->end<data_offset)){free(sr); return OP_EBADLINK;}
/*Now enumerate the bitstream structure.*/
ret = op_bisect_forward_serialno(_of,data_offset,sr,sizeof(sr)/sizeof(*sr),
ret = op_bisect_forward_serialno(_of,data_offset,sr,64,
&_of->serialnos,&_of->nserialnos,&_of->cserialnos);
free(sr);
return ret;
+4 -4
View File
@@ -332,9 +332,9 @@ class ESP8266SPIRAM {
}
digitalWrite(csPin, HIGH);
pinMode(sck, SPECIAL);
pinMode(miso, SPECIAL);
pinMode(mosi, SPECIAL);
pinMode(sck, OUTPUT);
pinMode(miso, INPUT);
pinMode(mosi, OUTPUT);
pinMode(csPin, OUTPUT);
// Enable streaming read/write mode
@@ -364,4 +364,4 @@ class ESP8266SPIRAM {
#endif // ESP32
#endif
#endif
+48 -117
View File
@@ -2,98 +2,17 @@
set -ex
function print_size_info()
{
elf_file=$1
if [ -z "$elf_file" ]; then
printf "sketch data rodata bss text irom0.text dram flash\n"
return 0
fi
elf_name=$(basename $elf_file)
sketch_name="${elf_name%.*}"
# echo $sketch_name
declare -A segments
while read -a tokens; do
seg=${tokens[0]}
seg=${seg//./}
size=${tokens[1]}
addr=${tokens[2]}
if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then
segments[$seg]=$size
fi
done < <(xtensa-lx106-elf-size --format=sysv $elf_file)
total_ram=$((${segments[data]} + ${segments[rodata]} + ${segments[bss]}))
total_flash=$((${segments[data]} + ${segments[rodata]} + ${segments[text]} + ${segments[irom0text]}))
printf "%-28s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n" $sketch_name ${segments[data]} ${segments[rodata]} ${segments[bss]} ${segments[text]} ${segments[irom0text]} $total_ram $total_flash
return 0
}
function build_sketches()
{
set +e
local arduino=$1
local srcpath=$2
local build_arg=$3
local build_dir=build.tmp
local build_mod=$BUILD_MOD
local build_rem=$BUILD_REM
mkdir -p $build_dir
local build_cmd="python3 $arduino/$BUILD_PY -p $PWD/$build_dir $build_arg "
local sketches=$(find $srcpath -name *.ino)
print_size_info >size.log
export ARDUINO_IDE_PATH=$arduino
for sketch in $sketches; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
rm -rf $build_dir/*
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
echo "Skipping $sketch, because it is not the main sketch file";
continue
fi;
if [[ -f "$sketchdir/.test.skip" ]]; then
echo -e "\n ------------ Skipping $sketch ------------ \n";
continue
fi
echo -e "\n ------------ Building $sketch ------------ \n";
# $arduino --verify $sketch;
echo "$build_cmd $sketch"
time ($build_cmd $sketch >build.log)
local result=$?
if [ $result -ne 0 ]; then
echo "Build failed ($1)"
echo "Build log:"
cat build.log
set -e
return $result
fi
rm build.log
#print_size_info $build_dir/*.elf >>size.log
done
set -e
}
function install_libraries()
{
mkdir -p $HOME/Arduino/libraries
cp -a $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/ESP8266Audio
cp -a $GITHUB_WORKSPACE $HOME/Arduino/libraries/ESP8266Audio
git clone https://github.com/earlephilhower/ESP8266SAM $HOME/Arduino/libraries/ESP8266SAM
}
function install_ide()
{
local ide_path=$1
wget -q -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
wget -q -O arduino.tar.xz https://downloads.arduino.cc/arduino-nightly-linux64.tar.xz
tar xf arduino.tar.xz
mv arduino-nightly $ide_path
export PATH="$ide_path:$PATH"
@@ -111,84 +30,96 @@ function install_esp8266()
# Set custom warnings for all builds (i.e. could add -Wextra at some point)
echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > ../platform.local.txt
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> ../platform.local.txt
echo "mkbuildoptglobals.extra_flags=--ci --cache_core" >> ../platform.local.txt
echo -e "\n----platform.local.txt----"
cat ../platform.local.txt
git submodule init
git submodule update
python3 get.py
python3 get.py -q
export PATH="$ide_path/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin:$PATH"
popd
cd esp8266
}
function install_rp2040()
{
local ide_path=$1
mkdir -p $ide_path/hardware
cd $ide_path/hardware
mkdir pico
cd pico
git clone https://github.com/earlephilhower/arduino-pico rp2040
pushd rp2040/tools
# Set custom warnings for all builds (i.e. could add -Wextra at some point)
echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > ../platform.local.txt
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> ../platform.local.txt
echo -e "\n----platform.local.txt----"
cat ../platform.local.txt
git submodule update --init
cd ../pico-sdk
git submodule update --init
cd ../tools
python3 get.py -q
export PATH="$ide_path/hardware/pico/rp2040/system/arm-none-eabi/bin:$PATH"
popd
cd rp2040
}
function install_esp32()
{
local ide_path=$1
sudo pip install pyserial
pip install pyserial
pip3 install pyserial
cd $ide_path/hardware
mkdir espressif
cd espressif
git clone https://github.com/espressif/arduino-esp32.git esp32
pushd esp32
# Set custom warnings for all builds (i.e. could add -Wextra at some point)
# Set custom warnings for all builds
echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > platform.local.txt
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> platform.local.txt
echo -e "\n----platform.local.txt----"
cat platform.local.txt
git submodule init
git submodule update
git submodule update --init
cd tools
python3 get.py
export PATH="$ide_path/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/:$PATH"
popd
cd esp32
}
function install_arduino()
{
# Install Arduino IDE and required libraries
echo -e "travis_fold:start:sketch_test_env_prepare"
cd $TRAVIS_BUILD_DIR
install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR
cd "$GITHUB_WORKSPACE"
install_ide "$HOME/arduino_ide" "$GITHUB_WORKSPACE"
which arduino
cd $TRAVIS_BUILD_DIR
cd "$GITHUB_WORKSPACE"
install_libraries
echo -e "travis_fold:end:sketch_test_env_prepare"
}
function build_sketches_with_arduino()
{
# Compile sketches
echo -e "travis_fold:start:sketch_test"
build_sketches $HOME/arduino_ide $HOME/Arduino/libraries "-l $HOME/Arduino/libraries"
echo -e "travis_fold:end:sketch_test"
# Generate size report
echo -e "travis_fold:start:size_report"
cat size.log
echo -e "travis_fold:end:size_report"
}
set -e
if [ "$BUILD_MOD" == "" ]; then
export BUILD_MOD=1
export BUILD_REM=0
fi
export cache_dir=$(mktemp -d)
if [ "$BUILD_TYPE" = "build" ]; then
export BUILD_PY="hardware/esp8266com/esp8266/tools/build.py -b generic -s 4M1M -v -k "
install_arduino
install_esp8266 "$HOME/arduino_ide"
build_sketches_with_arduino
source "$HOME/arduino_ide/hardware/esp8266com/esp8266/tests/common.sh"
build_sketches "$HOME/arduino_ide" "$TRAVIS_BUILD_DIR" "-l $HOME/Arduino/libraries" "$BUILD_MOD" "$BUILD_REM" "lm2f"
elif [ "$BUILD_TYPE" = "build_esp32" ]; then
install_arduino
install_esp32 "$HOME/arduino_ide"
export ide_path=$HOME/arduino_ide
export FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app"
export GITHUB_WORKSPACE="$TRAVIS_BUILD_DIR"
export GITHUB_REPOSITORY="$TRAVIS_REPO_SLUG"
source $ide_path/hardware/espressif/esp32/.github/scripts/install-arduino-ide.sh
source $ide_path/hardware/espressif/esp32/.github/scripts/install-arduino-core-esp32.sh
build_sketches "$FQBN" "$HOME/Arduino/libraries" "$BUILD_REM" "$BUILD_MOD"
mkdir -p "$GITHUB_WORKSPACE/hardware"
ln -s "$GITHUB_WORKSPACE/../" "$GITHUB_WORKSPACE/libraries"
source "$HOME/arduino_ide/hardware/espressif/esp32/.github/scripts/sketch_utils.sh" chunk_build "$HOME/arduino_ide" "$GITHUB_WORKSPACE" "$FQBN" esp32 "$GITHUB_WORKSPACE" $BUILD_REM $BUILD_MOD
elif [ "$BUILD_TYPE" = "build_rp2040" ]; then
install_arduino
install_rp2040 "$HOME/arduino_ide"
source "$HOME/arduino_ide/hardware/pico/rp2040/tests/common.sh"
build_sketches "$HOME/arduino_ide" "$TRAVIS_BUILD_DIR" "-l $HOME/Arduino/libraries" "$BUILD_MOD" "$BUILD_REM"
fi