This repository is an experimental WebAssembly build of the [ymfm] Yamaha FM sound cores library.

Overview

libymfm.wasm

This repository is an experimental WebAssembly build of the ymfm Yamaha FM sound cores library.

aaronsgiles / ymfm

BSD-licensed Yamaha FM sound cores (OPM, OPN, OPL, and others)

Supported Sound Chips

chip from note
YM2149 ymfm
YM2151 ymfm
YM2203 ymfm
YM2413 ymfm
YM2608 ymfm
YM2610/YM2610B ymfm
YM2612 ymfm
YM3526 ymfm
Y8950 ymfm
YM3812 ymfm
YMF262 ymfm
YMF278B ymfm
SN76489 mame Rust ports
SEGAPCM mame Rust ports
PWM mame Rust ports
OKIM6285 mame Rust ports

Web Browser Interface

WebAssembly VGM Player

Firefox or Chromium is recommended. Currently, Safari does not support SharedArrayBuffer because it is not available.

  • Web Worker/Worklet architecture
  • WASI build on browser

Source code:

https://github.com/h1romas4/libymfm.wasm/tree/main/examples/web

Python Example

Source code:

https://github.com/h1romas4/libymfm.wasm/tree/main/examples/python

WASI Commnad Line Interface

Options

$ wasmer run libymfm-cli.wasm -- -h
libymfm-cli 0.3.1
h1romas4 
   
    
libymfm CLI

USAGE:
    libymfm-cli.wasm [OPTIONS] 
    
     

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --output 
         Output file path
    -r, --rate 
      
                        Output sampling rate

ARGS:
    
       
         Play .vgm/.vzg file path 
       
      
    
   

Example 1 - Specify output file name

$ wasmer run libymfm-cli.wasm --mapdir /:./docs/vgm -- /ym2612.vgm -o ym2612.pcm
$ ffplay -f f32le -ar 44100 -ac 2 ./docs/vgm/ym2612.pcm

Example 2 - Direct play

$ wasmer run libymfm-cli.wasm --mapdir /:./docs/vgm -- /ym2612.vgm | ffplay -f f32le -ar 44100 -ac 2 -i -

Example 3 - Specify samplig rate

$ wasmer run libymfm-cli.wasm --mapdir /:./docs/vgm -- /ym2612.vgm -r 96000 | ffplay -f f32le -ar 96000 -ac 2 -i -

Source code:

https://github.com/h1romas4/libymfm.wasm/tree/main/examples/libymfm-cli

Build

Build require Rust 2021 edition

Cargo.toml

[package]
edition = "2021"
rust-version = "1.56"

Setup wasi-sdk-12

.bashrc

export WASI_SDK_PATH=/home/hiromasa/devel/toolchain/wasi-sdk-12.0
export CARGO_TARGET_WASM32_WASI_LINKER=${WASI_SDK_PATH}/bin/lld
export CARGO_TARGET_WASM32_WASI_RUSTFLAGS="-L ${WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasi"
$ echo ${WASI_SDK_PATH}
/home/hiromasa/devel/toolchain/wasi-sdk-12.0
$ ls -alF ${WASI_SDK_PATH}
drwxr-xr-x 2 hiromasa hiromasa 4096 12月  3  2020 bin/
drwxr-xr-x 3 hiromasa hiromasa 4096 12月  3  2020 lib/
drwxr-xr-x 6 hiromasa hiromasa 4096 12月  3  2020 share/
$ ${WASI_SDK_PATH}/bin/clang -v
clang version 11.0.0 (https://github.com/llvm/llvm-project 176249bd6732a8044d457092ed932768724a6f06)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /home/hiromasa/devel/toolchain/wasi-sdk-12.0/bin

cmake / make

git clone --recursive https://github.com/h1romas4/libymfm.wasm
cd libymfm.wasm
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/wasi.cmake  ..
make -j4

Web Browser Interface (examples/web)

Install wasm-bindgen

cargo install wasm-bindgen-cli

Rust build and wasm-bindgen

rustup target add wasm32-wasi
cargo build --release --target wasm32-wasi --features bindgen
wasm-bindgen target/wasm32-wasi/release/libymfm.wasm --out-dir ./examples/web/src/wasm/

npm

cd examples/web
npm install
npm run start

WASI Commnad Line Interface (examples/libymfm-cli)

@see libymfm command line interface

Python Binding Test (examples/python)

Rust build and copy .wasm to Python project

rustup target add wasm32-wasi
cargo build --release --target wasm32-wasi
cp -p target/wasm32-wasi/release/libymfm.wasm ./examples/python/src/wasm/

Run Python

cd examples/python
# Install require
pip3 install -r requirements.txt
# Simple VGM Player
python src/sample_vgmplay.py
# Pyxel impliments example
python src/sample_pyxel.py

Build Note

Essentially, wasm-bindgen is incompatible with wasm32-wasi.

improve panic message when compiling to wasi #2554

panicked at 'unknown instruction LocalTee

To link Rust 1.55 with C/C++ using wasm32-wasi, you need LLD for LLVM 12.

WASI: Cannot open paths with nightly >= 2021-03-11 when linked with LLD 11.1 #85840

failed to find a pre-opened file descriptor

wasm-bindgen outputs a TextEncoder TextDecoder function that cannot be used in a Worklet.

Unblock AudioWorklets: Find an alternative to TextEncoder / TextDecoder #2367

License

BSD 3-Clause License

Thanks

TODO / Known Issues

  • VGM driver
    • YM2141 clock worng?
    • Is there a problem with the file parser? The beginning of the song may be wrong.
    • Support all data stream (now only support YM2612 and OKIM6285)
  • Non-vgm driver support
    • XGM
  • Multilingual Interface
    • CLI
    • Web/JavaScript
    • Python wasmer-python
    • Add an interface that does not depend on wasm-bindgen
  • ymfm
    • Add direct ymfm intarfece
    • Support yfmf's all sound chips
  • Refactoring
    • Better upsampling
    • Separate the sound stream from the sound driver.
    • Support for arbitrary input tick rate and output sampling rate.
    • Support data stream.
  • Add support sound chip
    • Fix SEGAPCM
    • OKIM6285
    • Next to be determined
  • Examples source
    • Web Frontend: Support YM2608 ADPCM ROM (wasmer-js WASI fopen)
    • Web Frontend: AudioWorklet
    • Web Frontend: Web Worker AudioWorklet and SharedArrayBuffer (The Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers cannot be set in github pages, so they cannot be deployed)
    • Web Frontend: Add buffering mode
    • CLI: Support loop and feedout
  • To BSD license
    • SN76489
    • PWM
You might also like...
Rust Sound Synthesis Library

Oscen Oscen [“oh-sin”] is a library for building modular synthesizers in Rust. It contains a collection of components frequently used in sound synthes

A CLI and library to convert data to sound, and vice versa (dependency-free)

Data to sound A simple crate to convert data to sound, and sound to data. The sound file format is wave (.wav). You can use it as a library or as a co

Procedural engine sound generator controlled via GUI or CLI
Procedural engine sound generator controlled via GUI or CLI

enginesound GUI Application used to generate purely synthetic engine sounds with advanced options written in Rust loosely based on this paper Reading

A Rust environment for sound synthesis and algorithmic composition.

Sorceress A Rust environment for sound synthesis and algorithmic composition, powered by SuperCollider. Overview Sorceress is a Rust crate that provid

📜🔁🎶 A CLI which converts morse code into sound

morse2sound 🎵 A CLI which converts morse code to sound Big shoutout to Br1ght0ne for guiding me how to use Rust on stream

A Rust CLI that makes mechanical keyboard sound effects on every key press
A Rust CLI that makes mechanical keyboard sound effects on every key press

Rustyvibes A Rust CLI that makes mechanical keyboard sound effects on every key press Rustyvibes.mp4 Installation macOS: brew install kb24x7/rustyvibe

A cross-platform sequencer that internally uses a Game Boy emulator to synthesize the sound
A cross-platform sequencer that internally uses a Game Boy emulator to synthesize the sound

chiptrack chiptrack is a cross-platform sequencer that internally uses a Game Boy emulator to synthesize the sound. It uses: SixtyFPS for the UI. RBoy

🔌 A curseforge proxy server, keeping your API key safe and sound.

🔌 CFPROXY - The curseforge proxy server Curseforge has locked down their API and now restricts access without authentification. This spells trouble f

A simple interactive OSC (Open Sound Control) debugger for terminal
A simple interactive OSC (Open Sound Control) debugger for terminal

oscd, a simple interactive OSC debugger for the terminal by using nom as a lexer/parser, oscd offers auto type casting and support sending multiple osc arguments.

Detects Linux input, notifies with bell sound

Keypress Notifier keypress-notifier는 리눅스에서 동작하는 입력 이벤트 감지 및 벨 소리 알림 프로젝트입니다. 소개 keypress-notifier는 Rust 언어로 개발되었으며, 키패드, 마우스 등의 입력 이벤트를 감지하고, 벨 소리로 사용

A (very experimental) WebAssembly backend for Cranelift.

cranelift_codegen_wasm Experimental code generation for WebAssembly from Cranelift IR. note: not ready for usage yet Setup Contains an item called Was

⚙️ Experimental JVM bytecode to WebAssembly compiler

⚙️ montera Final year university project: a highly experimental JVM bytecode to WebAssembly compiler ⚠️ Do NOT use this for serious projects yet! It's

An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets.

Promise x Tokio = Prokio An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets. Rationale When designing components and libr

Experimental language build in Rust to make it fast and robust

Reg-lang Experimental language build with Rust. Its aim is : To be simple to help learning programmation with, and in a second hand, to be robust enou

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.

Percy Build frontend browser apps with Rust + WebAssembly. Supports server side rendering. The Percy Book This README gives a light introduction to Pe

An attempt to build full-featured WebAssembly-based monolith charts

Graphima Graphima (Greek: γράφημα) is an attempt to build full-featured WebAssembly-based monolith charts. See "Can I Use" WebAssembly for browser sup

Meta-repository for Miscreant: misuse-resistant symmetric encryption library with AES-SIV (RFC 5297) and AES-PMAC-SIV support

The best crypto you've never heard of, brought to you by Phil Rogaway A misuse resistant symmetric encryption library designed to support authenticate

This repository features a simple Kalman filter and RTS smoother (KFS) implementation in Rust by using the ndarray library.
This repository features a simple Kalman filter and RTS smoother (KFS) implementation in Rust by using the ndarray library.

Kalman filter and RTS smoother in Rust (ndarray) This repository features a simple Kalman filter and RTS smoother (KFS) implementation in Rust by usin

Rust library for build scripts to compile C/C++ code into a Rust library

A library to compile C/C++/assembly into a Rust library/application.

Releases(v0.14.0)
Owner
hiromasa
Retro Futuristic Gadget
hiromasa
Just-config is a configuration library for rust

Config Library for Rust Just-config is a configuration library for rust. It strives for the old Unix mantra "Do one thing and to it well".

FlashSystems 7 Apr 15, 2022
A Rust library for processing application configuration easily

Configure me A Rust library for processing application configuration easily About This crate aims to help with reading configuration of application fr

Martin Habovštiak 48 Dec 18, 2022
hosts file parsing, modification library, and some derivatives.

hosts-rs hosts: Hosts file parsing, modification library resolve-github: Use Cloudflare DoH to resolve GitHub domains and generate hosts files github-

zu1k 33 Jul 4, 2022
cfg-rs: A Configuration Library for Rust Applications

cfg-rs: A Configuration Library for Rust Applications Major Features One method to get all config objects, see get. Automatic derive config object, se

Daniel YU 20 Dec 16, 2022
A systemd-boot configuration and boot entry configuration parser library

A systemd-boot configuration and boot entry configuration parser library

Kaiyang Wu 2 May 22, 2022
This is a test to port C++'s ymfm and Rust's vgmplay to ESP32(Xtensa).

m5stack-chipstream This is a test to port C++'s ymfm and Rust's vgmplay to ESP32(Xtensa). Still slow and impractical, depending on the sound chip you

hiromasa 4 Feb 26, 2023
SysEx editor for Roland SC-55 (GS), Roland SC-7, and eventually maybe Yamaha XG

SoundPalette: MIDI SysEx Generator This is the source code for SoundPalette, a tool for editing MIDI System Exclusive (SysEx) messages for the Roland

hikari_no_yume 9 Dec 8, 2023
Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...

LibAFL, the fuzzer library. Advanced Fuzzing Library - Slot your own fuzzers together and extend their features using Rust. LibAFL is written and main

Advanced Fuzzing League ++ 1.2k Dec 29, 2022
Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...

LibAFL, the fuzzer library. Advanced Fuzzing Library - Slot your own fuzzers together and extend their features using Rust. LibAFL is written and main

Advanced Fuzzing League ++ 1.2k Jan 6, 2023
RustSBI support on SiFive FU740 board; FU740 is a five-core heterogeneous processor with four SiFive U74 cores, and one SiFive S7 core

RustSBI 在 HiFive Unmatched 主板的支持软件 这个项目的目的是在SiFive HiFive Unmatched主板上支持RustSBI。 RustSBI是一个引导程序环境;主板上电时,RustSBI将会先行启动,而后,它将会找到一个可引导的操作系统,引导启动这个操作系统。 在

RustSBI 15 Dec 1, 2022