Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chiptune3.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export class ChiptuneJsPlayer {
setRepeatCount(val) { this.postMsg('repeatCount', val) }
setPitch(val) { this.postMsg('setPitch', val) }
setTempo(val) { this.postMsg('setTempo', val) }
// Live-update the stereo-separation render param (0..200 percent;
// 100 = libopenmpt default, 0 = mono). Also mutates the worklet's
// this.config.stereoSeparation so subsequently-loaded modules
// inherit the value without a reload.
setStereoSeparation(val) { this.postMsg('setStereoSeparation', val) }
setPos(val) { this.postMsg('setPos', val) }
setOrderRow(o,r) { this.postMsg('setOrderRow', {o:o,r:r}) }
setVol(val) { this.gain.gain.value = val }
Expand Down
9 changes: 9 additions & 0 deletions chiptune3.worklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ class MPT extends AudioWorkletProcessor {
if (!libopenmpt.stackSave || !this.modulePtr) return
libopenmpt._openmpt_module_ctl_set(this.modulePtr, asciiToStack('play.tempo_factor'), asciiToStack(v.toString()))
break
case 'setStereoSeparation': {
// Clamp to [0, 200] (libopenmpt's documented range) and
// fall back to the default 100 on non-finite values.
const n = Number.isFinite(v) ? Math.max(0, Math.min(200, Math.trunc(v))) : 100
this.config.stereoSeparation = n
if (!this.modulePtr) break
libopenmpt._openmpt_module_set_render_param(this.modulePtr, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, n)
break
}
case 'selectSubsong':
if (!this.modulePtr) return
libopenmpt._openmpt_module_select_subsong(this.modulePtr, v)
Expand Down