krig / go-sox

libsox bindings for go
MIT License
134 stars 26 forks source link

Play 2 files stimulatingly #4

Open quangbuule opened 7 years ago

quangbuule commented 7 years ago

Hi, I tried played the second file while the first file was playing but failed, the second file can only be play when being triggered after the first file finished playing. Is there any solution for this?

Thanks so much!

krig commented 7 years ago

I think this is simply how sox works: if you want to play two files at once, you need a software mixer. To do that with sox, you need to chain two streams together with a mixer, like the remix effect.

quangbuule commented 7 years ago

I can't imaging how I could do that, since the second file is playing in the middle of first file (trigger from keyboard event). I would really appreciate if you could hint more by a tiny example.

krig commented 7 years ago

Unfortunately as far as I understand how sox works, this is not possible :( The effect chain has to be pre-built, it isn't possible to change it later. But maybe I am wrong. I have not looked too deeply into that use case myself.

quangbuule commented 7 years ago

Yeah, from what I see in the sox manual (http://sox.sourceforge.net/sox.html):

"Note that applying multiple effects in real-time (i.e. when playing audio) is likely to require a high performance computer"

But I don't know how they would do the real-time.

jonpastore commented 3 years ago

@krig Is it possible to get the same functionality as this command with libsox? /usr/bin/sox -m file1.wav file2.wav NewFile.wav I'm trying to overlay 2 files together that I'm reading into a byte[]. Is there an example of recommendation on how I can set file1 and file2 as 2 separate channels and then output as 1 channel?

krig commented 3 years ago

Hi @jonpastore , most likely this would need a new API, but at least in theory anything that is possible using the sox command line should be possible to do with the library as well.