POKE 23609,255

The second number in this determines the length of the beep (try various values between 0 and 255). When it is 0, the beep is so short that it sounds like a soft click.

Enhanced Sound and Music with PLAY

When using NextBASIC, you have two different ways to make music and sound effects. You can still use the BEEP command (as discussed above) but you also have access to the PLAY command which allows you to make much more sophisticated music with up to nine notes playing at once. It also gives you more control over the sound of each individual note than is possible using BEEP.

Making music and sound effects with PLAY is simple. You just type in the series of notes that make up a tune, then ask the ZX Spectrum Next to PLAY them. You can also include instructions that tell your machine what sort of tone you want for the sound. Please note that case is important when typing in the string expressions in the examples ie. ga should not be typed as Ga, gA or GA.

To hear some of the wide range of sounds that you can make, type in one of the two programs below, RUN it, then try the other example. Don't worry if the program lines look complicated, they are explained in detail later.

Music:

10 b$="O4(CDEC)(5EF7G)(3GAGF5EC)
   5Eb7E9EbE"
20 PLAY "T180O6(CDEC)(5EF7G)(3GAGF5EC)
   5Cg7C9CgC",b$,"O3(7CG)(7CG)(7CG)
   5GD7G9GDG"

Sound Effects:

10 a$="M8UX350W5O7(((C)))": PLAY a$ :
   PAUSE 25
20 PLAY "M56UX5000W1O3(((C)))": PAUSE 25
30 a$="M56W2O1N8C" : PLAY a$ : PAUSE
   25

Using the PLAY command

In the examples above, you will see that each time the PLAY command appears, it is followed by up to nine different parameters in the form of either string variables, string literals or a combination of both in a statement like:

PLAY P1C1,P1C2,P1C3,P2C1,P2C2,P2C3,P3C1,P3C2,P3C3

where PxCy are strings that refer to the PSG (P) number (x) (1 to 3) and channel (C) number (y) (1 to 3). The order of these is specific and each PLAY command must have the full complement if you require all the channels to reproduce a sound. You cannot issue two or more PLAY commands to control individual PSGs as each PLAY statement sends a batch of instructions to the audio hardware. If you wish one or more channels to be silent you should replace them with the empty string "". As we will examine below, the strings contain all the information to tell your ZX Spectrum Next which sounds to make.

As we discussed, PLAY controls nine separate sound channels over the 3 available PSGs, each called A, B, and C.

In the Music example given above, "T180O6(CDEC)(5EF7G)(3GAGF5EC)5Cg7C9CgC" tells channel A of PSG1 to play the melody line, b$ tells channel B of PSG1 to play a harmony, and "O3(7CG)(7CG)(7CG)5GD7G9GDG" tells channel C of PSG1 to play a bass part. In the Sound Effects example, only one noise is used at a time (although up to nine


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.