Simple test
Ensure your device works with this simple test.
examples/ay8912_emulator_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2026 Liz Clark for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4
5import time
6
7import audiobusio
8import board
9
10from adafruit_ay8912.ay8912_emulator import AY8912
11from adafruit_ay8912.vgm_player import VGMFile
12
13audio = audiobusio.I2SOut(board.D9, board.D10, board.D11)
14
15# --- Load VGM/VGZ file ---
16VGM_FILE = "song.vgz" # .vgm or .vgz both work
17
18vgm = VGMFile(VGM_FILE)
19
20# --- Create AY8912 with the file's clock rate ---
21ay = AY8912(sample_rate=22050, clock_rate=vgm.clock_hz)
22ay.begin(audio)
23
24# --- Play ---
25print("Playing...")
26if vgm.loops:
27 print(" (song loops — will play through once then loop)")
28vgm.play(ay)
29
30STOP_AFTER_FIRST_LOOP = True
31last_status = time.monotonic()
32
33while vgm.playing:
34 vgm.update()
35
36 if STOP_AFTER_FIRST_LOOP and vgm.loop_count >= 1:
37 print(" Reached loop point — stopping.")
38 break
39
40 now = time.monotonic()
41 if now - last_status >= 5.0:
42 last_status = now
43 print(f" {vgm.elapsed:.0f}s / {vgm.duration:.0f}s ({int(vgm.progress * 100)}%)")
44
45ay.reset()
46print("Done.")