The description of `AACDecode()` function states that the output buffer
must be big enough for 1024 samples per channel _or_ 2048 if SBR is
enabled. By default SBR is enabled on non-ESP8266 platforms, yet the
buffer in `AudioGeneratorAAC` is always 1024 samples per channel long.
This causes memory corruption on ESP32 and possibly Pi Pico. This change
makes the output buffer correct.
For AudioGeneratorWAV, the upsample from u8 to i16 bits has been fixed. Previously, playback of wav files with u8 encoding resulted in silence. The data was read, but not used in calculations. Additionally, in mono mode, I removed the unnecessary resolution increase for the second channel and implemented simple duplication. Now, when playing mono wav files, the audio will be in both the left and right channels.
i2s_channel_enable(_tx_handle) was only called within
AudioOutputSPDIF::SetRate(), which caused i2s_channel_write to fail
if the rate was the same with the default 44100Hz.
This fixes the issue by calling it in begin().
The I2S write was always blocking meaning only a single loop call
might have ended up playing the entire audio output.
Replace the timeout of `10` with `0`.
By rendering into a 32b int we don't have to saturate check in the inner
loop of the voice render, which is called multiple times per actual output
block. That check is very expensive.
In tsf_render_short make the input `short *buffer` have 2x the space as
normal to allow the full 32b quantity for each sample to accumulate.
After all voices have been rendered, then resample with saturation into
int16_t values.
About 24% faster on the Pico while still saturating properly.
* Pull untouched upstream TinySoundFont
Start from the upstream TinySoundFont by @schellingb at
https://github.com/schellingb/TinySoundFont and rearchitect the MIDI
processing.
* Convert to PROGMEM-based SoundFont structures.
This makes it much faster to access the SoundFont and also removes all the
static RAM usage. The samples, the regions, the instruments are all now
in ROM. Only the dynamic voices and related info takes up RAM. No caching.
* (Re)convert to fixed point math.
TSF upstream is built for systems with real floating point units (and
produces great sound with it!), but processors like the Pico, ESP8266,
and several models of ESP32 don't have one so emulate FP in *extremely*
slow SW. Use fixed point (integer) representations for the inner loop
and wherever possible to avoid `float` math.
For processors like the Pico 2 or original ESP32 with hardware FPUs this
still increases performance since integer is still much faster.
* Redo the example and add default SF2s
Rewrite the MIDI examples to use PROGMEM for both SF2 and MID file.
It simplifies life for the casual user and me.
* Breaking change
The MIDI object now has a `midi::SetSoundFont(tsf *)` instead of a
`midi::SetSoundfont(AudioFileSource *)`. It no longer supports reading
SF2 from LittleFS or SD.
Espressif changes the contents of the PDM struct depending on the
chip model. Use a hopefully valid `#define` to avoid setting a
member that's not there in some cases.
Fixes#785
Move to the new I2S driver for the ESP chips, since the next revisioncl
of the IDF will remove them completely.
Make the I2S constructors saner and add consistent SetPinout() and
SetBuffers calls to allow configuration.
Remove need for separate UseMCLK or SwapClocks calls, we can figure
that out from the pins selected.
Fixes#758
Only the WAV and FLAC generators can generate 8-bit values, so it is
more efficient and sane to just have those generators upscale to 16-bit
signed (if necessary) in generation and simplify all the other
Generators and Outputs.
Move to Opus 1.5.1
Remove OpusFile and OGG libraries because we parse the OGG file in
the object directly with way less memory and overhead.
Update example for LittleFS and RP2040
Fixes#372
* Fix ULP on ESP32
CONFIG_IDF_TARGET_ESP32 is not yet defined before #include "AudioOutputULP.h"
* AudioOutputULP: Fix DAC2 stereo in case of DAC1+DAC2
* ULP - no ESP32S2 / S3
On ESP32S2 it compiles, but no audio is coming out
On ESP32S3 DAC is not supported
* Astyle
---------
Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
* Tell the mixer at which rate to consume the next sample
* Update SetRate method to include id parameter
* Refactor SetRate to minimize redundant updates
Optimize rate setting to avoid unnecessary calls.
* Add newHz and lastHz variables to AudioOutputMixer
---------
Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
On the ESP32 it seems the i2s clock set will cause a hiccup, even
if it's setting the exact same clock as before.
Avoid it by only setting the I2S clock if it differs from the last set.
Initialize it to 0hz to ensure the first setRate call always works.
Supercedes #656
Very minor fix for damaged SoundFont files.
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>