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

How to fade out playing sound or start/stop without clicking/popping #134

Open
macbutch opened this issue Oct 20, 2021 · 0 comments
Open

Comments

@macbutch
Copy link

I've read the docs + tutorial (and #49) but somehow this isn't quite sticking in my head right. I have a list of .wav files and when the user clicks on one I want to load and play it. So far so good and that's proved very easy with beep - thanks!

What I started with was when the selected file changed I load it up and then call speaker.Clear() and then speaker.Play() with the new data. It works nicely but sometimes there is a bit of a click or pop (fair enough). I've tried to add a quick fade out over a few milliseconds but I'm clearly not understanding how the volume scaling works.

I have an effects.Volume using Base 10 (but 2 also doesn't seem to do what I want). So I've done stuff like this:

	for i := 0; i < 80; i++ {
		volume.Volume = 0 - float64(i)/2
		time.Sleep(1 * time.Millisecond)
	}

Then I

	volume.Silent = true
	time.Sleep(5 * time.Millisecond)
	speaker.Clear()
	volume.Silent = false
	volume.Volume = 0

	// skipping some resampling but I update the Volume streamer here.

	speaker.Play(beep.Seq(&volume, beep.Callback(func() {
		done <- true
	})))
     

Theres is some latency (unsurprising given 85ms sleeping!) but this doesn't really seem to affect my clicks much at all. I think I've missed something really fundamental here. Would appreciate any help you can give.

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

1 participant