61 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
Earle F. Philhower, III de30f61899 Update to Rel 1.9.4 for ESP-C3 support (#455) 2021-11-30 12:28:02 -08:00
FedericoBusero 2c1aeba4ab ESP32-C3 Support (#454)
* ESP32-C3 has no ULP coprocessor

Only the ESP32, ESP32-S2 and ESP32-S3 chips have an ULP coprocessor, ESP32-C3 doesn't have it. So exclude this code from compiling, as it cannot compile in the C3 environment.

* uint32_t and size_t is not the same on RISC-V

This change is necessary to be able to compile it on ESP32-C3

* uint32_t and size_t is not the same on RISC-V

The change is necessary to compile it on ESP32-C3

* ESP32-C3: I2S_MODE_DAC_BUILT_IN / I2S_MODE_PDM not available

On some ESP32 chips (e.g. ESP32-C3), builtin DAC is not possible as it lacks the hardware module. In order to be able to compile the library on ESP32-C3 the defines cannot be used.
2021-11-30 12:25:30 -08:00
Jesper Noer 617b06d09a Fixing I2S includes to work with ESP8266 Arduino version < 3.0.0 (#453) 2021-11-29 12:11:57 -08:00
Earle F. Philhower, III e254ad9543 Add MOD test, update DIVIDER name (#451)
Fixes #449
2021-11-28 16:20:05 -08:00
Earle F. Philhower, III 86a1818da5 Add codespell to CI checks (#450) 2021-11-28 10:52:33 -08:00
Wouter van der Put b65bc2df8f Fix: add missing SPIFFS.begin() (#443)
Without this fix, there is no sound and the serial monitor shows:

Starting up...

[E][vfs_api.cpp:22] open(): File system is not mounted
[E][vfs_api.cpp:22] open(): File system is not mounted
BEGIN...
MIDI done
MIDI done

After this fix there is sound and no error on the serial monitor.
Then change is similar to the code in https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino
2021-11-28 10:31:36 -08:00
Wouter van der Put f9a78e7ef5 Fix typo in comment (#444) 2021-11-28 10:29:24 -08:00
Wouter van der Put 701ca39669 Fix typo in comment (#445) 2021-11-28 10:29:06 -08:00
Wouter van der Put 84593933e5 Fix typo in comment (#446) 2021-11-28 10:28:40 -08:00
Pixtxa 9485887879 Set FollowRedirects in AudioFileSourceICYStream (#448) 2021-11-27 12:35:07 -08:00
Oderik 62463b15f7 Document ESP8266 I2S pinout (#439) 2021-11-04 10:29:02 -07:00
pintomax c55abbfba5 Stream MP3 from HTTP to SPDIF (#436)
Stream MP3 from HTTP to SPDIF
2021-11-02 19:55:43 -07:00
Earle F. Philhower, III 5411abef6b Update Linear Clock links 2021-10-19 12:19:10 -07:00
Martin-Laclaustra f47793bc4c Make LittleFS file source available for ESP32 (#430) 2021-09-13 18:06:55 -07:00
Earle F. Philhower, III 9dd4f24056 Update library.properties 2021-09-08 08:58:14 -07:00
Earle F. Philhower, III 627a106479 Update library.json 2021-09-08 08:57:51 -07:00
qnxsgwy 6882b6e1b6 Fix 'i2s_write_bytes' was not declared in this scope on ESP32 (#428) 2021-09-08 08:57:25 -07:00
Earle F. Philhower, III 6ed2604015 Update library.json 2021-06-28 21:47:06 -07:00
Earle F. Philhower, III 5a5c2a88a3 Update library.properties 2021-06-28 21:46:50 -07:00
david gauchard c3c9a147c5 i2s on esp8266: fix include (#402) 2021-06-28 21:45:16 -07:00
Earle F. Philhower, III 4111404bac Update library.properties 2021-06-12 15:15:44 -07:00
Earle F. Philhower, III d4c09498c5 Update library.json 2021-06-12 15:15:21 -07:00
Hideaki Tai 8bf52d4c11 Fix the start of the arg “time” is not zero (#386)
In the first call of funcs[0](time), time should be zero but it was not.
2021-04-13 07:35:52 -07:00
Hideaki Tai f974af9bf3 Add AudioFileSourceFunction which can generate sound from functions (#383) 2021-04-11 18:37:38 -07:00
Hideaki Tai 9b4f36009b Fix compile error due to insufficient capacity (#384) 2021-04-11 13:57:55 -07:00
Earle F. Philhower, III 0d6e1340f0 Merge branch 'master' of https://github.com/earlephilhower/ESP8266Audio 2021-04-05 17:04:05 -07:00
Earle F. Philhower, III 8d6631e4ab Update I2S class API for RP2040 2021-04-05 17:03:34 -07:00
Earle F. Philhower, III a72bee6d73 Update README.md 2021-04-02 19:54:28 -07:00
Earle F. Philhower, III 09b1fd1788 Update library.properties 2021-04-02 19:43:20 -07:00
Earle F. Philhower, III b37e9d232b Add support for Raspberry Pi Pico Arduino Core
Adds support for the RP2040 core and the PIO based I2S output device.
https://github.com/earlephilhower/arduino-pico

Poisons some ARM optimizations which don't work on modern Thumbs.
2021-04-02 19:40:58 -07:00
Earle F. Philhower, III f4d4e69332 Move large OPUS locals to the heap (#374) 2021-02-24 20:50:22 -08:00
William Bérubé 714e8cf594 Adding a working implementation of a Biquad filter adapted for use with the fixed-point CPU of the ESP8266 (#370) 2021-02-13 15:32:45 -08:00
david gauchard 6ecb6afe30 API to force HTTPv1.0 allowing streaming clean data from some servers (#363) 2021-01-27 16:27:04 -08:00
Earle F. Philhower, III 4994de7cb7 Revert "Work around Arduino-Builder bug causing ESP8266 build fail (#358)" (#365)
This reverts commit b832ec2434.

Arduino-CLI has fixed a bug in their code, attempt to run nightly builds in CI again.
2021-01-27 16:26:44 -08:00
78 changed files with 1569 additions and 376 deletions

No files matched your search

+44 -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
@@ -93,3 +119,20 @@ jobs:
- uses: arduino/arduino-lint-action@v1
with:
library-manager: 'update'
# Validate orthography
code-spell:
name: Check spelling
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Run codespell
uses: codespell-project/actions-codespell@master
with:
skip: ./src/libmad,./src/libhelix-aac,./src/libopus
ignore_words_list: ESP8266,esp8266,esp,dout,DOUT,ser,ans,inout,numer,hist
+17 -7
View File
@@ -1,4 +1,4 @@
# ESP8266Audio - supports ESP8266 & ESP32 [![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.
@@ -31,7 +31,9 @@ JohannesMTC has built a similar project especially for model trains: https://git
A neat MQTT-driven ESP8266 light-and-sound device (alarm? toy? who can say!) was built by @CosmicMac, available at https://github.com/CosmicMac/ESParkle
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 http://home.kpn.nl/bderogee1980/projects/linear_clock/linear_clock.html
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.
@@ -100,7 +102,7 @@ AudioFileSourcePROGMEM: Reads a file from a PROGMEM array. Under UNIX you can
AudioFileSourceHTTPStream: Simple implementation of a streaming HTTP reader for ShoutCast-type MP3 streaming. Not yet resilient, and at 44.1khz 128bit stutters due to CPU limitations, but it works more or less.
## AudioFileSourceBuffer - Double buffering, useful for HTTP streams
AudioFileSourceBuffer is an input source that simpy adds an additional RAM buffer of the output of any other AudioFileSource. This is particularly useful for web streaming where you need to have 1-2 packets in memory to ensure hiccup-free playback.
AudioFileSourceBuffer is an input source that simply adds an additional RAM buffer of the output of any other AudioFileSource. This is particularly useful for web streaming where you need to have 1-2 packets in memory to ensure hiccup-free playback.
Create your standard input file source, create the buffer with the original source as its input, and pass this buffer object to the generator.
```cpp
@@ -158,7 +160,15 @@ AudioOutputSPIFFSWAV: Writes a binary WAV format with headers to a SPIFFS files
AudioOutputNull: Just dumps samples to /dev/null. Used for speed testing as it doesn't artificially limit the AudioGenerator output speed since there are no buffers to fill/drain.
## I2S DACs
I've used both the Adafruit [I2S +3W amp DAC](https://www.adafruit.com/product/3006) and a generic PCM5102 based DAC with success. The biggest problems I've seen from users involve pinouts from the ESP8266 for GPIO and hooking up all necessary pins on the DAC board.
I've used both the Adafruit [I2S +3W amp DAC](https://www.adafruit.com/product/3006) and a generic PCM5102 based DAC with success. The biggest problems I've seen from users involve pinouts from the ESP8266 for GPIO and hooking up all necessary pins on the DAC board. The essential pins are:
I2S pin | Common label* | ESP8266 pin
--------|---------------|-------------
LRC | D4 | GPIO2
BCLK | D8 | GPIO15
DIN | RX | GPIO3
\* The "common label" column applies to common NodeMCU and D1 Mini development boards. Unfortunately some manufacturers use different mappings so the labels listed here might not apply to your particular model.
### Adafruit I2S DAC
This is quite simple and only needs the GND, VIN, LRC, BCLK< and DIN pins to be wired. Be sure to use +5V on the VIN to get the loudest sound. See the [Adafruit example page](https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp) for more info.
@@ -171,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!
@@ -206,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.
@@ -239,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"
@@ -8,7 +12,7 @@
// Espressif Audio Development Framework at:
// https://docs.espressif.com/projects/esp-adf/en/latest/design-guide/audio-samples.html
//
// On ESP8266 you might need to reencode FLAC files with max '-2' compression level
// On ESP8266 you might need to re-encode FLAC files with max '-2' compression level
// (i.e. 1152 maximum block size) or you will run out of memory. FLAC files will be
// slightly bigger but you don't loose audio quality with reencoding (lossles codec).
@@ -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"
@@ -25,6 +32,7 @@ void setup()
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
SPIFFS.begin();
Serial.println("Starting up...\n");
audioLogger = &Serial;
@@ -43,7 +51,6 @@ void loop()
{
if (midi->isRunning()) {
if (!midi->loop()) {
uint32_t e = millis();
midi->stop();
}
} else {
@@ -52,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
@@ -0,0 +1,78 @@
#include <Arduino.h>
#include "AudioFileSourceFunction.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2SNoDAC.h"
float hz = 440.f;
// pre-defined function can also be used to generate the wave
float sine_wave(const float time) {
float v = sin(TWO_PI * hz * time); // C
v *= fmod(time, 1.f); // change linear
v *= 0.5; // scale
return v;
};
AudioGeneratorWAV* wav;
AudioFileSourceFunction* file;
AudioOutputI2SNoDAC* out;
void setup() {
Serial.begin(115200);
delay(1000);
// ===== create instance with length of song in [sec] =====
file = new AudioFileSourceFunction(8.);
//
// you can set (sec, channels, hz, bit/sample) but you should care about
// the trade-off between performance and the audio quality
//
// file = new AudioFileSourceFunction(sec, channels, hz, bit/sample);
// channels : default = 1
// hz : default = 8000 (8000, 11025, 22050, 44100, 48000, etc.)
// bit/sample : default = 16 (8, 16, 32)
// ===== set your sound function =====
file->addAudioGenerators([&](const float time) {
float v = sin(TWO_PI * hz * time); // generate sine wave
v *= fmod(time, 1.f); // change linear
v *= 0.5; // scale
return v;
});
//
// sound function should have one argument(float) and one return(float)
// param : float (current time [sec] of the song)
// return : float (the amplitude of sound which varies from -1.f to +1.f)
//
// sound function can be registered only one or the same number with channels
// if the channels > 1 && the number of function == 1,
// same function are used to generate the sound in every channel
//
// file = new AudioFileSourceFunction(8., 2);
// file->addAudioGenerators(
// // L (channel 0)
// [](const float time) {
// return 0.25 * sin(TWO_PI * 440.f * time) * fmod(time, 1.f); // C
// },
// // R (channel 1)
// [](const float time) {
// return 0.25 * sin(TWO_PI * 550.f * time) * fmod(time, 1.f); // E
// }
// );
//
// you can also use the pre-defined function
// file->addAudioGenerators(sine_wave);
out = new AudioOutputI2SNoDAC();
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
void loop() {
if (wav->isRunning()) {
if (!wav->loop()) wav->stop();
} else {
Serial.println("function done!");
delay(1000);
}
}
@@ -1,9 +1,4 @@
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
@@ -18,7 +13,6 @@ AudioOutputI2SNoDAC *out;
void setup()
{
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
delay(1000);
Serial.printf("WAV start\n");
@@ -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
@@ -0,0 +1,148 @@
#include <Arduino.h>
#ifdef ARDUINO_ARCH_RP2040
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
//#include "AudioOutputI2SNoDAC.h"
#include "AudioOutputSPDIF.h"
//
// Stream MP3 from HTTP to SPDIF
//
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
// Note:
// If using ESP8266 NodeMCU connect LED to RX pin and GND pin
// Enter your WiFi setup here:
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
// Examples URLs
//const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
// Italian Rock Radio
const char *URL="http://streamingv2.shoutcast.com/radiofreccia";
// Stream URL of Logitech Media Server, aka LMS, Version: 8.2.0 (August 2021)
// const char *URL="http://192.168.1.121:9000/stream.mp3";
AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff;
// Output device is SPDIF
AudioOutputSPDIF *out;
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
(void) isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
char s1[32], s2[64];
strncpy_P(s1, type, sizeof(s1));
s1[sizeof(s1)-1]=0;
strncpy_P(s2, string, sizeof(s2));
s2[sizeof(s2)-1]=0;
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
Serial.flush();
}
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1)-1]=0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
}
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("Connecting to WiFi");
WiFi.disconnect();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// Try forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");
delay(1000);
}
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
// Commented out for performance issues with high rate MP3 stream
//file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, 4096); // Doubled form default 2048
// Commented out for performance issues with high rate MP3 stream
//buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
// Set SPDIF output
out = new AudioOutputSPDIF();
mp3 = new AudioGeneratorMP3();
// Commented out for performance issues with high rate MP3 stream
//mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out);
}
void loop()
{
// Commented out
//static int lastms = 0;
if (mp3->isRunning()) {
/* Commented out
if (millis()-lastms > 1000) {
lastms = millis();
Serial.printf("Running for %d ms...\n", lastms);
Serial.flush();
}
*/
if (!mp3->loop()) {
mp3->stop();
}
} else {
Serial.printf("MP3 done\n");
// Restart ESP when streaming is done or errored
delay(10000);
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;
+13 -7
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
@@ -28,10 +32,10 @@ const char* ssid = STASSID;
const char* password = STAPSK;
// Randomly picked URL
const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
//const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
//const char *URL="http://stream2.pvpjamz.com:8706/stream";
// that one is not well decoded:
//const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3";
const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3";
AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
@@ -86,8 +90,10 @@ void setup()
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
file = new AudioFileSourceICYStream();
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
file->useHTTP10();
file->open(URL);
buff = new AudioFileSourceBuffer(file, 2048);
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
out = new AudioOutputNullSlow();
@@ -113,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
+1
View File
@@ -22,6 +22,7 @@ AudioGeneratorWAV KEYWORD1
AudioOutput KEYWORD1
AudioOutputI2S KEYWORD1
AudioOutputI2SNoDAC KEYWORD1
AudioOutputI2SClass KEYWORD1
AudioOutputNull KEYWORD1
AudioOutputBuffer KEYWORD1
AudioOutputSerialWAV KEYWORD1
+6 -9
View File
@@ -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,16 +14,13 @@
"type": "git",
"url": "https://github.com/earlephilhower/ESP8266Audio"
},
"version": "1.8.1",
"version": "1.9.7",
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
"dependencies": {
"SPI": "1.0",
"SPIFFS": "1.0",
"HTTPClient": "1.0",
"WiFiClientSecure": "1.0"
},
"frameworks": "Arduino",
"examples": [
"examples/*/*.ino"
]
],
"build": {
"libLDFMode": "deep"
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
name=ESP8266Audio
version=1.8.1
version=1.9.7
author=Earle F. Philhower, III
maintainer=Earle F. Philhower, III
sentence=Audio file and I2S sound playing routines.
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
+148
View File
@@ -0,0 +1,148 @@
/*
AudioFileSourceFunction
Audio output generator which can generate WAV file data from function
Copyright (C) 2021 Hideaki Tai
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AudioFileSourceFunction.h"
AudioFileSourceFunction::AudioFileSourceFunction(float sec, uint16_t channels, uint32_t sample_per_sec, uint16_t bits_per_sample) {
uint32_t bytes_per_sec = sample_per_sec * channels * bits_per_sample / 8;
uint32_t len = uint32_t(sec * (float)bytes_per_sec);
// RIFF chunk
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
memcpy(wav_header.riff.format, "WAVE", 4);
// format chunk
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;
wav_header.format.sample_per_sec = sample_per_sec;
wav_header.format.avg_bytes_per_sec = bytes_per_sec;
wav_header.format.block_align = channels * bits_per_sample / 8;
wav_header.format.bits_per_sample = bits_per_sample;
// data chunk
memcpy(wav_header.data.chunk_id, "data", 4);
wav_header.data.chunk_size = len;
funcs.reserve(channels);
pos = 0;
size = sizeof(WavHeader) + len;
is_ready = false;
is_unique = false;
}
AudioFileSourceFunction::~AudioFileSourceFunction() {
close();
}
uint32_t AudioFileSourceFunction::read(void* data, uint32_t len) {
// callback size must be 1 or equal to channels
if (!is_ready)
return 0;
uint8_t* d = reinterpret_cast<uint8_t*>(data);
uint32_t i = 0;
while (i < len) {
uint32_t p = pos + i;
if (p < sizeof(WavHeader)) {
// header bytes
d[i] = wav_header.bytes[p];
i += 1;
} else {
// data bytes
float time = (float)(p - sizeof(WavHeader)) / (float)wav_header.format.avg_bytes_per_sec;
float v = funcs[0](time);
for (size_t ch = 0; ch < wav_header.format.channels; ++ch) {
if (!is_unique && ch > 0)
v = funcs[ch](time);
switch (wav_header.format.bits_per_sample) {
case 8: {
Uint8AndInt8 vs {int8_t(v * (float)0x7F)};
d[i] = vs.u;
break;
}
case 32: {
Uint8AndInt32 vs {int32_t(v * (float)0x7FFFFFFF)};
d[i + 0] = vs.u[0];
d[i + 1] = vs.u[1];
d[i + 2] = vs.u[2];
d[i + 3] = vs.u[3];
break;
}
case 16:
default: {
Uint8AndInt16 vs {int16_t(v * (float)0x7FFF)};
d[i + 0] = vs.u[0];
d[i + 1] = vs.u[1];
break;
}
}
}
i += wav_header.format.block_align;
}
}
pos += i;
return (pos >= size) ? 0 : i;
}
bool AudioFileSourceFunction::seek(int32_t pos, int dir) {
if (dir == SEEK_SET) {
if (pos < 0 || (uint32_t)pos >= size)
return false;
this->pos = pos;
} else if (dir == SEEK_CUR) {
int32_t p = (int32_t)this->pos + pos;
if (p < 0 || (uint32_t)p >= size)
return false;
this->pos = p;
} else {
int32_t p = (int32_t)this->size + pos;
if (p < 0 || (uint32_t)p >= size)
return false;
this->pos = p;
}
return true;
}
bool AudioFileSourceFunction::close() {
funcs.clear();
pos = 0;
size = 0;
is_ready = false;
is_unique = false;
return true;
}
bool AudioFileSourceFunction::isOpen() {
return is_ready;
}
uint32_t AudioFileSourceFunction::getSize() {
return size;
}
uint32_t AudioFileSourceFunction::getPos() {
return pos;
}
+119
View File
@@ -0,0 +1,119 @@
/*
AudioFileSourceFunction
Audio output generator which can generate WAV file data from function
Copyright (C) 2021 Hideaki Tai
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCEFUNCTION_H
#define _AUDIOFILESOURCEFUNCTION_H
#include <Arduino.h>
#include <vector>
#include <functional>
#include "AudioFileSource.h"
class AudioFileSourceFunction : public AudioFileSource {
union WavHeader {
struct {
// RIFF chunk
struct {
char chunk_id[4]; // "RIFF"
uint32_t chunk_size; // 4 + (8 + sizeof(format_chunk)(16)) + (8 + sizeof(data_chunk))
char format[4]; // "WAVE"
} riff;
// format chunk
struct {
char chunk_id[4]; // "fmt "
uint32_t chunk_size; // 16
uint16_t format_tag; // 1: PCM
uint16_t channels; // 1: MONO, 2: STEREO
uint32_t sample_per_sec; // 8000, 11025, 22050, 44100, 48000
uint32_t avg_bytes_per_sec; // sample_per_sec * channels * bits_per_sample / 8
uint16_t block_align; // channels * bits_per_sample / 8
uint16_t bits_per_sample; // 8, 16, 32
} format;
// data chunk
struct {
char chunk_id[4]; // "data"
uint32_t chunk_size; // num_samples * channels * bytes_per_sample
// audio data follows here...
} data;
};
uint8_t bytes[44];
} wav_header;
union Uint8AndInt8 {
int8_t i;
uint8_t u;
};
union Uint8AndInt16 {
int16_t i;
uint8_t u[2];
};
union Uint8AndInt32 {
int32_t i;
uint8_t u[4];
};
using callback_t = std::function<float(float)>;
std::vector<callback_t> funcs;
uint32_t pos;
uint32_t size;
bool is_ready;
bool is_unique;
public:
AudioFileSourceFunction(float sec, uint16_t channels = 1, uint32_t sample_per_sec = 8000, uint16_t bits_per_sample = 16);
virtual ~AudioFileSourceFunction() override;
template <typename F, typename... Fs>
bool addAudioGenerators(const F& f, Fs&&... fs) {
funcs.emplace_back(f);
return addAudioGenerators(std::forward<Fs>(fs)...);
}
bool addAudioGenerators() {
funcs.shrink_to_fit();
if (funcs.size() == 1) {
is_ready = true;
is_unique = true;
return true;
} else if (funcs.size() == wav_header.format.channels) {
is_ready = true;
is_unique = false;
return true;
} else {
is_ready = false;
is_unique = false;
funcs.clear();
return false;
}
}
virtual uint32_t read(void* data, uint32_t len) override;
virtual bool seek(int32_t pos, int dir) override;
virtual bool close() override;
virtual bool isOpen() override;
virtual uint32_t getSize() override;
virtual uint32_t getPos() override;
};
#endif // _AUDIOFILESOURCEFUNCTION_H
+4
View File
@@ -18,6 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(ESP32) || defined(ESP8266)
#include "AudioFileSourceHTTPStream.h"
AudioFileSourceHTTPStream::AudioFileSourceHTTPStream()
@@ -152,3 +154,5 @@ uint32_t AudioFileSourceHTTPStream::getPos()
{
return pos;
}
#endif
+3 -2
View File
@@ -18,8 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCEHTTPSTREAM_H
#define _AUDIOFILESOURCEHTTPSTREAM_H
#if defined(ESP32) || defined(ESP8266)
#pragma once
#include <Arduino.h>
#ifdef ESP32
@@ -47,6 +47,7 @@ class AudioFileSourceHTTPStream : public AudioFileSource
virtual uint32_t getSize() override;
virtual uint32_t getPos() override;
bool SetReconnect(int tries, int delayms) { reconnectTries = tries; reconnectDelayMs = delayms; return true; }
void useHTTP10 () { http.useHTTP10(true); }
enum { STATUS_HTTPFAIL=2, STATUS_DISCONNECTED, STATUS_RECONNECTING, STATUS_RECONNECTED, STATUS_NODATA };
+9
View File
@@ -17,6 +17,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(ESP32) || defined(ESP8266)
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
#define _GNU_SOURCE
#include "AudioFileSourceICYStream.h"
@@ -44,6 +50,7 @@ bool AudioFileSourceICYStream::open(const char *url)
http.addHeader("Icy-MetaData", "1");
http.collectHeaders( hdr, 4 );
http.setReuse(true);
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
int code = http.GET();
if (code != HTTP_CODE_OK) {
http.end();
@@ -215,3 +222,5 @@ retry:
icyByteCount += ret;
return read;
}
#endif
+2 -4
View File
@@ -18,8 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCEICYSTREAM_H
#define _AUDIOFILESOURCEICYSTREAM_H
#if defined(ESP32) || defined(ESP8266)
#pragma once
#include <Arduino.h>
#ifdef ESP32
@@ -45,6 +45,4 @@ class AudioFileSourceICYStream : public AudioFileSourceHTTPStream
int icyByteCount;
};
#endif
+2 -6
View File
@@ -18,10 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCESPIFFS_H
#define _AUDIOFILESOURCESPIFFS_H
#ifndef ESP32 // No LittleFS there, yet
#ifndef _AUDIOFILESOURCELITTLEFS_H
#define _AUDIOFILESOURCELITTLEFS_H
#include <Arduino.h>
#include <LittleFS.h>
@@ -39,5 +37,3 @@ class AudioFileSourceLittleFS : public AudioFileSourceFS
#endif
#endif
+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:
+5 -1
View File
@@ -22,6 +22,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(ESP32) || defined(ESP8266)
#include <Arduino.h>
#include "AudioFileSourceSPIRAMBuffer.h"
@@ -103,7 +105,7 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
}
// Read up to the entire buffer from RAM
uint32_t toReadFromBuffer = std::min(len, writePtr - readPtr);
uint32_t toReadFromBuffer = std::min(len, (uint32_t)(writePtr - readPtr));
uint8_t *ptr = reinterpret_cast<uint8_t*>(data);
if (toReadFromBuffer > 0) {
#ifdef FAKERAM
@@ -165,3 +167,5 @@ bool AudioFileSourceSPIRAMBuffer::loop()
}
return true;
}
#endif
+2 -2
View File
@@ -19,8 +19,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCESPIRAMBUFFER_H
#define _AUDIOFILESOURCESPIRAMBUFFER_H
#if defined(ESP32) || defined(ESP8266)
#pragma once
#include "AudioFileSource.h"
#include <SPI.h>
+7 -4
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) {
@@ -177,9 +180,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;
}
+10 -4
View File
@@ -1,6 +1,6 @@
/*
AudioGeneratorMIDI
Audio output generator that plays MIDI files using a SF2 SoundFont
Audio output generator that plays MIDI files using an SF2 SoundFont
Copyright (C) 2017 Earle F. Philhower, III
@@ -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
@@ -172,7 +176,7 @@ unsigned int AudioGeneratorMIDI::buffer_int32 (int offset) {
unsigned long AudioGeneratorMIDI::get_varlen (int *ptr) {
/* Get a 1-4 byte variable-length value and adjust the pointer past it.
These are a succession of 7-bit values with a MSB bit of zero marking the end */
These are a succession of 7-bit values with an MSB bit of zero marking the end */
unsigned long val;
int i, byte;
@@ -331,7 +335,7 @@ note_off:
}
// Open file, parse headers, get ready tio process MIDI
// Open file, parse headers, get ready to process MIDI
void AudioGeneratorMIDI::PrepareMIDI(AudioFileSource *src)
{
MakeStreamFromAFS(src, &afsMIDI);
@@ -364,7 +368,7 @@ void AudioGeneratorMIDI::PrepareMIDI(AudioFileSource *src)
int AudioGeneratorMIDI::PlayMIDI()
{
/* Continue processing all tracks, in an order based on the simulated time.
This is not unlike multiway merging used for tape sorting algoritms in the 50's! */
This is not unlike multiway merging used for tape sorting algorithms in the 50's! */
do { /* while there are still track notes to process */
static struct track_status *trk;
@@ -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
+60 -24
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();
@@ -124,7 +129,7 @@ bool AudioGeneratorMOD::begin(AudioFileSource *source, AudioOutput *out)
UpdateAmiga();
for (int i = 0; i < CHANNELS; i++) {
FatBuffer.channels[i] = reinterpret_cast<uint8_t*>(malloc(fatBufferSize));
FatBuffer.channels[i] = reinterpret_cast<uint8_t*>(calloc(fatBufferSize, 1));
if (!FatBuffer.channels[i]) {
stop();
return false;
@@ -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;
}
@@ -565,7 +575,7 @@ bool AudioGeneratorMOD::ProcessRow()
Mixer.channelFrequency[channel] = Player.amiga / Player.lastAmigaPeriod[channel];
if (note != NONOTE)
Mixer.channelSampleOffset[channel] = sampleOffset << DIVIDER;
Mixer.channelSampleOffset[channel] = sampleOffset << FIXED_DIVIDER;
if (sampleNumber)
Mixer.channelSampleNumber[channel] = Player.lastSampleNumber[channel];
@@ -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;
@@ -757,12 +768,12 @@ void AudioGeneratorMOD::GetSample(int16_t sample[2])
if (!Mixer.channelVolume[channel]) continue;
samplePointer = Mixer.sampleBegin[Mixer.channelSampleNumber[channel]] +
(Mixer.channelSampleOffset[channel] >> DIVIDER);
(Mixer.channelSampleOffset[channel] >> FIXED_DIVIDER);
if (Mixer.sampleLoopLength[Mixer.channelSampleNumber[channel]]) {
if (samplePointer >= Mixer.sampleLoopEnd[Mixer.channelSampleNumber[channel]]) {
Mixer.channelSampleOffset[channel] -= Mixer.sampleLoopLength[Mixer.channelSampleNumber[channel]] << DIVIDER;
Mixer.channelSampleOffset[channel] -= Mixer.sampleLoopLength[Mixer.channelSampleNumber[channel]] << FIXED_DIVIDER;
samplePointer -= Mixer.sampleLoopLength[Mixer.channelSampleNumber[channel]];
}
@@ -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 << DIVIDER) - 1)) >> 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()
+10 -4
View File
@@ -53,19 +53,25 @@ 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 {DIVIDER = 10}; // Fixed-point mantissa used for integer arithmetic
enum {FIXED_DIVIDER = 10}; // Fixed-point mantissa used for integer arithmetic
int stereoSeparation; //STEREOSEPARATION = 32; // 0 (max) to 64 (mono)
bool usePAL;
// Hz = 7093789 / (amigaPeriod * 2) for PAL
// Hz = 7159091 / (amigaPeriod * 2) for NTSC
int AMIGA;
void UpdateAmiga() { AMIGA = ((usePAL?7159091:7093789) / 2 / sampleRate << DIVIDER); }
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();
+245
View File
@@ -0,0 +1,245 @@
/*
AudioOutputFilterBiquad
Implements a Biquad filter
Copyright (C) 2012 Nigel Redmon
Copyright (C) 2021 William Bérubé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#include "AudioOutputFilterBiquad.h"
AudioOutputFilterBiquad::AudioOutputFilterBiquad(AudioOutput *sink)
{
this->sink = sink;
type = bq_type_lowpass;
a0 = 1.0;
a1 = a2 = b1 = b2 = 0.0;
Fc = 0.50;
Q = 0.707;
peakGain = 0.0;
z1 = z2 = 0.0;
}
AudioOutputFilterBiquad::AudioOutputFilterBiquad(int type, float Fc, float Q, float peakGain, AudioOutput *sink)
{
this->sink = sink;
SetBiquad(type, Fc, Q, peakGain);
z1 = z2 = 0.0;
}
AudioOutputFilterBiquad::~AudioOutputFilterBiquad() {}
bool AudioOutputFilterBiquad::SetRate(int hz)
{
return sink->SetRate(hz);
}
bool AudioOutputFilterBiquad::SetBitsPerSample(int bits)
{
return sink->SetBitsPerSample(bits);
}
bool AudioOutputFilterBiquad::SetChannels(int channels)
{
return sink->SetChannels(channels);
}
bool AudioOutputFilterBiquad::SetGain(float gain)
{
return sink->SetGain(gain);
}
void AudioOutputFilterBiquad::SetType(int type)
{
this->type = type;
CalcBiquad();
}
void AudioOutputFilterBiquad::SetFc(float Fc)
{
this->Fc = Fc;
CalcBiquad();
}
void AudioOutputFilterBiquad::SetQ(float Q)
{
this->Q = Q;
CalcBiquad();
}
void AudioOutputFilterBiquad::SetPeakGain(float peakGain)
{
this->peakGain = peakGain;
CalcBiquad();
}
void AudioOutputFilterBiquad::SetBiquad(int type, float Fc, float Q, float peakGain)
{
this->type = type;
this->Fc = Fc;
this->Q = Q;
this->peakGain = peakGain;
CalcBiquad();
}
void AudioOutputFilterBiquad::CalcBiquad()
{
float norm;
float V = pow(10, fabs(peakGain) / 20.0);
float K = tan(M_PI * Fc);
switch (this->type) {
case bq_type_lowpass:
norm = 1 / (1 + K / Q + K * K);
a0 = K * K * norm;
a1 = 2 * a0;
a2 = a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
break;
case bq_type_highpass:
norm = 1 / (1 + K / Q + K * K);
a0 = 1 * norm;
a1 = -2 * a0;
a2 = a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
break;
case bq_type_bandpass:
norm = 1 / (1 + K / Q + K * K);
a0 = K / Q * norm;
a1 = 0;
a2 = -a0;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - K / Q + K * K) * norm;
break;
case bq_type_notch:
norm = 1 / (1 + K / Q + K * K);
a0 = (1 + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = a0;
b1 = a1;
b2 = (1 - K / Q + K * K) * norm;
break;
case bq_type_peak:
if (peakGain >= 0) { // boost
norm = 1 / (1 + 1/Q * K + K * K);
a0 = (1 + V/Q * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - V/Q * K + K * K) * norm;
b1 = a1;
b2 = (1 - 1/Q * K + K * K) * norm;
} else { // cut
norm = 1 / (1 + V/Q * K + K * K);
a0 = (1 + 1/Q * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - 1/Q * K + K * K) * norm;
b1 = a1;
b2 = (1 - V/Q * K + K * K) * norm;
}
break;
case bq_type_lowshelf:
if (peakGain >= 0) { // boost
norm = 1 / (1 + sqrt(2) * K + K * K);
a0 = (1 + sqrt(2*V) * K + V * K * K) * norm;
a1 = 2 * (V * K * K - 1) * norm;
a2 = (1 - sqrt(2*V) * K + V * K * K) * norm;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - sqrt(2) * K + K * K) * norm;
}
else { // cut
norm = 1 / (1 + sqrt(2*V) * K + V * K * K);
a0 = (1 + sqrt(2) * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - sqrt(2) * K + K * K) * norm;
b1 = 2 * (V * K * K - 1) * norm;
b2 = (1 - sqrt(2*V) * K + V * K * K) * norm;
}
break;
case bq_type_highshelf:
if (peakGain >= 0) { // boost
norm = 1 / (1 + sqrt(2) * K + K * K);
a0 = (V + sqrt(2*V) * K + K * K) * norm;
a1 = 2 * (K * K - V) * norm;
a2 = (V - sqrt(2*V) * K + K * K) * norm;
b1 = 2 * (K * K - 1) * norm;
b2 = (1 - sqrt(2) * K + K * K) * norm;
}
else { // cut
norm = 1 / (V + sqrt(2*V) * K + K * K);
a0 = (1 + sqrt(2) * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - sqrt(2) * K + K * K) * norm;
b1 = 2 * (K * K - V) * norm;
b2 = (V - sqrt(2*V) * K + K * K) * norm;
}
break;
}
i_a0 = a0 * BQ_DECAL;
i_a1 = a1 * BQ_DECAL;
i_a2 = a2 * BQ_DECAL;
i_b1 = b1 * BQ_DECAL;
i_b2 = b2 * BQ_DECAL;
i_lz1 = i_rz1 = z1 * BQ_DECAL;
i_lz2 = i_rz2 = z2 * BQ_DECAL;
i_Fc = Fc * BQ_DECAL;
i_Q = Q * BQ_DECAL;
i_peakGain = peakGain * BQ_DECAL;
}
bool AudioOutputFilterBiquad::begin()
{
return sink->begin();
}
bool AudioOutputFilterBiquad::ConsumeSample(int16_t sample[2])
{
int32_t leftSample = (sample[LEFTCHANNEL] << BQ_SHIFT) / 2;
int32_t rightSample = (sample[RIGHTCHANNEL] << BQ_SHIFT) / 2;
int64_t leftOutput = ((leftSample * i_a0) >> BQ_SHIFT) + i_lz1;
i_lz1 = ((leftSample * i_a1) >> BQ_SHIFT) + i_lz2 - ((i_b1 * leftOutput) >> BQ_SHIFT);
i_lz2 = ((leftSample * i_a2) >> BQ_SHIFT) - ((i_b2 * leftOutput) >> BQ_SHIFT);
int64_t rightOutput = ((rightSample * i_a0) >> BQ_SHIFT) + i_rz1;
i_rz1 = ((rightSample * i_a1) >> BQ_SHIFT) + i_rz2 - ((i_b1 * rightOutput) >> BQ_SHIFT);
i_rz2 = ((rightSample * i_a2) >> BQ_SHIFT) - ((i_b2 * rightOutput) >> BQ_SHIFT);
int16_t out[2];
out[LEFTCHANNEL] = (int16_t)(leftOutput >> BQ_SHIFT);
out[RIGHTCHANNEL] = (int16_t)(rightOutput >> BQ_SHIFT);
return sink->ConsumeSample(out);
}
bool AudioOutputFilterBiquad::stop()
{
return sink->stop();
}
+80
View File
@@ -0,0 +1,80 @@
/*
AudioOutputFilterBiquad
Implements a Biquad filter
Copyright (C) 2012 Nigel Redmon
Copyright (C) 2021 William Bérubé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AudioOutputFilterBiquad_H
#define _AudioOutputFilterBiquad_H
#include "AudioOutput.h"
#define BQ_SHIFT 16
#define BQ_DECAL 65536
enum {
bq_type_lowpass = 0,
bq_type_highpass,
bq_type_bandpass,
bq_type_notch,
bq_type_peak,
bq_type_lowshelf,
bq_type_highshelf
};
class AudioOutputFilterBiquad : public AudioOutput
{
public:
AudioOutputFilterBiquad(AudioOutput *sink);
AudioOutputFilterBiquad(int type, float Fc, float Q, float peakGain, AudioOutput *sink);
virtual ~AudioOutputFilterBiquad() override;
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
virtual bool SetChannels(int chan) override;
virtual bool SetGain(float f) override;
virtual bool begin() override;
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual bool stop() override;
private:
void SetType(int type);
void SetFc(float Fc);
void SetQ(float Q);
void SetPeakGain(float peakGain);
void SetBiquad(int type, float Fc, float Q, float peakGain);
protected:
AudioOutput *sink;
int buffSize;
int16_t *leftSample;
int16_t *rightSample;
int writePtr;
int readPtr;
bool filled;
int type;
void CalcBiquad();
int64_t i_a0, i_a1, i_a2, i_b1, i_b2;
int64_t i_Fc, i_Q, i_peakGain;
int64_t i_lz1, i_lz2, i_rz1, i_rz2;
float a0, a1, a2, b1, b2;
float Fc, Q, peakGain;
float z1, z2;
};
#endif
+106 -23
View File
@@ -21,11 +21,14 @@
#include <Arduino.h>
#ifdef ESP32
#include "driver/i2s.h"
#else
#elif defined(ARDUINO_ARCH_RP2040) || ARDUINO_ESP8266_MAJOR >= 3
#include <I2S.h>
#elif ARDUINO_ESP8266_MAJOR < 3
#include <i2s.h>
#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;
@@ -39,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;
@@ -48,6 +52,19 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
SetGain(1.0);
}
#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
@@ -55,24 +72,15 @@ AudioOutputI2S::~AudioOutputI2S()
audioLogger->printf("UNINSTALL I2S\n");
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
}
#else
#elif defined(ESP8266)
if (i2sOn)
i2s_end();
#elif defined(ARDUINO_ARCH_RP2040)
stop();
#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
@@ -80,6 +88,7 @@ bool AudioOutputI2S::SetPinout()
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,
@@ -94,6 +103,16 @@ 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;
}
bool AudioOutputI2S::SetRate(int hz)
{
// TODO - have a list of allowable rates from constructor, check them
@@ -102,8 +121,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;
@@ -129,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
@@ -149,17 +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)
{
#if CONFIG_IDF_TARGET_ESP32
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
#else
return false;
#endif
}
else if (output_mode == INTERNAL_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 = {
@@ -170,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)
@@ -180,8 +239,12 @@ bool AudioOutputI2S::begin(bool txDAC)
}
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
{
#if CONFIG_IDF_TARGET_ESP32
i2s_set_pin((i2s_port_t)portNo, NULL);
i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
#else
return false;
#endif
}
else
{
@@ -189,7 +252,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 +272,13 @@ bool AudioOutputI2S::begin(bool txDAC)
}
#endif
}
#elif defined(ARDUINO_ARCH_RP2040)
(void)txDAC;
if (!i2sOn) {
i2s.setBCLK(bclkPin);
i2s.setDATA(doutPin);
i2s.begin(hertz);
}
#endif
i2sOn = true;
SetRate(hertz); // Default
@@ -239,16 +309,24 @@ 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
{
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
//"i2s_write_bytes" has been removed in the ESP32 Arduino 2.0.0, use "i2s_write" instead.
// return i2s_write_bytes((i2s_port_t)portNo, (const char *)&s32, sizeof(uint32_t), 0);
size_t i2s_bytes_written;
i2s_write((i2s_port_t)portNo, (const char*)&s32, sizeof(uint32_t), &i2s_bytes_written, 0);
return i2s_bytes_written;
#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)
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return !!i2s.write((int32_t)s32, false);
#endif
}
@@ -256,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++)
{
@@ -265,6 +343,8 @@ void AudioOutputI2S::flush()
delay(10);
}
}
#elif defined(ARDUINO_ARCH_RP2040)
i2s.flush();
#endif
}
@@ -275,6 +355,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;
}
+19 -9
View File
@@ -18,17 +18,27 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOOUTPUTI2S_H
#define _AUDIOOUTPUTI2S_H
#pragma once
#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);
virtual ~AudioOutputI2S() override;
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;
virtual bool SetChannels(int channels) override;
@@ -37,11 +47,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 };
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
protected:
bool SetPinout();
@@ -49,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;
@@ -59,7 +68,8 @@ class AudioOutputI2S : public AudioOutput
uint8_t bclkPin;
uint8_t wclkPin;
uint8_t doutPin;
};
#if defined(ARDUINO_ARCH_RP2040)
I2S i2s;
#endif
};
+35 -4
View File
@@ -21,22 +21,46 @@
#include <Arduino.h>
#ifdef ESP32
#include "driver/i2s.h"
#else
#elif defined(ARDUINO_ARCH_RP2040) || ARDUINO_ESP8266_MAJOR >= 3
#include <I2S.h>
#elif ARDUINO_ESP8266_MAJOR < 3
#include <i2s.h>
#endif
#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);
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
}
#endif
AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC()
{
@@ -95,14 +119,21 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
// Either send complete pulse stream or nothing
#ifdef ESP32
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){
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)
for (int i = 0; i < oversample / 32; i++) {
i2s.write((int32_t)dsBuff[i], true);
}
#endif
return true;
}
+10 -5
View File
@@ -18,15 +18,23 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOOUTPUTI2SNODAC_H
#define _AUDIOOUTPUTI2SNODAC_H
#pragma once
#include "AudioOutputI2S.h"
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;
@@ -42,6 +50,3 @@ class AudioOutputI2SNoDAC : public AudioOutputI2S
fixed24p8_t lastSamp; // Last sample value
fixed24p8_t cumErr; // Running cumulative error since time began
};
#endif
+16 -4
View File
@@ -3,7 +3,7 @@
S/PDIF output via I2S
Needs transciever from CMOS level to either optical or coaxial interface
Needs transceiver from CMOS level to either optical or coaxial interface
See: https://www.epanorama.net/documents/audio/spdif.html
Original idea and sources:
@@ -37,6 +37,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(ESP32) || defined(ESP8266)
#include <Arduino.h>
#if defined(ESP32)
@@ -93,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"));
@@ -142,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,
@@ -264,7 +274,7 @@ bool AudioOutputSPDIF::ConsumeSample(int16_t sample[2])
#if defined(ESP32)
// Assume DMA buffers are multiples of 16 bytes. Either we write all bytes or none.
uint32_t bytes_written;
size_t bytes_written;
esp_err_t ret = i2s_write((i2s_port_t)portNo, (const char*)&buf, 8 * channels, &bytes_written, 0);
// If we didn't write all bytes, return false early and do not increment frame_num
if ((ret != ESP_OK) || (bytes_written != (8 * channels))) return false;
@@ -286,3 +296,5 @@ bool AudioOutputSPDIF::stop()
frame_num = 0;
return true;
}
#endif
+3 -3
View File
@@ -3,7 +3,7 @@
S/PDIF output via I2S
Needs transciever from CMOS level to either optical or coaxial interface
Needs transceiver from CMOS level to either optical or coaxial interface
See: https://www.epanorama.net/documents/audio/spdif.html
Original idea and sources:
@@ -30,8 +30,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOOUTPUTSPDIF_H
#define _AUDIOOUTPUTSPDIF_H
#if defined(ESP32) || defined(ESP8266)
#pragma once
#include "AudioOutput.h"
+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
+5
View File
@@ -54,6 +54,11 @@ bool AudioOutputSTDIO::begin()
bool AudioOutputSTDIO::ConsumeSample(int16_t sample[2])
{
static int avail = 100;
if (!(--avail)) {
avail = 100;
return false;
}
for (int i=0; i<channels; i++) {
if (bps == 8) {
uint8_t l = sample[i] & 0xff;
+1 -1
View File
@@ -18,7 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef ESP32
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#include "AudioOutputULP.h"
#include <esp32/ulp.h>
+4 -4
View File
@@ -3,7 +3,7 @@
ESP8266Audio I2S Minimal driver
Most of this code is taken and reworked from ESP8266 Arduino core,
which itsef is reworked from Espessif's I2S examples.
which itself is reworked from Espessif's I2S examples.
Original code is licensed under LGPL 2.1 or above
Reasons for rewrite:
@@ -196,7 +196,7 @@ void SinglePinI2SDriver::setDividers(uint8_t div1, uint8_t div2)
// Ensure dividers fit in bit fields
div1 &= I2SBDM;
div2 &= I2SCDM;
// trans master(active low), recv master(active_low), !bits mod(==16 bits/chanel), clear clock dividers
// trans master(active low), recv master(active_low), !bits mod(==16 bits/channel), clear clock dividers
I2SC &= ~(I2STSM | I2SRSM | (I2SBMM << I2SBM) | (I2SBDM << I2SBD) | (I2SCDM << I2SCD));
// I2SRF = Send/recv right channel first
// I2SMR = MSB recv/xmit first
@@ -249,7 +249,7 @@ void SinglePinI2SDriver::startI2S()
I2SFC |= I2SDE; // Enable DMA
// I2STXCMM, I2SRXCMM=0 => Dual channel mode, RX/TX CHAN_MOD=0
I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM));
// Set dividers to something resonable
// Set dividers to something reasonable
currentRate = 0;
setRate(44100);
// Start I2S peripheral
@@ -280,4 +280,4 @@ int SinglePinI2SDriver::getUnderflowCount()
// Global instance
SinglePinI2SDriver I2SDriver;
#endif // defined(ESP8266)
#endif // defined(ESP8266)
+1 -1
View File
@@ -31,7 +31,7 @@
*/
//#ifdef HAVE_CONFIG_H
# include <config.h>
# include "config.h"
//#endif
#include "private/cpu.h"
+8 -8
View File
@@ -2199,14 +2199,14 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
* Three kinds of things can go wrong when reading the frame header:
* 1) We may have sync'ed incorrectly and not landed on a frame header.
* If we don't find a sync code, it can end up looking like we read
* a valid but unparseable header, until getting to the frame header
* a valid but unparsable header, until getting to the frame header
* CRC. Even then we could get a false positive on the CRC.
* 2) We may have sync'ed correctly but on an unparseable frame (from a
* 2) We may have sync'ed correctly but on an unparsable frame (from a
* future encoder).
* 3) We may be on a damaged frame which appears valid but unparseable.
* 3) We may be on a damaged frame which appears valid but unparsable.
*
* For all these reasons, we try and read a complete frame header as
* long as it seems valid, even if unparseable, up until the frame
* long as it seems valid, even if unparsable, up until the frame
* header CRC.
*/
@@ -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;
}
@@ -2839,7 +2839,7 @@ FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
* FLAC__STREAM_DECODER_UNPARSEABLE_STREAM and increment its
* unparseable_frame_count. But there is a remote possibility
* that it is properly synced at such a "future-codec frame",
* so to make sure, we wait to see many "unparseable" errors in
* so to make sure, we wait to see many "unparsable" errors in
* a row before bailing out.
*/
if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
@@ -3146,7 +3146,7 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
return false;
}
/* Now we need to get a frame. First we need to reset our
* unparseable_frame_count; if we get too many unparseable
* unparseable_frame_count; if we get too many unparsable
* frames in a row, the read callback will return
* FLAC__STREAM_DECODER_READ_STATUS_ABORT, causing
* FLAC__stream_decoder_process_single() to return false.
+3 -3
View File
@@ -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)
{
@@ -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
+1
View File
@@ -44,6 +44,7 @@
**************************************************************************************/
#if defined(USE_DEFAULT_STDLIB) || defined(ARDUINO)
#include <stdio.h>
#include <stdlib.h>
#else
#include "hlxclib/stdlib.h"
+2 -2
View File
@@ -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
+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 -1
View File
@@ -201,7 +201,7 @@ and 3, above.
4.2 Compatible Source Licenses. Software modules that have been independently
developed without any use of Covered Code and which contain no portion of the
Covered Code, Modifications or other Derivative Works, but are used or combined
in any way wtih the Covered Code or any Derivative Work to form a larger
in any way with the Covered Code or any Derivative Work to form a larger
Derivative Work, are exempt from the conditions described in Section 4.1 but
only to the extent that: the software module, including any software that is
linked to, integrated with, or part of the same applications as, the software
+4 -4
View File
@@ -40,7 +40,7 @@
*
* assembly.h - assembly language functions and prototypes for supported platforms
*
* - inline rountines with access to 64-bit multiply results
* - inline routines with access to 64-bit multiply results
* - x86 (_WIN32) and ARM (ARM_ADS, _WIN32_WCE) versions included
* - some inline functions are mix of asm and C for speed
* - some functions are in native asm files, so only the prototype is given here
@@ -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)
{
@@ -241,7 +241,7 @@ static __inline int MULSHIFT32(int x, int y)
static __inline int FASTABS(int x)
{
int t=0; /*Really is not necessary to initialiaze only to avoid warning*/
int t=0; /*Really is not necessary to initialize only to avoid warning*/
__asm {
eor t, x, x, asr #31
@@ -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)
+1 -1
View File
@@ -74,7 +74,7 @@ static const char SFLenTab[16][2] = {
* Return: none
*
* Notes: set order of short blocks to s[band][window] instead of s[window][band]
* so that we index through consectutive memory locations when unpacking
* so that we index through consecutive memory locations when unpacking
* (make sure dequantizer follows same convention)
* Illegal Intensity Position = 7 (always) for MPEG1 scale factors
**************************************************************************************/
+1
View File
@@ -20,6 +20,7 @@
*/
#pragma GCC optimize ("O3")
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#include <pgmspace.h>
# include "config.h"
+2 -2
View File
@@ -7,7 +7,7 @@
Ogg project codecs use the Ogg bitstream format to arrange the raw,
compressed bitstream into a more robust, useful form. For example,
the Ogg bitstream makes seeking, time stamping and error recovery
possible, as well as mixing several sepearate, concurrent media
possible, as well as mixing several separate, concurrent media
streams into a single physical bitstream.
## What's here ##
@@ -18,7 +18,7 @@ use with Ogg bitstreams.
Directory:
- `src` The source for libogg, a BSD-license inplementation of the public domain Ogg bitstream format
- `src` The source for libogg, a BSD-license implementation of the public domain Ogg bitstream format
- `include` Library API headers
+2 -1
View File
@@ -482,7 +482,7 @@ static int celt_plc_pitch_search(celt_sig *decode_mem[2], int C, int arch)
int pitch_index;
VARDECL( opus_val16, lp_pitch_buf );
SAVE_STACK;
ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 );
opus_val16 *lp_pitch_buf = (opus_val16*)malloc((DECODE_BUFFER_SIZE>>1) * sizeof(opus_val16)); //ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 );
pitch_downsample(decode_mem, lp_pitch_buf,
DECODE_BUFFER_SIZE, C, arch);
pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX>>1), lp_pitch_buf,
@@ -490,6 +490,7 @@ static int celt_plc_pitch_search(celt_sig *decode_mem[2], int C, int arch)
PLC_PITCH_LAG_MAX-PLC_PITCH_LAG_MIN, &pitch_index, arch);
pitch_index = PLC_PITCH_LAG_MAX-pitch_index;
RESTORE_STACK;
free(lp_pitch_buf);
return pitch_index;
}
+2
View File
@@ -206,3 +206,5 @@
# define _Restrict
# define __restrict__
#endif
#include <stdlib.h>
+48 -23
View File
@@ -239,21 +239,30 @@ opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus
int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
{
OpusRepacketizer rp;
OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer));
opus_int32 ret;
if (len < 1)
if (len < 1) {
free(rp);
return OPUS_BAD_ARG;
if (len==new_len)
}
if (len==new_len) {
free(rp);
return OPUS_OK;
else if (len > new_len)
}
else if (len > new_len) {
free(rp);
return OPUS_BAD_ARG;
opus_repacketizer_init(&rp);
}
opus_repacketizer_init(rp);
/* Moving payload to the end of the packet so we can do in-place padding */
OPUS_MOVE(data+new_len-len, data, len);
ret = opus_repacketizer_cat(&rp, data+new_len-len, len);
if (ret != OPUS_OK)
ret = opus_repacketizer_cat(rp, data+new_len-len, len);
if (ret != OPUS_OK) {
free(rp);
return ret;
ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, new_len, 0, 1);
}
ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, new_len, 0, 1);
free(rp);
if (ret > 0)
return OPUS_OK;
else
@@ -262,15 +271,20 @@ int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len)
{
OpusRepacketizer rp;
OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer));
opus_int32 ret;
if (len < 1)
if (len < 1) {
free(rp);
return OPUS_BAD_ARG;
opus_repacketizer_init(&rp);
ret = opus_repacketizer_cat(&rp, data, len);
if (ret < 0)
}
opus_repacketizer_init(rp);
ret = opus_repacketizer_cat(rp, data, len);
if (ret < 0) {
free(rp);
return ret;
ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, len, 0, 0);
}
ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, len, 0, 0);
free(rp);
celt_assert(ret > 0 && ret <= len);
return ret;
}
@@ -312,12 +326,14 @@ opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, in
unsigned char toc;
opus_int16 size[48];
opus_int32 packet_offset;
OpusRepacketizer rp;
OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer));
unsigned char *dst;
opus_int32 dst_len;
if (len < 1)
if (len < 1){
free(rp);
return OPUS_BAD_ARG;
}
dst = data;
dst_len = 0;
/* Unpad all frames */
@@ -325,25 +341,34 @@ opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, in
{
opus_int32 ret;
int self_delimited = s!=nb_streams-1;
if (len<=0)
if (len<=0) {
free(rp);
return OPUS_INVALID_PACKET;
opus_repacketizer_init(&rp);
}
opus_repacketizer_init(rp);
ret = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL,
size, NULL, &packet_offset);
if (ret<0)
if (ret<0) {
free(rp);
return ret;
ret = opus_repacketizer_cat_impl(&rp, data, packet_offset, self_delimited);
if (ret < 0)
}
ret = opus_repacketizer_cat_impl(rp, data, packet_offset, self_delimited);
if (ret < 0) {
free(rp);
return ret;
ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, dst, len, self_delimited, 0);
if (ret < 0)
}
ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, dst, len, self_delimited, 0);
if (ret < 0) {
free(rp);
return ret;
}
else
dst_len += ret;
dst += ret;
data += packet_offset;
len -= packet_offset;
}
free(rp);
return dst_len;
}
+8 -3
View File
@@ -80,10 +80,11 @@ void silk_NLSF2A(
};
const unsigned char *ordering;
opus_int k, i, dd;
opus_int32 cos_LSF_QA[ SILK_MAX_ORDER_LPC ];
opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ];
opus_int32 *cos_LSF_QA = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC );
opus_int32 *P = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC / 2 + 1));
opus_int32 *Q= (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC / 2 + 1));
opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta;
opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ];
opus_int32 *a32_QA1 = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC );
silk_assert( LSF_COS_TAB_SZ_FIX == 128 );
celt_assert( d==10 || d==16 );
@@ -137,5 +138,9 @@ void silk_NLSF2A(
a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */
}
}
free(cos_LSF_QA);
free(P);
free(Q);
free(a32_QA1);
}
+12 -6
View File
@@ -57,12 +57,12 @@ void silk_burg_modified_c(
opus_int k, n, s, lz, rshifts, reached_max_gain;
opus_int32 C0, num, nrg, rc_Q31, invGain_Q30, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2;
const opus_int16 *x_ptr;
opus_int32 C_first_row[ SILK_MAX_ORDER_LPC ];
opus_int32 C_last_row[ SILK_MAX_ORDER_LPC ];
opus_int32 Af_QA[ SILK_MAX_ORDER_LPC ];
opus_int32 CAf[ SILK_MAX_ORDER_LPC + 1 ];
opus_int32 CAb[ SILK_MAX_ORDER_LPC + 1 ];
opus_int32 xcorr[ SILK_MAX_ORDER_LPC ];
opus_int32 *C_first_row = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC);
opus_int32 *C_last_row = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC);
opus_int32 *Af_QA = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC);
opus_int32 *CAf = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC+1));
opus_int32 *CAb = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC+1));
opus_int32 *xcorr = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC);
opus_int64 C0_64;
celt_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE );
@@ -277,4 +277,10 @@ void silk_burg_modified_c(
*res_nrg = silk_SMLAWW( nrg, silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32 ), C0 ), -tmp1 );/* Q( -rshifts ) */
*res_nrg_Q = -rshifts;
}
free(C_first_row);
free(C_last_row);
free(Af_QA);
free(CAf);
free(CAb);
free(xcorr);
}
@@ -49,8 +49,8 @@ void silk_warped_autocorrelation_FIX_c(
{
opus_int n, i, lsh;
opus_int32 tmp1_QS, tmp2_QS;
opus_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
opus_int64 corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
opus_int32 *state_QS = (opus_int32*)calloc(MAX_SHAPE_LPC_ORDER + 1, sizeof(opus_int32));
opus_int64 *corr_QC = (opus_int64*)calloc(MAX_SHAPE_LPC_ORDER + 1, sizeof(opus_int64));
/* Order must be even */
celt_assert( ( order & 1 ) == 0 );
@@ -88,5 +88,7 @@ void silk_warped_autocorrelation_FIX_c(
}
}
silk_assert( corr_QC[ 0 ] >= 0 ); /* If breaking, decrease QC*/
free(state_QS);
free(corr_QC);
}
#endif /* OVERRIDE_silk_warped_autocorrelation_FIX_c */
+3 -1
View File
@@ -48,7 +48,8 @@ void silk_resampler_down2_3(
opus_int32 *buf_ptr;
SAVE_STACK;
ALLOC( buf, RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR, opus_int32 );
// ALLOC( buf, RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR, opus_int32 );
opus_int32 *buf = (opus_int32*)malloc((RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR) * sizeof(opus_int32));
/* Copy buffered samples to start of buffer */
silk_memcpy( buf, S, ORDER_FIR * sizeof( opus_int32 ) );
@@ -99,5 +100,6 @@ void silk_resampler_down2_3(
/* Copy last part of filtered signal to the state for the next call */
silk_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( opus_int32 ) );
free(buf);
RESTORE_STACK;
}
+1 -1
View File
@@ -28,7 +28,7 @@ Even with the caching, it was found that SPIFFS, while having great
functionality, was horrbly slow. So I wrote a new "faster" ROM filesystem
called, surprisingly, FastROMFilesystem.
https://github.com/earlephilhower/ESP8266FastROMFS
If you are getting choppy playback, try this new filesytem or using a SD
If you are getting choppy playback, try this new filesystem or using a SD
card (not tested by myself, but it'd be hard top be slower than SPIFFS).
Simply going from SPIFFS to FastROMFilesystem took my testing of
FURELISE.MID and 1MGM.SF2 from 0.5x realtime to 2.5x (i.e. from unusable
+2 -2
View File
@@ -104,7 +104,7 @@ TSFDEF tsf* tsf_load(struct tsf_stream* stream);
// Free the memory related to this tsf instance
TSFDEF void tsf_close(tsf* f);
// Stop all playing notes immediatly and reset all channel parameters
// Stop all playing notes immediately and reset all channel parameters
TSFDEF void tsf_reset(tsf* f);
// Returns the preset index from a bank and preset number, or -1 if it does not exist in the loaded SoundFont
@@ -201,7 +201,7 @@ TSFDEF void tsf_channel_set_tuning(tsf* f, int channel, float tuning);
TSFDEF void tsf_channel_note_on(tsf* f, int channel, int key, float vel);
TSFDEF void tsf_channel_note_off(tsf* f, int channel, int key);
TSFDEF void tsf_channel_note_off_all(tsf* f, int channel); //end with sustain and release
TSFDEF void tsf_channel_sounds_off_all(tsf* f, int channel); //end immediatly
TSFDEF void tsf_channel_sounds_off_all(tsf* f, int channel); //end immediately
// Apply a MIDI control change to the channel (not all controllers are supported!)
TSFDEF void tsf_channel_midi_control(tsf* f, int channel, int controller, int control_value);
+41 -26
View File
@@ -90,12 +90,12 @@ int op_test(OpusHead *_head,
ogg_sync_init(&oy);
data=ogg_sync_buffer(&oy,(long)_initial_bytes);
if(data!=NULL){
ogg_stream_state os;
ogg_stream_state *os = (ogg_stream_state*)malloc(sizeof(ogg_stream_state));
ogg_page og;
int ret;
memcpy(data,_initial_data,_initial_bytes);
ogg_sync_wrote(&oy,(long)_initial_bytes);
ogg_stream_init(&os,-1);
ogg_stream_init(os,-1);
err=OP_FALSE;
do{
ogg_packet op;
@@ -104,11 +104,11 @@ int op_test(OpusHead *_head,
if(ret<0)continue;
/*Stop if we run out of data.*/
if(!ret)break;
ogg_stream_reset_serialno(&os,ogg_page_serialno(&og));
ogg_stream_pagein(&os,&og);
ogg_stream_reset_serialno(os,ogg_page_serialno(&og));
ogg_stream_pagein(os,&og);
/*Only process the first packet on this page (if it's a BOS packet,
it's required to be the only one).*/
if(ogg_stream_packetout(&os,&op)==1){
if(ogg_stream_packetout(os,&op)==1){
if(op.b_o_s){
ret=opus_head_parse(_head,op.packet,op.bytes);
/*If this didn't look like Opus, keep going.*/
@@ -122,7 +122,8 @@ int op_test(OpusHead *_head,
}
}
while(err==OP_FALSE);
ogg_stream_clear(&os);
ogg_stream_clear(os);
free(os);
}
else err=OP_EFAULT;
ogg_sync_clear(&oy);
@@ -835,7 +836,7 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
ogg_int64_t cur_page_gp;
ogg_uint32_t serialno;
opus_int32 total_duration;
int durations[255];
int *durations = (int*)malloc(255 * sizeof(int));
int cur_page_eos;
int op_count;
int pi;
@@ -852,26 +853,31 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
Otherwise there are no audio data packets in the whole logical stream.*/
if(OP_UNLIKELY(page_offset<0)){
/*Fail if there was a read error.*/
if(page_offset<OP_FALSE)return (int)page_offset;
if(page_offset<OP_FALSE) { free(durations); return (int)page_offset; }
/*Fail if the pre-skip is non-zero, since it's asking us to skip more
samples than exist.*/
if(_link->head.pre_skip>0)return OP_EBADTIMESTAMP;
if(_link->head.pre_skip>0) {free(durations); return OP_EBADTIMESTAMP;}
_link->pcm_file_offset=0;
/*Set pcm_end and end_offset so we can skip the call to
op_find_final_pcm_offset().*/
_link->pcm_start=_link->pcm_end=0;
_link->end_offset=_link->data_offset;
free(durations);
return 0;
}
/*Similarly, if we hit the next link in the chain, we've gone too far.*/
if(OP_UNLIKELY(ogg_page_bos(_og))){
if(_link->head.pre_skip>0)return OP_EBADTIMESTAMP;
if(_link->head.pre_skip>0) {
free(durations);
return OP_EBADTIMESTAMP;
}
/*Set pcm_end and end_offset so we can skip the call to
op_find_final_pcm_offset().*/
_link->pcm_file_offset=0;
_link->pcm_start=_link->pcm_end=0;
_link->end_offset=_link->data_offset;
/*Tell the caller we've got a buffered page for them.*/
free(durations);
return 1;
}
/*Ignore pages from other streams (not strictly necessary, because of the
@@ -901,7 +907,10 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
cur_page_gp=_of->op[op_count-1].granulepos;
/*But getting a packet without a valid granule position on the page is not
okay.*/
if(cur_page_gp==-1)return OP_EBADTIMESTAMP;
if(cur_page_gp==-1) {
free(durations);
return OP_EBADTIMESTAMP;
}
cur_page_eos=_of->op[op_count-1].e_o_s;
if(OP_LIKELY(!cur_page_eos)){
/*The EOS flag wasn't set.
@@ -910,6 +919,7 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
if(OP_UNLIKELY(op_granpos_add(&pcm_start,cur_page_gp,-total_duration)<0)){
/*The starting granule position MUST not be smaller than the amount of
audio on the first page with completed packets.*/
free(durations);
return OP_EBADTIMESTAMP;
}
}
@@ -923,6 +933,7 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
/*However, the end-trimming MUST not ask us to trim more samples than
exist after applying the pre-skip.*/
if(OP_UNLIKELY(op_granpos_cmp(cur_page_gp,_link->head.pre_skip)<0)){
free(durations);
return OP_EBADTIMESTAMP;
}
}
@@ -957,6 +968,7 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
_link->pcm_file_offset=0;
_of->prev_packet_gp=_link->pcm_start=pcm_start;
_of->prev_page_offset=page_offset;
free(durations);
return 0;
}
@@ -1391,32 +1403,34 @@ static int op_open_seekable2_impl(OggOpusFile *_of){
/*64 seek records should be enough for anybody.
Actually, with a bisection search in a 63-bit range down to OP_CHUNK_SIZE
granularity, much more than enough.*/
OpusSeekRecord sr[64];
OpusSeekRecord *sr = (OpusSeekRecord*)malloc(64 * sizeof(OpusSeekRecord));
opus_int64 data_offset;
int ret;
/*We can seek, so set out learning all about this file.*/
(*_of->callbacks.seek)(_of->stream,0,SEEK_END);
_of->offset=_of->end=(*_of->callbacks.tell)(_of->stream);
if(OP_UNLIKELY(_of->end<0))return OP_EREAD;
if(OP_UNLIKELY(_of->end<0)){free(sr); return OP_EREAD;}
data_offset=_of->links[0].data_offset;
if(OP_UNLIKELY(_of->end<data_offset))return OP_EBADLINK;
if(OP_UNLIKELY(_of->end<data_offset)){ free(sr); return OP_EBADLINK;}
/*Get the offset of the last page of the physical bitstream, or, if we're
lucky, the last Opus page of the first link, as most Ogg Opus files will
contain a single logical bitstream.*/
ret=op_get_prev_page_serial(_of,sr,_of->end,
_of->links[0].serialno,_of->serialnos,_of->nserialnos);
if(OP_UNLIKELY(ret<0))return ret;
if(OP_UNLIKELY(ret<0)){free(sr); return ret;}
/*If there's any trailing junk, forget about it.*/
_of->end=sr[0].offset+sr[0].size;
if(OP_UNLIKELY(_of->end<data_offset))return OP_EBADLINK;
if(OP_UNLIKELY(_of->end<data_offset)){free(sr); return OP_EBADLINK;}
/*Now enumerate the bitstream structure.*/
return 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;
}
static int op_open_seekable2(OggOpusFile *_of){
ogg_sync_state oy_start;
ogg_stream_state os_start;
ogg_stream_state *os_start = (ogg_stream_state*)malloc(sizeof(ogg_stream_state));
ogg_packet *op_start;
opus_int64 prev_page_offset;
opus_int64 start_offset;
@@ -1435,9 +1449,9 @@ static int op_open_seekable2(OggOpusFile *_of){
start_op_count=_of->op_count;
/*This is a bit too large to put on the stack unconditionally.*/
op_start=(ogg_packet *)_ogg_malloc(sizeof(*op_start)*start_op_count);
if(op_start==NULL)return OP_EFAULT;
if(op_start==NULL){free(os_start); return OP_EFAULT;}
*&oy_start=_of->oy;
*&os_start=_of->os;
*os_start=_of->os;
prev_page_offset=_of->prev_page_offset;
start_offset=_of->offset;
memcpy(op_start,_of->op,sizeof(*op_start)*start_op_count);
@@ -1449,7 +1463,7 @@ static int op_open_seekable2(OggOpusFile *_of){
ogg_stream_clear(&_of->os);
ogg_sync_clear(&_of->oy);
*&_of->oy=*&oy_start;
*&_of->os=*&os_start;
*&_of->os=*os_start;
_of->offset=start_offset;
_of->op_count=start_op_count;
memcpy(_of->op,op_start,sizeof(*_of->op)*start_op_count);
@@ -1457,9 +1471,10 @@ static int op_open_seekable2(OggOpusFile *_of){
_of->prev_packet_gp=_of->links[0].pcm_start;
_of->prev_page_offset=prev_page_offset;
_of->cur_discard_count=_of->links[0].head.pre_skip;
if(OP_UNLIKELY(ret<0))return ret;
if(OP_UNLIKELY(ret<0)){free(os_start); return ret;}
/*And restore the position indicator.*/
ret=(*_of->callbacks.seek)(_of->stream,op_position(_of),SEEK_SET);
free(os_start);
return OP_UNLIKELY(ret<0)?OP_EREAD:0;
}
@@ -1980,7 +1995,7 @@ static int op_fetch_and_process_page(OggOpusFile *_of,
ogg_stream_pagein(&_of->os,&og);
if(OP_LIKELY(_of->ready_state>=OP_INITSET)){
opus_int32 total_duration;
int durations[255];
int *durations = (int*)malloc(255 * sizeof(int));
int op_count;
int report_hole;
report_hole=0;
@@ -2037,7 +2052,7 @@ static int op_fetch_and_process_page(OggOpusFile *_of,
Proceed to the next link, rather than risk playing back some
samples that shouldn't have been played.*/
_of->op_count=0;
if(report_hole)return OP_HOLE;
if(report_hole){ free(durations); return OP_HOLE; }
continue;
}
/*By default discard 80 ms of data after a seek, unless we seek
@@ -2145,9 +2160,9 @@ static int op_fetch_and_process_page(OggOpusFile *_of,
_of->prev_page_offset=_page_offset;
_of->op_count=op_count=pi;
}
if(report_hole)return OP_HOLE;
if(report_hole) { free(durations); return OP_HOLE; }
/*If end-trimming didn't trim all the packets, we're done.*/
if(op_count>0)return 0;
if(op_count>0) { free(durations); return 0; }
}
}
}
+2 -2
View File
@@ -729,7 +729,7 @@ struct OpusServerInfo{
/**The software used by the origin server (Server).
This is <code>NULL</code> if there was no <code>Server</code> header.*/
char *server;
/**The media type of the entity sent to the recepient (Content-Type).
/**The media type of the entity sent to the recipient (Content-Type).
This is <code>NULL</code> if there was no <code>Content-Type</code>
header.*/
char *content_type;
@@ -1436,7 +1436,7 @@ void op_free(OggOpusFile *_of);
Some of these functions may be used successfully on the partially open
streams returned by op_test_callbacks() or one of the associated
convenience functions.
Their documention will indicate so explicitly.*/
Their documentation will indicate so explicitly.*/
/*@{*/
/**Returns whether or not the stream being read is seekable.
+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
+49 -120
View File
@@ -2,102 +2,19 @@
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, beacause 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
local idever='1.8.10'
local ideurl="https://downloads.arduino.cc/arduino-$idever"
wget -q -O arduino.tar.xz "${ideurl}-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-${idever} $ide_path
mv arduino-nightly $ide_path
export PATH="$ide_path:$PATH"
}
@@ -113,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
+10 -4
View File
@@ -78,12 +78,12 @@ libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/mem
../../src/libflac/bitreader.c ../../src/libflac/bitmath.c ../../src/libflac/stream_decoder.c ../../src/libflac/float.c
CCOPTS=-g -Wunused-parameter -Wall -m32 -include Arduino.h
CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -include Arduino.h
CCOPTS=-g -Wunused-parameter -Wall -m32 -include Arduino.h -Wstack-usage=300
CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -Wstack-usage=300 -include Arduino.h
.phony: all
all: mp3 aac wav midi opus flac
all: mp3 aac wav midi opus flac mod
mp3: FORCE
rm -f *.o
@@ -106,6 +106,12 @@ flac: FORCE
rm -f *.o
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./flac
mod: FORCE
rm -f *.o
g++ $(CPPOPTS) -o mod mod.cpp Serial.cpp ../../src/AudioFileSourcePROGMEM.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorMOD.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
rm -f *.o
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./mod
wav: FORCE
rm -f *.o
g++ $(CPPOPTS) -o wav wav.cpp Serial.cpp ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorWAV.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
@@ -128,6 +134,6 @@ opus: FORCE
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./opus
clean:
rm -f mp3 aac wav midi opus flac *.o
rm -f mp3 aac wav midi opus flac mod *.o
FORCE:
+26
View File
@@ -0,0 +1,26 @@
#include <Arduino.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioOutputSTDIO.h"
#include "AudioGeneratorMOD.h"
#include "../../examples/PlayMODFromPROGMEMToDAC/enigma.h"
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
AudioFileSourcePROGMEM *file = new AudioFileSourcePROGMEM(enigma_mod, sizeof(enigma_mod));
AudioOutputSTDIO *out = new AudioOutputSTDIO();
out->SetFilename("mod.wav");
AudioGeneratorMOD *mod = new AudioGeneratorMOD();
mod->begin(file, out);
// The MOD plays forever, so only run for ~30 seconds worth
for (int i=0; i<10000; i++) mod->loop();
mod->stop();
delete out;
delete mod;
delete file;
}