Code: (Select All)
OPTION _EXPLICIT
PRINT "Loading...";
DIM Song AS LONG
Song = _SNDOPEN("STARDUST.MOD") ' Replace file name with your sound file
IF Song < 1 THEN
PRINT "Failed to load sound!"
END
END IF
PRINT "Done!"
DIM Channels AS _UNSIGNED _BYTE
Channels = SndChannels(Song)
IF Channels > 0 THEN
PRINT "The sound has"; Channels; "channels."
ELSE
PRINT "An error occurred."
END
END IF
DIM AS LONG i, rawSnd
rawSnd = _SNDOPENRAW
IF rawSnd < 1 THEN
PRINT "Failed to open sound pipe!"
END
END IF
FOR i = 0 TO Channels - 1
PRINT "Queueing channel"; i; "...";
PlaySoundChannel Song, i, rawSnd
PRINT "Done!"
PRINT "Waiting for playback to finish...";
DO WHILE _SNDRAWLEN(rawSnd) > 0 'Finish any left over queued sound!
SLEEP 1
LOOP
PRINT "Done!"
NEXT
_SNDCLOSE rawSnd
_SNDCLOSE Song 'closing the sound releases the mem blocks
END
' Here chan starts from 0
' So, chan 0 is the first channel, 1 the next one and so on
' rs is the raw sound handle
SUB PlaySoundChannel (handle AS LONG, chan AS _UNSIGNED _BYTE, rs AS LONG)
DIM AS _UNSIGNED _INTEGER64 i, sz, es, ofs
DIM SampleData AS _MEM
DIM channels AS _UNSIGNED _BYTE
DIM samp AS SINGLE
channels = SndChannels(handle)
SampleData = _MEMSOUND(handle, 0)
IF SampleData.SIZE = 0 THEN
EXIT SUB
END IF
$IF 64BIT THEN
sz = _CV(_UNSIGNED _INTEGER64, _MK$(_OFFSET, SampleData.SIZE)) ' sz is the total size of the sound in bytes
es = _CV(_UNSIGNED _INTEGER64, _MK$(_OFFSET, SampleData.ELEMENTSIZE))
$ELSE
sz = _CV(_Unsigned long, _MK$(_Offset, SampleData.SIZE)) ' sz is the total size of the sound in bytes
es = _CV(_Unsigned long, _MK$(_Offset, SampleData.ELEMENTSIZE))
$END IF
ofs = es \ channels
FOR i = 0 TO sz - es STEP es
IF SampleData.TYPE = 260 THEN ' 32-bit floating point
samp = _MEMGET(SampleData, SampleData.OFFSET + i + (chan * ofs), SINGLE)
ELSEIF SampleData.TYPE = 132 THEN ' 32-bit integer
samp = _MEMGET(SampleData, SampleData.OFFSET + i + (chan * ofs), LONG) / 2147483648
ELSEIF SampleData.TYPE = 130 THEN ' 16-bit integer
samp = _MEMGET(SampleData, SampleData.OFFSET + i + (chan * ofs), INTEGER) / 32768
ELSEIF SampleData.TYPE = 1153 THEN ' 8-bit unsigned integer
samp = (_MEMGET(SampleData, SampleData.OFFSET + i + (chan * ofs), _UNSIGNED _BYTE) - 128) / 128
END IF
IF chan MOD 2 = 0 THEN
_SNDRAW samp, 0, rs
ELSE
_SNDRAW 0, samp, rs
END IF
NEXT
END SUB
' This function returns the number of sound channels for a valid sound "handle"
' Note that we are assuming that the sound can have at most 2 channels
' In reality miniaudio can handle sounds with more than 2 channels
' 2 = stereo, 1 = mono, 0 = error
FUNCTION SndChannels~%% (handle AS LONG)
DIM SampleData AS _MEM
' Check if the sound is valid
SampleData = _MEMSOUND(handle, 0)
IF SampleData.SIZE = 0 THEN
EXIT FUNCTION
END IF
' Check the data type and then decide if the sound is stereo or mono
IF SampleData.TYPE = 260 THEN ' 32-bit floating point
IF SampleData.ELEMENTSIZE = 4 THEN
SndChannels = 1
ELSEIF SampleData.ELEMENTSIZE = 8 THEN
SndChannels = 2
END IF
ELSEIF SampleData.TYPE = 132 THEN ' 32-bit integer
IF SampleData.ELEMENTSIZE = 4 THEN
SndChannels = 1
ELSEIF SampleData.ELEMENTSIZE = 8 THEN
SndChannels = 2
END IF
ELSEIF SampleData.TYPE = 130 THEN ' 16-bit integer
IF SampleData.ELEMENTSIZE = 2 THEN
SndChannels = 1
ELSEIF SampleData.ELEMENTSIZE = 4 THEN
SndChannels = 2
END IF
ELSEIF SampleData.TYPE = 1153 THEN ' 8-bit unsigned integer
IF SampleData.ELEMENTSIZE = 1 THEN
SndChannels = 1
ELSEIF SampleData.ELEMENTSIZE = 2 THEN
SndChannels = 2
END IF
END IF
END FUNCTION
Here you go @Petr. Hope this will help.