Jump to content
  • Advertisement

Archived

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

RupertK

play sounds backwards

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

Advertisement
I haven''t touched directsound in a while, but from what I remember, you get a pointer to raw data from the sound file. All you should need to do is reverse the buffer.

Share this post


Link to post
Share on other sites
i use manageddx. so i don''t have a pointer
what i want to do is to play the sound faster and slower
and then slower until it stops and then backwards

Share this post


Link to post
Share on other sites
You don''t have a pointer, but you should have some sort of buffer to the data (an array of bytes, maybe?). Just read that buffer backwards.

Share this post


Link to post
Share on other sites
I am not sure what ''manageddx'' is but using only DirectSound there seems to be a challenge in this. There might be some tools like ->SetFrequency() that can help but I am not sure.

What you need to do and could do if there are no tools is either
(1) change the sampling rate or
(2) interpolate the data in the buffer.

My guess is that (2) is a much better alternative. The latter is probably what any ''tool'' will do. Just be careful that you don''t exceed what you can''t resolve by the set sampling rate.

If you have a simple situation, say a 1000 Hz sine wave in a data buffer and some fixed sampling rate, say 40000 Hz. One second of such data would contain 40000 points per channel. Now that hardware rate shall remain fixed but you are going to slow down the sound. That means you will need to add data values. If you load data into the DirectSoundBuffer every 10ms, that will require 400 points from your data buffer. It would be a direct copy. But if the sound slows down by a factor of 2 for the next load, you''ll still need 400 to load into the DirectSound Buffer (using ->Lock) but only the next 200 points of your data buffer will be used. You will have to insert a new value between each data point into the loaded value by interpolating between neighboring points. When you slow down to 0 all 400 points will be constant and it will be silent to the ear. As you go negative, the creation of the values from you data buffer are now in reverse order.

Of course, you will want to decrease the speed in much smaller increments than 1, 1/2, 0, -1/2, -1!

Just make sure that the final value (you could double or triple or whatever the speed) but the maximum frequency of your orignal sound sample * the maximum speed cannot be greater than 40000/2.

->SetFrequency() I think does this for you, but I have never used it and don''t know if it can handle negative values. Probably can.

Brian

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!