• Advertisement
Sign in to follow this  

Best way to play wav file in C++

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

First I want to say MERRY CHRISTMAS!! Now here is my question. I've read in a mono wav file and I converted it to stereo and put the mono track on one side of the stereo. Now I want to play back this wav file I have already read in but when its playing i want my program to record key presses pressed while the wav file is playing and record at what sample the key was pressed when the wav file was playing So my question is what is the best way to play the wav file so I would be able to constantly know what sample being played at a given time? Feel free to ask questions if this doesnt make any sense. I tried my best to explain it Thanks

Share this post


Link to post
Share on other sites
Advertisement
well, directx would suit your wav playing needs; but matching the key presses precisely with points in the music may be more tricky. It should be plausible given a multi-threaded environment.

last time I looked, given a wav buffer, directsound will give you the current play position in bytes; but i don't think its very accurate. Or you can trigger regular events in a wav play buffer, telling you the current position, which might be more useful.

Share this post


Link to post
Share on other sites
If you just want an application to go Ding, you could use something as simple as PlaySound(). However if you want decent audio for a game, try something like XAudio2.

You don't really need any special API to work out what sample you're on. If your file is, say, 44100 Hz, then you know that many samples are passing by every second. QueryPerformanceTimer will give you a very accurate time elapsed, then time elapsed * sample rate is the number of samples elapsed.

Share this post


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

  • Advertisement