Files
2026-07-08 01:15:18 +08:00

6.3 KiB

ModFM (Web-based Tracker Music Player)

License: MIT Nuxt WebAssembly


ModFM

ModFM is a web-based Tracker format music player built with Nuxt.js, WebAssembly (libopenmpt), and the Web Audio API (AudioWorklet). It supports playing various retro tracker formats (such as MOD, XM, S3M, IT, etc.) and integrates a SidWiz-style oscilloscope visualizer to display stable real-time waveforms for each channel.

ModFM Preview


Tech Stack

  • Core Framework: Nuxt.js (Vue 3 / TypeScript)
  • Audio Decoding: libopenmpt compiled to WebAssembly
  • Audio Playback: Web Audio API (AudioWorklet) running on an asynchronous rendering thread
  • Waveform Rendering: Waveform extraction and Canvas real-time rendering based on the SidWiz algorithm
  • Styling: Tailwind CSS

Directory Structure

modfm/
├── app/                  # Frontend views and interactive components (Vue 3 / Nuxt 3)
├── chiptune/             # AudioWorklet logic and WASM packaging scripts
├── data/                 # Local data storage (ignored, containing .gitkeep)
│   └── music/            # Default local folder for music files
├── libopenmpt/           # C/C++ core decoding library with the ported SidWiz algorithm
├── public/               # Static assets (including compiled WASM glue files)
├── server/               # Backend API routes and SQLite database integration layer
│   ├── db.ts             # Database initialization and schema setup
│   └── utils/
│       └── scanner.ts    # Incremental music directory scanner
├── types/                # TypeScript declaration files
├── package.json          # Project dependencies and scripts
├── LICENSE               # MIT open-source license file
└── BUILD_libopenmpt.md   # WebAssembly build instructions for the core library

Prerequisites

  • Node.js: node >= 18.0.0
  • Package Manager: npm or pnpm is recommended
  • C/C++ Toolchain (Optional): Only required if you modify and need to rebuild the libopenmpt WebAssembly binary. Local installation of Emscripten SDK is required.

Environment Variables

The project supports runtime configuration via the following environment variables:

Variable Description Default Example
MUSIC_PATH Custom absolute path to scan for music files. If not specified, it defaults to the local data/music directory. [Project Root]/data/music /var/music/my_mods
PORT The listening port for production preview (npm run preview) or dev mode. 3400 (preview) / 3401 (dev) 8080

Quick Start

1. Install Dependencies

# npm
npm install

# pnpm
pnpm install

2. Development Server

Start the development server (default port 3401):

npm run dev

Open http://localhost:3401 in your browser.

3. Production Build & Preview

Build the application for production:

npm run build

Preview the production build (default port 3400):

npm run preview

Development & Configuration Guide

1. Database Setup

The server uses SQLite (via the better-sqlite3 driver):

  • Automated Setup: On the first launch, the app automatically creates a data/ directory and app.sqlite database file in the project root, initializing all schema tables (users, songs, favorites, etc.) and indexes. No manual SQL scripts are required.

2. Music Import & Scan

  • Default Path: Place your music files (such as mod, xm, it, s3m tracker modules, or traditional mp3, ogg, wav files) in the local data/music/ folder, or specify a custom directory using the MUSIC_PATH environment variable.
  • Scanning Mechanism:
    • First-run Auto Scan: If the database songs table is empty upon startup, a background incremental scanner automatically populates the database from the designated path.
    • Manual Trigger: Send a POST request to /api/admin/scan to manually force an incremental scan and clean up obsolete records.

3. Custom Modifications to libopenmpt (Vendored Modifications)

To enable real-time, jitter-free oscilloscope rendering, we deeply integrated and customized the libopenmpt decoder. All modifications are in the libopenmpt/ folder:

  • Waveform Processor: Added waveform_processor.c and waveform_processor.h to implement the C version of the PeakSpeedTrigger alignment algorithm, 1-pole high-pass filter, and adaptive period tracking.
  • Mixer Interception: Modified Fastmix.cpp to intercept raw PCM float outputs from each active channel and feed them into the waveform processor.
  • Interface Exposure: Modified Sndfile.cpp to reset the processors when loading a track and export WASM bindings for the frontend AudioWorklet to read the stabilized waveform buffers.

Tip

If you make changes to the C/C++ files under libopenmpt/ and need to compile it, please refer to the WASM Build Guide.


License & Third-Party Credits

The primary codebase of ModFM is licensed under the MIT License.

This project vendors or links with several open-source subprojects:

  1. libopenmpt (located at libopenmpt/) - BSD-3-Clause License. Copyright (c) 2004-2026 OpenMPT Developers. Used for tracker decoding.
  2. SidWiz (algorithm reference) - MIT License reference. The waveform synchronization logic (PeakSpeedTrigger & adaptive width) is ported from Maxim's SidWizPlus.
  3. chiptune3.worklet.js (located at chiptune/) - MIT License. Custom fork based on DrSnuggles' chiptune3.js framework.

NPM Dependency Licenses

  • @nuxtjs/color-mode: MIT
  • bcryptjs: BSD-3-Clause
  • better-sqlite3: MIT
  • nuxt: MIT
  • vue: MIT
  • vue-router: MIT
  • @nuxtjs/tailwindcss: MIT
  • @types/node: MIT