phetsims / tambo

library containing code to support sonification of PhET simulations
MIT License
2 stars 4 forks source link

Add ability to start playing a SoundClip in the middle of the recorded sound #150

Open jessegreenberg opened 2 years ago

jessegreenberg commented 2 years ago

In https://github.com/phetsims/quadrilateral/issues/4 it was requested that we start playing a pre-recorded sound in the middle of the recording instead of at the start. For the use case in In https://github.com/phetsims/quadrilateral/issues/4 the sound would loop around and would loop around the offset time that you provide. @Ashton-Morris described it like

I would imagine if possible it would sound something like this in code: Play file as loop - start playhead or playing file at random point of the files duration.

The motivation for this is

Also since the same files will be playing simultaneously it would be best if they started at different start points so they would sound less repetitive.

@jbphet said that this was not yet a supported feature of tambo, but that it could be. He also mentioned a potential challenge:

Starting in the middle of a sound can be problematic, since if the value of the sound data at the specified location is non-zero, it will cause a fast transient, which creates a very audible clicking sound. We'd need to work out whether there should be any built-in detection of nearby zero-crossings or not to proactively address this.

I am not sure if this will end up being necessary for quadrilateral, Ill bring this up with the team during normal meetings 9/28/21 and get a sense of priority.

Ashton-Morris commented 2 years ago

Copy from Slack conversation:

During our meeting today we talked about starting a sound loop at random points and JB brought up that we can first start out by trying the delay function. So maybe when calling the 4 loops from the same source in Quad you can call: 1. immediately, 2. at 100ms delayed, 3. at 200ms delayed, and 4. at 300ms delayed.

Perhaps this would create the auditory illusion that we are not play the same sound file 4 times at once. If it sounds weird we can mess around with the lengths of the start delay