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

Cannot Play Two Sounds In Parallel #173

Open
zarkones opened this issue Jul 27, 2024 · 2 comments
Open

Cannot Play Two Sounds In Parallel #173

zarkones opened this issue Jul 27, 2024 · 2 comments

Comments

@zarkones
Copy link

Hello. The following code would crash the process with this stack trace:
stacktrace.txt

I might be missing something obvious, however, just not to me. :)

The code:
package main

import (
"bytes"
"fmt"
"time"
"ui/assets"

"github.com/faiface/beep/speaker"
"github.com/faiface/beep/wav"

)

func play() {
streamer, format, err := wav.Decode(bytes.NewReader(assets.ButtonClick))
if err != nil {
fmt.Println("failed to wav decide sfx:", err)
return
}

if err := speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10)); err != nil {
	fmt.Println("failed to speaker.Init sfx:", err)
	return
}

speaker.Play(streamer)

}

func main() {
play()
play()

time.Sleep(time.Second * 3)

}

@dusk125
Copy link
Collaborator

dusk125 commented Jul 30, 2024

This project is maintained at https://github.com/gopxl/beep, please direct all future inquiries there.

This is an incorrect usage of beep; in order to play multiple streams of audio at the same time, only one instance of play is called. You can use the Mix function https://github.com/faiface/beep/blob/master/compositors.go#L100 to create a Streamer that mixes the inputs together into a single stream

@MarkKremer
Copy link
Contributor

You can only initialize the speaker once, but it should be possible to call play multiple times. Speaker has a built-in mixer.

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

3 participants