Skip to main content
GameDev.net gamedev.net
🔒 Locked

play sounds backwards

Started by RupertK Jun 6, 2004 at 2:30 PM 3 replies 850+ views
Original Post
RupertK
RupertK
is there a posibility to play sounds backwards in directsound?
a²+b²=c², E=mc² => E=m(a²+b²)
Etnu
Etnu
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.
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
RupertK
RupertK
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
a²+b²=c², E=mc² => E=m(a²+b²)
Etnu
Etnu
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.
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
Gyannea
Gyannea
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
Brian Reinhold

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.