sfplay~ crossfade loops?

Tarik's icon

Hi All,

I don't know if it's me or the botched Max Forum search engine, but I can't find an easy solution to this nooby question:

I'd like to load audio files from the harddisk and play them as quickly as possible. sfplay~ seems to be the way to do that; it can play while loading.
BUT i'd also like to loop with little crossfades to prevent clicking

how do i do this elegantly?

thanks - tarik

hz37's icon

You gotta reflect on what you are really asking. Say you fully load an audio segment abcdefgh and if you play it in a looping fashion, the waveforms of a and z do not match. Instead of abcdefghabcdefghabcdefghabcdefghabcdefgh you then hear abcdefgh-CLICK-abcdefgh-CLICK-abcdefgh-CLICK etc. So what do you want sfplay~ to do about that? If it actually crossfades a and h, your loops will become shorter. It cannot look before a or after h, because that's non existing data. At best it could do a fast fade in at a and a fast fade out at h. But that would be a drop in amplitude at the looping point, which in itself could cause an audible artefact. So here are three more or less elegant solutions:

1) Only offer perfect looping material. This means you prepare your audio in a wave editor such as Audacity in a way that it loops perfectly. This is easier than you might think. If your software doesn't have a "Snap to zero crossing" editing function, you can take some of the audio following your loop end point and crossfade it manually onto the start of the loop. This way, the loop actually starts with the material beyond the loop end point. I've done this a lot with bird sounds and such and it works great.

2) The groove~ object has a loopinterp attribute which you can set to 1. You'll have to fiddle with the loop start and end points to make that work great.

3) The waveform~ object has a snapto attribute which you can set to 2: Zero Crossing.

Good luck and happy looping!

Stephane Morisse's icon

In order to prevent clicks, you could also consider objects like rampsmooth~ and trapezoid~.

Tarik's icon

Thanks a lot for your answers!

Yes, to be more precise: I'd like to loop a part of a bigger audiofile. I'll make sure to always have extra audio after the loop points, so I can use this extra audio to crossfade with the start of the loop. (eg. after end of loop, beginning of loop fades in over 10 ms while a bit of audio AFTER the end of the loop continues playing with a 10 ms fadeout)
Simultaneously, I absolutely need the loadspeed of a streaming object like sfplay~. Buffer~ objects simply take too long to read data, which excludes me from using buffer based objects like groove~.

Right now I'm working on a solution implementing usage of two sfplay~ objects, with one being the 'main' audio source, and the other one with adjusted loop points to provide the crossfade material, only audible during a 10 ms crossfade. Thats supercomplex and weird to make though, besides taking up unnecessary computer resources.

I'm hoping someone else has found a way to combine the speed of sfplay~ and the looping niceness of groove~