docs.rs failed to build ym2149-wasm-0.9.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
ym2149-wasm-0.8.0
ym2149-wasm
WebAssembly bindings for the YM2149 PSG emulator - play YM chiptunes, Arkos Tracker projects, and Project AY rips directly in your browser!
Features
- ๐ต Play YM2โYM6, Arkos Tracker
.aks, and ZXAY/EMUL.ayfiles in the browser - ๐ฎ Full playback control (play, pause, stop, seek)
- ๐ Volume control and channel muting
- ๐ Real-time waveform data for visualizations
- ๐ Metadata extraction (title, author, comments)
- โก High-performance cycle-accurate emulation
- ๐จ Web Audio API integration
Installation
Build from Source
# Install wasm-pack
|
# Build the WASM module
# Or for bundler (webpack, rollup, etc.)
# Shortcut: rebuild + copy into examples/pkg
Quick Start
Basic Usage
import init from './ym2149_wasm.js';
Web Audio API Integration
import init from './ym2149_wasm.js';
// Usage
const player = ;
await player.;
// Load file from user input
const input = document.;
input.;
Playback Control
// Play/Pause
if else
// Volume control (0.0 to 1.0)
player.;
// Seek to position
player.; // Seek to 50%
player.; // Seek to frame 1000
// Channel muting (for karaoke-style playback)
player.; // Mute channel A
player.; // Unmute channel B
player.; // Unmute channel C
// Get playback position
console.log;
console.log;
Metadata Access
const metadata = player.;
console.log;
console.log;
console.log;
console.log;
console.log;
console.log;
console.log;
Visualization
// Get current register values for visualization
const registers = player.; // Returns Uint8Array[16]
// Register layout:
// R0-R1: Channel A period
// R2-R3: Channel B period
// R4-R5: Channel C period
// R6: Noise period
// R7: Mixer control
// R8-R10: Channel volumes
// R11-R12: Envelope period
// R13: Envelope shape
// R14-R15: I/O ports
// Calculate frequencies
const channelAPeriod = registers | ;
const frequencyA = 2000000 / ; // Master clock / (16 * period)
// Draw waveform visualization
API Reference
Ym2149Player
Constructor
constructor(data: Uint8Array): Ym2149Player
Creates a new player from YM file data.
Properties
metadata: YmMetadata- Song metadata (read-only)
Methods
play(): void- Start playbackpause(): void- Pause playbackstop(): void- Stop and reset to beginningrestart(): void- Restart from beginningis_playing(): boolean- Check if currently playingstate(): string- Get playback state as string
Volume Control:
set_volume(volume: number): void- Set volume (0.0-1.0)volume(): number- Get current volume
Seeking:
seek_to_frame(frame: number): void- Seek to specific frameseek_to_percentage(percentage: number): void- Seek to percentage (0.0-1.0)frame_position(): number- Get current frameframe_count(): number- Get total framesposition_percentage(): number- Get position as percentage
Channel Control:
set_channel_mute(channel: number, mute: boolean): void- Mute/unmute channel (0-2)is_channel_muted(channel: number): boolean- Check if channel is muted
Audio Generation:
generateSamples(count: number): Float32Array- Generate audio samplesgenerateSamplesInto(buffer: Float32Array): void- Generate into buffer (zero-alloc)
Visualization:
get_registers(): Uint8Array- Get current PSG register values (16 bytes)
Effects:
set_color_filter(enabled: boolean): void- Enable/disable ST color filter
YmMetadata
interface YmMetadata {
title: string; // Song title
author: string; // Composer/author
comments: string; // Song comments
format: string; // YM format version (e.g., "YM6")
frame_count: number; // Total frames
frame_rate: number; // Frame rate in Hz (typically 50)
duration_seconds: number; // Duration in seconds
}
Examples
See the examples/ directory for complete working examples:
simple-player.html- Minimal web playeradvanced-player.html- Full-featured player with UIvisualizer.html- Player with oscilloscope and spectrum analyzerbundler-example/- Example using webpack/rollup
Performance
The WASM module is highly optimized:
- โก ~6ns per emulator clock cycle
- ๐ต Real-time generation of 44.1kHz audio
- ๐ฆ Small bundle size (~100KB gzipped)
- ๐ Minimal CPU usage (<1% on modern hardware)
Browser Support
Works in all modern browsers that support:
- WebAssembly
- Web Audio API
- ES6 Modules (or use a bundler)
Tested on:
- โ Chrome/Edge 90+
- โ Firefox 88+
- โ Safari 15+
- โ Mobile browsers (iOS Safari, Chrome Mobile)
Building
Development Build
Production Build
Build Options
# Target web (ES modules)
# Target bundler (webpack, rollup, parcel)
# Target Node.js
# With features
Credits
- Leonard/Oxygene (Arnaud Carrรฉ) - AtariAudio reference implementation
- Atari ST demoscene community - Original music and SNDH archive
License
MIT - See main repository for details.