demozoo / cowbell

A universal web audio player for demoscene / tracker music
https://demozoo.github.io/cowbell/
BSD 3-Clause "New" or "Revised" License
75 stars 6 forks source link

Enable Amiga resampler for libopenmpt #24

Closed sagamusix closed 2 years ago

sagamusix commented 4 years ago

The Amiga resampler enables crisp emulation of the Paula chip.

Here's what I do to enable it:

function asciiToStack(str) {
  var stackStr = stackAlloc(str.length + 1);
  writeAsciiToMemory(str, stackStr);
  return stackStr;
}

(...)
var stack = stackSave();
libopenmpt._openmpt_module_ctl_set(processNode.modulePtr, asciiToStack('render.resampler.emulate_amiga'), asciiToStack('1')); // enable Amiga resampler
libopenmpt._openmpt_module_ctl_set(processNode.modulePtr, asciiToStack('render.resampler.emulate_amiga_type'), asciiToStack('a1200')); // set emulated Amiga model to A1200
stackRestore(stack);

You may need to export several extra functions when building libopenmpt: export CXXFLAGS="-s \"EXTRA_EXPORTED_RUNTIME_METHODS=['stackAlloc','stackSave','stackRestore']\"" (I think at the time of writing only stackAlloc is required, the others are still exported implicitly, but seeing Emscripten's changelog, it is only a matter of time until that changes 😛 )

gasman commented 2 years ago

@sagamusix A question, as someone with very little knowledge of the finer points of Amiga audio... Is this something that we'd want to have enabled all the time? Or should it be exposed as a config option in Cowbell, so that on the Demozoo side we enable it just for things that are identified as Amiga modules? (And if so, what criteria do we use to decide that? Just the ones that explicitly have Amiga as a platform?)

Also, I assume this code needs to run after a module has been loaded, not just on the initial load of the library, right...?

sagamusix commented 2 years ago

The Amiga resampler is only used for Amiga modules, so e.g. 8-channel MODs never use it even if it's enabled. It's safe to always enable this option. As it's set on the module itself, it has to be done for each module that is loaded.

gasman commented 2 years ago

Thanks! Done in d0c4856a8445187f06194245d1aa70394be7ce86.

(For the record: the build option now seems to be export LDFLAGS="-s \"EXPORTED_RUNTIME_METHODS=['stackAlloc','stackSave','stackRestore']\"")