Magazine Archive

Home -> Magazines -> Issues -> Articles in this issue -> View

Software Envelope Generator

Use the Sinclair ZX Spectrum to create sophisticated digital envelopes.

With the tremendous upsurge of interest in micromusic at this time, E&MM devotes this month's project to a unique package we've commissioned for the popular ZX Spectrum.

While most readers will already understand the functions and applications of an envelope generator it is just as well to define its more important aspects. Figure 1 illustrates the mostly widely used ADSR (attack-decay-sustain-release) type of envelope and the generator used for this has four user adjustments. These are: (i) A, the time for the initial (attack) voltage to rise to the peak output voltage; (ii) D, the time for the peak voltage to decay to (iii) the sustain level, S; and (iv) R, the time for the voltage to drop to zero when the sustain period is complete. Having set these values, the envelope-generator is generally under the control of the gate voltage produced when a key is pressed. At this latter time the attack voltage commences and so long as the key is kept held down the decay phase will also be completed. The voltage will then remain constant at the sustain level until the key is released, which starts the release step. The gated period is also illustrated in Figure 1.

Figure 1. Hardware ADSR envelope.

In a basic analogue synthesiser, a voltage controlled oscillator (VCO) will receive a control voltage from the keyboard controller and produce a constant tone until a new key is pressed. The waveform will normally be filtered using a voltage controlled filter (VCF) and the output is connected to a voltage controlled amplifier (VCA). An envelope generator provides the control voltage for the VCA so that the contours of the envelope shape the sound output. As the release phase proceeds the sound level will decrease and with a properly matched generator and VCA it will eventually be completely cut off. The arrangement is shown in Figure 2.

Figure 2. Basic synthesizer patch.

In the role of a sound shaper, the settings of an envelope generator are not difficult to appreciate; for example, the longer the release time then the longer the note will take to die away; the higher the sustain level the louder the note; and the shorter the attack time the more percussive the sound. Indeed, for many percussion instruments a simpler AD (attack-decay) envelope is sufficient and this is obtainable from an ADSR generator by setting the sustain level to zero.

Another feature of the conventional envelope generator is that the attack curve shows a logarithmic increase while the decay and release curves have an exponential decay. Such shapes are easily obtained in hardware designs since they result from the charging and discharging of a capacitor via a variable resistor. The reason for using such shapes is that, as a reasonable approximation, the ear responds to amplitude in a logarithmic manner - hence the use of logarithmic taper potentiometers for volume control and similar applications.

This subject is referred to again later, but it is as well to appreciate the reasoning behind the shapes provided. Other variations of the envelope will also be discussed as they arise, but at this stage it should be understood that an envelope generator has a wide variety of applications in analogue synthesis, such as allowing timbre to be altered during the course of a note by connecting another generator to a control input on the filter (VCF) in Figure 2.

Software Envelope Generator

This project requires the hardware employed in the current series of articles on DIGITAL SIGNAL PROCESSING: Spectrum Interface board, A to D Controller, D to A Controller and PSU units.

One of the big advantages of using software control is that we are able to produce features which are difficult and expensive, or even impractical, to produce with hardware. On the other hand, it is almost impossible to describe all of the features and applications. It is said that a picture is worth a thousand words and even though abundant use has been made of screen displays they cannot convey the smoothness of the cursor editing routines and other professional features incorporated into the program.

Besides the hardware mentioned, a program cassette is available called 'THE ENVELOPE'. Load this cassette in the usual way with a LOAD " " command and when complete the screen will display the 'generation' menu, which is:

1. Generate env(elope)
2. Sample env(elope)
3. Load from tape
4. Load from memory
5. Calibrate ADC

On the first run you only have options 1 and 2, so let us get the sampling routine out of the way. In essence this is just a simplified version of the storage oscilloscope program presented in Digital Signal Processing but geared to suit slow inputs, as appropriate for envelopes. On entering '2' you will be prompted for 'sample time, seconds?', which may be any value up to about 150 seconds, and this is followed by 'Trigger level (volts)?' to which the desired trigger level is entered. The latter is on a scale of 0 to 5. After pressing ENTER the set sampling period commences when the trigger level is reached. Figure 3 shows the result of using this technique to sample a hardware ADSR envelope generator.

Figure 3. Sampled hardware ADSR envelope.

There are two main points to note, the first being that only 256 samples are taken during the sampling period and so any attempt to use this procedure for fast signals will give unusable results. Secondly, very low frequency waveforms will be affected by the coupling capacitors in the AC signal path of the A to D Controller and so the DC input should be used and the filter, if fitted, switched out. The ADC calibration routine, '5' from this menu, allows the input scale to be set to 0V using the zero adjust potentiometer. Pressing ENTER provides escape from the calibration routine.

Figure 4. Parameters for software generated envelope.

Loading from tape and memory will be described with their related save routines. The remaining command is 'Generate envelope' and on selecting this program prompts will be given for a conventional ADSR envelope and five parameters have to be defined, as shown in Figure 4. The total envelope period is 100 units and the main difference compared to setting up a hardware generator is that we have to define a period prompted as Sustain (time). When this time is combined with the times for the attack and decay phases, then it is equal to the gate period of Figure 1. Thus the first prompt is 'Attack (0 to 100)?' and you enter a value representing the percentage of the total time to be taken up by the attack phase. After entering this number there will be a short delay and then you will be successively prompted (sometimes after a short delay) for decay time; sustain level; sustain (time); and release. For the time factors, the prompt will display the number of units left and in the case of release it will simply ask whether the remaining value is acceptable. If you respond "n" for no, then the routine will restart with the prompt for a new attack time. After a positive response to the release time there will again be a short delay before the envelope that has been created is shown on the screen, together with the numerical values used. If values of 25 are used for all time constants and a value of 60 for the sustain level then the result is illustrated in Figure 5.

Figure 5. Generated linear ADSR envelope.
Figure 6. Generated linear AD envelope.
Figure 7. Logarithmic AD envelope.
Figure 8. Further logarithmic modification of Fig7.

Several things should be noted at this time. First, if the COPY command is used from the 'Spectrum' keyboard then the screen will be copied to a ZX printer - as used for Figure 5 and most of the other illustrations. Next, should the program crash for any reason, including a "q" for quit command, then it may be recovered by entering GOTO 3010. Third, the envelope created at this time has linear slopes and while such envelopes may be obtained from specialised generators they are not widely available. In fact, it will be rewarding to examine both linear and exponential envelopes in conjunction with linear and exponential VCAs - the combinations will produce markedly different outputs. Lastly, although the prompts are for an ADSR envelope, one may generate a variety of shapes: (i) attack = 0, decay = 100 and sustain level = 100 produces a square wave; (ii) attack = 0, decay = 100 and sustain level = 0 gives an inverted sawtooth; (iii) attack = 100 is a sawtooth; while (iv) attack = 50, decay = 50 and sustain = 0 produces a triangle.

Processing An Envelope

After generating an envelope with one of the above routines an ENTER will display the processing menu:

1. Input
2. Modify
3. Display
4. Save to tape
5. Save to memory
6. Output

A '1' input, will take you back to the generating menu just described but in so doing you will be prompted with 'Overwrite old envelope?'. A "y" will get you to the generating menu whereas a "n" will put you back to the processing menu and give you another opportunity to save, or otherwise use, the envelope. The 'Display' command gives a virtually instantaneous display of the current envelope which is available for processing.

The 'Save to tape' routine prompts for a 'Filename?' and there is no need to put the name in inverted commas. After an ENTER the usual prompt of 'Start tape, then press any key' will appear - do not forget to check that the cassette leads are set up for loading. On completion you are returned to the processing menu. When loading from tape using the generating menu you will again be prompted for the filename and then the load is carried out in the normal manner. When loaded you are back in the processing mode and so a '3' (display) will show the envelope recovered from the tape.

The envelope loaded from tape, or any envelope currently being processed, may be saved in memory by selecting '5'. This command will result in a 'Position in memory (1-16)?' prompt. It is wise to keep a list of envelopes currently in store, but if you enter a location which is already storing an envelope then you will be asked if you wish to overwrite the position. Having selected a location, or responded "y" to the latter message, the current envelope will be saved and the processing menu will simply prompt for 'position (1-16)?' and on entering the correct number the appropriate envelope will be displayed on the screen. Another ENTER and you will be in the processing mode. If no envelope exists at a selected location then this fact will be flashed onto the screen for a short time before putting you back the menu to allow another choice.

The output program will be discussed after we have dealt with the various modifying routines. So enter '2' and you wil have the following modification menu:

1. Smooth envelope
2. Point manipulation
3. Invert
4. Convert to log
5. Exit

The last command, 'exit', will return you to the processing menu so that a modified envelope may be saved or output or, if desired, a new envelope obtained for modification. It will be apparent that this process may be repeated such that a single envelope is able to undergo sixteen stages of modification which may then be stored in the memory locations provided so that the effect of the modifications can be subsequently heard rather than seen.

Although the 'Convert to log' is listed as command '4' there are some circumstances in which the command is not present and '4' becomes the exit command. As stated earlier, a conventional envelope generator has a logarithmic increase for the attack phase and exponential responses for the decay and release phases. The 'Convert to log' routine will convert a linear envelope to this conventional form. For this process it is necessary that the variables defining the envelope are in memory and this would generally only be the case when an envelope is generated from scratch. The routine has, however, been improved such that a generated envelope stored in one of the sixteen allocated memory positions will keep its variables. Thus, in most instances, if an envelope is stored in memory then it may be taken out and undergo the log conversion routine. If, however, the envelope has been entered from tape or it has been generated by the sampling technique then it does not have the appropriate variables for the calculations and so the 'Convert to log' will not appear on the processing menu.

Another point to remember is that the calculation is seeking the values of all variables and if a simple AD envelope is produced then some values are missing, or at least have not been entered. Under these circumstances the calculation may produce an error message, but you can quickly get back into the program with the GOTO 3010 command and you will usually find that when the envelope is displayed the log conversion was in fact completed before the error message was generated.

To avoid this potential problem the alternative is to create an AD envelope using the attack and release responses with a maximum sustain level. Figure 6 shows the linear version of such an envelope which was obtained by entering attack = 20, decay = 0, sustain level = 100, sustain (time) = 0 and release = 80. Figure 7 shows its log conversion while Figure 8 demonstrates the effect of two further log conversion processes. Thus it is possible to use the 'log convert' to produce more curved responses, but again it may not always operate correctly if the envelope has been significantly modified prior to the second, or subsequent, conversions.

Let us return to the ADSR envelope created earlier (Figure 5). First we can carry out the log conversion to make it look more like a conventional envelope and the result is shown in Figure 9. Next we could use the invert command, 3, and the envelope would be transformed to that shown in Figure 10. This may seem a trivial effect, but in fact inverted envelopes are extremely useful for modulating filters. For example, an inverted envelope of the type shown in Figure 11 would allow high harmonics through as the note is first played and then the harmonic content settles down to a fairly constant level. Later the harmonic content is gradually reduced as the release phase proceeds.

Figure 9. Logarithmic ADSR envelope.
Figure 10. Invert of Figure 9.
Figure 11. Inverted envelope.
Figure 12. Initial cursor position for point manipulation.
Figure 13. First cursor position for Figure 15.
Figure 14. Second cursor location for Figure 15.
Figure 15. Modified ADSR envelope.
Figure 16.

The most versatile modification technique is command '2', which is point manipulation. In simple terms two points on the envelope to be modified are selected and the routine will draw a straight line between these points. This process may be repeated as many times as required, or patience allows, and so intricate 'curved' lines may be produced. The routine is cursor operated but extremely fast and accurate since the cursor follows the contour of the envelope. On entering this mode the envelope being modified is displayed with the cursor located at 0,0 (Figure 12). The shift right and shift left keys on the 'SPECTRUM' keyboard move the cursor along the curve, within the constraints of the screen, and pressing 'CAPS SHIFT' at the same time will speed up the movement. In effect one has a coarse and fine positioning.

To demonstrate the process let us cut the top off the envelope in Figure 9. Move the cursor to about the position shown in Figure 13 and press ENTER which will then leave a cross at this first selection point. Press ENTER again and the cursor re-appears which should now be moved to a position similar to that shown in Figure 14. Note how the extended cursor allows accurate alignment with the previous point, or other feature. Press ENTER and a cross will be placed at this second selection. The numerical value of the selection is also displayed and the number is the horizontal position from a maximum of 256 screen locations. Press ENTER once more and after some calculations have been performed, the modified envelope (Figure 15) will be displayed.

Figure 17.
Figure 18.
Figure 19. Second peak on ADSR envelope.
Figure 20. Stage 1 for Figure 22.

Some synthesisers have the capability of re-triggering the envelope generator to obtain a double peak which is typical of the envelope generated by some wind instruments. Starting again with our basic ADSR envelope let us now add a peak from about two thirds the way down the decay curve to the start of the sustain period. Figure 16 shows the first cursor position and after ENTER the shift up and shift down keys, without or with CAPS SHIFT for extra speed, are available and Figure 17 shows the location of the cursor after shifting up to the point marked. Next the cursor is moved to the position illustrated in Figure 18 and the resultant envelope is shown in Figure 19. Although the last illustration shows a gap in the envelope it is only because the transition occurs in the space on one bit of the screen. In other words, no discontinuity is actually present as will be evident if the envelope is used to control a sound output. If, however, one requires a less sharp peak then Figures 20 and 21 show the cursor positions for producing the envelope of Figure 22. Because this stage has been reached by just drawing two straight lines the resultant peak is linear, although it is doubtful whether the effect would be noticeable under practical conditions of sound shaping. Nevertheless we could carry out another log conversion which would result in Figure 23. In the latter case, notice that the attack and release contours are more curved and to avoid this the peak could have been added to a linear envelope before carrying out a log conversion.

When using the point manipulation technique you will quickly realise that the peak attack value is the top of the screen. This means that a higher peak cannot be generated unless one reduces the peak attack value beforehand, such as the simple reduction of Figure 15.

The envelopes produced so far all have fast transitions from one stage to the next (the same is true of hardware generators), whereas in many real envelopes the attack tails off as its peak is reached. The smoothing command, 1, will round off corners. On selection you have two options to choose from:

1. Partial smooth
2. Entire smooth

Figure 21. Stage 2 for Figure 22.
Figure 22. Modified peak on ADSR envelope.
Figure 23. Logarithmic conversion of Figure 22.
Figure 24. Figure 9 with smoothing factor of 5.

Select the latter and prompt 'smoothing?' will appear. The response is a value which does not have a practical upper limit, but the larger the number the longer the process will take since it is an iteration technique. In other words if you enter 5 and then select smoothing again and enter another 5, the end result will be the same as if 10 had been entered in the first instance. The algorithm used is a simplified version of a technique known as Kalman filtering, which is widely used for extracting a signal from a noisy environment. The nature of the routine is such that the smoothing will be more effective on irregular features. This means that choosing the value for smoothing depends on trial and error until sufficient experience is gained. The best approach is to store the envelope to be smoothed in memory so that if it is smoothed further than desired you can recall the original envelope and use a lower smoothing factor. To illustrate the smoothing process Figures 24, 25, 26,27 and 28 show the effect of smoothing factors 5, 10, 20, 100 and 500 respectively on the ADSR envelope of Figure 9.

The other option is partial smoothing which uses the same cursor routine described earlier for point manipulation. In this case the cursor is used to select two points on the envelope and the smoothing process will only be applied between these points. Using the double peak envelope generated earlier (Figure 22) we could use partial smoothing instead of log conversion to suppress the peaks and Figure 29 shows a smoothing factor of 5 applied from the start of the attack curve to the start of the sustain period. If we did not wish to round off the attack peak then Figure 30 illustrates the result of a smoothing factor of 10 applied from the end of the attack period to the start of the sustain period. The log convert may now be applied to the latter envelope and the result is shown in Figure 31.

Figure 25. Smoothing factor of 10.
Figure 26. Smoothing factor of 20.
Figure 27. Smoothing factor of 100.
Figure 28. Smoothing factor of 500.
Figure 29. Partial smoothing of Figure 22.
Figure 30. Another partial smoothing of Figure 22.
Figure 31. Logarithmic conversion of Figure 30.
Figure 32. Unusual envelope No.1.
Figure 33. Unusual envelope No.2.
Figure 34. Unusual envelope No.3.
Figure 35. Unusual envelope No.4.
Figure 36. Unusual envelope No.5.

Using the Envelopes

Figures 32,33,34,35,36 and 37 show some unusual envelopes. While it may be fun to produce strange envelopes, the key factor is the contribution that such envelopes can make to electronic music. We have mentioned that the key role of an envelope generator is to contour the sound, while the other major use is in modulating a voltage controlled filter. An envelope may, however, be used as a control voltage for many other purposes, such as, sweeping oscillators and panning mixers, and one of the main advantages of using an envelope generator for these latter purposes is that it may be synchronised with the start of a note. In discussing the output process we will concentrate on the sound contouring application which requires the arrangement of Figure 38.

Figure 37. Unusual envelope No.6.

The complete signal processing hardware, described in Parts 1 and 2, is required in order to obtain all of the output functions. The envelope output must, however, be taken direct from the 'DAC OUT' and 'GROUND' pins on the Molex connector on the D to A Converter board. The best approach is to connect a length of screened cable to the appropriate pins in the Molex shell and to terminate the other end with a suitable connector for the VCA to be used. The reason for this step is that the D and A Controller is AC coupled for the sound processing routines and so an envelope will be blocked, or significantly distorted, if the output on the controller is used. The output routines do, however, make use of the push buttons on the two controllers and so these must be connected to the converter boards.

Figure 38. Arrangement fortesting envelopes.

It is rarely easy to access the voltage controlled amplifier (VCA) within an integrated synthesiser but a Digisound 80 Dual VCA module could be used and one channel could be modified to suit the nominal 3V8 available from the D to A Converter. Alternatively, a rudimentary VCA may be constructed using a CA 3080E and a suitable design is shown in Figure 39. In the latter R1 is selected such that the voltage is about +/-10mV at the junction of R1 and R2, marked 'X'. For a 10V p-p input a 120k resistor would be suitable. The diodes may be 1N4148 types and the output is suitable for the line input of an amplifier.

On accessing the output program from the processing menu you will have the following options:

1. Single shot (manual): On selection you will be prompted by 'output time (min 0.5 secs)?' and a value in seconds should be entered. The value entered is the total time for playing the envelope from the start of the attack to the end of the release. When entered, press the 'REST' button on the A to D Controller in order to generate the single shot envelope. The screen displays 'HOLD to stop' and the 'HOLD' button on the D to A Controller must be pressed during an output cycle in order to get back to the output menu. Note that the single shot routine can be repeated as many times as desired prior to discontinuing with the HOLD button.

2. Single shot (gated): This program allows the software generated envelopes to be played using a gate voltage, low frequency oscillator, or other synchronising pulse. Another feature of this mode is that after being prompted for the output time you will then be asked for a 'delay before output?'. A delay between gating the envelope and the start of the attack cycle is another useful variable especially when the envelope is being used to control a voltage controlled filter. For example, in conjunction with an inverted envelope an initial delay is effectively an initial sustain period during which high harmonics are allowed to pass. Generally the delay time will be quite short but a value up to about 180 seconds may be entered.

Figure 39. Simple voltage controlled amplifier.

The envelope is gated by using the GATE input on the A to D Controller and it may be a positive or negative-going pulse depending on the setting of the gate switch. In the absence of external gating devices then put the switch to '+' and connect a wire terminated with a 3.5mm jack plug to the positive gate socket. Touching the exposed end of this wire will gate the envelope. This mode is also terminated by pressing the HOLD button during the output phase - pressing it during the delay phase will not be effective. Note that the envelope may only be re-gated after it has completed the set cycle time.

3. Repeat: This program again prompts for an output time and on selection the current envelope in memory will be continuously repeated until the HOLD button is pressed. If this mode is used with a generated square wave then it should be realised that the output will be a continuous tone since there is no gap between successive 'squares'.

4. End output: This selection will take you back to the processing menu.

'THE ENVELOPE' cassette containing the above programs suitable for a 48K 'Spectrum' is available for £6.25, inclusive of postage and VAT, from Digisound Limited, (Contact Details). This company should also be contacted for other sales or technical information relating to the Digital Signal Processing series of articles.

It will be apparent that the software routines described will allow a thorough examination to be made of the role of envelopes in analogue synthesis. As with other programs in the Digital Signal Progressing series, the user may access the routines and examine other modifications, such as using different laws to shape the time factors. The possibilities are endless.

More with this topic

Browse by Topic:


Also featuring gear in this article

Featuring related gear

Previous Article in this issue

Talking Shop

Electronics & Music Maker - Copyright: Music Maker Publications (UK), Future Publishing.


Electronics & Music Maker - Nov 1983

Donated & scanned by: Stewart Lawler



Gear in this article:

Computer > Sinclair > ZX Spectrum

Previous article in this issue:

> Talking Shop

Help Support The Things You Love

mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.

If you value this resource, you can support this project - it really helps!

Donations for August 2022
Issues donated this month: 0

New issues that have been donated or scanned for us this month.

Funds donated this month: £136.00

All donations and support are gratefully appreciated - thank you.

Magazines Needed - Can You Help?

Do you have any of these magazine issues?

> See all issues we need

If so, and you can donate, lend or scan them to help complete our archive, please get in touch via the Contribute page - thanks!

Please Contribute to mu:zines by supplying magazines, scanning or donating funds. Thanks!

Monetary donations go towards site running costs, and the occasional coffee for me if there's anything left over!

Small Print

Terms of usePrivacy