Retain time-stretched WaveAudioClip's length when chaning tempo

Hi,

How can I retain the audio clip length when tempo is changed ? Right now, I’m not using auto-tempo but simply setLength + setSpeedRatio on the timestretched clips.

When I change the tempo, the clips stay the same size, which means each clips need to be resized to match their previous length which is kind of counter-productive.

Auto-tempo seems to need the appropriate tempo + signature + beat/bear length to work.

Should I use autoTempo (by deducting and setting the LoopInfo of each clip), or proportionally ajust the speedRatio with the old and new BPM (watching the Edit state).

Thanks !
E.

The best way to do things is with auto-tempo as that is really telling the Engine/Edit how it should relate things like tempo and pitch (it can do things like ensure multiple tempo changes are applied correctly and even sync time-stretching to beat positions for improved quality).

However, if you’ve set setSyncType (Clip::syncBarsBeats) on any clips, changing the tempo should adjust their start/end positions in proportion to the tempo changes (assuming you’re changing the tempo via TempoSetting::set....

1 Like

Thanks @dave96 !

The only concern about auto-tempo is that it’s not always possible to deduce the right tempo on some samples (especially purely melodic ones).

That said, I could initially call performTempoDetect and/or performTempoDetect when a new audio clip is loaded, check if it gives sensible results; if not, fall back to setSyncType.

Does this seems appropriate ?

E.

performTempoDetect is not very accurate I’m afraid.

You probably want setSyncType (Clip::syncBarsBeats) anyway to keep things adjusting when the tempo changes.

But you might want to set the tempo of clips without source tempo metadata to the Edit’s tempo, then instead of changing the speed ratio, change the LoopInfo’s tempo. The effect will be the same but the user is effectively “correcting” the root tempo rather than changing a “speed ratio”. Seems the cleanest way to me.

1 Like

Makes sense, thanks @dave96! Gonna try that asap!

I applied the same logic of updating the LoopInfo when resizing clips manually, using setNumBeats / setBpm on the LoopInfo, and also setting the new length with setLength.

This works perfectly, whetever the user is manually resizing a clip or when the Edit tempo changes.

Thanks, @dave96 !