Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two streams parallel #87

Open
ChristianFranke opened this issue Sep 18, 2016 · 4 comments
Open

Two streams parallel #87

ChristianFranke opened this issue Sep 18, 2016 · 4 comments

Comments

@ChristianFranke
Copy link

Hi! Is it possible to play two pcm-streams parallel? Like..

var Speaker = require("speaker");
var lame = require("lame");
var fs = require("fs");
var volume = require("pcm-volume");

var readable = fs.createReadStream("coming-out.mp3");

// see node-lame documentation for more information
var decoder1 = new lame.Decoder({
    channels: 2,
    bitDepth: 16,
    sampleRate: 44100,
    bitRate: 128,
    outSampleRate: 22050,
    mode: lame.STEREO
});

var masterSpeaker = new Speaker();


// Create a volume instance
var v1 = new volume();

v1.pipe(masterSpeaker); // pipe volume to speaker
decoder1.pipe(v1); // pipe PCM data to volume
readable.pipe(decoder1); // pipe file input to decoder


setTimeout(function() {
    // Create a volume instance
    // see node-lame documentation for more information
    var decoder2 = new lame.Decoder({
        channels: 2,
        bitDepth: 16,
        sampleRate: 44100,
        bitRate: 128,
        outSampleRate: 22050,
        mode: lame.STEREO
    });


    var v2 = new volume();
    v2.pipe(masterSpeaker); // pipe volume to speaker
    decoder2.pipe(v2); // pipe PCM data to volume
    readable.pipe(decoder2); // pipe file input to decoder
}, 2000);
@Flowr-es
Copy link

Flowr-es commented Jan 19, 2017

So it is possible to have multiple speaker streams in parallel.
I think it will not work to pipe into one speaker two pcm streams.

It should work like this (untested):

var Speaker = require("speaker");
var lame = require("lame");
var fs = require("fs");
var volume = require("pcm-volume");

var readable = fs.createReadStream("coming-out.mp3");

// see node-lame documentation for more information
var decoder1 = new lame.Decoder({
    channels: 2,
    bitDepth: 16,
    sampleRate: 44100,
    bitRate: 128,
    outSampleRate: 22050,
    mode: lame.STEREO
});

var masterSpeaker = new Speaker();
var masterSpeaker2 = new Speaker();

// Create a volume instance
var v1 = new volume();

v1.pipe(masterSpeaker); // pipe volume to speaker
decoder1.pipe(v1); // pipe PCM data to volume
readable.pipe(decoder1); // pipe file input to decoder


setTimeout(function() {
    // Create a volume instance
    // see node-lame documentation for more information
    var decoder2 = new lame.Decoder({
        channels: 2,
        bitDepth: 16,
        sampleRate: 44100,
        bitRate: 128,
        outSampleRate: 22050,
        mode: lame.STEREO
    });


    var v2 = new volume();
    v2.pipe(masterSpeaker2); // pipe volume to speaker
    decoder2.pipe(v2); // pipe PCM data to volume
    readable.pipe(decoder2); // pipe file input to decoder
}, 2000);

@remscli
Copy link

remscli commented Apr 16, 2017

Hi, I'm trying to play two streams simultaneously but when I pipe the second speaker it stops the first one. I tried with your code @Mexxxo and I still have this issue.

Did it worked for you @ChristianFranke ?

@Flowr-es
Copy link

Flowr-es commented Apr 16, 2017

Hi @remscli ,
I just found out, that it works with my Raspi when I'm using the Jack Output.
If I'm switchting to a USB Soundcard, it is also not possible for me to have two streams in parallel.

It is maybe possible to combine two streams as one, as possible workaround.

@ylh888
Copy link

ylh888 commented Jul 8, 2017

On a Mac, I have trouble playing two streams at the same time as well. The program does not return.

See example here https://gist.github.com/ylh888/51cda38e2b5cfbaa0fa009ed8ef17d53

The code works well as long as the different 'notes' don't overlap in time. When they do, the code does not return.

Any help to work around, or at least to avoid infinite loop, would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants