[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Multiple sounds with phonon
From:       Nikos Chantziaras <realnc () arcor ! de>
Date:       2010-06-16 19:19:10
Message-ID: hvb835$33i$1 () dough ! gmane ! org
[Download RAW message or body]

On 06/16/2010 10:04 PM, Danilo Cesar wrote:
> Hi guys,
>
> I'm having some problems with phonon, can you give-me a clue please? =)
>
> My pb is: I need to play 5 different sounds, and some of them need to
> be played at the same time
> (eg: playing an explosion sound while there is another 5 instance of
> the same sound being played).
>
> The simplest solution I found is:
> 1 - Ever time i need to play a sound I do:
>       audioOutput = new Phonon::AudioOutput(Phonon::GameCategory, this)
>       mediaObject = new Phonon::MediaObject(this)
>       Phonon::createPath(mediaObject, audioOutput);
>       mediaObject->setCurrentSource(Phonon::MediaSource("sound1.ogg"));
>       mediaObject->play();
>
>       First question is: Do I need an audioOutput for each mediaObject?
> Or can I connect
>       more than one mediaObject to an audioOuput?
>
> 2 - As solution above isn't effective, I changed it to reuse the
> mediaObject's if it's
>      already created and if it isn't playing a sound anymore. Like a
> pool... It works, but
>      I'm not feeling comfortable with this solution.
>
> Well, is there a better way to do that?

Phonon does not support mixing.  That means you can't connect more than 
one MediaObject to the same output.

Phonon is not really suitable for your use case.  You need something 
like SDL or fmod.  Phonon is only suitable for simple media playback, 
with only one sound at a time.

If you still want to do it with Phonon, then keep in mind that each 
concurrent AudioOutput you open will open the audio device.  So for 5 
sounds, the audio device is opened 5 times.  This is exactly the same as 
having 5 different applications accessing the audio device at once and 
the OS is doing the mixing, and there's an upper limit to many channels 
can be mixed.  Sometimes, only 1 is allowed (ALSA without dmix, for 
example.)

Long answer made short: use SDL, fmod or some other similar audio library.

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic