faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.08k stars 152 forks source link

two different audio streams at the same time? #43

Closed FM1337 closed 6 years ago

FM1337 commented 6 years ago

Okay, so I know mixers are a thing in this library but what I need to do doesn't appear to be covered by that.

So let's say I have a game with background music playing, but I want to do sound effects when something happens, but I don't want the music to be interrupted/restarted and I want it to continue playing but also play the sound effect when it's needed

how would I go about accomplishing this?

faiface commented 6 years ago

Hi, all of this can be done in Beep, I'll be happy to help! But to avoid wasting time, tell me what you can do and where you're stumbling and I'll explain it from there.

FM1337 commented 6 years ago

Well I can get background music looping by using beep.loop(-1, source) and then doing a speaker play of that.

but the moment I try to play another sound (such as a sound effect) it plays the sound effect but stops the music.

I tried the mixer but I can't seem to get it working.

faiface commented 6 years ago

I believe the mistake you are making is that you're calling speaker.Init each time you start playing something. That will reset the speaker. You should only call speaker.Init once at the beginning of your program.

FM1337 commented 6 years ago

Hmm okay, I'll try only calling it once; but wouldn't that mean if you tried to play two different kinds of audio files, one is a .wav and the other is .mp3 wouldn't the sound be messed up because both of them would have a different sample rate?

faiface commented 6 years ago

Yes, they would, but that's what you should use beep.Resample for.

FM1337 commented 6 years ago

Alright I appear to have it working, now I just need to find a way to lower the volume of the background music so I can hear some of the sound effects.

Thanks!

faiface commented 6 years ago

You can use the volume effect for that ;)

marinat commented 5 years ago

@FM1337 please, show example how did you do that :)

FM1337 commented 5 years ago

I got it mostly working but it would segment on itself after the music was finished playing. I haven't touched the code in a few months but I'll look into it when I get time.

marinat commented 5 years ago

Your game was for mobile devices?