user7733855
user7733855

Reputation: 59

How to stop a sound Smooth in OpenAL

I have too many sound to play in OpenAL,and the number of source is too much, Sometimes I have to stop some sources use function alSourceStop.but it often produce broken sound (sonic boom),How to avoid this phenomenon?

Upvotes: 2

Views: 810

Answers (1)

Daniil Dubrovsky
Daniil Dubrovsky

Reputation: 479

Note: I am not an iOS developer and just showing a solution which I would have used on any other platform.

You can implement sound fade out yourself by gradually changing source's gain over some period of time after you decided to stop it. Basically, that's what you have to do

float t = now - stopTime;
float d = 10
if(t > d)
   //Stop sound and delete source
else 
    alSourcef(source, AL_GAIN, originalGain * (1F - t / d)) 

In this pseudocode originalGain is the gain of the source without fadeout

now - current time stopTime - moment when you decided to stop source 10 - duration of fadeout

By using these values you can linearly interpolate between between full gain and 0 and prevent broken sound effect.

Upvotes: 2

Related Questions