Think its even better to split your audio data into pieces before opening it. Just like the dialogs in a game.
It also a solution to watching channel::getposition to see that it has reached the time, then you can call channel:stop.
You may also want to set the channel::setLoopCount to 0 (one-shot) then you can call channel::setLoopPoints, but you have to exchange between samples<->msec before setting the markers for setlooppoints.
im new to fmod, i cant test it right now, but i hope it helps u.
Ive been tested both methods, it seems like the getposition works only, because the loop doesnt stop after the loop is done, but it continues to play till the end of sound file. It doesnt matter that i set the "0-one-shot" or "1-loop once then stop". Is this a bug? Please confirm
here is a sample i made for testing. (vb6)
Private Sub PlayFromTo(ByRef lFmod As Long, ByRef lSound As Long, ByVal lPosFrom As Long, ByVal lPosTo As Long)
Dim lLen As Long, lPos As Long, lIsPlaying As Long, lChan As Long, result As FMOD_RESULT
'Getting length in mSec result = FMOD_Sound_GetLength(lSound, lLen, FMOD_TIMEUNIT_MS) ERRCHECK (result) 'Check if lPosFrom or lPosTo are out of bounds If lPosFrom >= lLen Or lPosTo >= lLen Or lPosFrom >= lLen Then Exit Sub 'Opening channel result = FMOD_System_PlaySound(lFmod, FMOD_CHANNEL_FREE, lSound, 1, lChan) ERRCHECK (result) 'Set start position result = FMOD_Channel_SetPosition(lChan, lPosFrom, FMOD_TIMEUNIT_MS) ERRCHECK (result) 'Unpause the channel, sound will play result = FMOD_Channel_SetPaused(lChan, 0) ERRCHECK (result) 'Check if reached the position. You may want to implement this into your game engine. Do While lPos < lPosTo result = FMOD_Channel_GetPosition(lChan, lPos, FMOD_TIMEUNIT_MS) ERRCHECK (result) DoEvents Loop 'Check if sound is still playing result = FMOD_Channel_IsPlaying(lChan, lIsPlaying) ERRCHECK result 'Stop channel playback If lIsPlaying = 1 Then result = FMOD_Channel_Stop(lChan) ERRCHECK (result) DoEvents End If
Private Sub cmdStereoHardware_Click()
Dim result As FMOD_RESULT
result = FMOD_System_CreateSound(system, "wuii.mp3", FMOD_SOFTWARE Or FMOD_ACCURATETIME, sound3) ERRCHECK (result) PlayFromTo system, sound3, 0, 1000
Here is the loop code, that seems not works as it should be… Or i’m just doing in wrong way. It doesnt stop after reaching the end of the loop, but continues to play the sound.
Private Type tSoundObj
tType As FMOD_SOUND_TYPE
tFormat As FMOD_SOUND_FORMAT
lChannels As Long
lBits As Long
sFrequency As Single
lLengthmS As Long
Private Sub PlayFromToLoop(ByRef lFmod As Long, ByRef lSound As Long, ByVal lPosFrom As Long, ByVal lPosTo As Long)
Dim result As FMOD_RESULT Dim lChan As Long, lPosFSMP As Long, lPosTSMP As Long, lLenSMP As Long Dim SoundObj As tSoundObj 'Activate loop mode result = FMOD_Sound_SetMode(lSound, FMOD_LOOP_NORMAL Or FMOD_SOFTWARE) ERRCHECK (result) 'Get frequency result = FMOD_Sound_GetDefaults(lSound, SoundObj.sFrequency, 0, 0, 0) ERRCHECK (result) 'Get some useless info result = FMOD_Sound_GetFormat(lSound, SoundObj.tType, SoundObj.tFormat, SoundObj.lChannels, SoundObj.lBits) ERRCHECK (result) 'Get length in mSec result = FMOD_Sound_GetLength(lSound, SoundObj.lLengthmS, FMOD_TIMEUNIT_MS) ERRCHECK (result) 'Check if lPosFrom or lPosTo are out of bounds If lPosFrom >= SoundObj.lLengthmS Or lPosTo >= SoundObj.lLengthmS Or lPosFrom >= SoundObj.lLengthmS Then Exit Sub With SoundObj 'Show useless info Debug.Print CStr(.sFrequency) + "Hz", CStr(.lBits) + "bit", IIf(.lChannels < 3, IIf(.lChannels = 1, "Mono", "Stereo"), "Multichannel (" + CStr(.lChannels)), CStr(.lLengthmS) + "ms" Debug.Print "Type: " + CStr(.tType), "Format: " + CStr(.tFormat) 'Exchange between msec->samples lPosFSMP = lPosFrom * CLng(.sFrequency / 1000) lPosTSMP = lPosTo * CLng(.sFrequency / 1000) End With 'Opening channel result = FMOD_System_PlaySound(lFmod, FMOD_CHANNEL_FREE, lSound, 1, lChan) ERRCHECK (result) 'Set loopcount=1; 1 = loop once then stop, well it doesnt stop :( 'You also can set to 0, but it seems like doesnt affect the actual playback... result = FMOD_Channel_SetLoopCount(lChan, 1) ERRCHECK (result) 'Set loop boundaries result = FMOD_Channel_SetLoopPoints(lChan, lPosFSMP, FMOD_TIMEUNIT_PCM, lPosTSMP, FMOD_TIMEUNIT_PCM) ERRCHECK (result) 'Set startposition result = FMOD_Channel_SetPosition(lChan, lPosFSMP, FMOD_TIMEUNIT_PCM) ERRCHECK (result) 'Unpause the channel, sound will play result = FMOD_Channel_SetPaused(lChan, 0)
This code may also generate some fault when you try to apply it on a sample were length is 2,147,483,648 samples or more (around 13.5 hours on 44100 hz). Its because of limitations of vb6.
- damil answered 9 years ago
- You must login to post comments
Please login first to submit.