Minimizing+sound+clicks

//by Richard Russell, January 2010//

When generating music using the [|SOUND] statement, **clicks** may sometimes be audible at the start and/or end of notes. These clicks are likely to be more noticeable when listening in high-quality, such as on headphones or when feeding the PC's sound output to a hi-fi system.

There are four main causes of such clicks; these are listed below along with methods for minimizing the effect.

Using SOUND OFF
Never use SOUND OFF to terminate a playing note; this shuts down the entire BB4W sound system and is likely to result in a large output transient. To terminate a note before its duration has been completed (or when the duration has been set to 'infinite') use the **flush** bit.

Instead of: code format="bb4w" SOUND OFF code Use: code format="bb4w" SOUND &10, 0, 0, 0 SOUND &11, 0, 0, 0 SOUND &12, 0, 0, 0 SOUND &13, 0, 0, 0 code

Sudden amplitude changes
If you are using the 'constant amplitude' form of the SOUND statement (where the second parameter is negative) then, when you need to change the amplitude, do so gradually.

Instead of doing this: code format="bb4w" SOUND 1,-15,148,20 SOUND 1,-10,148,20 code Do this: code format="bb4w" SOUND 1,-15,148,18 SOUND 1,-14,148,1 SOUND 1,-13,148,1 SOUND 1,-12,148,1 SOUND 1,-11,148,1 SOUND 1,-10,148,18 code Or consider using envelopes to achieve a similar effect: code format="bb4w" ENVELOPE 1,1,0,0,0,0,0,0,20,0,0,-20,120,0 ENVELOPE 2,1,0,0,0,0,0,0,-20,0,0,-20,80,0 SOUND 1,1,148,20 SOUND 1,2,148,20 code

Excessive attack or release rates
If you are using an amplitude envelope (where the second parameter of the SOUND statement is positive) don't make the attack and release rates too great.

For example, instead of using: code format="bb4w" ENVELOPE 1,1,0,0,0,0,0,0,127,0,0,-127,126,0 code Use: code format="bb4w" ENVELOPE 1,1,0,0,0,0,0,0,20,0,0,-20,126,0 code (where the attack and release rates have been reduced from 127 to 20).

Rests (silent notes)
If you need a period of silence on a particular channel (a **rest**) use one or other of the following techniques, depending on whether you are using a constant amplitude or an envelope:

Constant amplitude
Set the //pitch// to zero, **not** the //amplitude//.

Instead of: code format="bb4w" SOUND 1,-15,148,10 SOUND 1,0,148,10 : REM rest SOUND 1,-15,100,10 code Use: code format="bb4w" SOUND 1,-15,148,10 SOUND 1,-15,0,10 : REM rest SOUND 1,-15,100,10 code

Amplitude envelope
Use the **hold** bit to allow the sound to decay rather than stop suddenly:

Instead of: code format="bb4w" ENVELOPE 1,1,0,0,0,0,0,0,20,0,0,-20,126,0 SOUND 1,1,148,10 SOUND 1,1,0,10 : REM rest SOUND 1,1,100,10 code Use: code format="bb4w" ENVELOPE 1,1,0,0,0,0,0,0,20,0,0,-20,126,0 SOUND 1,1,148,10 SOUND &1001,1,0,10 : REM rest SOUND 1,1,100,10 code