Go to the first, previous, next, last section, table of contents.


Declaring Sounds

Before you can play a sample array, you must AHI_LoadSound() it. Why? Because if AHI knows what kind of sounds that will be played later, tables and stuff can be set up in advance. Some drivers may even upload the samples to the sound cards local RAM and play all samples from there, drastically reducing CPU and bus load.

AHI_LoadSound() also associates each sound or sample array with a number, which is later used to refer to that particular sound.

There are 2 types of sounds, namely AHIST_SAMPLE and AHIST_DYNAMICSAMPLE.

AHIST_SAMPLE
This is used for static samples. Most sounds that will be played are of this type. Once the samples has been "loaded", you may not alter the memory where the samples are located. You may, however, read from it.
AHIST_DYNAMICSAMPLE
If you wish to play samples that you calculate in realtime, or load in portions from disk, you must use this type. These samples will never be uploaded to a sound cards local RAM, but always played from the normal memory. There is a catch, however. Because of the fact that the sound is mixed in chunks, you must have a certain number of samples in memory before you start a sound of this type. To calculate the size of the buffer (in samples), use the following formula:
@math{size = samples * Fs / Fm}
where samples is the value returned from AHI_GetAudioAttrsA() when called with the AHIDB_MaxPlaySamples tag, Fs is the highest frequency the sound will be played at and Fm is the actual mixing frequency (AHI_ControlAudioA()/AHIC_MixFreq_Query).

If you know that you won't use a sound anymore, call AHI_UnloadSound(). AHI_FreeAudio() will also do that for you for any sounds left when called.

There is no need to place a sample array in Chip memory, but it must not be swapped out! Allocate your sample memory with the MEMF_PUBLIC flag set. If you wish to have your samples in virtual memory, you have to write a double-buffer routine that copies a chunk of memory to a MEMF_PUBLIC buffer. The SoundFunc should signal a task to do the transfer, since it may run in supervisor mode (see AHI_AllocAudioA()).


Go to the first, previous, next, last section, table of contents.