TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

Question unsure to ask where #113

Open Mmalherbe opened 6 years ago

Mmalherbe commented 6 years ago

Hey!

Im currently working on an art project where id love to use node speaker.

Its a raspberry pi with an usb soundcard Gigaport hd+ with 6 channels.

Is it possible to use speaker to simultaniously play seperate wav or mp3 files on seperate channels?

Thanks and sorry if i asked it in the wrong place

LinusU commented 6 years ago

Hmm, I would recommend asking on StackOverflow. I'm not sure if this library can currently do it 🤔

Mmalherbe commented 6 years ago

Thanks for the advice, my question is also postedon StackOverflow. But I guess an answer from someone of the library would help :)

LinusU commented 6 years ago

Hmm, actually, you probably should be able to use some other Node.js package to mix the channels, and then specify channels: 6 in this lib. Should be quite doable!

LinusU commented 6 years ago

Would you mind linking the StackOverflow post?

Mmalherbe commented 6 years ago

Ofcourse! here : https://stackoverflow.com/questions/49842361/nodejs-on-a-raspberry-pi-with-a-soundcard any idea of which package to use to mix the channels?

LinusU commented 6 years ago

https://www.npmjs.com/package/pcm-utils

Something like:

const pcmUtils = require('pcm-utils')
const Speaker = require('speaker')

const speaker = new Speaker()
const zipper = new pcmUtils.Zipper(6, pcmUtils.FMT_U16LE)

zipper.pipe(speaker)

yourStuff0.pipe(zipper.inputs[0])
yourStuff1.pipe(zipper.inputs[1])
yourStuff2.pipe(zipper.inputs[2])
yourStuff3.pipe(zipper.inputs[3])
yourStuff4.pipe(zipper.inputs[4])
yourStuff5.pipe(zipper.inputs[5])
Mmalherbe commented 6 years ago

Thank you very much! Ill try it in a little bit, any idea if its possible to edit the pipe? So lets say only on input 1 IS playing a file, and i can just add a file to 3 and play it simultanious?

LinusU commented 6 years ago

I think you would need to pipe in silence to the other zipper inputs in that case