Category Archives: Modelling

On the perils of cross-fading loops in organ samples

one common strategy when looping problematic organ samples is to employ a cross-fade. this is an irreversible audio modification that gradually transitions the samples leading up to the end of a loop to equal the samples that were leading into the start. the goal is to completely eliminate any sort of impulsive glitch and hopefully also create a “good spectral match”. while the ability to eliminate glitches is possible, creating a good spectral match might not be so simple.

we can think of an organ sample as being a linear combination of two signals:

  • A voiced/correlated/predictable component (choose your word) which represents the tonal part of the sample. Strictly speaking, the tonal component is not entirely predictable – there are continuous subtle variations in the speech of a pipe… but they are typically small and we will assume predictability.
  • An unvoiced/uncorrelated/unpredictable component which represents the pipe-noise of the sample.

云南快乐十分前三直选both of these components are necessary for realism in a sample.

云南快乐十分前三直选the following image shows a cross-fade of two entirely correlated signals. the top picture contains the input signals and the cross-fade transition that will be used, the bottom contains the input signals with the cross-faded signal overlaid on top. there is nothing interesting about this picture: the two input signals were the same. the cross-fade transitions between two identical signals i.e. the output signal is equal to both of the input signals.

Crossfade of correlated signal

云南快乐十分前三直选crossfade of correlated signal

云南快乐十分前三直选the next image shows a cross-fade of the same correlated signal with some uniform white noise overlaid on top. what is going on in the middle of output signal? it looks like it’s been attenuated a little bit and doesn’t appear to have a uniform distribution anymore.

Crossfade of correlated signal with uniform noise

云南快乐十分前三直选crossfade of correlated signal with uniform noise

this final image is a cross-fade purely consisting of two uniform random signals to add some more detail.

Crossfade of uniform noise

crossfade of uniform noise

it turns out that summing two uniformly distributed random variables yields a new random variable with a triangular distribution (this is how noise for triangular dither gets generated). during the cross-fade, the distribution of the uncorrelated components of the signal is actually changed. not only that, but the power of the signal is reduced in the middle of the transition. here is an audio sample of two white noise streams being cross-faded over 2 seconds:

listen for the level drop in the middle.

if the cross-fade is too long when looping a sample, it could make the pipe wind-noise duck over the duration of the cross-fade. while the effect is subtle, i have heard it in some samples and it’s not particularly natural. i suppose the tldr advice i can give is:

  • If you can avoid cross-fading – avoid it.
  • If you cannot avoid cross-fading – make the cross-fade as short as possible (milliseconds) to avoid an obvious level-drop of noise during the transition.

Release Alignment in Sampled Pipe Organs – Part 1

云南快乐十分前三直选at the most basic level, a sample from a digital pipe organ contains:

  • an attack transient leading into
  • a looped sustain block and
  • a release which will be cross-faded into when the note is released.

云南快乐十分前三直选the release cross-fade must be fast (otherwise it will not sound natural or transient details may be lost) and it must also be phase-aligned to the point where the cross-fade begins.

The necessity for phase alignment

without phase aligning the release, disturbing artefacts will likely be introduced. the effects are different with short and long cross-fades but are always unpleasant.

the following image shows an ideal cross-fade into a release sample. the crossfade begins at 0.1 seconds and lasts for 0.05 seconds. the release is aligned properly and the signal looks continuous.

A good crossfade into a release.

a good crossfade into a release.

云南快乐十分前三直选the following image shows a bad release where the cross-fade is lagging an ideal release offset by half-a-period. some cancellation occurs during the cross-fade and the result will either sound something like a “pluck” for long cross-fades or a “click” for short cross-fades.

A worst-case crossfade into a release.

云南快乐十分前三直选a worst-case crossfade into a release.

云南快乐十分前三直选(the cross-fade used in generating the above data sets was a raised cosine – linear cross-fades can be used but will result in worse distortions).

云南快乐十分前三直选the problem of aligning release cross-fades in virtual pipe organs is an interesting one. as an example: at the time of writing this article, release alignment in the project is not particularly good; it uses a lookup-table taking the value and first-order estimated derivative (both quantised heavily) of the last sample of the last played block as keys. this is not optimal as a single sample says nothing about phase and the first-order derivative estimate could be completely incorrect in the presence of noise.

Another approach for handling release alignment

If the pitch a pipe was to be completely stable, known (f=\frac{1}{T}) and we knew one point where the release was perfectly aligned (t_r), we know that we could cross-fade into the start of the release at:

    \[ \forall n \in \mathbb Z, t = t_r + T n \]

hence, for any sample offset we could compute an offset into the release to cross-fade into.

云南快乐十分前三直选in reality, pipe pitch wobbles around a bit and so the above would not strictly hold all the time – that being said, it is true for much of the time. if we could take a pipe sample and find all of the points where the release is aligned we could always find the best way to align the release.

it turns out that a simple way to do this is to find the cross-correlation of the attack and sustain segment with a short portion of the release. taking the whole release would be problematic because as it decays it becomes less similar to the sustaining segment (which leads to an unhelpful correlation signal).

The first 25000 samples of the signal used for the cross-correlation.

the first 25000 samples of the signal used for the cross-correlation.

the above image shows the attack and some sustain of bottom-c of the st. augustine’s closed horn. this shows visually why single sample amplitude and derivative matching is a poor way to align releases. during one period of the closed horn, there are 14 zero crossings and 16 obvious zero crossings in the derivative. one sample gives hardly enough information.

A 1024 sample cut from the start of the release.

a 1024 sample cut from the start of the release.

the above image shows a 1024 sample segment taken from the release marker of the same closed horn sample. it contains just over a single period of the horn.

the next image shows the cross-correlation of this release segment with the sample itself. my analysis program does correlation of the left and right channels and sums them to provide an overall correlation. positive maximums correspond to points where the release will phase-align well. minimums correspond to points where the signal has the least correlation to the release.

Normalised cross correlation of the signal with the release segment.

normalised cross correlation of the signal with the release segment.

using the correlation and a pitch guesstimate, we could construct a function which given any sample offset in the attack/sustain could produce an offset into the release which we should cross-fade into. this is for next time.