HELP! Issues with loop command - loops are clipping - Sugarcube Audio

Twine 2.31.1

2 questions:

  1. Tracks set to loop are clipping at the start of each loop. The tracks have no silence at the top or tail, so it should loop cleanly. Is there a delay in the loop command? If so, is there a way to get rid of it?

  2. I’m trying to get an audio track to fadein and then loop. Is there a way to do this within one set of audio commands?

If I try to do it as 2 commands (where the track is 9s long), the sound clips when the new track starts playing:

<<audio "track1" volume 0 fadein>>
<<timed 8s>><<audio "track1" loop>><</timed>>

Thanks again! Ben

Unfortunately, SugarCube’s audio subsystem is not currently capable of completely gapless looping because of the way it is implemented.

Is there a way to change the implementation? A loop that you can’t execute gapless-ly is basically useless for most sound design.

The limitation comes from the HTML media elements API, rather than SugarCube’s audio subsystem, so not really, no.

As an alternative, which would also allow for sprites, using the Howler library in Web Audio API mode would allow for gapless playback.

Good to know. Because I’m having a lot of fun working with this, l want to encourage you guys (who I believe have written Sugarcube itself…?) to dig into this problem:

Loops are crucial if you are trying to design sound for an experience where time is a variable. I can’t necessarily rely on tracks that have a set time. But I can use loops.

For example, imagine I have a track 50.5 seconds long. But a user might be on the page for as long as 90 seconds, or as short as 45 seconds. The last 5.5 seconds of my track is a standalone loop. Ideally in Twine, I would be able to specify that section of the track that I want to loop (45secs - 50.5secs). Failing that, I could trigger a second track, which is just the loop, at the precise moment that the first track ends. Either way, the last 5.5 seconds loops until the user moves on from the page. However, none of this is possible without continuous and seamless loop functionality.

It would be worth flagging this up in the Sugarcube documentation as well, as we’ve built a fairly complex sound design for this project around the assumption that loop meant “continuous and seamless.” I don’t think that the current definition:

“Set the selected tracks to repeat playback upon ending normally”

clearly implies a gap between repeats. My tracks begin and end with sound, so I would imagine continuous sound when track repeats.

I’m happy to discuss any of this further.

Many thanks, Ben

To be fair, this is implied in the limitations.

Although being more specific that gapless playback is not available for both transitions and loops couldn’t hurt.

As noted in my last reply, you could use the Web Audio API to get what you want—though, I do recommend a library like Howler rather than attempting to use it directly.

As far as SugarCube goes, there’s not much to discuss. As I noted, the limitation is not from SugarCube’s audio subsystem, but rather the backing audio API—the media elements API.

As to why SugarCube uses the media elements API, rather than the Web Audio API. Both come with pros/cons and the media elements API is, generally, a better fit for SugarCube users.

This is fair. But as you suggest, “between tracks” doesn’t immediately flag up “within a loop.” I’m going to take a look at the Howler control system in the meantime…