
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
sdl-mixer-multi-channels-player
Advanced tools
Node library to play sounds through SDL Mixer on specific channels of specific audio devices.
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.
yarn add node-sdl-mixer-multi-channels-player
or
npm install --save node-sdl-mixer-multi-channels-player
Create a multi-channel player :
const MultiChannelsPlayer = require('sdl-mixer-multi-channels-player')
const channels = new MultiChannelsPlayer({
channels: [
{channel: MultiChannelsPlayer.LEFT},
{channel: MultiChannelsPlayer.RIGHT} // Right
]
})
This player can dispatch sound to the system default audio device left or right channels.
To dispatch sound to a specific sound device, put deviceName in channels :
const player = new MultiChannelsPlayer({
channels: [
{deviceName: 'Built-in Output', channel: MultiChannelsPlayer.LEFT},
{deviceName: 'Built-in Output', channel: MultiChannelsPlayer.RIGHT},
{deviceName: 'USB audio CODEC', channel: MultiChannelsPlayer.LEFT},
{deviceName: 'USB audio CODEC', channel: MultiChannelsPlayer.RIGHT}
]
})
You may want to list your available sound devices names:
console.log(MultiChannelsPlayer.availableDevices())
The player can play WAV sound files only !
const file = 'test.wav'
player.playFile(0, file)
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.
To stop, just call stop(channel_id)
player.playFile(0, file)
// Stop after 1s
setTimeout(() => { player.stop(0) }, 1000)
// Check if channel 0 is playing sound
console.log(player.playing(0) ? 'Playing' : 'Not playing')
If you want to log the channels states:
const player = new MultiChannelsPlayer({
channels: [
{
deviceName: 'Built-in Output',
channel: MultiChannelsPlayer.LEFT,
debug: true
}
]
})
Every actions executed by the channel will be log to STDOUT. If you want to use a custom logger :
const player = new MultiChannelsPlayer({
channels: [
{
deviceName: 'Built-in Output',
channel: MultiChannelsPlayer.LEFT,
debug: true,
logger: (...args) => {
console.log('[Defaut::Ch.1]', ...args)
}
}
]
})
The player can play WAV sound buffer.
const fs = require('fs')
const buffer = Buffer.from(fs.readFileSync(file))
player.playBuffer(1, buffer)
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 = require('node-lame').Lame
const decoder = new Lame({
'output': 'buffer'
}).setFile('my-sound.mp3')
decoder.decode()
.then(() => {
player.playBuffer(0, decoder.getBuffer())
})
René BIGOT
FAQs
Node library to play sounds through SDL Mixer on specific channels of specific audio devices.
We found that sdl-mixer-multi-channels-player demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.