Home > Books > Amstrad CPC > Sound

This is a journey into sound: Creating music and sound on the Amstrad CPC

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
30 WEND
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.

Using stereo sound effects on the Amstrad CPC

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. Channel 1 should be on the left, channel 4 on the right, and channel 2 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.

Here's a demo, which shows a character walking left and right across the screen. You hear the footsteps as they walk. You can paste this program into Winape using the Auto Type feature (Ctrl + F5).

10 dim t(20):for g=1 to 7:t(g)=1:next:for g=8 to 13:t(g)=2:next:for g=14 to 20:t(g)=4:next
20 mode 0:call &bc02:border 0:ink 0,0:locate 1,11:pen 6:print string$(20,chr$(216));
30 locate 4,15:pen 1:print"Transound demo"
40 locate 4,17:pen 1:print"www.sean.co.uk":pen 11
50 while 1
60 for x=1 to 20:locate x,10:print chr$(250):sound t(x),0,5,15:for h=1 to 100:next:locate x,10:print" ":next
70 for x=20 to 1 step -1:locate x,10:print chr$(251):sound t(x),0,5,15:for h=1 to 100:next:locate x,10:print" ":next
80 wend

I called this technique "Transound" and used it in my games Wallbuster (ACU 10/91) and Paclone (1/92), as well as The Further Adventures of Fred. In the 80s I used a DK Tronics Speech Synthesiser and stereo speakers. For some reason, my left speaker was channel 4 and my right speaker was channel 1, so these games had the sound coming from the wrong direction when played on an emulator today. I've fixed that for Wallbuster and Paclone in the updated disc of my Amstrad games. I didn't try to fix it for Fred.

Back in the 80s, I imagine few people had stereo sound on their Amstrad CPC 464 or 6128. Today, using emulators, it's probably the norm. Perhaps others will consider including Transound in their games? :-)

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 4 and 1 to keep things balanced directionally. Sometimes the most impactful sound effects are created by playing across multiple channels at the same time.

Screenshot of Wallbuster

Wallbuster featured Transound, so that when the ball bounced off the side walls, you heard the sound come from the speaker on that side of the screen.

Conclusion

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 Amstrad Basic.

More Amstrad CPC tutorials and software

Find all my Amstrad CPC tutorials here, and download my updated software disc here!

Credits

© 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

Coding Compendium

Coding Compendium

A free 100-page ebook collecting my projects and tutorials for Raspberry Pi, micro:bit, Scratch and Python. Simply join my newsletter to download it.

Web Design in Easy Steps

Web Design IES

Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.

100 Top Tips: Microsoft Excel

100 Top Tips: Microsoft Excel

Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.

Scratch Programming in Easy Steps

Scratch Programming IES

This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.

Mission Python book

Mission Python

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

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 | Newsletter | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About