Play raw audio sample stream using Web Audio API.
- [x] Arbitrary channel count
- [x] Arbitrary sample rate
- [x] Basic OLA (overlap-add) resampler
- [ ] Adjustable buffer size
Depends on the sample format, there are multiple player classes:
-
Int16PcmPlayer
(little endian) Float32PcmPlayer
Float32PlanerPcmPlayer
No Planer
: audio samples are interleaved (left channel first).
With Planer
: audio samples are in a two-dimensional array (left channel first).
The constructors require user activation (must be invoked in a user event handler, e.g. onclick
), because they create AudioContext
s.
var player = Int16PcmPlayer(44100);
player.start();
player.feed(new Int16Array([0, 0, 0, 0, 0, 0, 0, 0]));
player.stop(); // `AudioContext` will be closed, so can't be restarted