node-sdl-mixer-multi-channels-player
The purpose of node-sdl-mixer-multi-channels-player
is to allow mono sound routing through any channel (left or right only) of any audio devices, in order to create audio automation devices.
node-sdl-mixer-multi-channels-player
contains a NodeJS C++ addon to drive SDL2_Mixer
.
Due to SDL2_Mixer
limitations, you can only play WAV files but more formats could be supported through libraries like node-lame
wich can convert MP3 to WAV.
Installation
yarn add node-sdl-mixer-multi-channels-player
or
npm install --save node-sdl-mixer-multi-channels-player
Usage
Create a player
Create a multi-channel player :
const MultiChannelsPlayer = const channels = channels: channel: MultiChannelsPlayerLEFT channel: MultiChannelsPlayerRIGHT // Right
This player can dispatch sound to the system default audio device left
or right
channels.
Dispatch sound
To dispatch sound to a specific sound device, put deviceName
in channels
:
const player = channels: deviceName: 'Built-in Output' channel: MultiChannelsPlayerLEFT deviceName: 'Built-in Output' channel: MultiChannelsPlayerRIGHT deviceName: 'USB audio CODEC' channel: MultiChannelsPlayerLEFT deviceName: 'USB audio CODEC' channel: MultiChannelsPlayerRIGHT
List sound devices
You may want to list your available sound devices names:
console
Play a sound from file
The player can play WAV sound files only !
const file = 'test.wav'player
0 here means that you want to play test.wav
through the first channel which is LEFT
channel of Built-in Output
.
If you play a file through a busy channel, the sound playing will be stopped and the new one will be play.
Stopping sound
To stop, just call stop(channel_id)
player// Stop after 1s
Check if channel is playing sound (busy)
// Check if channel 0 is playing soundconsole
Log events for debug
If you want to log the channels states:
const player = channels: deviceName: 'Built-in Output' channel: MultiChannelsPlayerLEFT debug: true
Every actions executed by the channel will be log to STDOUT
. If you want to use a custom logger :
const player = channels: deviceName: 'Built-in Output' channel: MultiChannelsPlayerLEFT debug: true { console }
Play sound from buffer
The player can play WAV sound buffer.
const fs = const buffer = Bufferplayer
We've created a buffer from a WAV file. It's not very useful here. But you could use node-lame
to create a WAV buffer from a MP3 file !!!
const Lame = Lameconst decoder = 'output': 'buffer' decoder
Author
René BIGOT