Jump to content
  • Advertisement
Sign in to follow this  
kurdt

Wav sounds' precise timing

This topic is 4874 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

Hello all, I wasn't sure if I should post this here or in the Music and Sound forum, so apologies if it's in the wrong place. I'm new to programming audio, and I'm having some troubles, so I thought of asking for help here. Basically, I'm trying to play WAV files in a certain order at very precise times in a loop. I have 5 wav files that must be played with a 100 ms gap in between them. All the WAV files are 44Khz, 16 bits/sample, and of varying lengths. I have tried several approaches, the first was to use the PlaySound() call with the A_SYNC and SND_MEMORY flags set. This approach works and it sounds fine, but if I open a browser or any other application, the timing gets stretched out and delays are introduced. I preload the WAV files into memory, so it can't be disk I/O that's slowing it down. I thought it might be the priorities, so I set both the process class and thread priority to RealTime. I used timeBeginPeriod and timeEndPeriod to improve the resolution of the timer, but these didn't fix it either. :( I tried DirectSound next, and my approach consisted of loading 5 DirectSoundBuffers and calling each DirectSoundBuffer's Play() method, with the same results. I tried the waveOut API next, and have managed to get all the files loaded and sent to the device with the waveOutWrite call, but this isn't asynchronous, and I need the following sound to start at the next 100 ms point, not when the first sound finishes playing. I'm not averse to using DirectSound or the waveOut API calls. I wonder if anyone knows if this is possible. I guess what I need is some way to "stitch" these files into one sequence, with each sound starting at a certain time and calling a Play() method only once that handles it as a single stream instead of repeated Play() calls. Failing that, can I play a sequence of wav files with each starting at a certain time, with no penalties when another process starts? Sorry for the long post, Any help would be greatly appreciated, Thanks, kurdt

Share this post


Link to post
Share on other sites
Advertisement
I would say that you shouldn't rely on timers for scheduling any real-time audio events, as you can't make good guarantees about scheduling. Instead, try rendering the sounds to the precise part of the output buffer that you need. You will probably have to do low-level copying of sounds to the primary buffer rather than relying upon Play() functions and the like. You may also need to zero out the intermediate part of the buffer to avoid unwanted noises.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!