Are you a musician?
Register here
Mobilmenu

Avoiding clicks'n'pops in your MODs

You may have noticed that certain MODs (or MEDs) on Amiga sometimes produce a click here and a pop there. You may even have grown so accustomed to these clicks'n'pops, that you just consider them to be a natural and charming part of "The Amiga Sound", whether it's on a subconscious level, or something you're fully aware of.

I personally notice any kind of noise in audio quite a lot - and these clicks'n'pops annoy my tiny audiophile brain just as much as quantisation noise does. Especially when I've created a nice MOD in Milkytracker that I am somewhat proud of, only to discover that it's full of clicks'n'pops when listening to it on my Amiga. I've therefor often pondered about whether anything could be done about this problem, but I never dived into any actual research until now.

During my research I ended up exploring many options and made quite a lot of discoveries along the way, which I will now share with you here. I will list all the different conditions that cause these clicks'n'pops to occur, and then describe various techniques you can use to work around them.

The looping bass

We'll start with a sample of a looping deep sine wave. It'll look like this when playing a single tone.

Sine

If you use this sample to play different notes in the same channel, the resulting output may look somewhat like this:

Sine tones

Every time a new note plays, the previous note is interrupted, and the sample is played from the beginning, with the samplerate of the new note. It's easy to see on the visual representation of the audio, where a tone is interrupted and a new tone begins. Especially when the previous tone is interrupted when the sample is at its highest amplitude. Because then the audio jumps from max amplitude to zero from one data-point to the next. And it is this jump that cause the click. That's simply the sound such a large jump makes.

This might puzzle a few readers, because the whole model with interrupting notes with new notes, is used in quite a lot of different tracker filetypes - which would logically mean that we should be hearing such clicks'n'pops all over the place when listening to tracker music in general. But we don't. We only hear them when playing MODs on Amiga. (Or other Amiga filetypes such as MED and DBM files).

There is quite clearly a difference between these Amiga filetypes and PC filetypes: The PC filetypes have a fancy feature called volume-ramping, which basically smoothens such large jumps in amplitude when they're too big. So we don't hear clicks'n'pops when playing these filetypes on a PC where they originate from. Like for example if you play an XM in FastTracker II, there are no clicks'n'pops. However, if you play the same XM with DigiBooster Pro on Amiga, then it will most likely be full of clicks'n'pops. Because there's no volume-ramping in DigiBooster Pro, but there is in FastTracker II. Even if you create a MOD on Amiga with clicks'n'pops, it will usually be free of clicks'n'pops if you play the same MOD with a random PC player.

So yes, it can be rather frustrating to be an Amiga musician, if you care a lot about producing clean sound.
But let's look into ways to avoid these clicks on Amiga when we have no volume-ramping available. There are plenty of workarounds we can use, and which one to use depends on the scenario. In this particular case; The looping bass, we can use a simple and commonly used workaround: The portamento to note (3xx) command for each new note. That way, instead of interrupting the previous note and starting the sample from the beginning again, the waveform will continue to play while gliding up/down to the next note.

Sine glide

As you can see, this approach completely eliminates all the large jumps in amplitude, and therefor the clicks are gone now. We'll call this first anti-click technique "The portamento method".

Fadeout solves nothing

But a constant bass sine isn't always what we want. Sometimes we want a short bass note instead. So the next logical idea will be to try to fade out the tones between each note with A0x commands. That way, the volume should be low or even zero when the next note is played, and it should therefor logically eliminate all the clicks'n'pops.

Sine fade

But two things may seem surprising here. The first surprise is that, despite fading out the volume of the previous note before playing the next note, there are still clicks that are equally loud and just as annoying as in the very first scenario. Even if waiting several seconds with total silence before playing the next note! This makes absolutely no sense, since the previous tone is definitely faded out now.

The other surprise is that a lot of smaller clicks'n'pops seem to have joined the party too now. So fading the tones seems to have resulted in the exact opposite of what we were aiming for: It has increased the amount of clicks'n'pops instead of removing them. What's going on???

Well, it turns out there's a limitation (some say bug) in Protracker: When a new note is played, the volume on that channel is reset to whatever volume the sample has. That makes sense of course. But the problem is, that the volume is turned up before the previous note stops playing. Which means that the last few milliseconds of the previous tone is turned up just before it's interrupted. This basically renders the whole volume fade-out approach completely useless, since it has no effect on the clicks'n'pops at all. We still have the exact same problem as in the first scenario, which is clearly visible when we zoom in:

Sine fadezoom

There is a workaround for this problem though: Once the previous note is faded out, we can play another sample that only has a few milliseconds of data at zero amplitude and zero volume. That way, when channel volume is changed before playing the new note, it doesn't matter that it plays the zero amplitude snippet from the previous sample first.

There are 3 drawbacks to this approach though:

  1. We need a whole row for this extra "anti-click" sample.
  2. We need to use up a sample slot too.
  3. It may interrupt the previous note before we want it to.

But appart from those drawbacks, it does effectively remove the click. Let's call this workaround "The silent sample trick".

You might get the idea of using EDx to delay the silent sample, to make the previous tone a few ticks longer before interrupting it. But no: There's another bug in Protracker here: Although EDx does indeed delay the sample with x ticks, the resetting of the channel volume is not delayed. Volume is set at the very first tick of the row regardless. So EDx doesn't help us at all here. The previous tone will be silenced at the beginning of the row with the silent sample regardless of any EDx value.

Ok, so that explained why the clicks where still there, and we found a workaround to fix it: The silent sample trick. But what about all those additional smaller clicks then?

Well, all these smaller clicks are caused by the volume fade A0x commands, because that's how sensitive audio is without volume-ramping.
A0x works by reducing volume x values per tick (except the first tick) for each row. If tickspeed is set to F06 then A01 will decrease the volume with 1 value 5 times for that row, and A0F will decrease the volume with 15 values 5 times. So it's not a smooth fade, but rather a kind of staircase fade that produce a lot of smaller jumps in the amplitude. So the higher A0x value, the bigger the jumps, and therefor the louder the clicks.

Sine fadezoom2

These circumstances will probably make you try to settle with A01 to get the least amount of these clicks'n'pops - and that might be fine in some cases. But you may also find that even A01 can cause clicks'n'pops that annoys you, or else you may find that A01 doesn't fade fast enough.

So what kind of workarounds can we find here? Well... since the clicks'n'pops happen because there's a jump in the sample amplitude, it's obvious that the solution is to somehow avoid these jumps. In other words: If all the tick locations are placed where the sound amplitude is (near) zero, then we'd be all set. Because then the jumps wouldn't be noticeable.

The "magic" frequency

Since tones are frequencies, and samplerates are frequencies, and tempo is a frequency too, then it is possible to find a tone-frequency that matches the samplerate and tempo, so that the each (half) wavelength is placed exactly where the tick offsets are. So when A0x turns down volume by x steps, it does so where the amplitude is zero, and thus doesn't cause a click.

But how to calculate what this frequency is?

Well, if you (like myself) don't know anything about the inner workings of the Amiga, then you'll probably try to calculate this frequency like this:

Let's say we have a track playing at 125 bpm. Then we know that each beat is 60000/125 = 480 ms, which means each row is 480/4 = 120 ms, and each tick is 120/6 = 20 ms.
At a samplerate of 16574,27 Hz that means each tick is 16574,27*0.02 = 331,48 samples.
We can then calculate that we'll need a tone frequency of 16574,27/331,48 = 50 Hz (or a multiple thereof) in order to make sure all the tick locations are placed at the zero amplitude offsets in the sample.
And yes, this absolutely works! Suddenly all the clicks'n'pops are gone, no matter how rough a fade we do. Even interrupting the tone and playing a new one doesn't give any clicks! Listening to this deep click-free bass sine is so amazing that it's difficult to believe it's a MOD in Protracker we're listening to.

If you're a master on Amiga audio though, and therefor knows a great deal about the inner working of the Amiga, then you'll most likely find the above calculation method silly, and instead calculate the frequency like this:

First, you'll find the actual tempo on Amiga, which is 1773447,5/(floor(1773447/tempo)+1). So if we've set a tempo of 125 bpm, then the actual tempo on Amiga will be 1773447,5/(floor(1773447/125)+1) = 124,99629969 bpm.
And then to get the actual samples per tick, we have to divide the samplerate with (actual_tempo/2,5). So actual samples per tick becomes 16574,27/(124,99629969/2,5) = 331,49521308 samples.
And the frequency then becomes 16574,27/331,49521308 = 49,998519876 Hz.
As you can see though, the difference between the two calculation methods is tiny (0,001480124), and doesn't affect the outcome of this experiment at all.

Anyway, we can sadly only produce this "magic clickless frequency" for one specific tone-frequency (or a multiple thereof) for each tempo setting. And that means it's not a whole lot useful in praxis. It basically only serves as a proof that this technique works... at least for some samples.

So how can we achieve the same awesome anti-click effect with any other kind of sample? Well, I had 4 ideas on how to do this, and did extensive experiments with all of them.

Idea 1: "The burned volume-ramp". Edit the sample, and boost the amplitude at the exact tick locations with the exact amount that the A0x command has, and then fade to normal. In other words; add a kind of static volume-ramping burned into the sample to counter the A0x effect.
This requires extremely precise timing that is tricky to get right, and it also renders the sample useles for any other kind of Axy commands. Meaning, it'll produce clicks'n'pops with any other combination of Axy commands - or if you don't use any Axy commands at all. In other words, idea 1 is useles.

Idea 2: "The sample-fade in/out trick". Edit the sample and adjust the waveform to make sure the amplitude is (near) zero at the tick locations, by fading the sample in and out around the tick offsets.
This is less demanding in regards of accuracy, but the fade ins'n'outs that are necessary to prevent clicks, will alter the sound to such a degree that it becomes equally annoying as the clicks'n'pops. Some will probably say even worse. So idea 2 is worthless too.

Idea 3: "The stretch'n'shrink trick". Edit the sample and stretch or shrink each snippet of audio between tick locations to make sure the amplitudes end up (near) zero at each tick location.
Sounds promising at first, thinking that the strething'n'shrinking of snippets will "just" result in some kind of vibrato effect, which might even sound cool? But sadly no. This approach too will alter the sound to such a degree that it is useless.

Idea 4: "The tick frequency trick". Create an additional frequency matching (half) the tick sample size, and mix it with the audio in order to get the amplitude at the tick-offsets placed at zero.
This is it! By reading the data-point values at each tick-offset, and then applying a counter frequency between each tick-offset, we can alter the sound so that all the tick-offsets will have an amplitude of zero. This will cause the signal to go outside the scope sometimes, but we can try different tone-frequencies, tempos and volume adjustments until it stays inside the scope. And best of all: The sample still sounds fine, since the signal we're adding is at such a low frequency that we can't hear it.

This will require us to "unroll" the short looped bass though, so that it becomes a much longer sample. In other words, it'll take up more space.
Another disadvantage is that the sample can only be used at a specific samplerate and tempo. So if you want to use this approach for a bass, then you'll need a bass sample for each tone you want to play. You might be fine with this - I personally am - because quality matters more to me than filesize. But I understand if you feel you'll be using too many samples and too much space with this approach, and therefor want to hear about other options.
Personally though, the tick frequency trick is exactly the kind of trick I was looking for. Because it allows me to do fades and cut off notes without clicks, and I've really been missing that.

But nothing is ever easy, is it? No it isn't.

It turns out, there's a sample-trigger delay on Amiga, which means the tick offsets doesn't match our precalculated locations where we made sure the amplitude is (near) zero. In one experiment, playing a 16574 Hz sample, judging solely by listening, the delay was about 8-9 sample-points. But in another experiment, the delay was about 11 sample-points. That may not sound like much, but it's enough to affect the clicks'n'pops. So by deleting this amount of sample-points in the beginning of the sample(s), the clicks were gone again on my Amiga.

Curious to find a formula that lets us calculate how many sample-points this delay is, I reached out to a couple of masters on the topic. But although I did get some interesting info, I never found a useful formula. It seems the delay varies too much depending on various factors.
In other words: If you want to use the tick frequency trick, then you have to listen to the MOD with the playback library that's going to be used, and then delete the number of sample-points it requires for the clicks to be gone. There is no way to guarantee a click-free MOD with this approach on all players out there.

The sample fade-out trick

So the next idea, in order to avoid all the small clicks'n'pops that the Axy commands creates, will probably be to simply fade out the amplitude in the sample data itself.

This approach of course also means we'll be using more bytes for sampledata than a short looped sine, since we'll be including the fade-out in the actual sample data now. And we will probably also want to have more than one sample, to avoid the fade-outs varying too much in speed when you play the bass sample at different notes.

The advantage with this approach is that, if the tone is interrupted, it'll most likely happen at a low amplitude, and thus won't cause a click. The disadvantage is that fading out the amplitude in an 8-bit sample will create more quantisation noise.

The sample playthrough method

A method similar to the sample fade-out trick, is to have samples of the same instrument, in varying lengths - but without a (long) fade-out.
This will work just as the sample fade-out trick works, except without the additional quantisation noise since we don't fade the amplitude in the sample.

The sample-offset method

What about an option that only requires us to use a single sample, while still avoiding clicks'n'pops? Are there any such options available? Yes there is. :-)

Let's go back to the initial deep bass sine - but unroll it so that it becomes a longer sample.
If you can shape this deep bass sine so that each 256 data-points matches the zero amplitude points of the tone-frequency, then you can use the sample-offset (9xx) command to start the sample at various offsets - and thus make it reach the end quicker, resulting in a shorter tone.

For example, if we use a samplerate of 16574,27 Hz, then we'll need a tone frequency of 16574,27/256 = 64,743242188 Hz - or a multiple thereof, in order for the 9xx offsets to match the zero-amplitude points of the sample.

While this method works quite nicely, it comes with several disadvantages too:

  1. Since the tone-frequency has to match the tick offsets, it'll be difficult to get the tone in tune with the other instruments in the track.
  2. Though it does eliminate cut-off clicks (since the sample gets to play through before the next note), it doesn't help us with fade pops.
  3. And the method will only work with certain types of instruments: The ones that has very little variation.

Details matter

Lack of volume-ramping makes everything really sensitive to clicks'n'pops. If we start a sample with a non-zero data-value - then it will create a click when starting the sample. If we end a sample with a non-zero data-value - it will create a click when the sample is done playing.
Samples should always begin with two data-values of zero, and the last twp data-values (in a non-looping sample) should also be (at least close to) zero.

Summary

All in all we ended up exploring a whole 9 different techniques for avoiding clicks'n'pops. 3 of them were useless, which leaves us 6 options to choose from.
Each method has its own ideal usages. Some are great for removing fade-pops. Some are good for avoiding cut-pops. Some are optimal for short looped samples while others are best for "unrolled" samples. Here's an overview:

| Eliminate | | Fade| Cut | | Pop | Pop | Best for ------------------------------+-----+-----+-------------------------------- The portamento method | No | Yes | Looped samples ------------------------------+-----+-----+-------------------------------- The silent sample trick | No | Yes | Looped samples ------------------------------+-----+-----+-------------------------------- The tick frequency trick | Yes | Yes | Chords and single tones ------------------------------+-----+-----+-------------------------------- The sample fade-out method | Yes | Yes | Melody samples ------------------------------+-----+-----+-------------------------------- The sample playthrough method | Yes | Yes | Melody samples ------------------------------+-----+-----+-------------------------------- The sample-offset method | No | Yes | Melody samples ------------------------------+-----+-----+--------------------------------

And that finally brings me to the end of my noise-reduction exploration adventure. It's been fun and enlightning to discover these techniques, and I'm personally looking forward to create some cleaner-sounding MODs in the future. I hope it has been somewhat interesting to other MOD musicians out there as well.


Back to table of contents