API Reference
AY8912
AY-3-8910 / AY-8912 emulator for CircuitPython with synthio.
Translates AY-3-8910 register writes into synthio.Note property updates. Three
synthesizers (one per channel) feed an audiomixer.Mixer for
per-channel volume and stereo panning.
Author(s): Liz Clark
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class adafruit_ay8912.ay8912_emulator.AY8912(sample_rate: int = 22050, clock_rate: int = 1773400, waveform_size: int = 256, noise_size: int = 256, volume: int = 32000)
AY-3-8910 / AY-8912 emulator backed by
synthio.- Parameters:
sample_rate (int) – Output sample rate in Hz.
clock_rate (int) – AY chip clock frequency in Hz. Defaults to the ZX Spectrum 128K clock (1773400 Hz).
waveform_size (int) – Number of samples in the square waveform.
noise_size (int) – Number of samples in the noise waveform.
volume (int) – Peak sample amplitude used when building the waveforms.
- begin(audio_out) None
Begin audio signal chain.
Handles
audio_out.play(mixer)first, then connects the synth voices:ay = AY8912(sample_rate=22050) ay.begin(audio)
- Parameters:
audio_out – The audio output object
- enable_noise(channel: int, enable: bool = True) None
Enable or disable noise output for a channel via the mixer (R7).
- enable_tone(channel: int, enable: bool = True) None
Enable or disable tone output for a channel via the mixer (R7).
- property mixer: audiomixer.Mixer
The
audiomixer.Mixer. Connect to audio output withaudio.play(ay.mixer)(or just callbegin()).
- property notes: Tuple[synthio.Note, ...]
Direct access to the three
synthio.Noteobjects (read-only tuple).
- read_register(reg: int) int
Read an AY register.
- Parameters:
reg (int) – Register index (0-15).
- Returns:
The stored register value, or 0 if
regis out of range.
- set_envelope(period: int, shape: int) None
Set the envelope period (R11/R12) and shape (R13).
Writing R13 resets the envelope generator.
- set_noise_period(period: int) None
The 5-bit noise period (R6).
- Parameters:
period (int) – Noise period (only the low 5 bits are used).
- set_tone_period(channel: int, period: int) None
The 12-bit tone period directly (R0/R1, R2/R3, R4/R5).
- set_volume(channel: int, volume: int, envelope: bool = False) None
Set a channel’s volume (R8/R9/R10).
VGMFile
VGM chiptune file parser and player for CircuitPython.
Plays VGM (and gzip-compressed VGZ) files through an
AY8912 instance.
Only files with a non-zero AY-3-8910 clock (header offset 0x74) are
supported. Files targeting other chips (SN76489, YM2612, etc.) are rejected.
Author(s): Liz Clark
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class adafruit_ay8912.vgm_player.VGMFile(filename: str | None = None)
Parse and play an AY8912 VGM/VGZ file.
- Parameters:
filename (str) – Path to a
.vgmor.vgzfile to load immediately. PassNoneto create an empty object and callload()later.
- load(filename: str) None
Load a
.vgmor.vgzfile, decompressing gzip natively.- Parameters:
filename (str) – Path to the file to load.
- Raises:
RuntimeError – If the file is not a VGM, cannot be decompressed, or does not target the AY-3-8910.
- play(ay: AY8912) None
Start playback through the AY8912 instance.
- Parameters:
ay (AY8912) – The emulator that register writes will be sent to. It is reset before playback.