buffer.js:1396
binding.writeFloatLE(this, val, offset);
^
RangeError: out of range index
at Buffer.writeFloatLE (buffer.js:1396:13)
at PCMBufferWriter.pcm32f (/Users/john/tmp/web-audio-engine/demo/node_modules/web-audio-engine/lib/utils/PCMBufferWriter.js:42:20)
at Object.encode (/Users/john/tmp/web-audio-engine/demo/node_modules/web-audio-engine/lib/utils/PCMEncoder.js:41:29)
at Immediate.renderingProcess [as _onImmediate] (/Users/john/tmp/web-audio-engine/demo/node_modules/web-audio-engine/lib/context/StreamAudioContext.js:161:34)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
sample program
const useFloat = true;
const Speaker = require("speaker");
const AudioContext = new require("web-audio-engine").StreamAudioContext;
const context = new AudioContext({
float: useFloat,
});
context.pipe(new Speaker({
float: useFloat,
}));
context.resume();
var keypress = require('keypress');
keypress(process.stdin);
function ticktack(e) {
var t0 = context.currentTime;
var t1 = t0 + e.args.duration;
var osc = context.createOscillator();
var amp = context.createGain();
osc.frequency.value = e.args.frequency;
osc.start(t0);
osc.stop(t1);
osc.connect(amp);
amp.gain.setValueAtTime(0.5 * e.args.amp, t0);
amp.gain.exponentialRampToValueAtTime(1e-6, t1);
amp.connect(context.destination);
}
process.stdin.on('keypress', function (ch, key) {
ticktack({args: { frequency: 880, amp: 1.0, duration: 1.00 }});
if (key && key.ctrl && key.name == 'c') {
process.exit(0);
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
sample program