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

Questions about sound implementation in WaveInterferenceSlider.js #523

Closed
pixelzoom opened this issue Apr 26, 2021 · 2 comments
Closed

Questions about sound implementation in WaveInterferenceSlider.js #523

pixelzoom opened this issue Apr 26, 2021 · 2 comments
Assignees

Comments

@pixelzoom
Copy link
Contributor

pixelzoom commented Apr 26, 2021

Some questions, to help proceed with phetsims/fourier-making-waves#56 and phetsims/sun#697

WaveInterference.js adds sound support to HSlider.

For the if ( event.isFromPDOM() ) code path:

(1) Why is a different code path required when event.isFromPDOM()?

(2) Why is TOLERANCE needed in this code path, and not the mouse/touch code path?

(3) Why is there no need to verify the elapsed time between sounds, as in the mouse/touch code path?

For the mouse/touch code path:

(4) Why is it not necessary to check elapsed time before playing generalBoundaryBoopSoundPlayer?

(5) MIN_INTER_CLICK_TIME is documented as "min time between clicking sounds", and I interpret "between" to mean the gap between sounds. But it actually appears to be the min time since play was called for a clicking sound. Do I understand that correctly?

(6) MIN_INTER_CLICK_TIME is "set empirically" for the specific sound files used, correct? If I used a longer/shorter sound, then I'd need to adjust it? And if SoundClip had a getDuration method (see phetsims/tambo#141) would that make it possible to compute this programmatically, as "duration + gap"?

@samreid
Copy link
Member

samreid commented Apr 28, 2021

(1) Why is a different code path required when event.isFromPDOM()?

From the keyboard, there should be a sound with every keypress. For mouse/pointer, there should only be a sound when you reach a tickmark.

(2) Why is TOLERANCE needed in this code path, and not the mouse/touch code path?

From my testing, it doesn't appear to be needed in either code path. It was described in 0b93187 but that doesn't seem accurate any more.

(3) Why is there no need to verify the elapsed time between sounds, as in the mouse/touch code path?

Same as the response to (1). Also, for mouse/touch you can move quickly and get too many sounds to play at the same time, so it has to be throttled.

Why is it not necessary to check elapsed time before playing generalBoundaryBoopSoundPlayer?

Because hitting the extrema is rare (compared to passing over tick marks). For example, it would be difficult for a user to hit the boundary more than 1-2 times per frame, but it could be easy to cross many tick marks in one frame.

(5) MIN_INTER_CLICK_TIME is documented as "min time between clicking sounds", and I interpret "between" to mean the gap between sounds. But it actually appears to be the min time since play was called for a clicking sound. Do I understand that correctly?

Yes, it's the delta between start times.

(6) MIN_INTER_CLICK_TIME is "set empirically" for the specific sound files used, correct?

Yes

If I used a longer/shorter sound, then I'd need to adjust it?

Yes, because longer sounds would be more prone to overlapping.

And if SoundClip had a getDuration method (see phetsims/tambo#141) would that make it possible to compute this programmatically, as "duration + gap"?

Yes. That being said, it may not require exact fine tuning. For example, if one sound is 0.3sec and the new sound is 0.2sec, then the same inter click time would probably be OK. It's just about making sure that not too many sounds play at the same time, which would increase the volume.

@samreid samreid assigned pixelzoom and unassigned samreid Apr 28, 2021
@pixelzoom
Copy link
Contributor Author

pixelzoom commented Apr 28, 2021

Thanks for the answers!

for mouse/touch you can move quickly and get too many sounds to play at the same time, so it has to be throttled.

It sounds like you're assuming that event.isFromPDOM() equates to keyboard, which is slower than mouse/touch. That's not the case - event.isFromPDOM() is any alternative input, see SceneryEvent.js:

/**
   * Specifies whether or not the SceneryEvent came from alternative input. 
...
   */
  isFromPDOM() {

.... and I can certainly imagine an input device that has the same "too many sounds to play at the same time" problem as mouse/touch. So this solution is not future-proof.

Closing.

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

No branches or pull requests

2 participants