0
0

hello,
I want to read an audio file specifying the duration of reading,
saying read from 0 ms up to 1000 ms..

I dont know how do it

please heeeeeeeeelp
thanks

  • You must to post comments
0
0

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)

[code:1pef021l]
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 &gt;= lLen Or lPosTo &gt;= lLen Or lPosFrom &gt;= 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 &lt; 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

End Sub

Private Sub cmdStereoHardware_Click()
Dim result As FMOD_RESULT

result = FMOD_System_CreateSound(system, &quot;wuii.mp3&quot;, FMOD_SOFTWARE Or FMOD_ACCURATETIME, sound3)
ERRCHECK (result)

PlayFromTo system, sound3, 0, 1000

End Sub
[/code:1pef021l]

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.

[code:1pef021l]
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
End Type

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 &gt;= SoundObj.lLengthmS Or lPosTo &gt;= SoundObj.lLengthmS Or lPosFrom &gt;= SoundObj.lLengthmS Then Exit Sub

With SoundObj

    'Show useless info
    Debug.Print CStr(.sFrequency) + &quot;Hz&quot;, CStr(.lBits) + &quot;bit&quot;, IIf(.lChannels &lt; 3, IIf(.lChannels = 1, &quot;Mono&quot;, &quot;Stereo&quot;), &quot;Multichannel (&quot; + CStr(.lChannels)), CStr(.lLengthmS) + &quot;ms&quot;
    Debug.Print &quot;Type: &quot; + CStr(.tType), &quot;Format: &quot; + CStr(.tFormat)

    'Exchange between msec-&gt;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)

End Sub
[/code:1pef021l]

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.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.