Difference between revisions of "SOUND"

From BeebWiki
Jump to: navigation, search
m (Typo in volume.)
m (See also)
 
(One intermediate revision by one user not shown)
Line 94: Line 94:
 
         to              } 8-bit pitch &xx00 to &xxFF (see notes)
 
         to              } 8-bit pitch &xx00 to &xxFF (see notes)
 
  SOUND chn,vol,&03FF,dur /
 
  SOUND chn,vol,&03FF,dur /
  SOUND chn,vol,&x400,dur \
+
  SOUND chn,vol,&x400,dur \ RISC OS extension:
 
         to              } 15-bit pitch &4000+&ORRR, O=octave, RRR=residual, &4000=middle C (expansion)
 
         to              } 15-bit pitch &4000+&ORRR, O=octave, RRR=residual, &4000=middle C (expansion)
 
  SOUND chn,vol,&7FFF,dur /
 
  SOUND chn,vol,&7FFF,dur /
  SOUND chn,vol,&8000,dur \
+
  SOUND chn,vol,&8000,dur \ RISC OS extension:
 
         to              } 15-bit pitch change &C000+delta (expansion)
 
         to              } 15-bit pitch change &C000+delta (expansion)
 
  SOUND chn,vol,&FFFF,dur /
 
  SOUND chn,vol,&FFFF,dur /
Line 189: Line 189:
  
 
== See also ==
 
== See also ==
See OSWORD 7 for implementation
+
See [[OSWORD &07|OSWORD 7]] for implementation
  
 
== References ==
 
== References ==

Latest revision as of 23:40, 20 March 2020

SOUND is a BASIC command to make sounds.

SOUND
Availability Present in all versions of BBC BASIC.
Syntax SOUND <numeric>,<numeric>,<numeric>,<numeric>
Token (hex) D4 (command)
Description Generates sounds.

Contents

Description

SOUND calls OSWORD &07 to generate sounds. It is most commonly used to generate sounds with the internal sound generator, but it can also be used to create speech or MIDI sounds, as specified by the channel parameter.

Defined channel numbers

&0xxx Sound generator
&1xxx Sound generator
&20xx Watford Electronics Speech system[1]
&FExx MIDI control [2]
&FFxx Speech system [3]

Specification

Internal sound system

SOUND &0xxx,volume,pitch,duration

SOUND &1xxx,ignored,ignored,ignored

The channel number encodes &HSFC where:

  • H: Hold 0 or 1
  • S: Sync 0 to 15, 0 to 3 usually implemented
  • F: Flush 0 or 1, 2-15 reserved
  • C: Channel 0 to 15, 0 to 3 usually implemented

The internal sound system implements 4 channels (1 on the Electron), but extensions can increase the number of supported channels. For example, the Electron Sound Expansion supports four channels, and MIDI redirection can support 16 channels treating each channel as a polyphonic note. Channel 0 is conventionally a 'noise' channel.

Channel parameter
-----------------
SOUND &xxxC,vol,pitch,dur    play a note on channel C

SOUND &xx0x,vol,pitch,dur    don't flush channel
SOUND &xx1x,vol,pitch,dur    flush channel before playing note
SOUND &xx2x,vol,pitch,dur \
        to                 } future expansion
SOUND &xxFx,vol,pitch,dur /

SOUND &xSxx,vol,pitch,dur    synchronise with S other channels

SOUND &0xxx,vol,pitch,dur    play specified note
SOUND &1xxx,ign,ign,ign      continue the current note on the channel

Volume parameter
----------------
SOUND chn,-32768,pitch,dur \
        to                  } future expansion
SOUND chn,-16   ,pitch,dur /
SOUND chn,-15   ,pitch,dur \
        to                  } play a note with volume 1 (quiet) to 15 (loudest)
SOUND chn, -1   ,pitch,dur /
SOUND chn, 0    ,pitch,dur    stop note (zero volume)
SOUND chn, 1    ,pitch,dur \
        to                  } play a note with an envelope
SOUND chn,16    ,pitch,dur /
SOUND chn,17    ,pitch,dur \
        to                  } future expansion
SOUND chn,32767 ,pitch,dur /

Pitch parameter
---------------
SOUND chn,vol,&0000,dur \
        to               } 8-bit pitch &xx00 to &xxFF
SOUND chn,vol,&00FF,dur /
SOUND chn,vol,&0100,dur \
        to               } 8-bit pitch &xx00 to &xxFF (see notes)
SOUND chn,vol,&03FF,dur /
SOUND chn,vol,&x400,dur \  RISC OS extension:
        to               } 15-bit pitch &4000+&ORRR, O=octave, RRR=residual, &4000=middle C (expansion)
SOUND chn,vol,&7FFF,dur /
SOUND chn,vol,&8000,dur \  RISC OS extension:
        to               } 15-bit pitch change &C000+delta (expansion)
SOUND chn,vol,&FFFF,dur /

8-bit pitches are 48 units per octave, with middle C=101 (see notes)
15-bit pitches are &1000 units per octave, with middle C=&4000

Duration parameter
------------------
SOUND chn,vol,pitch,-32768 \
        to                  } future expansion
SOUND chn,vol,pitch,-2     /
SOUND chn,vol,pitch,-1        play note forever (until flushed)
SOUND chn,vol,pitch,0      \
        to                  } play for specified 1/20th second
SOUND chn,vol,pitch,32767  /

Watford Speech

SOUND &20xx,word,library,0

Watford speach commands can be sent with SOUND &2000, which is usually coded as SOUND 8192.

Bit 0-7 of the channel number is ignored.

MIDI control

SOUND &FExx,command,note,velocity

MIDI commands can be sent with SOUND &FEFF and SOUND &FEFE which are usually coded as SOUND -257 and SOUND -258.

  • SOUND -257,Command,Note,Velocity - Send to current channel (channel=&FEFF)
  • SOUND -258,Command,Note,Velocity - Send raw MIDI command (channel=&FEFE)
  • SOUND -257 or -258,Command<0,num,num - MIDI system control

If Command is &0000-&007F it is a MIDI data byte and sent straight to the MIDI system unchanged. This allows extended sequences to be sent, such as MIDI System Exclusives.

If Command is &0080-&00FF it is a MIDI command byte. Command bytes &80-&EF are channel-specific commands. SOUND -258 uses them as supplied, SOUND -257 sends them to the current MIDI channel by adding the current channel to the bottom nybble. So, if the current MIDI channel is 4, SOUND -257,&80... will send to MIDI channel 4, and SOUND -257,&8F should send to MIDI channel 3. Some implementations do not correctly round the channel number within the nybble in the second example.

Note and Velocity are 7-bit numbers with bit 7 and higher ignored, other than MIDI command &Ex which can specify a 14-bit Note number.

SOUND -257,&0000,ignore,ignore   \
         to                       } send data byte
SOUND -257,&007F,ignore,ignore   /
SOUND -257,&0080,param1,param2   \
         to                       } send command and 0, 1 or 2 data bytes
SOUND -257,&00FF,param1,param2   /
SOUND -257,&0100,param1,param2   \
         to                       } reserved for expansion
SOUND -257,&7FFF,param1,param2   /
SOUND -257,-32768,param1,param2  \
         to                       } reserved for expansion
SOUND -257,-2   ,param1, param2  /
SOUND -257,-1   ,channel,param2     set MIDI channel
SOUND -257,-1   ,0      ,param2     silence all channels

SOUND -258: as SOUND -257 to specified channel

SOUND -259 (&FEFD)               \
         to                       } reserved for expansion
SOUND -512 (&FE00)               /

Speech system

SOUND &FFxx,command,0,0 The channel number indicates what to do with the command.

  • SOUND &FFFx,number,0,0 - speak from PHROM 15-x with word number.
    This is usually written as SOUND -1,n,0,0 to SOUND -16,n,0,0.
  • SOUND &FFBx,address,0,0 - speak from PHROM 15-x from the absolute address.
  • SOUND &FF60,command,0,0 - start sending speech using phoneme command.
  • SOUND &FF00,command,0,0 - continue sending speech using phoneme command.

SOUND &FF01-&FF7F actually send the bottom byte as the Speech command to use.

Trivia

In the original development of BBC BASIC, the sound command was BEEP which can be seen from the token position for SOUND, alphabetically with other keywords starting with 'B'[4]:

 Originally:   Became:
 D4: BEEP      D4: SOUND
 D5: BPUT      D5: BPUT
 D6: CALL      D6: CALL
 D7: CHAIN     D7: CHAIN
 etc.

See also

See OSWORD 7 for implementation

References

  1. Watford Speech Synthesizer Manual
  2. *MIDI command
  3. Speech System User Guide
  4. Outline specification of the BASIC language interpreter, 1981

Jgharston 00:30, 2 January 2008 (UTC) Jgharston (talk) 23:58, 7 March 2020 (CET)