You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
AudioFlinger: re-add viper optimizations
These make a notable difference when playing audio on ESP32. Without them, each UI action causes a stutter, so it's not fun to listen to audio while doing anything on the device. With them, most UI actions don't cause a stutter. Long maxed out CPU runs and storage access still do, though.
This commit is contained in:
+3
-2
@@ -1,7 +1,8 @@
|
||||
0.5.1
|
||||
=====
|
||||
- Fri3d Camp 2024 Badge: workaround ADC2+WiFi conflict by temporarily disable WiFi to measure battery level
|
||||
- Fri3d Camp 2024 Badge: improve battery monitor calibration to fix 0.1V delta
|
||||
- Fri3d Camp 2024 Board: add startup light and sound
|
||||
- Fri3d Camp 2024 Board: workaround ADC2+WiFi conflict by temporarily disable WiFi to measure battery level
|
||||
- Fri3d Camp 2024 Board: improve battery monitor calibration to fix 0.1V delta
|
||||
- API: improve and cleanup animations
|
||||
- API: SharedPreferences: add erase_all() function
|
||||
- API: add defaults handling to SharedPreferences and only save non-defaults
|
||||
|
||||
@@ -7,14 +7,16 @@ import os
|
||||
import time
|
||||
import sys
|
||||
|
||||
# Volume scaling function - regular Python version
|
||||
# Note: Viper optimization removed because @micropython.viper decorator
|
||||
# causes cross-compiler errors on Unix/macOS builds even inside conditionals
|
||||
def _scale_audio(buf, num_bytes, scale_fixed):
|
||||
"""Volume scaling for 16-bit audio samples."""
|
||||
# Volume scaling function - Viper-optimized for ESP32 performance
|
||||
# NOTE: The line below is automatically commented out by build_mpos.sh during
|
||||
# Unix/macOS builds (cross-compiler doesn't support Viper), then uncommented after build.
|
||||
import micropython
|
||||
@micropython.viper
|
||||
def _scale_audio(buf: ptr8, num_bytes: int, scale_fixed: int):
|
||||
"""Fast volume scaling for 16-bit audio samples using Viper (ESP32 native code emitter)."""
|
||||
for i in range(0, num_bytes, 2):
|
||||
lo = buf[i]
|
||||
hi = buf[i + 1]
|
||||
lo = int(buf[i])
|
||||
hi = int(buf[i + 1])
|
||||
sample = (hi << 8) | lo
|
||||
if hi & 128:
|
||||
sample -= 65536
|
||||
|
||||
@@ -101,12 +101,23 @@ if [ "$target" == "esp32" ]; then
|
||||
elif [ "$target" == "unix" -o "$target" == "macOS" ]; then
|
||||
manifest=$(readlink -f "$codebasedir"/manifests/manifest.py)
|
||||
frozenmanifest="FROZEN_MANIFEST=$manifest"
|
||||
|
||||
# Comment out @micropython.viper decorator for Unix/macOS builds
|
||||
# (cross-compiler doesn't support Viper native code emitter)
|
||||
echo "Temporarily commenting out @micropython.viper decorator for Unix/macOS build..."
|
||||
stream_wav_file="$codebasedir"/internal_filesystem/lib/mpos/audio/stream_wav.py
|
||||
sed -i 's/^@micropython\.viper$/#@micropython.viper/' "$stream_wav_file"
|
||||
|
||||
# LV_CFLAGS are passed to USER_C_MODULES
|
||||
# STRIP= makes it so that debug symbols are kept
|
||||
pushd "$codebasedir"/lvgl_micropython/
|
||||
# USER_C_MODULE doesn't seem to work properly so there are symlinks in lvgl_micropython/extmod/
|
||||
python3 make.py "$target" LV_CFLAGS="-g -O0 -ggdb -ljpeg" STRIP= DISPLAY=sdl_display INDEV=sdl_pointer INDEV=sdl_keyboard "$frozenmanifest"
|
||||
popd
|
||||
|
||||
# Restore @micropython.viper decorator after build
|
||||
echo "Restoring @micropython.viper decorator..."
|
||||
sed -i 's/^#@micropython\.viper$/@micropython.viper/' "$stream_wav_file"
|
||||
else
|
||||
echo "invalid target $target"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user