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.
You should AHI_LoadSound()
the most important sounds first, since
the sound cards RAM may not be large enough to hold all your sounds.
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
AHIST_DYNAMICSAMPLE
@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
).
The samples can be in one of four different formats, named AHIST_M8S
,
AHIST_S8S
, AHIST_M16S
, and AHIST_S16S
.
AHIST_M8S
AHIST_S8S
AHIST_M16S
AHIST_S16S
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.