audiolib
A sound is a Blitz object, numbered from 0: a sample in chip memory with
its period, which sets the pitch (a smaller period plays faster and
higher), and an optional repeat part. LoadSound reads an IFF 8SVX
file, DecodeSound takes one that is already in memory, for example
included in the program, and InitSound makes an empty sound that
SoundData fills byte by byte.
The commands drive the audio hardware directly. A channel mask chooses
the channels: bit 0 is channel 0, up to bit 3 for channel 3, so 15 means
all four. Where the help text has Vol1[,Vol2...], the volumes (0 to 64)
are given one per channel of the mask; with Sound, LoopSound and
DiskPlay, a channel without a volume plays at 64. This plays a sound
on channels 0 and 1 at half volume:
LoadSound 0,"bang.8svx"
Sound 0,1+2,32,32With runtime error checking, a channel mask above 15 is the error “Illegal Chanel Mask”, spelled as in the original.
Based on the audiolib guide by Acid Software.
Library number 116. It manages Sound objects, by default at most 10 (the compiler options set the maximum).
Commands
DecodeSound
Makes a sound from an IFF 8SVX file that is already in memory at the address. A file in chip memory is used where it is, other data is copied to chip memory.
Statement. Help text: Sound#,MemoryLocation
Arguments: .w, .l
DiskBuffer
The size in bytes of each of the two halves of the chip memory buffer that DiskPlay streams through; the start value is 1024.
Statement. Help text: Bufferlen
Arguments: .l
DiskPlay
Plays an IFF 8SVX file straight from disk on the channels of the mask, without loading it as a whole, and returns when the file has been played; the program waits meanwhile. It needs much less memory than LoadSound and Sound, and the sample may be longer than 128 KB.
Statement. Help text: Filename$,Channelmask[,Vol1[,Vol2...]]
2 forms:
$, .w$, .w, { .b }...
The buffer is two halves of DiskBuffer bytes of chip memory. The
file is closed and the buffer freed before each of these errors:
| Situation | Error |
|---|---|
| the file cannot be opened | “Illegal Sound file” |
| the file has no sound header | “Can’t Find VHDR” |
| the file cannot be read | “Error Reading File” |
Filter
Filter On (any value other than 0) switches the Amiga’s audio low-pass filter on and Filter Off switches it off. The filter is controlled by bit 1 of the CIA-A port A, the bit that also sets the power light: Filter On clears it, which makes the light bright, and Filter Off sets it.
Statement. Help text: On|Off
Arguments: .w
Fixed in the port: the original had On and Off the other way
round, so a program written for its sound gets the other filter state
(#985).
InitSound
Makes an empty sound (all bytes 0) of Length bytes in chip memory, with the period (428 if none is given) and the offset where the repeat part starts (0 if none is given).
Statement. Help text: Sound#,Length[,Period[,Repeat]]
3 forms:
.w, .l.w, .l, .w.w, .l, .w, .l
With runtime error checking, the length must be even and below 128 KB, and the repeat offset even and less than the length.
LoadSound
Loads an IFF 8SVX file into the sound, with its period and repeat part. Errors are “Illegal Sound file” when the file cannot be opened, “Can’t Find VHDR”, “Error Reading File”, and “Sound too long” for a sample of 128 KB or more.
Statement. Help text: Sound#,Filename$
Arguments: .w, $
The file is closed before each of these errors except the first.
LoopSound
Plays the sound on the channels of the mask and then repeats its repeat part until another sound is played on the channel or the program ends.
Statement. Help text: Sound#,Channelmask[,Vol1[,Vol2...]]
2 forms:
.w, .w.w, .w, { .w }...
PeekSound
One byte of the sample at the offset, from -128 to 127.
Function, result .w. Help text: (Sound#,Offset)
Arguments: .w, .l
Fixed in the port: used inside a string expression, the original wrote the rest of the expression into the sound object; the port leaves the sound as it is (#46).
SetPeriod
Sets the period of the sound, for the next time it is played. A sound that is not set up is the error “Uninitialized Sound”.
Statement. Help text: Sound#,Period
Arguments: .w, .w
Sound
Plays the sound once on the channels of the mask, with the volumes given or 64. Channels outside the mask go on with what they play.
Statement. Help text: Sound#,Channelmask[,Vol1[,Vol2...]]
2 forms:
.w, .w.w, .w, { .w }...
SoundData
Writes Data, from -128 to 127, as one byte of the sample at the offset (in bytes, from 0), for example to build a sine or square wave in a sound made with InitSound.
Statement. Help text: Sound#,Offset,Data
Arguments: .w, .l, .b
Volume
Sets the volume (0 to 64) of the channels of the mask while they play, one value per channel, for example for fading a sound in or out.
Statement. Help text: Channelmask,Vol1[,Vol2...]
Arguments: .w, { .w }...