From Amiga Coding
Jump to: navigation, search

Blitz Basic offers simple built-in commands that directly access to the native Amiga chipset for efficient sound reproduction through Paula. AmiBlitz also comes with audio include files which allow much more flexibility, such as allowing your program to play audio via AHI, and to load audio formats other than the native 8SVX. Both methods allow you to load disk-based samples and play them through the relevant hardware.

Built-in Commands

As mentioned, the built-in sound commands are simple and efficient, and ideal for playing sound on native Amiga hardware with little processing overhead. There are some constraints on their usage however due to the design of the Amiga's audio hardware. You can only load and use 8-bit mono 8SVX samples, and you can only play up to 4 samples simultaneously. Also, the maximum frequency is limited to ~28kHz by what's going on with the chipset at the time that it's playing due to the chip RAM bottleneck. (Note: running a multiscan video mode frees up more chip RAM access time, effectively increasing the limit to ~56kHz.)

At its simplest level, sounds are produced by loading them as a Blitz sound object, and then playing them as required on the selected channel(s) and at the selected volume. Your program does not wait for the sound to stop playing - it will carry on executing commands while the Amiga's hardware handles the sample playback for you in the background. More advanced usage allows your program to adjust the speed and volume of an already playing sample, and to create sound objects from scratch by using data your program provides.

Loading Sound Samples

Loading sounds samples is a simple operation using the LoadSound command:

LoadSound 0, "Files:Sound/Sample2.iff"

This example creates Blitz sound object ID 0, and loads the sound sample from the given filename into that object. Note that if the file doesn't exist, or the file is in any format other than the native 8-bit 8SVX format, this command will generate a run-time error. Also, remember that these samples are stored in chip RAM, so be careful you don't use it all up!

Playing Sounds

Playing sounds is pretty straightforward too using the Sound command. You simply provide the Blitz sound object ID, a channel mask and a volume, and the sound will be played directly from chip RAM through the native audio outputs. Volume is any value from 0 to 64 (64 being the loudest, 0 being no output at all). The channel mask is a little more complicated as it is a 4-bit mask that determines which channels to play the sample on. Each bit corresponds to one channel, and the same sample can be played across any number of channels. Bit 0 is channel 0, bit 1 is channel 1 and so on. This value can be given as a decimal (1=bit 0, 2=bit 1, 4=bit 2 and 8=bit 3), so a value of 5 will mean the sample is played on channels 0 and 2 (1 + 4). For example, playing sound object ID 0 through channels 0 and 2:

Sound 0, 5

This may be easier to follow however if you use the % character to specify a binary number - specifying a channelmask of %0101 instead of 5 makes it easy to see that the first and third channels are used (bit 0 is on the right). For each channel that you use (as in, you set the channelmask bit to 1), you can also give a volume level from 0 to 64, starting from channel 0:

Sound 3, %0101, 48, 24

This plays sound ID 3 in channel 0 at volume 32, and channel 2 at volume 16. If volume values aren't specified, they default to the maximum of 64.

The four sound channels are mixed together in the Amiga's audio hardware to produce stereo output, with channels 0 and 3 routed to the right output and channels 1 and 2 routed to the left output.

Personal tools