Files
romm/docker/gme/romm_gme.cpp
Sam Dornan 38eaf89438 feat(soundtrack): play chiptune soundtracks through game-music-emu
Soundtrack files in NSF, NSFE, SPC, GBS, VGM, VGZ, GYM, HES, KSS, AY and
SAP formats now play in the v2 soundtrack panel, mini player and Jukebox.

- Build libgme 0.6.5 to a standalone WebAssembly module in a pinned
  emsdk stage of both Dockerfiles, with a small shim that opens a file
  from memory and starts a track with a fade at its resolved length.
  zlib is left out; the player gunzips VGZ files in the browser.
- Run the emulator inside an AudioWorklet, so playback keeps going in a
  background tab and through main-thread stalls.
- Add a ChiptunePlayer that mirrors the <audio> properties and events,
  and a SoundtrackSink interface on the player store that both satisfy.
  The v2 mini player picks the sink per track from the stream URL.
- Accept the new extensions for soundtrack uploads, give scanned
  chiptune files an untagged TrackMeta row so the Jukebox lists them,
  and serve them as application/octet-stream.

Multi-song files play their first song for now; per-song rows and
metadata from libgme follow separately.

Refs #4778

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XHgJG3xRgUKwuHJHwKkPg
2026-09-25 20:34:26 +00:00

42 lines
1.1 KiB
C++

// Entry points the soundtrack player's AudioWorklet calls on top of libgme's
// own C API, which returns its handles and track info through out-parameters.
#include <emscripten/emscripten.h>
#include "gme/gme.h"
// Fade applied when the file doesn't specify one.
static int const DEFAULT_FADE_MSECS = 8000;
extern "C" {
EMSCRIPTEN_KEEPALIVE
Music_Emu* romm_gme_open( void const* data, long size, int sample_rate )
{
Music_Emu* emu = nullptr;
if ( gme_open_data( data, size, &emu, sample_rate ) )
return nullptr;
return emu;
}
// Starts a track with a fade-out at its resolved length, so looping songs end.
// Returns the length including the fade in milliseconds, or -1 on error.
EMSCRIPTEN_KEEPALIVE
int romm_gme_start( Music_Emu* emu, int track )
{
if ( gme_start_track( emu, track ) )
return -1;
gme_info_t* info = nullptr;
if ( gme_track_info( emu, &info, track ) )
return -1;
int const length = info->play_length;
int const fade = info->fade_length > 0 ? info->fade_length : DEFAULT_FADE_MSECS;
gme_free_info( info );
gme_set_fade_msecs( emu, length, fade );
return length + fade;
}
}