87 Commits
Author SHA1 Message Date
Earle F. Philhower, III 3044568f85 Update version 2024-12-31 10:30:46 -08:00
Earle F. Philhower, III 8adeb31d20 Automate version bumps, avoid manual mistakes (#725) 2024-12-31 10:30:06 -08:00
Kurt Haenenandkurt.haenen b0a06edde2 Fixing crash on MP3 playback on ESP8266. (#723)
Co-authored-by: kurt.haenen <kurt.haenen@quintux.com>
2024-12-25 13:19:16 -08:00
Earle F. Philhower, III cdd07c92c2 Only block tsf.h on Xtensa ESP32, not RISCV (#722)
Fixes #721
2024-12-19 14:33:24 -08:00
Earle F. Philhower, III aafabf2367 Ensure MP3 can safely exit on OOM (#716)
Fixes #715.  Good catch, @EternityForest
2024-12-19 09:33:01 -08:00
Earle F. Philhower, III 90b83fb95e Update README.md 2024-12-18 15:11:36 -08:00
Earle F. Philhower, III fbe69b8cd8 Fix AAC HR decode on RP2040
U64 big/little endian mismatch for ARM cores.  Remove the whole PowerPC support option as there aren't any commerically significant PPC embedded systems still being developed.
2024-12-18 14:39:07 -08:00
Earle F. Philhower, III 2f43b3b57d Update README.md 2024-10-14 17:48:14 -07:00
Earle F. Philhower, III 0e5870a440 Update library.properties
dot_a_linkage seems to cause issues with CI
2024-10-08 18:24:41 -07:00
Earle F. Philhower, III 7e50a43b4b Update README.md 2024-10-08 18:13:22 -07:00
Earle F. Philhower, III 1278b10717 Update library.properties 2024-10-08 17:51:13 -07:00
Roman Lut 52c49afbc0 NoDAC and PDM documentation update for ESP32 (#519) 2024-10-08 17:49:03 -07:00
TorrenteroandEdgar d32d8b4cc8 Performance improvement: ~13% faster on ESP32 and ~21% faster on ESP8266 (empirically tested) (#554)
* Performance improvement
- new tsf_note_on_fast returning playIndex and removing lowpass filter setup since it is not being processed in tsf_voice_render_fast anyway but is consuming a lot of cpu
- new tsf_note_off_fast using playIndex to stop voices faster
- Removing lowpass filter setup from tsf_voice_render_fast since it is not being processed
- Math tweaks trying to avoid complex math operations (specially conversions) at voice render stage
- Precalculating *F32P32 values to avoid doing them at voice render stage
* Fixing data type
* Initializing play indexes
---------
Co-authored-by: Edgar <edgar.coria@xema.tech>
2024-10-08 17:45:57 -07:00
Earle F. Philhower, III 235bcb12de Fix UTF-8 warning in RCSL doc 2024-10-08 13:59:49 -07:00
Earle F. Philhower, III a4a974363d Update Arduino Lint GH Action 2024-10-08 13:56:03 -07:00
jmr-esandRASMUSSEN Joern 96dc79c9fa AudioOutputPWM: added amplification (#605)
Co-authored-by: RASMUSSEN Joern <joern.rasmussen-ext@hexagon.com>
2024-10-08 13:50:43 -07:00
Piotr Gaczkowski 50bc3f7279 Add MCLK support for RP2040 (#707) 2024-10-06 16:54:01 -07:00
Earle F. Philhower, III 79208f6701 Fix GCC14-detected warnings (#711)
* Fix pedantic GCC14 warnings on calloc order
* Ensure AAC read-in doesn't overflow internal structures when the file is corrupted/illegal.
2024-10-06 16:53:22 -07:00
Earle F. Philhower, III a0a4a00757 Fix release numbering 2024-09-21 09:26:24 -07:00
Earle F. Philhower, III c93201483f Update pr-or-master-push.yml (#687) 2024-06-06 14:59:31 -07:00
Earle F. Philhower, III a6141473fb Update for ESP32 Arduino 3.x (#685)
Implement the renamed network client and other API changes when built
under the 3.x branch of the Arduino ESP32 core.

Disable building TSF on the ESP32, the Xtensa G++ backend bug is still there.

Minimal changes to get I2S to build under new IDF.  Deprecated but
not removed, so warnings are expected but should not be fatal in
use.

Fixes #683
2024-06-06 14:43:45 -07:00
ChuckMash b837e7d36a Stop output on OOM in MP3 (#658) 2024-04-25 17:53:07 -07:00
Infinity 51a584c2b7 Update AudioGeneratorRTTTL.cpp for dotted length (#668) 2024-04-25 17:51:42 -07:00
Earle F. Philhower, III 492a5beba4 Update GH CI actions to latest (#681) 2024-04-17 10:22:17 -07:00
Earle F. Philhower, III 89a5a07712 Get ESP32 CI builds working again (#680) 2024-04-17 10:11:03 -07:00
Earle F. Philhower, III b3c41668a2 Fix GCC12.3 new warnings for RP2040 (#679)
* Fix GCC12.3 new warnings for RP2040

* Remove OPUS encoder, not supported on embedded
2024-04-16 16:32:16 -07:00
Earle F. Philhower, III 139fba4116 Update opusfile.c (#678) 2024-04-16 15:14:14 -07:00
Earle F. Philhower, III b7d89058dd Update polyphase.c 2024-04-16 15:11:31 -07:00
Earle F. Philhower, III e306df208c Update AudioOutputSPDIF.h 2024-04-16 15:10:49 -07:00
Earle F. Philhower, III f6c0d562f8 Update AudioOutputSPDIF.cpp (#677) 2024-04-16 15:10:24 -07:00
KDM 60b93433d8 Update README.md (#675)
Corrected format to formant.
2024-04-16 14:55:52 -07:00
Nils Trubkin 0abcf71012 Add ability to SwapClocks(bool) on I2S. rp2040 only. (#639)
Fixes #638
2023-06-30 11:02:49 -07:00
Earle F. Philhower, III 12131e9826 Update README.md 2023-01-28 14:32:54 -08:00
Sylwester 4ba7df1928 Add support for I2S MCLK. (#594) 2023-01-04 09:46:05 -08:00
Earle F. Philhower, III 0b5da0e9dd Add PWMAudio support for the RP2040 (#597)
Uses the RP2040 HW PWM generator to provide a stereo audio signal.
2023-01-03 17:08:56 -08:00
lovyan03 46b36574ed fix: Invalid data is assigned to the right channel when playing a mono MP3. (#559) 2022-09-04 13:27:05 -07:00
FedericoBusero f95f15fcb3 I2S: register I2S object to platform failed (#568)
ESP32: When calling destructor after stop, and then create a new object, then an error is shown "I2S: register I2S object to platform failed" because i2s_driver_uninstall had not been called.
ESP8266 : i2s_end is not called when stopping, but i2sOn is false, resulting in new call i2s_rxtx_begin
2022-09-01 12:16:14 -07:00
Earle F. Philhower, III 72ed4f76dd Update pr-or-master-push.yml 2022-09-01 12:15:29 -07:00
Earle F. Philhower, III a323627243 Update pr-or-master-push.yml 2022-08-31 10:54:49 -07:00
刘帅 93c4e3a15a Fix build support gcc8 for other arch (#567) 2022-08-31 10:54:19 -07:00
Earle F. Philhower, III bf31f0f8be Update macros.h 2022-08-31 10:52:24 -07:00
FedericoBusero e24223e3d5 ESP32: Fix compilation of I2S in Arduino ESP32 core 1.0.6 (#565) 2022-08-24 12:49:24 -07:00
TorrenteroandEdgar 6d3b8665f4 sketch_utils.sh now uses flags and breaks current functionality (#555)
Co-authored-by: Edgar <edgar.coria@xema.tech>
2022-07-16 18:05:28 -07:00
Earle F. Philhower, III 02225bcaa9 Fix overflow with x256 oversampling in I2SNoDAC (#543)
Fixes #542
2022-06-14 08:23:22 -07:00
Earle F. Philhower, III c4bf70bccf Fix typo in README (#541)
Fixes #540
2022-06-13 08:32:18 -07:00
TorrenteroandEdgar 3b329b8201 fixed: tmpSourceSamplePositionF32P32 jumping to incorrect position causing distorted sound (#539)
Co-authored-by: Edgar <edgar.coria@xema.tech>
2022-06-10 17:57:53 -07:00
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
86 changed files with 12674 additions and 502 deletions

No files matched your search

+52 -9
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@v4
with:
submodules: true
- uses: actions/setup-python@v5
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
@@ -20,10 +43,10 @@ jobs:
matrix:
chunk: [0, 1, 2, 3, 4]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Build Sketches
@@ -36,7 +59,6 @@ jobs:
run: |
bash ./tests/common.sh
build-esp32:
name: Build ESP-32
runs-on: ubuntu-latest
@@ -44,10 +66,10 @@ jobs:
matrix:
chunk: [0, 1, 2, 3, 4]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Build Sketches
@@ -65,10 +87,10 @@ jobs:
name: Host tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Run host tests
@@ -84,12 +106,33 @@ 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
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v2
with:
library-manager: 'update'
# Validate orthography
code-spell:
name: Check spelling
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Run codespell
uses: codespell-project/actions-codespell@master
with:
skip: ./src/libmad,./src/libhelix-aac,./src/libopus,./src/libflac
ignore_words_list: ESP8266,esp8266,esp,dout,DOUT,ser,ans,inout,numer,hist
+45 -31
View File
@@ -1,37 +1,34 @@
# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040[![Gitter](https://badges.gitter.im/ESP8266Audio/community.svg)](https://gitter.im/ESP8266Audio/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi Pico RP2040 and Pico 2 RP2350 [![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.
# Raspberry Pi Pico (RP2040 and RP2350) Users
Consider using [BackgroundAudio](https://github.com/earlephilhower/BackgroundAudio) instead of this library as it can provide a simpler usage model and better results and performance on the Pico by using an interrupt-based, frame-aligned output model.
# ESP8266 and ESP32 Users
ESP8266 is fully supported and most mature, but ESP32 is also mostly there with built-in DAC as well as external ones.
For real-time, autonomous speech synthesis, check out [ESP8266SAM](https://github.com/earlephilhower/ESP8266SAM), a library which uses this one and a port of an ancient format-based synthesis program to allow your ESP8266 to talk with low memory and no network required.
For real-time, autonomous speech synthesis, check out [ESP8266SAM](https://github.com/earlephilhower/ESP8266SAM), a library which uses this one and a port of an ancient formant-based synthesis program to allow your ESP8266 to talk with low memory and no network required.
## Disclaimer
All this code is released under the GPL, and all of it is to be used at your own risk. If you find any bugs, please let me know via the GitHub issue tracker or drop me an email. The MOD and MP3 routines were taken from StellaPlayer and libMAD respectively. The software I2S delta-sigma 32x oversampling DAC was my own creation, and sounds quite good if I do say so myself.
All this code is released under the GPL, and all of it is to be used at your own risk. If you find any bugs, please let me know via the GitHub issue tracker or drop me an email.
The AAC decode code is from the Helix project and licensed under RealNetwork's RSPL license. For commercial use you're still going to need the usual AAC licensing from [Via Licensing](http://www.via-corp.com/us/en/licensing/aac/overview.html).
On the ESP32, AAC-SBR is supported (many webradio stations use this to reduce bandwidth even further). The ESP8266, however, does not support it due to a lack of onboard RAM.
MIDI decoding comes from a highly ported [MIDITONES](https://github.com/LenShustek/miditones) combined with a massively memory-optimized [TinySoundFont](https://github.com/schellingb/TinySoundFont), see the respective source files for more information.
Opus, OGG, and OpusFile are from [Xiph.org](https://xiph.org) with the Xiph license and patent described in src/{opusfile,libggg,libopus}/COPYING.. **NOTE** Opus decoding currently only works on the ESP32 due to the large memory requirements of opusfile. PRs to rewrite it to be less memory intensive would be much appreciated.
* The MOD and MP3 routines were taken from StellarPlayer and libMAD respectively.
* The software I2S delta-sigma 32x oversampling DAC was my own creation, and sounds quite good if I do say so myself.
* The AAC decode code is from the Helix project and licensed under RealNetwork's RSPL license. For commercial use you're still going to need the usual AAC licensing from [Via Licensing](http://www.via-corp.com/us/en/licensing/aac/overview.html). On the ESP32, AAC-SBR is supported (many webradio stations use this to reduce bandwidth even further). The ESP8266, however, does not support it due to a lack of onboard RAM.
* MIDI decoding comes from a highly ported [MIDITONES](https://github.com/LenShustek/miditones) combined with a massively memory-optimized [TinySoundFont](https://github.com/schellingb/TinySoundFont), see the respective source files for more information.
* Opus, OGG, and OpusFile are from [Xiph.org](https://xiph.org) with the Xiph license and patent described in src/{opusfile,libggg,libopus}/COPYING.. **NOTE** Opus decoding currently only works on the ESP32 due to the large memory requirements of opusfile. PRs to rewrite it to be less memory intensive would be much appreciated.
## Neat Things People Have Done With ESP8266Audio
If you have a neat use for this library, [I'd love to hear about it](mailto:earlephilhower@yahoo.com)!
My personal use of the ESP8266Audio library is only to drive a 3D-printed, network-time-setting alarm clock for my kids which can play an MP3 instead of a bell to wake them up, called [Psychoclock](https://github.com/earlephilhower/psychoclock).
Harald Sattler has built a neat German [word clock with MP3 alarm](http://www.harald-sattler.de/html/mini-wecker.htm). Detailed discussion on the process and models are included.
Erich Heinemann has developed a Stomper (instrument for playing samples in real-time during a live stage performance) that you can find more info about [here](https://github.com/ErichHeinemann/hman-stomper).
Dagnall53 has integrated this into a really neat MQTT based model train controller to add sounds to his set. More info is available [here](https://github.com/dagnall53/ESPMQTTRocnetSound), including STL files for 3D printed components!
JohannesMTC has built a similar project especially for model trains: https://github.com/JohannesMTC/ESP32_MAS
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
* My personal use of the ESP8266Audio library is only to drive a 3D-printed, network-time-setting alarm clock for my kids which can play an MP3 instead of a bell to wake them up, called [Psychoclock](https://github.com/earlephilhower/psychoclock).
* Harald Sattler has built a neat German [word clock with MP3 alarm](http://www.harald-sattler.de/html/mini-wecker.htm). Detailed discussion on the process and models are included.
* Erich Heinemann has developed a Stomper (instrument for playing samples in real-time during a live stage performance) that you can find more info about [here](https://github.com/ErichHeinemann/hman-stomper).
* Dagnall53 has integrated this into a really neat MQTT based model train controller to add sounds to his set. More info is available [here](https://github.com/dagnall53/ESPMQTTRocnetSound), including STL files for 3D printed components!
* JohannesMTC has built a similar project especially for model trains: https://github.com/JohannesMTC/ESP32_MAS
* 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 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 +97,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
@@ -145,7 +142,7 @@ AudioGeneratorRTTTL: Enjoy the pleasures of monophonic, 4-octave ringtones on y
## AudioOutput classes
AudioOutput: Base class for all output drivers. Takes a sample at a time and returns true/false if there is buffer space for it. If it returns false, it is the calling object's (AudioGenerator's) job to keep the data that didn't fit and try again later.
AudioOutputI2S: Interface for any I2S 16-bit DAC. Sends stereo or mono signals out at whatever frequency set. Tested with Adafruit's I2SDAC and a Beyond9032 DAC from eBay. Tested up to 44.1KHz. To use the internal DAC on ESP32, instantiate this class as `AudioOutputI2S(0,1)`, see example `PlayMODFromPROGMEMToDAC` and code in [AudioOutputI2S.cpp](src/AudioOutputI2S.cpp#L29) for details.
AudioOutputI2S: Interface for any I2S 16-bit DAC. Sends stereo or mono signals out at whatever frequency set. Tested with Adafruit's I2SDAC and a Beyond9032 DAC from eBay. Tested up to 44.1KHz. To use the internal DAC on ESP32, instantiate this class as `AudioOutputI2S(0,AudioOutputI2S::INTERNAL_DAC)`, see example `PlayMODFromPROGMEMToDAC` and code in [AudioOutputI2S.cpp](src/AudioOutputI2S.cpp#L29) for details. To use the hardware Pulse Density Modulation (PDM) on ESP32, instantiate this class as `AudioOutputI2S(0,AudioOutputI2S::INTERNAL_PDM)`. For both later cases, default output pins are GPIO25 and GPIO26.
AudioOutputI2SNoDAC: Abuses the I2S interface to play music without a DAC. Turns it into a 32x (or higher) oversampling delta-sigma DAC. Use the schematic below to drive a speaker or headphone from the I2STx pin (i.e. Rx). Note that with this interface, depending on the transistor used, you may need to disconnect the Rx pin from the driver to perform serial uploads. Mono-only output, of course.
@@ -158,7 +155,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 +176,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!
@@ -189,7 +194,8 @@ Use the `AudioOutputI2S*No*DAC` object instead of the `AudioOutputI2S` in your c
ESP8266-GND ------------------+ | +------+ K|
| | | E|
ESP8266-I2SOUT (Rx) -----/\/\/\--+ | \ R|
| +-|
or ESP32 DOUT pin | +-|
|
USB 5V -----------------------------+
You may also want to add a 220uF cap from USB5V to GND just to help filter out any voltage droop during high volume playback.
@@ -202,11 +208,18 @@ ESP8266-RX(I2S tx) -- Resistor (~1K ohm, not critical) -- 2N3904 Base
ESP8266-GND -- 2N3904 Emitter
USB-5V -- Speaker + Terminal
2N3904-Collector -- Speaker - Terminal
*For ESP32, default output pin is GPIO22. Note that GPIO25 ang GPIO26 are occupied by wclk/bclk and can not be used.
```
*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.
### Hardware PDM on ESP32
Hardware PDM outputs 128 * 48Khz pulses regardless of sample rate.
It seems that currently hardware PDM either does not output constant One at maximum sample level, or does not output 3.3V voltage at pulse sound is not as loud as desired. You may consider using software delta-sigma DAC instead.
### 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 +252,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.
@@ -255,10 +268,11 @@ I've been told the Wemos SD card shield uses GPIO15 as the SD chip select. This
There's no ESP8266-specific code in the AudioGenerator routines, so porting to other controllers should be relatively easy assuming they have the same endianness as the Xtensa core used. Drop me a line if you're doing this, I may be able to help point you in the right direction.
## Thanks
Thanks to the authors of StellaPlayer and libMAD for releasing their code freely, and to the maintainers and contributors to the ESP8266 Arduino port.
Thanks to the authors of StellarPlayer and libMAD for releasing their code freely, and to the maintainers and contributors to the ESP8266 Arduino port.
Also, big thanks to @tueddy for getting the initial ESP32 porting into the tree!
-Earle F. Philhower, III
earlephilhower@yahoo.com
+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 Espressif GCC8+, compiler bug
#if defined(ARDUINO_ARCH_RP2040) || (defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__))
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>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,47 @@
#include <Arduino.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorMOD.h"
#include "AudioOutputPWM.h"
#if !defined(ARDUINO_ARCH_RP2040)
void setup() {
Serial.begin(115200);
Serial.printf("Only for the RP2040/Raspberry Pi Pico\n");
}
void loop() {
}
#else
// 5_steps.mod sample from the mod archive: https://modarchive.org/
#include "5steps.h"
AudioGeneratorMOD *mod;
AudioFileSourcePROGMEM *file;
AudioOutputPWM *out;
void setup()
{
Serial.begin(115200);
delay(1000);
audioLogger = &Serial;
file = new AudioFileSourcePROGMEM(steps_mod, sizeof(steps_mod));
out = new AudioOutputPWM();
mod = new AudioGeneratorMOD();
mod->SetBufferSize(3*1024);
mod->SetSampleRate(44100);
mod->SetStereoSeparation(32);
mod->begin(file, out);
}
void loop()
{
if (mod->isRunning()) {
if (!mod->loop()) mod->stop();
} else {
Serial.printf("MOD done\n");
delay(1000);
}
}
#endif
@@ -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
@@ -44,7 +44,7 @@ void setup() {
// 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 registerd only one or the same number with channels
// 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
//
@@ -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;
+8 -4
View File
@@ -1,6 +1,10 @@
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -9,10 +13,10 @@
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#if AUDIO
#pragma message("Outputting audio")
// #pragma message("Outputting audio")
#include "AudioOutputLinuxDSP.h"
#else
#pragma message("No audio")
// #pragma message("No audio")
#include "AudioOutputNullSlow.h"
#endif
@@ -115,4 +119,4 @@ void loop()
delay(1000);
}
}
#endif
+9 -1
View File
@@ -2,7 +2,14 @@
// https://github.com/going-digital/Talkie/blob/master/Talkie/examples/Vocab_US_Clock/Vocab_US_Clock.ino
// Released under GPL v2
#ifdef ESP32
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -183,3 +190,4 @@ void loop()
sayTime(tmstruct.tm_hour, tmstruct.tm_min, talkie);
delay(1000);
}
#endif
+10 -1
View File
@@ -19,7 +19,15 @@
*/
#include <Arduino.h>
#ifdef ESP32
#if defined(ARDUINO_ARCH_RP2040)
void setup() {}
void loop() {}
#else
// ESP8266 server.available() is now server.accept()
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
@@ -439,3 +447,4 @@ void loop()
}
}
#endif
+4 -4
View File
@@ -19,6 +19,9 @@
*/
#include <Arduino.h>
#if defined(ARDUINO_ARCH_RP2040)
// Nothing here
#else
#ifdef ESP32
#include <WiFi.h>
#else
@@ -308,7 +311,4 @@ void Read4Int(char *str, byte *p)
str += ParseInt(str, &i); p[2] = i; if (*str) str++;
str += ParseInt(str, &i); p[3] = i;
}
#endif
+1
View File
@@ -23,6 +23,7 @@ AudioOutput KEYWORD1
AudioOutputI2S KEYWORD1
AudioOutputI2SNoDAC KEYWORD1
AudioOutputI2SClass KEYWORD1
AudioOutputPWM KEYWORD1
AudioOutputNull KEYWORD1
AudioOutputBuffer KEYWORD1
AudioOutputSerialWAV KEYWORD1
+7 -4
View File
@@ -12,12 +12,15 @@
],
"repository": {
"type": "git",
"url": "https://github.com/earlephilhower/ESP8266Audio"
"url": "https://github.com/earlephilhower/ESP8266Audio"
},
"version": "1.9.3",
"version": "2.0.0",
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
"frameworks": "Arduino",
"examples": [
"examples/*/*.ino"
]
}
],
"build": {
"libLDFMode": "deep"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
name=ESP8266Audio
version=1.9.3
version=2.0.0
author=Earle F. Philhower, III
maintainer=Earle F. Philhower, III
sentence=Audio file and I2S sound playing routines for ESP8266, ESP32, and Raspberry Pi Pico RP2040
+5 -5
View File
@@ -1,6 +1,6 @@
/*
AudioFileSourceFunction
Audio ouptut generator which can generate WAV file data from function
Audio output generator which can generate WAV file data from function
Copyright (C) 2021 Hideaki Tai
@@ -25,14 +25,14 @@ AudioFileSourceFunction::AudioFileSourceFunction(float sec, uint16_t channels, u
uint32_t len = uint32_t(sec * (float)bytes_per_sec);
// RIFF chunk
strncpy(wav_header.riff.chunk_id, "RIFF", 4);
memcpy(wav_header.riff.chunk_id, "RIFF", 4);
wav_header.riff.chunk_size = 4 // size of riff chunk w/o chunk_id and chunk_size
+ 8 + 16 // size of format chunk
+ 8 + len; // size of data chunk
strncpy(wav_header.riff.format, "WAVE", 4);
memcpy(wav_header.riff.format, "WAVE", 4);
// format chunk
strncpy(wav_header.format.chunk_id, "fmt ", 4);
memcpy(wav_header.format.chunk_id, "fmt ", 4);
wav_header.format.chunk_size = 16;
wav_header.format.format_tag = 0x0001; // PCM
wav_header.format.channels = channels;
@@ -42,7 +42,7 @@ AudioFileSourceFunction::AudioFileSourceFunction(float sec, uint16_t channels, u
wav_header.format.bits_per_sample = bits_per_sample;
// data chunk
strncpy(wav_header.data.chunk_id, "data", 4);
memcpy(wav_header.data.chunk_id, "data", 4);
wav_header.data.chunk_size = len;
funcs.reserve(channels);
+1 -1
View File
@@ -1,6 +1,6 @@
/*
AudioFileSourceFunction
Audio ouptut generator which can generate WAV file data from function
Audio output generator which can generate WAV file data from function
Copyright (C) 2021 Hideaki Tai
+4
View File
@@ -102,7 +102,11 @@ retry:
}
if ((size > 0) && (pos >= size)) return 0;
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient *stream = http.getStreamPtr();
#else
WiFiClient *stream = http.getStreamPtr();
#endif
// Can't read past EOF...
if ( (size > 0) && (len > (uint32_t)(pos - size)) ) len = pos - size;
+4
View File
@@ -53,7 +53,11 @@ class AudioFileSourceHTTPStream : public AudioFileSource
private:
virtual uint32_t readInternal(void *data, uint32_t len, bool nonBlock);
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient client;
#else
WiFiClient client;
#endif
HTTPClient http;
int pos;
int size;
+8
View File
@@ -20,6 +20,9 @@
#if defined(ESP32) || defined(ESP8266)
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
#define _GNU_SOURCE
#include "AudioFileSourceICYStream.h"
@@ -47,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();
@@ -111,7 +115,11 @@ retry:
}
if ((size > 0) && (pos >= size)) return 0;
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
NetworkClient *stream = http.getStreamPtr();
#else
WiFiClient *stream = http.getStreamPtr();
#endif
// Can't read past EOF...
if ( (size > 0) && (len > (uint32_t)(pos - size)) ) len = pos - size;
+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:
+1 -1
View File
@@ -105,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
+5 -2
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) {
@@ -193,7 +196,7 @@ char AudioGeneratorFLAC::error_cb_str[64];
void AudioGeneratorFLAC::error_cb(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
{
(void) decoder;
strncpy_P(error_cb_str, FLAC__StreamDecoderErrorStatusString[status], 64);
strncpy_P(error_cb_str, FLAC__StreamDecoderErrorStatusString[status], sizeof(AudioGeneratorFLAC::error_cb_str) - 1);
cb.st((int)status, error_cb_str);
}
+13 -6
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 defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__)
// Do not build, Espressif's 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;
@@ -439,8 +443,9 @@ int AudioGeneratorMIDI::PlayMIDI()
for (tgnum = 0; tgnum < num_tonegens; ++tgnum) { /* find which generator is playing it */
tg = &tonegen[tgnum];
if (tg->playing && tg->track == tracknum && tg->note == trk->note) {
tsf_note_off (g_tsf, tg->instrument, tg->note);
tsf_note_off_fast (g_tsf, tg->instrument, tg->note, tg->playIndex);
tg->playing = false;
tg->playIndex = -1;
trk->tonegens[tgnum] = false;
}
}
@@ -472,7 +477,7 @@ int AudioGeneratorMIDI::PlayMIDI()
if (tg->instrument != midi_chan_instrument[trk->chan]) { /* new instrument for this generator */
tg->instrument = midi_chan_instrument[trk->chan];
}
tsf_note_on (g_tsf, tg->instrument, tg->note, trk->velocity / 127.0); // velocity = 0...127
tg->playIndex = tsf_note_on_fast (g_tsf, tg->instrument, tg->note, trk->velocity / 127.0); // velocity = 0...127
} else {
++notes_skipped;
}
@@ -637,3 +642,5 @@ void AudioGeneratorMIDI::MakeStreamFromAFS(AudioFileSource *src, tsf_stream *afs
afs->size = &afs_size;
}
#endif //__GNUC__ == 8
+9 -1
View File
@@ -21,6 +21,10 @@
#ifndef _AUDIOGENERATORMIDI_H
#define _AUDIOGENERATORMIDI_H
#if defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__)
// Do not build, Espressif's GCC8+ has a compiler bug
#else // __GNUC__ == 8
#include "AudioGenerator.h"
#define TSF_NO_STDIO
@@ -90,10 +94,13 @@ class AudioGeneratorMIDI : public AudioGenerator
unsigned long earliest_time = 0;
struct tonegen_status { /* current status of a tone generator */
bool playing; /* is it playing? */
bool playing; /* is it playing? */
char track; /* if so, which track is the note from? */
char note; /* what note is playing? */
char instrument; /* what instrument? */
int playIndex; /* is index provided?
Unique identifier generated when note starts playing.
This help us to turn the note off faster */
} tonegen[MAX_TONEGENS];
struct track_status { /* current processing point of a MIDI track */
@@ -176,6 +183,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;
+24 -7
View File
@@ -1,7 +1,7 @@
/*
AudioGeneratorMP3
Wrap libmad MP3 library to play audio
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
@@ -27,6 +27,9 @@ AudioGeneratorMP3::AudioGeneratorMP3()
file = NULL;
output = NULL;
buff = NULL;
synth = NULL;
frame = NULL;
stream = NULL;
nsCountMax = 1152/32;
madInitted = false;
}
@@ -37,6 +40,9 @@ AudioGeneratorMP3::AudioGeneratorMP3(void *space, int size): preallocateSpace(sp
file = NULL;
output = NULL;
buff = NULL;
synth = NULL;
frame = NULL;
stream = NULL;
nsCountMax = 1152/32;
madInitted = false;
}
@@ -51,6 +57,9 @@ AudioGeneratorMP3::AudioGeneratorMP3(void *buff, int buffSize, void *stream, int
file = NULL;
output = NULL;
buff = NULL;
synth = NULL;
frame = NULL;
stream = NULL;
nsCountMax = 1152/32;
madInitted = false;
}
@@ -62,7 +71,7 @@ AudioGeneratorMP3::~AudioGeneratorMP3()
free(synth);
free(frame);
free(stream);
}
}
}
@@ -182,7 +191,7 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
output->SetChannels(synth->pcm.channels);
lastChannels = synth->pcm.channels;
}
// If we're here, we have one decoded frame and sent 0 or more samples out
if (samplePtr < synth->pcm.length) {
sample[AudioOutput::LEFTCHANNEL ] = synth->pcm.samples[0][samplePtr];
@@ -190,7 +199,7 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
samplePtr++;
} else {
samplePtr = 0;
switch ( mad_synth_frame_onens(synth, frame, nsCount++) ) {
case MAD_FLOW_STOP:
case MAD_FLOW_BREAK: audioLogger->printf_P(PSTR("msf1ns failed\n"));
@@ -248,6 +257,10 @@ retry:
running = false;
goto done;
}
if (lastChannels == 1)
{
lastSample[1] = lastSample[0];
}
} while (running && output->ConsumeSample(lastSample));
done:
@@ -298,6 +311,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
synth = reinterpret_cast<struct mad_synth *>(preallocateSynthSpace);
}
else {
output->stop();
audioLogger->printf_P("OOM error in MP3: Want %d/%d/%d/%d bytes, have %d/%d/%d/%d bytes preallocated.\n",
preAllocBuffSize(), preAllocStreamSize(), preAllocFrameSize(), preAllocSynthSize(),
preallocateSize, preallocateStreamSize, preallocateFrameSize, preallocateSynthSize);
@@ -315,6 +329,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
p += preAllocSynthSize();
int neededBytes = p - reinterpret_cast<uint8_t *>(preallocateSpace);
if (neededBytes > preallocateSize) {
output->stop();
audioLogger->printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
return false;
}
@@ -332,17 +347,20 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
stream = NULL;
frame = NULL;
synth = NULL;
output->stop();
audioLogger->printf_P("OOM error in MP3\n");
return false;
}
}
mad_stream_init(stream);
mad_frame_init(frame);
mad_synth_init(synth);
synth->pcm.length = 0;
mad_stream_options(stream, 0); // TODO - add options support
madInitted = true;
running = true;
return true;
}
@@ -409,4 +427,3 @@ extern "C" {
}
#endif
}
+7 -4
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();
@@ -233,13 +236,13 @@ bool AudioGeneratorRTTTL::GetNextNote()
ptr++;
note++;
}
if (!ReadInt(&scale)) {
scale = defaultOctave;
}
if ((ptr < len) && (buff[ptr] == '.')) {
ptr++;
dur += dur / 2;
}
if (!ReadInt(&scale)) {
scale = defaultOctave;
}
// Eat any trailing whitespace and comma
SkipWhitespace();
if ((ptr < len) && (buff[ptr]==',')) {
+2 -2
View File
@@ -127,7 +127,7 @@ bool AudioGeneratorWAV::ReadWAVInfo()
return false;
};
if (u32 != 0x46464952) {
Serial.printf_P(PSTR("AudioGeneratorWAV::ReadWAVInfo: cannot read WAV, invalid RIFF header, got: %08X \n"), (uint32_t) u32);
Serial.printf_P(PSTR("AudioGeneratorWAV::ReadWAVInfo: cannot read WAV, invalid RIFF header\n"));
return false;
}
@@ -143,7 +143,7 @@ bool AudioGeneratorWAV::ReadWAVInfo()
return false;
};
if (u32 != 0x45564157) {
Serial.printf_P(PSTR("AudioGeneratorWAV::ReadWAVInfo: cannot read WAV, invalid WAVE header, got: %08X \n"), (uint32_t) u32);
Serial.printf_P(PSTR("AudioGeneratorWAV::ReadWAVInfo: cannot read WAV, invalid WAVE header\n"));
return false;
}
+135 -40
View File
@@ -21,8 +21,10 @@
#include <Arduino.h>
#ifdef ESP32
#include "driver/i2s.h"
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
#elif defined(ARDUINO_ARCH_RP2040) || ARDUINO_ESP8266_MAJOR >= 3
#include <I2S.h>
#elif ARDUINO_ESP8266_MAJOR < 3
#include <i2s.h>
#endif
#include "AudioOutputI2S.h"
@@ -40,15 +42,38 @@ 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;
bclkPin = 26;
wclkPin = 25;
doutPin = 22;
mclkPin = 0;
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;
mclkPin = 0;
use_mclk = false;
swap_clocks = false;
SetGain(1.0);
}
#endif
AudioOutputI2S::~AudioOutputI2S()
{
stop();
}
bool AudioOutputI2S::SetPinout()
{
#ifdef ESP32
@@ -56,6 +81,9 @@ bool AudioOutputI2S::SetPinout()
return false; // Not allowed
i2s_pin_config_t pins = {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.mck_io_num = mclkPin,
#endif
.bck_io_num = bclkPin,
.ws_io_num = wclkPin,
.data_out_num = doutPin,
@@ -66,6 +94,8 @@ bool AudioOutputI2S::SetPinout()
(void)bclkPin;
(void)wclkPin;
(void)doutPin;
(void)mclkPin;
(void)use_mclk;
return false;
#endif
}
@@ -80,33 +110,20 @@ bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
return true;
}
#elif defined(ARDUINO_ARCH_RP2040)
AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) {
i2sOn = false;
mono = false;
bps = 16;
channels = 2;
hertz = sampleRate;
bclkPin = sck;
doutPin = data;
SetGain(1.0);
}
#endif
AudioOutputI2S::~AudioOutputI2S()
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout, int mclk)
{
#ifdef ESP32
if (i2sOn) {
audioLogger->printf("UNINSTALL I2S\n");
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
}
#elif defined(ESP8266)
bclkPin = bclk;
wclkPin = wclk;
doutPin = dout;
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
mclkPin = mclk;
if (i2sOn)
i2s_end();
#elif defined(ARDUINO_ARCH_RP2040)
stop();
return SetPinout();
#else
(void)mclk;
#endif
i2sOn = false;
return true;
}
bool AudioOutputI2S::SetRate(int hz)
@@ -120,7 +137,7 @@ bool AudioOutputI2S::SetRate(int hz)
#elif defined(ESP8266)
i2s_set_rate(AdjustI2SRate(hz));
#elif defined(ARDUINO_ARCH_RP2040)
I2S.setFrequency(hz);
i2s.setFrequency(hz);
#endif
}
return true;
@@ -146,6 +163,34 @@ bool AudioOutputI2S::SetOutputModeMono(bool mono)
return true;
}
bool AudioOutputI2S::SetLsbJustified(bool lsbJustified)
{
this->lsb_justified = lsbJustified;
return true;
}
bool AudioOutputI2S::SwapClocks(bool swap_clocks)
{
if (i2sOn) {
return false; // Not allowed
}
this->swap_clocks = swap_clocks;
return true;
}
bool AudioOutputI2S::SetMclk(bool enabled){
(void)enabled;
#ifdef ESP32
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
return false; // Not allowed
use_mclk = enabled;
#elif defined(ARDUINO_ARCH_RP2040)
use_mclk = enabled;
#endif
return true;
}
bool AudioOutputI2S::begin(bool txDAC)
{
#ifdef ESP32
@@ -155,9 +200,9 @@ bool AudioOutputI2S::begin(bool txDAC)
{
// don't use audio pll on buggy rev0 chips
use_apll = APLL_DISABLE;
esp_chip_info_t out_info;
esp_chip_info(&out_info);
if (out_info.revision > 0)
//esp_chip_info_t out_info;
//esp_chip_info(&out_info);
//if (out_info.revision > 0)
{
use_apll = APLL_ENABLE;
}
@@ -166,17 +211,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 = {
@@ -187,8 +260,14 @@ 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 = use_mclk, // Unused
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.mclk_multiple = I2S_MCLK_MULTIPLE_256, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
#endif
};
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK)
@@ -197,8 +276,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
{
@@ -229,9 +312,16 @@ bool AudioOutputI2S::begin(bool txDAC)
#elif defined(ARDUINO_ARCH_RP2040)
(void)txDAC;
if (!i2sOn) {
I2S.setBCLK(bclkPin);
I2S.setDOUT(doutPin);
I2S.begin(hertz);
i2s.setSysClk(hertz);
i2s.setBCLK(bclkPin);
i2s.setDATA(doutPin);
i2s.setMCLK(mclkPin);
i2s.setMCLKmult(256);
if (swap_clocks) {
i2s.swapClocks();
}
i2s.setBitsPerSample(bps);
i2s.begin(hertz);
}
#endif
i2sOn = true;
@@ -263,7 +353,7 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
{
int16_t l = Amplify(ms[LEFTCHANNEL]) + 0x8000;
int16_t r = Amplify(ms[RIGHTCHANNEL]) + 0x8000;
s32 = (r << 16) | (l & 0xffff);
s32 = ((r & 0xffff) << 16) | (l & 0xffff);
}
else
{
@@ -279,7 +369,8 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
#elif defined(ARDUINO_ARCH_RP2040)
return !!I2S.write((void*)ms, 4);
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return !!i2s.write((int32_t)s32, false);
#endif
}
@@ -287,7 +378,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++)
{
@@ -297,7 +388,7 @@ void AudioOutputI2S::flush()
}
}
#elif defined(ARDUINO_ARCH_RP2040)
I2S.flush();
i2s.flush();
#endif
}
@@ -308,8 +399,12 @@ bool AudioOutputI2S::stop()
#ifdef ESP32
i2s_zero_dma_buffer((i2s_port_t)portNo);
audioLogger->printf("UNINSTALL I2S\n");
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
#elif defined(ESP8266)
i2s_end();
#elif defined(ARDUINO_ARCH_RP2040)
I2S.end();
i2s.end();
#endif
i2sOn = false;
return true;
+18 -1
View File
@@ -22,17 +22,23 @@
#include "AudioOutput.h"
#if defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include <I2S.h>
#endif
class AudioOutputI2S : public AudioOutput
{
public:
#if defined(ESP32) || defined(ESP8266)
AudioOutputI2S(int port=0, int output_mode=EXTERNAL_I2S, int dma_buf_count = 8, int use_apll=APLL_DISABLE);
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
enum : int { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
#elif defined(ARDUINO_ARCH_RP2040)
AudioOutputI2S(long sampleRate = 44100, pin_size_t sck = 26, pin_size_t data = 28);
#endif
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
bool SetPinout(int bclkPin, int wclkPin, int doutPin, int mclkPin);
virtual ~AudioOutputI2S() override;
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
@@ -44,6 +50,9 @@ class AudioOutputI2S : public AudioOutput
bool begin(bool txDAC);
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
bool SetMclk(bool enabled); // Enable MCLK output (if supported)
bool SwapClocks(bool swap_clocks); // Swap BCLK and WCLK
protected:
bool SetPinout();
@@ -51,9 +60,12 @@ class AudioOutputI2S : public AudioOutput
uint8_t portNo;
int output_mode;
bool mono;
int lsb_justified;
bool i2sOn;
int dma_buf_count;
int use_apll;
bool use_mclk;
bool swap_clocks;
// We can restore the old values and free up these pins when in NoDAC mode
uint32_t orig_bck;
uint32_t orig_ws;
@@ -61,4 +73,9 @@ class AudioOutputI2S : public AudioOutput
uint8_t bclkPin;
uint8_t wclkPin;
uint8_t doutPin;
uint8_t mclkPin;
#if defined(ARDUINO_ARCH_RP2040)
I2S i2s;
#endif
};
+27 -7
View File
@@ -21,12 +21,33 @@
#include <Arduino.h>
#ifdef ESP32
#include "driver/i2s.h"
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
#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);
@@ -36,7 +57,10 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, orig_bck);
WRITE_PERI_REG(PERIPHS_IO_MUX_GPIO2_U, orig_ws);
#endif
}
#endif
AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC()
{
@@ -95,9 +119,6 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
// Either send complete pulse stream or nothing
#ifdef ESP32
//"i2s_write_bytes" has been removed in the ESP32 Arduino 2.0.0, use "i2s_write" instead.
// if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
size_t i2s_bytes_written;
i2s_write((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), &i2s_bytes_written, 0);
if (!i2s_bytes_written){
@@ -110,9 +131,8 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
for (int i = 32; i < oversample; i+=32)
i2s_write_sample( dsBuff[i / 32]);
#elif defined(ARDUINO_ARCH_RP2040)
int16_t *p = (int16_t *) dsBuff;
for (int i = 0; i < oversample / 16; i++) {
I2S.write(*(p++));
for (int i = 0; i < oversample / 32; i++) {
i2s.write((int32_t)dsBuff[i], true);
}
#endif
return true;
+10 -1
View File
@@ -25,7 +25,16 @@
class AudioOutputI2SNoDAC : public AudioOutputI2S
{
public:
//
// Define a different constructor for the RP2040, as this class calls the constructor
// of the AudioOutputI2S which has an alternate constructor for the RP2040
//
#if defined(ARDUINO_ARCH_RP2040)
AudioOutputI2SNoDAC(int port = 28,int sck = 26);
#else
AudioOutputI2SNoDAC(int port = 0);
#endif
virtual ~AudioOutputI2SNoDAC() override;
virtual bool begin() override { return AudioOutputI2S::begin(false); }
virtual bool ConsumeSample(int16_t sample[2]) override;
@@ -34,7 +43,7 @@ class AudioOutputI2SNoDAC : public AudioOutputI2S
protected:
virtual int AdjustI2SRate(int hz) override { return hz * oversample/32; }
uint8_t oversample;
int oversample;
void DeltaSigma(int16_t sample[2], uint32_t dsBuff[4]);
typedef int32_t fixed24p8_t;
enum {fixedPosValue=0x007fff00}; /* 24.8 of max-signed-int */
+2 -2
View File
@@ -71,8 +71,8 @@ bool AudioOutputMixerStub::stop()
AudioOutputMixer::AudioOutputMixer(int buffSizeSamples, AudioOutput *dest) : AudioOutput()
{
buffSize = buffSizeSamples;
leftAccum = (int32_t*)calloc(sizeof(int32_t), buffSize);
rightAccum = (int32_t*)calloc(sizeof(int32_t), buffSize);
leftAccum = (int32_t*)calloc(buffSize, sizeof(int32_t));
rightAccum = (int32_t*)calloc(buffSize, sizeof(int32_t));
for (int i=0; i<maxStubs; i++) {
stubAllocated[i] = false;
stubRunning[i] = false;
+117
View File
@@ -0,0 +1,117 @@
/*
AudioOutputPWM
Base class for the RP2040 PWM audio
Copyright (C) 2023 Earle F. Philhower, III
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/>.
*/
#if defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include "AudioOutputPWM.h"
AudioOutputPWM::AudioOutputPWM(long sampleRate, pin_size_t data) {
pwmOn = false;
mono = false;
bps = 16;
channels = 2;
hertz = sampleRate;
doutPin = data;
SetGain(1.0);
pwm.setStereo(true);
}
AudioOutputPWM::~AudioOutputPWM() {
stop();
}
bool AudioOutputPWM::SetRate(int hz) {
this->hertz = hz;
if (pwmOn) {
pwm.setFrequency(hz);
}
return true;
}
bool AudioOutputPWM::SetBitsPerSample(int bits) {
if ( (bits != 16) && (bits != 8) ) return false;
this->bps = bits;
return true;
}
bool AudioOutputPWM::SetChannels(int channels) {
if ( (channels < 1) || (channels > 2) ) return false;
this->channels = channels;
return true;
}
bool AudioOutputPWM::SetOutputModeMono(bool mono) {
this->mono = mono;
return true;
}
bool AudioOutputPWM::begin() {
if (!pwmOn) {
pwm.setPin(doutPin);
pwm.begin(hertz);
}
pwmOn = true;
SetRate(hertz); // Default
return true;
}
bool AudioOutputPWM::ConsumeSample(int16_t sample[2]) {
if (!pwmOn)
return false;
int16_t ms[2];
ms[0] = sample[0];
ms[1] = sample[1];
MakeSampleStereo16( ms );
if (this->mono) {
// Average the two samples and overwrite
int32_t ttl = ms[LEFTCHANNEL] + ms[RIGHTCHANNEL];
ms[LEFTCHANNEL] = ms[RIGHTCHANNEL] = (ttl>>1) & 0xffff;
}
ms[LEFTCHANNEL] = Amplify(ms[LEFTCHANNEL]);
ms[RIGHTCHANNEL] = Amplify(ms[RIGHTCHANNEL]);
if (pwm.available()) {
pwm.write((int16_t) ms[0]);
pwm.write((int16_t) ms[1]);
return true;
} else {
return false;
}
}
void AudioOutputPWM::flush() {
pwm.flush();
}
bool AudioOutputPWM::stop() {
if (!pwmOn)
return false;
pwm.end();
pwmOn = false;
return true;
}
#endif
+57
View File
@@ -0,0 +1,57 @@
/*
AudioOutputPWM
Base class for the RP2040 PWM audio output
Copyright (C) 2023 Earle F. Philhower, III
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/>.
*/
#pragma once
#include "AudioOutput.h"
#if defined(ARDUINO_ARCH_RP2040)
#include <Arduino.h>
#include <PWMAudio.h>
class AudioOutputPWM : public AudioOutput
{
public:
AudioOutputPWM(long sampleRate = 44100, pin_size_t data = 0);
virtual ~AudioOutputPWM() override;
virtual bool SetRate(int hz) override;
virtual bool SetBitsPerSample(int bits) override;
virtual bool SetChannels(int channels) override;
virtual bool begin() override;
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual void flush() override;
virtual bool stop() override;
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
protected:
bool SetPinout();
virtual int AdjustI2SRate(int hz) { return hz; }
uint8_t portNo;
int output_mode;
bool mono;
bool pwmOn;
uint8_t doutPin;
PWMAudio pwm;
};
#endif
+23 -5
View File
@@ -3,11 +3,11 @@
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:
Forum thread dicussing implementation
Forum thread discussing implementation
https://forum.pjrc.com/threads/28639-S-pdif
Teensy Audio Library
https://github.com/PaulStoffregen/Audio/blob/master/output_spdif2.cpp
@@ -94,11 +94,24 @@ 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
#if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
.mclk_multiple = I2S_MCLK_MULTIPLE_512, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, // Unused
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
#endif
};
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_spdif, 0, NULL) != ESP_OK) {
audioLogger->println(F("ERROR: Unable to install I2S drivers"));
@@ -143,6 +156,9 @@ bool AudioOutputSPDIF::SetPinout(int bclk, int wclk, int dout)
{
#if defined(ESP32)
i2s_pin_config_t pins = {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.mck_io_num = 0, // unused
#endif
.bck_io_num = bclk,
.ws_io_num = wclk,
.data_out_num = dout,
@@ -170,12 +186,14 @@ bool AudioOutputSPDIF::SetRate(int hz)
int adjustedHz = AdjustI2SRate(hz);
#if defined(ESP32)
if (i2s_set_sample_rates((i2s_port_t)portNo, adjustedHz) == ESP_OK) {
#if defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR < 3)
if (adjustedHz == 88200) {
// Manually fix the APLL rate for 44100.
// See: https://github.com/espressif/esp-idf/issues/2634
// sdm0 = 28, sdm1 = 8, sdm2 = 5, odir = 0 -> 88199.977
rtc_clk_apll_enable(1, 28, 8, 5, 0);
}
#endif
} else {
audioLogger->println("ERROR changing S/PDIF sample rate");
}
@@ -265,7 +283,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;
+2 -2
View File
@@ -3,11 +3,11 @@
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:
Forum thread dicussing implementation
Forum thread discussing implementation
https://forum.pjrc.com/threads/28639-S-pdif
Teensy Audio Library
https://github.com/PaulStoffregen/Audio/blob/master/output_spdif2.cpp
+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>
+1
View File
@@ -41,6 +41,7 @@
#include "AudioOutput.h"
#include "AudioOutputI2S.h"
#include "AudioOutputI2SNoDAC.h"
#include "AudioOutputPWM.h"
#include "AudioOutputMixer.h"
#include "AudioOutputNull.h"
#include "AudioOutputSerialWAV.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
@@ -35,7 +35,7 @@
* print an error message if it fails (ie returns a value < 0).
*
* Ideally, a library should not print anything, but this macro is only used
* for things that extremely unlikely to fail, like `chown` to a previoulsy
* for things that extremely unlikely to fail, like `chown` to a previously
* saved `uid`.
*/
+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.
-6
View File
@@ -558,14 +558,8 @@ static __inline int CLZ(int x)
typedef union _U64 {
Word64 w64;
struct {
#ifdef __XTENSA__
unsigned int lo32;
signed int hi32;
#else
/* PowerPC = big endian */
signed int hi32;
unsigned int lo32;
#endif
} r;
} U64;
+2 -2
View File
@@ -258,10 +258,10 @@ int DecodeProgramConfigElement(ProgConfigElement *pce, BitStreamInfo *bsi)
pce->bce[i] |= GetBits(bsi, 4); /* tag select */
}
for (i = 0; i < pce->numLCE; i++)
for (i = 0; i < pce->numLCE && i < MAX_NUM_LCE; i++)
pce->lce[i] = GetBits(bsi, 4); /* tag select */
for (i = 0; i < pce->numADE; i++)
for (i = 0; i < pce->numADE && i < MAX_NUM_ADE; i++)
pce->ade[i] = GetBits(bsi, 4); /* tag select */
for (i = 0; i < pce->numCCE; i++) {
+1 -1
View File
@@ -253,7 +253,7 @@ static int DecodeOneScaleFactor(BitStreamInfo *bsi)
pi->numPulse = GetBits(bsi, 2) + 1; /* add 1 here */
pi->startSFB = GetBits(bsi, 6);
for (i = 0; i < pi->numPulse; i++) {
for (i = 0; i < pi->numPulse && i < MAX_PULSES; i++) {
pi->offset[i] = GetBits(bsi, 5);
pi->amp[i] = GetBits(bsi, 4);
}
+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
+6 -6
View File
@@ -195,7 +195,7 @@ static void UnpackSBRGrid(BitStreamInfo *bsi, SBRHeader *sbrHdr, SBRGrid *sbrGri
absBorder = GetBits(bsi, 2) + NUM_TIME_SLOTS;
numRelBorder = GetBits(bsi, 2);
sbrGrid->numEnv = numRelBorder + 1;
for (rel = 0; rel < numRelBorder; rel++)
for (rel = 0; rel < numRelBorder && rel < 3; rel++)
relBorder[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[sbrGrid->numEnv + 1];
@@ -221,13 +221,13 @@ static void UnpackSBRGrid(BitStreamInfo *bsi, SBRHeader *sbrHdr, SBRGrid *sbrGri
absBorder = GetBits(bsi, 2);
numRelBorder = GetBits(bsi, 2);
sbrGrid->numEnv = numRelBorder + 1;
for (rel = 0; rel < numRelBorder; rel++)
for (rel = 0; rel < numRelBorder && rel < 3; rel++)
relBorder[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[sbrGrid->numEnv + 1];
sbrGrid->pointer = GetBits(bsi, pBits);
for (env = 0; env < sbrGrid->numEnv; env++)
for (env = 0; env < sbrGrid->numEnv && env < MAX_NUM_ENV; env++)
sbrGrid->freqRes[env] = GetBits(bsi, 1);
absBordLead = absBorder;
@@ -253,16 +253,16 @@ static void UnpackSBRGrid(BitStreamInfo *bsi, SBRHeader *sbrHdr, SBRGrid *sbrGri
sbrGrid->numEnv = numRelBorder0 + numRelBorder1 + 1;
ASSERT(sbrGrid->numEnv <= 5);
for (rel = 0; rel < numRelBorder0; rel++)
for (rel = 0; rel < numRelBorder0 && rel < 3; rel++)
relBorder0[rel] = 2*GetBits(bsi, 2) + 2;
for (rel = 0; rel < numRelBorder1; rel++)
for (rel = 0; rel < numRelBorder1 && rel < 3; rel++)
relBorder1[rel] = 2*GetBits(bsi, 2) + 2;
pBits = cLog2[numRelBorder0 + numRelBorder1 + 2];
sbrGrid->pointer = GetBits(bsi, pBits);
for (env = 0; env < sbrGrid->numEnv; env++)
for (env = 0; env < sbrGrid->numEnv && env < MAX_NUM_ENV; env++)
sbrGrid->freqRes[env] = GetBits(bsi, 1);
numRelLead = numRelBorder0;
+1 -1
View File
@@ -801,7 +801,7 @@ REQUIRED IN ALL CASES
Notice to be included in header file of all Error Corrections and Shared
Modifications:
Portions Copyright 1994-2003 © RealNetworks, Inc. All rights reserved.
Portions Copyright 1994-2003 (c) RealNetworks, Inc. All rights reserved.
The contents of this file, and the files included with this file, are
subject to the current version of RealNetworks Community Source License
+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
+2 -2
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
@@ -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
+1 -1
View File
@@ -70,7 +70,7 @@ public:
// return.
// pPCM pointer to a buffer to decode into
// pulPCMSize size of the PCM buffer. It will contain the
// number of PCM bytes prodced upon return.
// number of PCM bytes produced upon return.
///////////////////////////////////////////////////////////////////////////
void DecodeFrame_v(unsigned char *pSource,
unsigned long *pulSize,
+1 -1
View File
@@ -54,7 +54,7 @@
* (see comment on Dequantize() for more info)
*/
#define DEF_NFRACBITS (DQ_FRACBITS_OUT - 2 - 2 - 15)
#define CSHIFT 12 /* coefficients have 12 leading sign bits for early-terminating mulitplies */
#define CSHIFT 12 /* coefficients have 12 leading sign bits for early-terminating multiplies */
static __inline short ClipToShort(int x, int fracBits)
{
+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
**************************************************************************************/
+75 -71
View File
@@ -20,6 +20,7 @@
*/
#pragma GCC optimize ("O3")
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#include <pgmspace.h>
# include "config.h"
@@ -351,19 +352,19 @@ struct fixedfloat {
root_table[3 + x] = 2^(x/4)
*/
static mad_fixed_t const root_table_val[7] PROGMEM = {
MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
};
static inline mad_fixed_t root_table(int i)
{
static mad_fixed_t const root_table_val[7] PROGMEM = {
MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
};
volatile uint32_t a = *(uint32_t*)&root_table_val[i];
return *(mad_fixed_t*)&a;
volatile mad_fixed_t a = root_table_val[i];
return a;
}
/*
coefficients for aliasing reduction
@@ -373,28 +374,28 @@ static inline mad_fixed_t root_table(int i)
cs[i] = 1 / sqrt(1 + c[i]^2)
ca[i] = c[i] / sqrt(1 + c[i]^2)
*/
static mad_fixed_t const cs_val[8] PROGMEM = {
+MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
+MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
+MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
+MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
};
static inline mad_fixed_t cs(int i)
{
static mad_fixed_t const cs_val[8] PROGMEM = {
+MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
+MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
+MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
+MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
};
volatile uint32_t a = *(uint32_t*)&cs_val[i];
return *(mad_fixed_t*)&a;
volatile mad_fixed_t a = cs_val[i];
return a;
}
static mad_fixed_t const ca_val[8] PROGMEM = {
-MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
-MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
-MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
-MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
};
static inline mad_fixed_t ca(int i)
{
static mad_fixed_t const ca_val[8] PROGMEM = {
-MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
-MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
-MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
-MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
};
volatile uint32_t a = *(uint32_t*)&ca_val[i];
return *(mad_fixed_t*)&a;
volatile mad_fixed_t a = ca_val[i];
return a;
}
/*
@@ -416,31 +417,31 @@ mad_fixed_t const imdct_s[6][6] PROGMEM = {
window_l[i] = sin((PI / 36) * (i + 1/2))
*/
static mad_fixed_t const window_l_val[36] PROGMEM = {
MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
};
static inline mad_fixed_t window_l(int i)
{
static mad_fixed_t const window_l_val[36] PROGMEM = {
MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
};
volatile uint32_t a = *(uint32_t*)&window_l_val[i];
volatile mad_fixed_t a = window_l_val[i];
return *(mad_fixed_t*)&a;
}
# endif /* ASO_IMDCT */
@@ -451,18 +452,18 @@ static inline mad_fixed_t window_l(int i)
window_s[i] = sin((PI / 12) * (i + 1/2))
*/
static mad_fixed_t const window_s_val[12] PROGMEM = {
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
};
static inline mad_fixed_t window_s(int i)
{
static mad_fixed_t const window_s_val[12] PROGMEM = {
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
};
volatile uint32_t a = *(uint32_t*)&window_s_val[i];
return *(mad_fixed_t*)&a;
volatile mad_fixed_t a = window_s_val[i];
return a;
}
/*
@@ -472,19 +473,19 @@ static inline mad_fixed_t window_s(int i)
is_ratio[i] = tan(i * (PI / 12))
is_table[i] = is_ratio[i] / (1 + is_ratio[i])
*/
static mad_fixed_t const is_table_val[7] PROGMEM = {
MAD_F(0x00000000) /* 0.000000000 */,
MAD_F(0x0361962f) /* 0.211324865 */,
MAD_F(0x05db3d74) /* 0.366025404 */,
MAD_F(0x08000000) /* 0.500000000 */,
MAD_F(0x0a24c28c) /* 0.633974596 */,
MAD_F(0x0c9e69d1) /* 0.788675135 */,
MAD_F(0x10000000) /* 1.000000000 */
};
static inline mad_fixed_t is_table(int i)
{
static mad_fixed_t const is_table_val[7] PROGMEM = {
MAD_F(0x00000000) /* 0.000000000 */,
MAD_F(0x0361962f) /* 0.211324865 */,
MAD_F(0x05db3d74) /* 0.366025404 */,
MAD_F(0x08000000) /* 0.500000000 */,
MAD_F(0x0a24c28c) /* 0.633974596 */,
MAD_F(0x0c9e69d1) /* 0.788675135 */,
MAD_F(0x10000000) /* 1.000000000 */
};
volatile uint32_t a = *(uint32_t*)&is_table_val[i];
return *(mad_fixed_t*)&a;
volatile mad_fixed_t a = is_table_val[i];
return a;
}
/*
@@ -1738,7 +1739,10 @@ void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
s = *(volatile mad_fixed_t*)(volatile uint32_t*)&scale[i + 2]; tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], s); //scale[i + 2]);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
fastsdct(tmp, &X[1]);
#pragma GCC diagnostic pop
/* output accumulation */
+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
@@ -24,7 +24,7 @@
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
//#ifdef HAVE_CONFIG_H
#include "config.h"
//#endif
@@ -2781,3 +2781,4 @@ void opus_encoder_destroy(OpusEncoder *st)
{
opus_free(st);
}
#endif
+2 -1
View File
@@ -24,7 +24,7 @@
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
//#ifdef HAVE_CONFIG_H
#include "config.h"
//#endif
@@ -1326,3 +1326,4 @@ void opus_multistream_encoder_destroy(OpusMSEncoder *st)
{
opus_free(st);
}
#endif
+2 -2
View File
@@ -24,7 +24,7 @@
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
//#ifdef HAVE_CONFIG_H
#include "config.h"
//#endif
@@ -465,4 +465,4 @@ bad_arg:
va_end(ap);
return OPUS_BAD_ARG;
}
#endif
+3 -1
View File
@@ -62,6 +62,8 @@ static OPUS_INLINE void silk_NLSF2A_find_poly(
}
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
/* compute whitening filter coefficients from normalized line spectral frequencies */
void silk_NLSF2A(
opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
@@ -143,4 +145,4 @@ void silk_NLSF2A(
free(Q);
free(a32_QA1);
}
#pragma GCC diagnostic pop
+2
View File
@@ -24,6 +24,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#if 0
//#ifdef HAVE_CONFIG_H
#include "../config.h"
@@ -574,3 +575,4 @@ opus_int silk_Encode( /* O Returns error co
return ret;
}
#endif
@@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "../../celt/stack_alloc.h"
#include "../tuning_parameters.h"
#if 0
/* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */
static OPUS_INLINE void silk_LBRR_encode_FIX(
silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
@@ -446,3 +447,4 @@ static OPUS_INLINE void silk_LBRR_encode_FIX(
silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof( opus_int32 ) );
}
}
#endif
+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
+159 -58
View File
@@ -42,6 +42,18 @@
*/
// ESP32 as of 3.x has a compiler bug in this section, with the G++ generated assembly
// being illegal. There's nothing wrong with the code here, it just looks like an
// Xtensa backend issue. Until that's fixed, no MIDI for you!
///home/earle/Arduino/libraries/ESP8266Audio/src/libtinysoundfont/tsf.h: In function 'void tsf_channel_midi_control(tsf*, int, int, int)':
// /home/earle/Arduino/libraries/ESP8266Audio/src/libtinysoundfont/tsf.h:2101:1: error: insn does not satisfy its constraints:
// 2101 | }
// | ^
#if defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__)
// Not defined, can't build
#else
#ifndef TSF_INCLUDE_TSF_INL
#define TSF_INCLUDE_TSF_INL
@@ -104,7 +116,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 +213,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);
@@ -602,11 +614,11 @@ struct tsf_voice
{
int playingPreset, playingKey, playingChannel;
struct tsf_region* region;
double pitchInputTimecents, pitchOutputFactor;
double pitchRatio;
double sourceSamplePosition;
fixed32p32 sourceSamplePositionF32P32;
float noteGainDB, panFactorLeft, panFactorRight;
unsigned int playIndex, loopStart, loopEnd;
fixed32p32 sourceSamplePositionF32P32, loopStartF32P32, loopEndF32P32, loopSizeF32P32, pitchRatioF32P32;
float noteGain, panFactorLeft, panFactorRight;
int playIndex, loopStart, loopEnd;
struct tsf_voice_envelope ampenv, modenv;
struct tsf_voice_lowpass lowpass;
struct tsf_voice_lfo modlfo, viblfo;
@@ -625,6 +637,14 @@ struct tsf_channels
int channelNum, activeChannel;
};
// Math properties of tsf_timecents2Secs* (tc2s):
// # tc2s(a + b) = tc2s(a) * tc2s(b)
// # tc2s(a - b) = tc2s(a) / tc2s(b)
// # 1 / tc2s(a) = tc2s(-a)
// # The same applies to tsf_cents2Hertz and tsf_decibelsToGain
// Path properties of tsf_decibelsToGain (db2g) and tsf_gainToDecibels (g2db)
// # db2g(g2db(a)) = a
// # g2db(db2g(a)) = a
static double tsf_timecents2Secsd(double timecents) { return TSF_POW(2.0, timecents / 1200.0); }
static float tsf_timecents2Secsf(float timecents) { return TSF_POWF(2.0f, timecents / 1200.0f); }
static float tsf_cents2Hertz(float cents) { return 8.176f * TSF_POWF(2.0f, cents / 1200.0f); }
@@ -1220,6 +1240,7 @@ static void tsf_voice_end(struct tsf_voice* v, float outSampleRate)
{
// Continue playing, but stop looping.
v->loopEnd = v->loopStart;
v->loopSizeF32P32 = 0;
}
}
@@ -1232,10 +1253,9 @@ static void tsf_voice_endquick(struct tsf_voice* v, float outSampleRate)
static void tsf_voice_calcpitchratio(struct tsf_voice* v, float pitchShift, float outSampleRate)
{
double note = v->playingKey + v->region->transpose + v->region->tune / 100.0;
double adjustedPitch = v->region->pitch_keycenter + (note - v->region->pitch_keycenter) * (v->region->pitch_keytrack / 100.0);
if (pitchShift) adjustedPitch += pitchShift;
v->pitchInputTimecents = adjustedPitch * 100.0;
v->pitchOutputFactor = v->region->sample_rate / (tsf_timecents2Secsd(v->region->pitch_keycenter * 100.0) * outSampleRate);
double adjustedPitch = (note - v->region->pitch_keycenter) * v->region->pitch_keytrack;
if (pitchShift) adjustedPitch += adjustedPitch * 100.0f;
v->pitchRatio = v->region->sample_rate * tsf_timecents2Secsd(adjustedPitch) / outSampleRate;
}
short tsf_read_short_cached(tsf *f, int pos)
@@ -1303,10 +1323,10 @@ static void tsf_voice_render(tsf* f, struct tsf_voice* v, float* outputBuffer, i
else tmpInitialFilterFc = 0, tmpModLfoToFilterFc = 0, tmpModEnvToFilterFc = 0;
if (dynamicPitchRatio) pitchRatio = 0, tmpModLfoToPitch = (float)region->modLfoToPitch, tmpVibLfoToPitch = (float)region->vibLfoToPitch, tmpModEnvToPitch = (float)region->modEnvToPitch;
else pitchRatio = tsf_timecents2Secsd(v->pitchInputTimecents) * v->pitchOutputFactor, tmpModLfoToPitch = 0, tmpVibLfoToPitch = 0, tmpModEnvToPitch = 0;
else pitchRatio = v->pitchRatio, tmpModLfoToPitch = 0, tmpVibLfoToPitch = 0, tmpModEnvToPitch = 0;
if (dynamicGain) tmpModLfoToVolume = (float)region->modLfoToVolume * 0.1f;
else noteGain = tsf_decibelsToGain(v->noteGainDB), tmpModLfoToVolume = 0;
else noteGain = v->noteGain, tmpModLfoToVolume = 0;
while (numSamples)
{
@@ -1323,10 +1343,10 @@ static void tsf_voice_render(tsf* f, struct tsf_voice* v, float* outputBuffer, i
}
if (dynamicPitchRatio)
pitchRatio = tsf_timecents2Secsd(v->pitchInputTimecents + (v->modlfo.level * tmpModLfoToPitch + v->viblfo.level * tmpVibLfoToPitch + v->modenv.level * tmpModEnvToPitch)) * v->pitchOutputFactor;
pitchRatio = v->pitchRatio * tsf_timecents2Secsd(v->modlfo.level * tmpModLfoToPitch + v->viblfo.level * tmpVibLfoToPitch + v->modenv.level * tmpModEnvToPitch);
if (dynamicGain)
noteGain = tsf_decibelsToGain(v->noteGainDB + (v->modlfo.level * tmpModLfoToVolume));
noteGain = v->noteGain * tsf_decibelsToGain(v->modlfo.level * tmpModLfoToVolume);
gainMono = noteGain * v->ampenv.level;
@@ -1435,39 +1455,22 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
TSF_BOOL updateModEnv = (region->modEnvToPitch || region->modEnvToFilterFc);
TSF_BOOL updateModLFO = (v->modlfo.delta && (region->modLfoToPitch || region->modLfoToFilterFc || region->modLfoToVolume));
TSF_BOOL updateVibLFO = (v->viblfo.delta && (region->vibLfoToPitch));
TSF_BOOL isLooping = (v->loopStart < v->loopEnd);
unsigned int tmpLoopStart = v->loopStart, tmpLoopEnd = v->loopEnd;
//double tmpSampleEndDbl = (double)v->sampleEnd, tmpLoopEndDbl = (double)tmpLoopEnd + 1.0;
//double tmpSourceSamplePosition = v->sourceSamplePosition;
fixed32p32 tmpSampleEndF32P32 = ((fixed32p32)(region->end)) << 32;
fixed32p32 tmpLoopEndF32P32 = ((fixed32p32)(tmpLoopEnd + 1)) << 32;
TSF_BOOL isLooping = (v->loopSizeF32P32 > 0);
fixed32p32 tmpSampleEndF32P32 = (fixed32p32)(region->end) << 32;
fixed32p32 tmpSourceSamplePositionF32P32 = v->sourceSamplePositionF32P32;
struct tsf_voice_lowpass tmpLowpass = v->lowpass;
TSF_BOOL dynamicLowpass = (region->modLfoToFilterFc || region->modEnvToFilterFc);
float tmpSampleRate = f->outSampleRate, tmpInitialFilterFc, tmpModLfoToFilterFc, tmpModEnvToFilterFc;
TSF_BOOL dynamicPitchRatio = (region->modLfoToPitch || region->modEnvToPitch || region->vibLfoToPitch);
//double pitchRatio;
fixed32p32 pitchRatioF32P32;
fixed32p32 pitchRatioF32P32, tmpPitchRatioF32P32;
float tmpModLfoToPitch, tmpVibLfoToPitch, tmpModEnvToPitch;
TSF_BOOL dynamicGain = (region->modLfoToVolume != 0);
float noteGain, tmpModLfoToVolume;
float noteGain, tmpNoteGain, tmpModLfoToVolume;
if (dynamicLowpass) tmpInitialFilterFc = (float)region->initialFilterFc, tmpModLfoToFilterFc = (float)region->modLfoToFilterFc, tmpModEnvToFilterFc = (float)region->modEnvToFilterFc;
else tmpInitialFilterFc = 0, tmpModLfoToFilterFc = 0, tmpModEnvToFilterFc = 0;
if (dynamicPitchRatio) tmpPitchRatioF32P32 = v->pitchRatioF32P32, pitchRatioF32P32 = 0, tmpModLfoToPitch = (float)region->modLfoToPitch, tmpVibLfoToPitch = (float)region->vibLfoToPitch, tmpModEnvToPitch = (float)region->modEnvToPitch;
else pitchRatioF32P32 = v->pitchRatioF32P32, tmpModLfoToPitch = 0, tmpVibLfoToPitch = 0, tmpModEnvToPitch = 0;
if (dynamicPitchRatio) pitchRatioF32P32 = 0, tmpModLfoToPitch = (float)region->modLfoToPitch, tmpVibLfoToPitch = (float)region->vibLfoToPitch, tmpModEnvToPitch = (float)region->modEnvToPitch;
else {
double pr = tsf_timecents2Secsd(v->pitchInputTimecents) * v->pitchOutputFactor;
fixed32p32 adj = 1LL<<32;
pr *= adj;
pitchRatioF32P32 = (int64_t)pr, tmpModLfoToPitch = 0, tmpVibLfoToPitch = 0, tmpModEnvToPitch = 0;
}
if (dynamicGain) noteGain = 0, tmpModLfoToVolume = (float)region->modLfoToVolume * 0.1f;
else noteGain = tsf_decibelsToGain(v->noteGainDB), tmpModLfoToVolume = 0;
if (dynamicGain) noteGain = 0, tmpNoteGain = v->noteGain, tmpModLfoToVolume = (float)region->modLfoToVolume * 0.1f;
else noteGain = v->noteGain, tmpModLfoToVolume = 0;
while (numSamples)
{
@@ -1475,19 +1478,17 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
int blockSamples = (numSamples > TSF_RENDER_EFFECTSAMPLEBLOCK ? TSF_RENDER_EFFECTSAMPLEBLOCK : numSamples);
numSamples -= blockSamples;
if (dynamicLowpass)
{
float fres = tmpInitialFilterFc + v->modlfo.level * tmpModLfoToFilterFc + v->modenv.level * tmpModEnvToFilterFc;
tmpLowpass.active = (fres <= 13500.0f);
if (tmpLowpass.active) tsf_voice_lowpass_setup(&tmpLowpass, tsf_cents2Hertz(fres) / tmpSampleRate);
if (dynamicPitchRatio) {
if (v->modlfo.level || v->viblfo.level || v->modenv.level)
pitchRatioF32P32 = tmpPitchRatioF32P32 * tsf_timecents2Secsd(v->modlfo.level * tmpModLfoToPitch + v->viblfo.level * tmpVibLfoToPitch + v->modenv.level * tmpModEnvToPitch);
else
pitchRatioF32P32 = tmpPitchRatioF32P32; // If all levels are 0, just bypass conversion function
}
if (dynamicPitchRatio) {
pitchRatioF32P32 = tsf_timecents2Secsd(v->pitchInputTimecents + (v->modlfo.level * tmpModLfoToPitch + v->viblfo.level * tmpVibLfoToPitch + v->modenv.level * tmpModEnvToPitch)) * v->pitchOutputFactor * (1LL<<32);
}
if (dynamicGain)
noteGain = tsf_decibelsToGain(v->noteGainDB + (v->modlfo.level * tmpModLfoToVolume));
if (dynamicGain) {
if (v->modlfo.level) noteGain = tmpNoteGain * tsf_decibelsToGain(v->modlfo.level * tmpModLfoToVolume);
else noteGain = tmpNoteGain; // If level is 0, just bypass conversion function
}
gainMono = noteGain * v->ampenv.level;
short gainMonoFP = gainMono * 32767;
@@ -1500,7 +1501,7 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
if (updateModLFO) tsf_voice_lfo_process(&v->modlfo, blockSamples);
if (updateVibLFO) tsf_voice_lfo_process(&v->viblfo, blockSamples);
while (blockSamples-- && tmpSourceSamplePositionF32P32 < tmpSampleEndF32P32)
while (blockSamples--)
{
unsigned int pos = (unsigned int)(tmpSourceSamplePositionF32P32>>32);
if (pos == 0xffffffff) pos = 0;
@@ -1512,8 +1513,14 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
// Next sample.
tmpSourceSamplePositionF32P32 += pitchRatioF32P32;
if (tmpSourceSamplePositionF32P32 >= tmpLoopEndF32P32 && isLooping)
tmpSourceSamplePositionF32P32 -= (tmpLoopEndF32P32 - tmpLoopStart + (1LL<<32));
if (tmpSourceSamplePositionF32P32 >= v->loopEndF32P32)
{
if (isLooping)
tmpSourceSamplePositionF32P32 -= v->loopSizeF32P32;
else if (tmpSourceSamplePositionF32P32 >= tmpSampleEndF32P32)
break;
}
}
if (tmpSourceSamplePositionF32P32 >= tmpSampleEndF32P32 || v->ampenv.segment == TSF_SEGMENT_DONE)
@@ -1524,7 +1531,6 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
}
v->sourceSamplePositionF32P32 = tmpSourceSamplePositionF32P32;
if (tmpLowpass.active || dynamicLowpass) v->lowpass = tmpLowpass;
}
@@ -1719,13 +1725,14 @@ TSFDEF void tsf_note_on(tsf* f, int preset_index, int key, float vel)
}
voice = &f->voices[f->voiceNum - 4];
voice[1].playingPreset = voice[2].playingPreset = voice[3].playingPreset = -1;
voice[1].playIndex = voice[2].playIndex = voice[3].playIndex = -1;
}
voice->region = region;
voice->playingPreset = preset_index;
voice->playingKey = key;
voice->playIndex = voicePlayIndex;
voice->noteGainDB = f->globalGainDB - region->attenuation - tsf_gainToDecibels(1.0f / vel);
voice->noteGain = vel * tsf_decibelsToGain(f->globalGainDB - region->attenuation);
if (f->channels)
{
@@ -1741,7 +1748,6 @@ TSFDEF void tsf_note_on(tsf* f, int preset_index, int key, float vel)
// Offset/end.
voice->sourceSamplePosition = region->offset;
voice->sourceSamplePositionF32P32 = ((int64_t)region->offset)<< 32;
// Loop.
doLoop = (region->loop_mode != TSF_LOOPMODE_NONE && region->loop_start < region->loop_end);
@@ -1766,6 +1772,86 @@ TSFDEF void tsf_note_on(tsf* f, int preset_index, int key, float vel)
}
}
/**
* Returns the generated playing index that can be used to identify all voices related to this note.
*/
TSFDEF int tsf_note_on_fast(tsf* f, int preset_index, int key, float vel)
{
if (preset_index < 0 || preset_index >= f->presetNum) return -1;
if (!vel) { tsf_note_off(f, preset_index, key); return -1; }
if (f->presets[preset_index].regions == NULL) tsf_load_preset(f, f->hydra, preset_index);
short midiVelocity = (short)(vel * 127);
struct tsf_region *region, *regionEnd;
// Play all matching regions.
int voicePlayIndex = f->voicePlayIndex++;
for (region = f->presets[preset_index].regions, regionEnd = region + f->presets[preset_index].regionNum; region != regionEnd; region++)
{
if (key < region->lokey || key > region->hikey || midiVelocity < region->lovel || midiVelocity > region->hivel) continue;
struct tsf_voice *voice, *v, *vEnd; TSF_BOOL doLoop;
voice = TSF_NULL, v = f->voices, vEnd = v + f->voiceNum;
if (region->group)
{
for (; v != vEnd; v++)
if (v->playingPreset == preset_index && v->region->group == region->group) tsf_voice_endquick(v, f->outSampleRate);
else if (v->playingPreset == -1 && !voice) voice = v;
}
else for (; v != vEnd; v++) if (v->playingPreset == -1) { voice = v; break; }
if (!voice)
{
f->voiceNum += 4;
struct tsf_voice *saveVoice = f->voices;
f->voices = (struct tsf_voice*)TSF_REALLOC(f->voices, f->voiceNum * sizeof(struct tsf_voice));
if (!f->voices) {
f->voices = saveVoice;
printf("OOM, no room for new voice. Ignoring note_on\n");
return -1;
}
voice = &f->voices[f->voiceNum - 4];
voice[1].playingPreset = voice[2].playingPreset = voice[3].playingPreset = -1;
voice[1].playIndex = voice[2].playIndex = voice[3].playIndex = -1;
}
voice->region = region;
voice->playingPreset = preset_index;
voice->playingKey = key;
voice->playIndex = voicePlayIndex;
voice->noteGain = vel * tsf_decibelsToGain(f->globalGainDB - region->attenuation);
if (f->channels)
{
f->channels->setupVoice(f, voice);
}
else
{
tsf_voice_calcpitchratio(voice, 0, f->outSampleRate);
voice->pitchRatioF32P32 = voice->pitchRatio * (1LL << 32);
}
// Offset/end.
voice->sourceSamplePositionF32P32 = ((int64_t)region->offset)<< 32;
// Loop.
doLoop = (region->loop_mode != TSF_LOOPMODE_NONE && region->loop_start < region->loop_end);
voice->loopStartF32P32 = doLoop ? ((int64_t)region->loop_start + 1) << 32 : 0;
voice->loopEndF32P32 = doLoop ? ((int64_t)region->loop_end + 1) << 32 : 0;
voice->loopSizeF32P32 = doLoop ? voice->loopEndF32P32 - voice->loopStartF32P32 + (1LL << 32) : 0;
// Setup envelopes.
tsf_voice_envelope_setup(&voice->ampenv, &region->ampenv, key, midiVelocity, TSF_TRUE, f->outSampleRate);
tsf_voice_envelope_setup(&voice->modenv, &region->modenv, key, midiVelocity, TSF_FALSE, f->outSampleRate);
// Setup LFO filters.
tsf_voice_lfo_setup(&voice->modlfo, region->delayModLFO, region->freqModLFO, f->outSampleRate);
tsf_voice_lfo_setup(&voice->viblfo, region->delayVibLFO, region->freqVibLFO, f->outSampleRate);
}
return voicePlayIndex;
}
TSFDEF int tsf_bank_note_on(tsf* f, int bank, int preset_number, int key, float vel)
{
int preset_index = tsf_get_presetindex(f, bank, preset_number);
@@ -1794,6 +1880,19 @@ TSFDEF void tsf_note_off(tsf* f, int preset_index, int key)
}
}
/**
* Stops all voices with the given playing index. If no key provided or if -1, fallbacks to tsf_note_off
*/
TSFDEF void tsf_note_off_fast(tsf* f, int preset_index, int key, int playIndex = -1)
{
if (playIndex < 0)
tsf_note_off(f, preset_index, key);
else
for (struct tsf_voice *v = f->voices, *vEnd = v + f->voiceNum; v != vEnd; v++)
if (v->playIndex == playIndex && v->playingPreset == preset_index && v->playingKey == key && v->ampenv.segment < TSF_SEGMENT_RELEASE)
tsf_voice_end(v, f->outSampleRate);
}
TSFDEF int tsf_bank_note_off(tsf* f, int bank, int preset_number, int key)
{
int preset_index = tsf_get_presetindex(f, bank, preset_number);
@@ -1873,7 +1972,7 @@ static void tsf_channel_setup_voice(tsf* f, struct tsf_voice* v)
struct tsf_channel* c = &f->channels->channels[f->channels->activeChannel];
float newpan = v->region->pan + c->panOffset;
v->playingChannel = f->channels->activeChannel;
v->noteGainDB += c->gainDB;
v->noteGain *= tsf_decibelsToGain(c->gainDB);
tsf_voice_calcpitchratio(v, (c->pitchWheel == 8192 ? c->tuning : ((c->pitchWheel / 16383.0f * c->pitchRange * 2.0f) - c->pitchRange + c->tuning)), f->outSampleRate);
if (newpan <= -0.5f) { v->panFactorLeft = 1.0f; v->panFactorRight = 0.0f; }
else if (newpan >= 0.5f) { v->panFactorLeft = 0.0f; v->panFactorRight = 1.0f; }
@@ -1983,7 +2082,7 @@ TSFDEF void tsf_channel_set_volume(tsf* f, int channel, float volume)
if (gainDBChange == 0) return;
for (v = f->voices, vEnd = v + f->voiceNum; v != vEnd; v++)
if (v->playingChannel == channel && v->playingPreset != -1)
v->noteGainDB += gainDBChange;
v->noteGain *= tsf_decibelsToGain(gainDBChange);
c->gainDB = gainDB;
}
@@ -2144,3 +2243,5 @@ TSFDEF float tsf_channel_get_tuning(tsf* f, int channel)
#endif
#endif //TSF_IMPLEMENTATION
#endif // ! ESP32
+3 -3
View File
@@ -1422,7 +1422,7 @@ static int op_open_seekable2_impl(OggOpusFile *_of){
_of->end=sr[0].offset+sr[0].size;
if(OP_UNLIKELY(_of->end<data_offset)){free(sr); return OP_EBADLINK;}
/*Now enumerate the bitstream structure.*/
ret = op_bisect_forward_serialno(_of,data_offset,sr,sizeof(sr)/sizeof(*sr),
ret = op_bisect_forward_serialno(_of,data_offset,sr,64,
&_of->serialnos,&_of->nserialnos,&_of->cserialnos);
free(sr);
return ret;
@@ -1481,7 +1481,7 @@ static int op_open_seekable2(OggOpusFile *_of){
/*Clear out the current logical bitstream decoder.*/
static void op_decode_clear(OggOpusFile *_of){
/*We don't actually free the decoder.
We might be able to re-use it for the next link.*/
We might be able to reuse it for the next link.*/
_of->op_count=0;
_of->od_buffer_size=0;
_of->prev_packet_gp=-1;
@@ -1749,7 +1749,7 @@ opus_int64 op_raw_total(const OggOpusFile *_of,int _li){
ogg_int64_t op_pcm_total(const OggOpusFile *_of,int _li){
OggOpusLink *links;
ogg_int64_t pcm_total;
ogg_int64_t diff;
ogg_int64_t diff = 0;
int nlinks;
nlinks=_of->nlinks;
if(OP_UNLIKELY(_of->ready_state<OP_OPENED)
+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
+73 -126
View File
@@ -2,98 +2,17 @@
set -ex
function print_size_info()
{
elf_file=$1
if [ -z "$elf_file" ]; then
printf "sketch data rodata bss text irom0.text dram flash\n"
return 0
fi
elf_name=$(basename $elf_file)
sketch_name="${elf_name%.*}"
# echo $sketch_name
declare -A segments
while read -a tokens; do
seg=${tokens[0]}
seg=${seg//./}
size=${tokens[1]}
addr=${tokens[2]}
if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then
segments[$seg]=$size
fi
done < <(xtensa-lx106-elf-size --format=sysv $elf_file)
total_ram=$((${segments[data]} + ${segments[rodata]} + ${segments[bss]}))
total_flash=$((${segments[data]} + ${segments[rodata]} + ${segments[text]} + ${segments[irom0text]}))
printf "%-28s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n" $sketch_name ${segments[data]} ${segments[rodata]} ${segments[bss]} ${segments[text]} ${segments[irom0text]} $total_ram $total_flash
return 0
}
function build_sketches()
{
set +e
local arduino=$1
local srcpath=$2
local build_arg=$3
local build_dir=build.tmp
local build_mod=$BUILD_MOD
local build_rem=$BUILD_REM
mkdir -p $build_dir
local build_cmd="python3 $arduino/$BUILD_PY -p $PWD/$build_dir $build_arg "
local sketches=$(find $srcpath -name *.ino)
print_size_info >size.log
export ARDUINO_IDE_PATH=$arduino
for sketch in $sketches; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
rm -rf $build_dir/*
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
echo "Skipping $sketch, 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
wget -q -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
wget -q -O arduino.tar.xz https://downloads.arduino.cc/arduino-nightly-linux64.tar.xz
tar xf arduino.tar.xz
mv arduino-nightly $ide_path
export PATH="$ide_path:$PATH"
@@ -111,84 +30,112 @@ 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
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)
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
cd tools
python3 get.py
export PATH="$ide_path/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/:$PATH"
pip install pyserial
pip3 install pyserial
mkdir -p ~/bin
pushd ~/bin
wget -q https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz
tar xvf arduino-cli_latest_Linux_64bit.tar.gz
export PATH=$PATH:$PWD
popd
arduino-cli core install --additional-urls https://espressif.github.io/arduino-esp32/package_esp32_index.json esp32: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()
function skip_esp32()
{
# 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"
local ino=$1
local skiplist=""
# Add items to the following list with "\n" netween them to skip running. No spaces, tabs, etc. allowed
read -d '' skiplist << EOL || true
/MixerSample/
EOL
echo $ino | grep -q -F "$skiplist"
echo $(( 1 - $? ))
}
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"
export ESP8266_ARDUINO_SKETCHES=$(find $HOME/Arduino/libraries/ESP8266Audio -name *.ino | sort)
# ESP8266 scripts now expect tools in wrong spot. Use simple and dumb fix
mkdir -p "$HOME/work/ESP8266Audio/ESP8266Audio"
ln -s "$HOME/arduino_ide/hardware/esp8266com/esp8266/tools" "$HOME/work/ESP8266Audio/ESP8266Audio/tools"
build_sketches "$TRAVIS_BUILD_DIR" "$HOME/arduino_ide" "$HOME/arduino_ide/hardware" "$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"
export testcnt=0
for i in $(find ~/Arduino/libraries/ESP8266Audio -name "*.ino"); do
testcnt=$(( ($testcnt + 1) % $BUILD_MOD ))
if [ $testcnt -ne $BUILD_REM ]; then
continue # Not ours to do
fi
if [[ $(skip_esp32 $i) = 1 ]]; then
echo -e "\n ------------ Skipping $i ------------ \n";
continue
fi
arduino-cli compile --fqbn esp32:esp32:esp32 --warnings all $i
done
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
+8 -2
View File
@@ -83,7 +83,7 @@ CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -Wstack-usage=300 -include A
.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;
}
+15
View File
@@ -0,0 +1,15 @@
Publishing New Releases
=======================
First, update the version number throughout the repo and push the change:
./tools/makever.py --version X.Y.Z
git commit -a -m "Update version"
git push
Then tag it
git tag X.Y.Z
git push origin X.Y.Z
Then on the GH web interface make a new release from that tag.
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import sys
import struct
import subprocess
import re
import os
import os.path
import argparse
import time
import shutil
import json
def main():
parser = argparse.ArgumentParser(description='Version updater')
parser.add_argument('-v', '--version', action='store', required=True, help='Version in X.Y.Z form')
args = parser.parse_args()
major, minor, sub = args.version.split(".")
# Silly way to check for integer x.y.z
major = int(major)
minor = int(minor)
sub = int(sub)
# library.properties
with open("library.properties", "r") as fin:
with open("library.properties.new", "w") as fout:
for l in fin:
if l.startswith("version="):
l = "version=" + str(args.version) + "\n"
fout.write(l);
shutil.move("library.properties.new", "library.properties")
# package.json
with open("library.json", "r") as fin:
library = json.load(fin);
library["version"] = str(args.version);
with open("library.json.new", "w") as fout:
json.dump(library, fout, indent = 4);
shutil.move("library.json.new", "library.json")
main()