AL LOAD SOUND This function will create a new sound from data stored in a chunk of memory space. Since it accepts a memory pointer as input, it means you can use anything from memblocks to third party methods of memory manipulation in DBPro for preparing raw audio data.
Syntax
    AL MAKE SOUND FROM MEMORY soundNumber, memoryPointer, bytes, frequency, format
Parameters
    soundNumber
Integer The ID you want to use to create this sound.
    memoryPointer
Double Integer A memory pointer value where the raw audio data starts in memory.
    bytes
Double Integer The number of bytes to use as raw audio data. The size of the audio data in bytes.
    frequency
Integer The frequency to use when playing the raw audio data, in Hurtz (Hz). This is also known as the number of samples per second, or sample rate. For example, if your set the frequency to 22050 and your data contains enough information for 44100 samples, your audio data will play for exactly 2 seconds (2x 22050 = 44100).
    format
Integer The format to play the raw audio data in. Each format has a corresponding integer value which must be used with this parameter: 0 = 8-Bit Mono 1 = 8-Bit Stereo 2 = 16-Bit Mono 3 = 16-Bit Stereo
Raw Audio Data Structure
When writing the raw audio data into memory, there are several ways the data can be written and the correct format must be used for each. 8-Bit Mono In 8-bit mode, each sample is written as a single byte, which means they can only have 255 different levels of amplitude. Writing 8-Bit audio Data into memory would be done as:
    sample 1 | sample 2 | sample 3 | sample 4 | sample 5 | and so on ->
    BYTE 1   | BYTE 2   | BYTE 3   | BYTE 4   | BYTE 5   | and so on ->
16-Bit Mono In 16-bit mode, each sample is written as a WORD, which means they can have an amplitude level ranging from -32768 to 32767. The WORD datatype in DBPro is 16 bits in size, so it is perfect for writing 16 bit sample data into a memblock or other method of memory manipulation.
    sample 1 | sample 2 | sample 3 | sample 4 | sample 5 | and so on ->
    WORD 1   | WORD 2   | WORD 3   | WORD 4   | WORD 5   | and so on ->
8-Bit Stereo In 8-bit stereo mode, things get a little trickier. The raw audio data requires data for 2 channels, left and right. Samples are written in an interleaving fashion, with the first sample being left channel, followed by the sample for the right channel and so on. Again, since each sample is only 1 byte in since, they can only have 255 levels of amplitude each.
    sample 1 left | sample 1 right | sample 2 left | sample 2 right | sample 3 left | sample 3 right | and so on ->
    BYTE 1        | BYTE 2         | BYTE 3        | BYTE 4         | BYTE 5        | BYTE 6         | and so on ->
16-Bit Stereo The same interleaving structure as 8-bit stereo is used when writing data for left and right channels in 16-bit stereo mode, with the exception of each sample being 16-bits (2 bytes) each, allowing for amplitude levels ranging from -32768 to 32767.
    sample 1 left | sample 1 right | sample 2 left | sample 2 right | sample 3 left | sample 3 right | and so on ->
    WORD 1        | WORD 2         | WORD 3        | WORD 4         | WORD 5        | WORD 6         | and so on ->
How Many Bytes are Needed Before storing any audio data you obviously need to know how many bytes of memory you will need. This could be worked out as follows:
    numberOfBytes = (sampleSize * numberOfSamples) * channels
Where 'sampleSize' is how many bytes (bits/8) each sample is and 'numberOfSamples' is the total number of samples your audio data will have. The result of those two are multiplied by the number of channels, 1 channel for mono and 2 channels for stereo. Calculating the Bit-Rate Although the bitrate isn't important for creating a sound from raw data with this function, it may be useful information to know anyway. The Bit-Rate is simply how many bits are played/processed per second. This can be calculated as follows:
    bitRate = frequency * sampleSize
Where 'sampleSize' is how many bytes (bits/8) each sample is and 'frequency' is how many samples are played per second. Dividing the result by 1000 will give you kilobits per second (kbps) which is a common sight in media players of all sorts.
Returns
This function does not return a value.

See also

DarkAL Functions Menu