node-sdl-speaker
Output PCM stream data to speaker with SDL2. Especially for realtime audio stream.
Features
- Stream Support. You can pipe a pcm stream to audio channel.
- Multi Channels Support. You can open multi channels, it will mix all channels via
SDL_MixAudioFormat
. - Low Latency.
Installing / Getting started
$ npm install sdl-speaker
Example
const Speaker = ;// Init SDL Speaker.Speaker; // Register a channel for write buf.const testChannel = Speaker; // pipe a pcm data to stream;fs; // When you are ready..// Start play audioSpeakerstart;
Api Reference
Speaker.init([ option ])
Init SDL. option
is optional.
channels
: Channel count. default:2
.samplesRate
: Sample rate for every channel. default:44100
.samplesPerFrame
: Samples per frame. default:1024
.
Speaker.start()
Start play audio. Read audio data from a ring buffer. If data in ring buffer less than samplesPerFrame
, fill 0.
Speaker.stop()
Close and Destroy SDL player.
Speaker.pause()
Pause SDL player.
Speaker.resume()
Resume SDL player.
Speaker.detach(name)
Detach audio source from SDL.
Speaker.cleanAll()
Clean all audio sources's buffer.
Speaker.register(name) -> audioChannel
Register a audio source for write buffer. The name
must unique.
audioChannel.write(buffer)
Write audio buffer to ring buffer. You can write before speaker start.
audioChannel.clean()
Clean this audio source's buffer.
TODO
- More Test.
- Fix Travis-CI build failed.
- Pipe stream to
audioSource
. - Customise
rbuf
capability. - Self contained
SDL2
.