This is an old revision of the document!
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.
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.
SOUND &10, 0, 0, 0 SOUND &11, 0, 0, 0 SOUND &12, 0, 0, 0 SOUND &13, 0, 0, 0
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:
SOUND 1,-15,148,20 SOUND 1,-10,148,20
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
Or consider using envelopes to achieve a similar effect:
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
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:
(where the attack and release rates have been reduced from 127 to 20).
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:
Set the pitch to zero, not the amplitude.
SOUND 1,-15,148,10 SOUND 1,0,148,10 : REM rest SOUND 1,-15,100,10
SOUND 1,-15,148,10 SOUND 1,-15,0,10 : REM rest SOUND 1,-15,100,10
Use the hold bit to allow the sound to decay rather than stop suddenly:
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
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