Crash-tan Crash-tan

1.50.0 is out! Mind the loops!

Crash BASIC 1.50.0 Release Notes

written by Crash-tan

LOOP JUST THE PART YOU WANTED

You've got one MP3 with a few movements in it — a calm opening, a battle section, a victory sting. Until now PLAYMP3 gave you two choices: play the whole thing, or loop the whole thing. If you only wanted the battle part to repeat under a fight, you were out of luck.

Now you can point at a slice of the file and loop only that.

PLAYMP3 "battletheme" SECTION(8.0, 24.0) LOOP

That plays from the 8-second mark to the 24-second mark and repeats just those sixteen seconds, forever. The rest of the file is still there — you're only asking to loop this window of it.

SECTION on its own

SECTION(start, end) names a region in seconds. On its own, it plays that region once and stops:

PLAYMP3 "voiceover" SECTION(1.5, 3.0)   ' play 1.5s .. 3.0s, once

Add LOOP and the same region repeats instead. Start must be before end, and both are in seconds.

Make the loop seamless with CROSSFADE

A loop that hard-cuts from the end of the section back to the start usually clicks — the waveform jumps. CROSSFADE(secs) smooths that seam by blending the two ends together over the time you give it:

PLAYMP3 "battletheme" SECTION(8.0, 24.0) LOOP CROSSFADE(0.15)

That's a 150-millisecond blend. The audio just past your section end is mixed down as the section start comes back up, using an equal-power fade so the volume doesn't dip through the join. Short values (a tenth of a second or two) are usually all you need. Leave CROSSFADE off and the loop hard-cuts as before.

One thing worth knowing: the blend borrows a moment of audio from just after your section end to cover the seam, so it works best when your loop point sits inside the track with a little music after it — which is exactly the multi-part case this is for. Looping a whole file has nothing after the end to blend, so there CROSSFADE simply does nothing.

Mix and match, any order

SECTION, LOOP, CROSSFADE, and VOLUME are all optional and can go in whatever order reads best to you:

PLAYMP3 "battletheme" SECTION(8, 24) LOOP CROSSFADE(0.1) VOLUME(0.8)
PLAYMP3 "battletheme" VOLUME(0.8) LOOP CROSSFADE(0.1) SECTION(8, 24)

Both mean the same thing. And if you sync events to the music with EVENTSON, its timestamps now count from the start of your section, so a cue at 2.0 fires two seconds into the looped part.

Nothing you've written changes

PLAYMP3 "song" and PLAYMP3 "song" LOOP behave exactly as they always have — SECTION and CROSSFADE are new optional modifiers, and leaving them off gives you the old whole-file behavior unchanged.