Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Dynamic WAV

This topic is 6254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, I''m using wav segments for my soundtrack. 1 big wav file, which has 10 loopable segments one after another. What I wan to be able to do, while playing the file, jump to any segment i want seamlesly.. I figure using s_Sound.SetCurrentPosition, which should jump to the specified position in the wav. How do i find out the total length of the wav? And if I do it this way, would it be seamless without any breakups? thanks for any help!

Share this post

Link to post
Share on other sites
You can use the following code to get the length of the wave in milliseconds from the size of the DS buffer

// get the format of the buffer
pdsBuffer->GetFormat( &wf, sizeof(wf), NULL );
// get the size of the buffer
ZeroMemory( &caps, sizeof(caps) );
caps.dwSize = sizeof(caps);
pdsBuffer->GetCaps( &caps );
// calculates the length in milliseconds
DWORD length = 1000*caps.dwBufferBytes/wf.nAvgBytesPerSec;

I''m not sure about seamless playback at the moment of jumping, but I think it won''t be seamless. Anyway, you can try it to find out and if it was not seamless, I suggest you to do the following:
Break the wav file into many wave files and load them into many sound buffers and when you want to jump from one to another, you can fade the current sound out and at the same time fade the new sound in.

Share this post

Link to post
Share on other sites
Ah, you''re using VB, so what? It sould be the same. Here is the same code in VB:

Dim caps As DSBCAPS
Dim length As Long

'' get the format of the buffer
pdsBuffer.GetFormat( wf )
'' get the size of the buffer
pdsBuffer.GetCaps( caps )
'' calculates the length in milliseconds
length = 1000*caps.lBufferBytes/wf.lAvgBytesPerSec

Share this post

Link to post
Share on other sites
First of all, thanks for all the help!!!!!!!!

I actually figured out how to do it, and I got it working seamlesly. This is what I did, in VB code, s_BackMusic being the DirectSound Buffer: (10 segments)

Dim sCursor As DSCURSORS
Dim sSize As Long
Dim sOldPos As Long
Dim sCaps As DSBCAPS
Dim SegmentLength as long
Dim sDif as long
Dim iPOS as long

SegmentLength = s_BackMusic.GetCaps.IBufferSize /10
s_BackMusic.GetCurrentPosition sCursor

If sCursor.lPlay > sOldPos + SegmentLength Then
sDif = sCursor.lWrite - (sOldPos + SegmentLength )
sOldPos = Int(Rnd * 10) * SegmentLength
iPOS = sOldPos + sDif
s_BackMusic.SetCurrentPosition iPOS
End If

Basically, this code jumps to any segment of a wav file (10 all together, perfectly looping with each other, stacked one after another) perfectly seamlessly!!! I have 10 different verses, with the same beats, randomly kick one after another, therefore making an almost dynamic soundtrack. The whole thing is kept inside one wave file. It loops perfect, with no breaks, or noise.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!