Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Fading out Sounds OpenAL

Using OpenAL to manage my sounds in my cascades application. My issue is that stopping a sound abruptly causes it to create a popping sound when it is stopped and rather than this I would like the sound to fade out on command. I currently do this by having a loop decreasing the gain to essentially zero and then stopping the sound, which works but causes all actions to hang until this returns which can take up to about half a second and speed is essential. Is there a way to have this run on a separate thread? Or perhaps should I find a better way to fade out a sound. I was unsure if this section of the forum would be best but it is a cascades application, not a native one for the pb. Thanks all!

Retired
Posts: 29
Registered: ‎03-19-2012
My Device: Z10
My Carrier: BELL

Re: Fading out Sounds OpenAL

[ Edited ]

Hi,

 

Thanks for posting! 

 

here are a few things you can try:

 

1. The first thing to check would be the sound file.  Does it happen to all sound files or just this one? 

2. If it occurs on all sound files, you may want to try and normalize the audio file. 

3. Another thing to try would be to set the gain to 0 right before you stop it.  This should also get rid of the pop. 

 

As for decreasing the gamin to zero in a loop, you should be able to do that in a separate thread so that you can continue with your core processing.  The OpenAL playback is already in its own thread.

 

let us know if it helped you!

 

Cheerrs, Ram 

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Fading out Sounds OpenAL

thanks for the response. The pop/click is noticeable on high frequency sounds when abruptly stopped. I am looking to try running the gain loop on a separate thread, how can this be accomplished? Could you point me to an article on threading in the blackberry documentation or would I need to search qt threading?

Retired
Posts: 29
Registered: ‎03-19-2012
My Device: Z10
My Carrier: BELL

Re: Fading out Sounds OpenAL

Hi again,

 

if you are using a Cascades for your App then I suggest using qthread. here is an example : http://tinyurl.com/9zvayg4

if your app is entirely native (C/C++) you can use pthread. here is an FYI: http://tinyurl.com/9adz7s4

 

cheers, Ram

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Fading out Sounds OpenAL

Hate asking again and will continue to search for the solution on my own but, if my custom QThread class is created in a separate file and I need its start method to change objects declared in the file where it is called, say, App.cpp, how can I edit the run method of the QThread, defined in  QThread.cpp, in App.cpp? I also tried pthread, which is not suitable in this situation.

Retired
Posts: 29
Registered: ‎03-19-2012
My Device: Z10
My Carrier: BELL

Re: Fading out Sounds OpenAL

Hi vingilot,

 

I am not able to understand your question clearly especially "how can I edit the run method of the QThread, defined in  QThread.cpp, in App.cpp?" part. If you can provide more details I would be glad to help.

 

cheers, Ram

Highlighted
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Fading out Sounds OpenAL

Great thanks, so I made a QThread in a QThread.hpp and .cpp file and now instantiate it in my app.cpp file. The issue is, when started, the Thread processes the run() method in the QThread.cpp file. I want to change this run method to include objects defined in my app.cpp file though and am not sure how to accomplish this.

 

I need to execute this loop on another thread:  

while (gain<1) {
       alSourcef(mSoundSources[source], AL_GAIN, 1.0f-gain);
       gain=gain+0.000001;

}

 

to decrease the gain of the source where the sound is playing, I am using openAL. The problem is that the QThread.cpp file does not have access to the sources and variables associated with playing the sounds. I need to be able to tell the new thread to do this loop from the app.cpp file where everything can be recognized. Thanks again for your assistance.