npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sdl-mixer-multi-channels-player

v1.0.4

Published

Node library to play sounds through SDL Mixer on specific channels of specific audio devices.

Downloads

3

Readme

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 = 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.

Dispatch sound

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}
  ]
})

List sound devices

You may want to list your available sound devices names:

console.log(MultiChannelsPlayer.availableDevices())

Play a sound from file

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.

Stopping sound

To stop, just call stop(channel_id)

player.playFile(0, file)
// Stop after 1s
setTimeout(() => { player.stop(0) }, 1000)

Check if channel is playing sound (busy)

// Check if channel 0 is playing sound
console.log(player.playing(0) ? 'Playing' : 'Not playing')

Log events for debug

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)
      }
    }
  ]
})

Play sound from buffer

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())
  })

Author

René BIGOT

License

MIT : http://opensource.org/licenses/MIT