Skip to content

Commit 217e7e7

Browse files
committed
Stereo
Not yet documented, but AudioMasher now supports listeners with multiple ears. Patches will now play in stereo if they start with "# stereo" and leave two values on the stack.
1 parent cf346b3 commit 217e7e7

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

static/masher.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,38 @@ var initStartAudio = function () {
7171
scriptNode.connect(audioCtx.destination);
7272
}
7373

74+
var initStartAudioStereo = function () {
75+
audioCtx = new AudioContext();
76+
// buf size, input channels, outpout channels
77+
scriptNode = audioCtx.createScriptProcessor(4096, 0, 2);
78+
console.log(scriptNode.bufferSize);
79+
scriptNode.onaudioprocess = function(evt) {
80+
var num_frames = evt.outputBuffer.length;
81+
var ptr = sporthem_process_stereo(num_frames);
82+
if (!ptr) return;
83+
var num_channels = evt.outputBuffer.numberOfChannels;
84+
for (var chidx = 0; chidx < num_channels; chidx++) {
85+
var ch = evt.outputBuffer.getChannelData(chidx);
86+
for (var i = 0; i < num_frames; i++) {
87+
ch[i] = HEAPF32[(ptr>>2) + ((num_channels*i)+chidx)]
88+
}
89+
}
90+
}
91+
scriptNode.connect(audioCtx.destination);
92+
}
7493

7594

95+
window.masher_stereo = false;
7696
var play = function () {
7797
cleanupStopAudio();
7898
gotError = false;
7999
playButton.classList.add("playing");
80100
sporthem_compile(editor.getValue().replace(/\t/g , " "));
81101
parseParams();
82-
initStartAudio();
102+
if (editor.getValue().startsWith('# stereo'))
103+
initStartAudioStereo();
104+
else
105+
initStartAudio();
83106
playing = true;
84107
};
85108
var stop = function() {
@@ -103,6 +126,7 @@ var Module = {
103126
sporthem_getp = cwrap('sporthem_getp', 'number', ['number']);
104127
sporthem_setp = cwrap('sporthem_setp', 'number', ['number', 'number']);
105128
sporthem_process = cwrap('sporthem_process', 'number', ['number']);
129+
sporthem_process_stereo = cwrap('sporthem_process_stereo', 'number', ['number']);
106130
if (editor) parseParams();
107131
var playLoading = document.getElementById("play_loading");
108132
if (playLoading) {

static/sporthem.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/sporthem.wasm

119 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)