Home > Books > Amstrad CPC > Sound

This is a journey into sound

Sean McManus explains how to create music and sound effects in Amstrad Basic

As music technology embraces the floppy disc in a way never before, eight bit computers remain a good place to experiment with the techniques that shape hit albums. On a very much smaller scale, many of the features of expensive synthesisers are available for you to play with.

Tone envelopes and volume envelopes shape the way a sound changes over time, but are difficult to design. Expecting the user to draw the waves on graph paper and then reach for the calculator is a little dull and leads many people to use for-next loops for controlling their sounds. These loops shouldn't be frowned upon because they can create sounds that envelopes cannot and because they make it easier to visualise the sound's waveform over time. They can also link a sound to some other action.

Screenshot of Envelope Definer utility

This utility helps you craft your sound bytes

The disc contains an Envelope Definer program to help you experiment with tone and volume envelopes. Pressing K will call up a list of keys. Tapping space plays the sound you've defined. There are sliders for volume and hiss, advanced by pressing v and h respectively. Hiss is the key to creating percussion and explosion sounds. R will toggle the tone envelope's repeat and must be selected before the tone envelope is defined to have any effect. Pressing T takes you into edit mode for the tone envelope (press A for amplitude - a.k.a. the volume envelope). In this mode, you move the cross hair cursor using the cursor keys and fix a point by pressing the space bar. Press E to end if you want to end before reaching the right of the grid or before running out of lines to plot. If you want your envelope to run to the end of the note, set the note's length (using L) to 250. Press P to change the pitch and O to end and return to Basic, OUTPUTting your result.

The best way to get to grips with this program is to play with it, one part at a time. The scale is quite large, so you might want to only use a tiny section of the grid. The disc also contains many tunes in the various games. There are lots of books about converting sheet music to the CPC, but this book is going to assume that you don't know much about sheet music. The tunes on the disc are as much a result of their program as they are of the notes they use. When you're making music on the CPC, you can get away with musical murder. Notes that pianists wouldn't dream of using in the same piece can be thrown in recklessly and notes may be used that don't even exist on the piano. What's more, you can get away with nearly anything if you repeat it: Clanging once is a dischordant mistake. Doing it twice, it becomes an inventive musical pattern.

Musak factory

It sounds rather punk, but the best way to begin to write CPC music is to play with the driver program. Most tunes will consist of data (the notes) and a driver (which plays the notes). How your driver works will probably shape the tune more than the actual notes will. On the disc, Paclone has a driver which cuts in with a different noise when the data tells it to and Wallbuster relies on the fact that the channels are out of step. Throughout the whole tune, channel two lags behind channel four which comes in later than channel one. When things get progressively more out of step, they run out of control. When a tune stays uniformly out of step, it creates a new effect. Try removing the line of sound commands before the main loop of Cosmos to see how different it sounds. Begin experimenting with a routine something like this:

10 s=0: WHILE s<>2.77: READ s
20 SOUND 1,s,40,15
40 DATA 478,379,478,2.77

I tend to use 2.77 to end my data because it's distinctive. You often need to use zero as a note or a silence and 2.77 has just stuck as my flag for the end of a tune. You could make up your own, but will need to write your routine so that it doesn't play your end code if you don't want it to. Once the data is complete, you can use a for-next to play it, since you will know exactly how much of it there should be.

This is the skeleton for your tune. The first place to start putting flesh is on line 40. Find a few notes that make sense together and sound okay to you. Look in the back of the manual for a complete list of periods for notes. All you need to know is to avoid those that are sharp or flat and the tune will stay in key. (Go out of key for special effects or emphasis. If you overdo it, it sounds rather oriental). Once you have enough notes to play with, start making them sound interesting by changing line twenty. You could try using envelopes; or using different combinations of the note on each channel (s-20, s*2, s/3 ?). You could use a for-next loop to create a curved loop (not possible using envelopes). If you want some sort of percussion, look at the noise parameter.

Thereafter it's an experiment in both programming and composition. Your driver might be set to end when the tune's finished or might have a menu selection routine built in. You might have a subtune which runs through the whole lot. You might need to include data for two different notes at each point so you can do harmonies. If lengths are to change, you might need to include them in the data. The rules are that there are no rules.

Look at the tunes in the games on the disc to see how different drivers have been created and how this affects the overall tune. The Bugs also includes plenty of music, which you can investigate when you've finished playing the game. Or right away if you've got no plans to play it, of course. I've made no effort to hide the puzzles in the code.

If you have a stereo set-up, your games can benefit from using directional sound. Even if you don't, it might prove an easy way of allocating channels to sound effects. The screen can be divided into three vertical stripes of roughly equal size (e.g. 7,6,7 for mode zero). Each of these areas can then be given a channel number. My channel four speaker is on the left, channel one on the right and channel two in the middle. A routine to allocate the right channel to a noise depending on where it is supposed to be coming from is very simple, but can be very effective in play. When writing tunes, it's as well to remember how speakers are laid out when writing them. If only using one channel, make it the central channel 2. If using two channels, make them numbers four and one to keep things balanced directionally.

Although you only have three channels to play with and can only define square waves if you stick to using envelopes, your CPC has waveform editing abilities envied by the bottom of the synthesiser market. Your CPC is always going to sound like a CPC, never an orchestra and never any real instrument. Playing with the shapes of notes and making music from maths, you can nevertheless play quite a sophisticated instrument and get away with using and abusing musically suspect notes. This is a journey into SOUND.

In the next chapter we look at using machine code routines in Basic.


© Sean McManus. All rights reserved.

Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books and music

Artificial: album cover shows a steampunk heart


What happens beyond AI when the machines become emotional? Discover my new album of electronic music here.

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Coder Academy book

Coder Academy

Learn to make games and other programs in Scratch, and make a web page in HTML. Highly interactive book for 7-10 year olds.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About