ConnorChristie / Audio-Mixer

Allows mixing of PCM audio streams.
31 stars 22 forks source link

Mixing process doesn't end/close stream #1

Open CmdrShepardsPie opened 6 years ago

CmdrShepardsPie commented 6 years ago

This probably isn't a bug, but I am not able to get this process to work. I'm trying to mix a variable number of pcm files into one output file from the command line. Here's the mixing stream code. Node does get to the end of this, but then just pauses and doesn't end the script/process. Am I missing a command to "finish" the process?

  const mixer = new AudioMixer.Mixer({
    channels: 1,
    bitDepth: 16,
    sampleRate: 16000,
  });

  for (const filename of inFilenames) {
    const fileStream = fs.createReadStream(filename);

    const input = mixer.input({
      channels: 1,
      volume: 75,
    });

    fileStream.pipe(input);
  }

  const write = fs.createWriteStream(outFilename);

  mixer.pipe(write);
ConnorChristie commented 5 years ago

@chawson Did your PR fix this issue? Thanks

chawson commented 5 years ago

@chawson Did your PR fix this issue? Thanks

@ConnorChristie The execution of setImmediate was manually stopped in an unreasonable way.

 let timer:any = null
 ws.on('drain',()=>{
        clearTimeout(timer)
        timer = setTimeout(()=>{
            clearTimeout(timer)
            mixer.close()
            mixer.destroy()
            ws.end()
        },2000)
 })

Assuming that the waiting time exceeds 2 seconds, the task is considered completed. The optimization plan is under investigation.

timo-klarshift commented 1 year ago

I see a similar behaviour: playing 10 times a file to an input will result in 10 open file handles and the file readstream is never terminated.