Skip to content

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

Open
@macbutch

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions