Direct Sound help

Started by
2 comments, last by Evil Steve 18 years ago
hey guys, I need some help with Direct Sound. I have a 27 second looping sound that I am using for a vehicles engine. When the vehicle increases speed I increase the frequency of the sound effect. The problem is this, the sound frequency changes and sounds good. But the sound effect will end quicker then at the standard frequency. This would be fine but when doind an infinite loop it waits 27 seconds before restarting the sound clip. This means that there is a silence when the sound effect is played at a high frequency. code below: setup: engineSound = WDWSound::getSound(eS); engineSound->SetRepeats(DMUS_SEG_REPEAT_INFINITE); engineSound->Get3DBuffer()->SetMinDistance(10.0f,DS3D_IMMEDIATE); engineSound->Get3DBuffer()->SetMaxDistance(100.0f,DS3D_IMMEDIATE); frequency = engineSound->getFrequency(); every frame: engineSound->setFrequency(normal_frequency + (velocity*1000)); can anyone offer a solution. Thanks Andy
Advertisement
BUMP...anyone?
Hello
The reason is when you are using the SetFrequency( .. ) not only the pitch(frequency) of the sound that is changed, but it also make the sound play faster (the tempo ). Therfore the sample may be shorter or longer when changeing the frequency. This is because of the nature of a wave sound. It's possible to use timestretching techniques (keeping the tempo of the sample ) to avoid this.

- BJF
What you want to look into is Fast Fourier Transforms.

Alternatively, just increase the frequency and hence reduce the length, and instead of waiting for 27 seconds, wait for the sound to end. That'll be better for if you ever change the engine noise too. You could use GetCurrentPosition for that, and compare that to the size of the buffer. If you're streaming the sound (which you probably should be for a 27 second sample), it gets a bit more tricky, but you can keep track of how many times you fill the buffer, and work out how far through the sample you are from that.

Slightly offtopic - isn't 27 seconds a bit long for just a looping engine noise?

This topic is closed to new replies.

Advertisement