Skip to content

Commit 7f2c30c

Browse files
Remove @micropython.viper fallback for macOS
1 parent 965eec1 commit 7f2c30c

File tree

1 file changed

+15
-22
lines changed
  • internal_filesystem/apps/com.micropythonos.musicplayer/assets

1 file changed

+15
-22
lines changed

internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -201,29 +201,22 @@ def play_wav(cls, filename, result_callback=None):
201201
print(f"Playing {data_size} original bytes (vol {cls._volume}%) ...")
202202
f.seek(data_start)
203203

204-
# Fallback to non-viper and non-functional code on desktop, as macOS/darwin throws "invalid micropython decorator"
204+
# ----- Viper volume scaler (16-bit only) -------------------------
205+
@micropython.viper # throws "invalid micropython decorator" on macOS / darwin
205206
def scale_audio(buf: ptr8, num_bytes: int, scale_fixed: int):
206-
pass
207-
208-
try:
209-
# ----- Viper volume scaler (16-bit only) -------------------------
210-
@micropython.viper # throws "invalid micropython decorator" on macOS / darwin
211-
def scale_audio(buf: ptr8, num_bytes: int, scale_fixed: int):
212-
for i in range(0, num_bytes, 2):
213-
lo = int(buf[i])
214-
hi = int(buf[i+1])
215-
sample = (hi << 8) | lo
216-
if hi & 128:
217-
sample -= 65536
218-
sample = (sample * scale_fixed) // 32768
219-
if sample > 32767:
220-
sample = 32767
221-
elif sample < -32768:
222-
sample = -32768
223-
buf[i] = sample & 255
224-
buf[i+1] = (sample >> 8) & 255
225-
except SyntaxError:
226-
print("Viper not supported (e.g., on desktop)—using plain Python.")
207+
for i in range(0, num_bytes, 2):
208+
lo = int(buf[i])
209+
hi = int(buf[i+1])
210+
sample = (hi << 8) | lo
211+
if hi & 128:
212+
sample -= 65536
213+
sample = (sample * scale_fixed) // 32768
214+
if sample > 32767:
215+
sample = 32767
216+
elif sample < -32768:
217+
sample = -32768
218+
buf[i] = sample & 255
219+
buf[i+1] = (sample >> 8) & 255
227220

228221
chunk_size = 4096
229222
bytes_per_original_sample = (bits_per_sample // 8) * channels

0 commit comments

Comments
 (0)