[Kde-games-devel] Junior job not only for GSoCers: Low-latency sound playback with KgSound

Ian Wadham iandw.au at gmail.com
Tue Mar 20 05:08:50 UTC 2012


On 20/03/2012, at 11:42 AM, Roney Gomes wrote:

> On 03/18/2012 01:50 AM, Ian Wadham wrote:
>> 
>> On 18/03/2012, at 12:07 PM, Roney Gomes wrote:
>> 
>>> On 03/07/2012 08:10 PM, Stefan Majewsky wrote:
>>>> If you decide to work on porting a game, do not hesitate to ask for
>>>> further assistance on this mailing list. Once your patch is done,
>>>> upload it to http://svn.reviewboard.kde.org to get it reviewed.
>>> 
>>> Hi, I began to browse Kapman's source code in an attempt to port it to KgSound, but some doubts came to my mind. Here follows the first.
>>> 
>>> In the following assignment:
>>> m_media1 = Phonon::createPlayer(Phonon::Gamecategory)
>>> 
>>> A sound file is "attached" to m_media1, but in the documentation[1] I saw that this function takes a second argument (const MediaSource&  source), that is the source of the sound file itself.
>> 
>> Two things to look at more closely:
>> a) that second argument is a generalisation of a media source (not necessarily a file) and is optional,
>> b) kapman is using two media players, m_media1 and m_media2.
>> 
>>> So, taking in consideration that I can't explicitly see the file passed, wich file should I choose when calling the KgSound's constructor?
>> 
>> Phonon opens a file every time it plays a sound and is not good at playing short sounds promptly
>> and overlapping them correctly.  That is why we are switching to KgSound and OpenAL library
>> for sounds in games.  You may need to experiment and think about how to use KgSound and
>> OpenAL to best effect, e.g. whether to open and load all the sound files at startup time.an/listinfo/kde-games-devel
> 
> I worked in the code today and (almost) ported kapman to KgSound. Unluckly, a running-time error happens all the time: I can't hear the sounds while playing the game, in any circumstance.
> 
> I tried to debug it by myself but I'm still blind about what's happening.
> 
> Granatier was the example I followed, and I'm sure I reproduced exactly the same schema in my changes; there are pieces of code almost identical. I don't really know what's wrong.
> 
> I'm sending within this e-mail the files I've changed, game.h and game.cpp. I'd really appreciate your help.

At a very quick glance, the code looks OK, so maybe it is something missing in your environment.  You need:
   - Hardware/OS sound turned on,
   - Sound setting on in Kapman Settings menu,
   - OpenAL library installed,
   - LibSndFile library installed,
   - Sound files installed in your $KDEDIR area (Is KStandardDirs::locate finding any files?),
   - Any other "obvious" things.

If you do not have both libraries, I think KgSound will default to Phonon, which might or might not play OK.

If all the above things seem OK, try making the problem smaller, e.g. have a few lines of code that just play
*one* sound, such as bonus.ogg, at a moment of your choosing.  Oh, and did the game play sounds before
you started to change the code?

Happy hunting!

Cheers, Ian W.



More information about the kde-games-devel mailing list