Home Papers Reports Projects Code Fragments Dissertations Presentations Posters Proposals Lectures given Course notes

Stepwise Tempo Changes in BpmDj

Werner Van Belle1* - werner@yellowcouch.org, werner.van.belle@gmail.com

1- Yellowcouch;

Abstract :  kbpm-play provides an algorithm that automatically changes the play-rate from its current speed back to normal speed. A first version of the software relied on a linear change of pace, which turned out to be slightly wrong. In this short article we describe what went wrong and how to do it right.

Keywords:  tempo changes, psychoacoustics, preceived tempo change, bpmdj
Reference:  Werner Van Belle; Stepwise Tempo Changes in BpmDj; YellowCouch Scientific; May 2006

1 Defining Variables

We define a number of variables necessary to investigate the problem.

The values placed in these two variables will lie around the sample rate.
We further assume a linear change of pace. E.g: every second the play-speed is updated.
We now want to calculate the lplaying speed we need at step $i$

2 Linear change

A first straightforward approach to determine $s_{i}$ seems linear interpolation, as follows


The main problem we observed with this approach was that the music seemed to step up (or down) with an uneven pace. It did sound wrong. A closer investigation reveals that simple interpolation will lead to a non linear frequency change. To demonstrate this closer, we will work with a song which has only one waveform: a pure sine with frequency $f$.

We can now determine the frequency of that note at step $i$ (call it $f_{i}$) through multiplying it by the current speed ($s_{i}$) and division by its normal speed (the sample-rate $r$).


Since human beings perceive frequencies in a non equally spaced manner, we need to convert this frequency to a note in a (for this purpose) equi-temporal scale. Rising one octave amounts to doubling of the note frequency. If A4 is 440 Hz, then A5 will be 880 Hz and A3 is 220 Hz. Therefore, to map the frequency $f_{i}$ to its note number we need to take $log_{2}$ (which will yield the octave number) and multiply it by 12 (to yield the note number). The perceived note at step $i$ will be

\end{displaymath} (2)

Clearly, we will hear a non-linear scale. To illustrate this, let us assume that we would like to change the tempo of a song from half the playing speed ($=0.5r$) to its normal playing speed ($=1r$) in 10 steps. Figure 1 lays out the transposition at a given time step.

Figure 1: Perceived note during change. Horizontal: time step. Vertical the transposition.

The slight bend we can observe does not look as much, but when looking at the local effect by measuring the transposition at every step then the problem becomes more obvious (see figure 2)

Figure 2: Perceived note change at every step. Horizontal: time step. Vertical the local step transposition.

3 Non linear change

To resolve this problem we must compensate for the logarithm and express our requirements on the note scale instead of the speed-scale. We actually want the transposition at every step to be constant (called $C$). Formalized:

n_{i}-n_{i-1}\equiv C\end{displaymath}

According to 2 this becomes $12.log_{2}(f_{i})-12.log_{2}(f_{i-1})\equiv C$. According to 1 this further gives

\frac{C}{12}\equiv log_{2}(\frac{f}{r}s_{i})-log_{2}(\frac{f}{r}s_{i-1})\end{displaymath}

Merging various constant factors (12, $f$ and $r$) into $C$ gives

C\equiv log_{2}s_{i}-log_{2}s_{i-1}=log_{2}\frac{s_{i}}{s_{i-1}}\end{displaymath}

and thus $2^{C}\equiv\frac{s_{i}}{s_{i-1}}$, in which $2^{C}$ will be a constant itself.


In other words we need a constant multiplier for the playing speeds instead of a constant difference. By induction we get $s_{1}=Cs_{0}$, $s_{2}=Cs_{1}$, $s_{i}=Cs_{i-1}$ which leads to

\end{displaymath} (3)

We further know that $s_{0}=a$ and that $s_{N}=b$, so


Isolating $C$gives

\end{displaymath} (4)

Practically, filling 4 into 3 gives


To calculate the logarithm using a specific base $B$ (10 or $e$ for instance) use the following