Developer postOriginal post (opens in a new tab)

Version 0.5D - Sound Support

The latest version of Ozapell Basic adds support for wave audio.

Assuming there is a valid audio file called AUDIO.WAV in the Documents -> Ozapell Basic folder, then the following code will load it:

FILENAME="AUDIO"
AUDIOARRAY=0
ARRAY=AUDIOARRAY
WAVEFILELOAD

Now the array AUDIOARRAY contains the audio data. This data can be analyzed or manipulated. RESULT will contain the number of entries (samples) in the array.

Currently, the only wave audio format supported is Uncompressed PCM format, 16 bits per sample (CD quality), 44,100 samples per second (CD quality) and 1 channel (mono).

To copy the audio data from an array to a sound buffer:

ARRAY=AUDIOARRAY
BUFFER=0
WAVEFILEBUFFER

There are 32 sound buffers (0 to 31).

Audio data under 15 seconds in length will be considered a sound effect. 16 sound buffers will be created for these sound effects to allow for up to 16 simultaneous plays of the same sound.

Audio data over 15 seconds in length (with a current maximum of 5 minutes) will only be provided one sound buffer. Only one instance of this sound can be played from this buffer at one time. Playing the sound while it is already playing will cause it stop and start over from the beginning.

To play a sound:

BUFFER=0
WAVEFILEPLAY

To loop a sound:

BUFFER=0
WAVEFILELOOP

To stop all sound buffers for a specific sound:

BUFFER=0
WAVEFILESTOP

https://www.youtube.com/watch?v=T4450ylkSaQ

Have fun!