Apr 222010

Getting sound out of a Symbian app is difficult in the best of times – if you add an extra abstraction layer (hello, Qt), the situation (obviously) does not improve. Nevertheless, sound is needed especially for games – and I think that I have a well-working way to get it done.

Once again: this is for Symbian ONLY! It will not work on Maemo, etc

Step 1 – create the files
Our friends at Nokia’s have offered a nice sound engine in their Sound Mixer example. Adapting it to Qt for Symbian is not difficult – just create a folder s60sound, and extract the files found in the archive below into the folder:

Step 2 – store the WAV files
Next up, create a /rsc folder in the project home, and store the wav files here. I have found out that long wav files (longer than 20secs) or very large WAV files (more than 300kb) cause problems – this might have something to do with stack sizes, and has been discussed on Forum Nokia.

Step 3 – update the pro file
Next up is the pro file. First of all, add the headers and cpp files to the relevant sections. Then, add the libraries and the wav files above by editing the Symbian segment of the .pro file as to look like this:

symbian: {
LIBS += -lcone
myFiles.sources = rsc*.wav

Step 4 – update the ConstructL of the wrapper
Next, look into the SoundMixerContainer. You will see how I load four samples there – abstract from it.

Step 5 – update sound routines
Then, look at the sound routines I use to play the nion-background music SFX. Create your own – the integer which always changes is the channel.

Step 6 – use
Not much to add here…

P.S. I would love to provide you with sampole WAV files here, but cannot due to copyright reasons!

Related posts:

  1. Bitmap application icons for Symbian – Qt edition
  2. Change to .pro file syntax – Unescaped backslashes are deprecated
  3. Packaging Qt applications for the Nokia N900 – the smart way
  4. Signing QT apps for Ovi – the inofficial how-to
  5. Carbide 2.4 – the .pro file bug

  9 Responses to “Proper sound and background music with Qt for Symbian”

  1. Hi,

    Nice! Having played with the sound mixer code myself in the past, I though I’d share what I found: The sample loader expects 8bit PCM data, but they mixer itself runs at 16bits. I don’t know why it was originally implemented so, but you can easily upgrade the sound quality produced by the mixer by using 16bit PCM little-endian samples, and modifying CWavLoader::LoadL() a bit:

    User::LeaveIfError( file.Open( fs, nameAndPath, EFileStream | EFileRead ) );
    TInt size;
    User::LeaveIfError( file.Size( size ) );

    if( size % 2 ) // must have even number of bytes (16-bit samples)
    User::Leave( KErrCorrupt );

    TUint8* tbuf = new( ELeave )TUint8[ size ];

    TPtr8 ptr( (TUint8*)tbuf, size );
    User::LeaveIfError( file.Read( ptr ) );

    TInt16* buf = new( ELeave )TInt16[ size >> 1 ];
    TInt i16, i8;
    for( i16 = i8 = 0; i16 >1); i16++ )
    buf[ i16 ] = ( TInt16 )tbuf[ i8++ ]; // little-endian
    buf[ i16 ] += (( TInt16 )tbuf[ i8++ ]) <> 1; // length in number of samples, not bytes
    sample.iRepStart = 0;
    sample.iRepEnd = 0;

    return sample;

  2. Argh, looks like the comment system choked on bit-shift operators.. here:


    Oh yeah, the class names are a bit misleading – the code doesn’t really handle WAV format. Your samples need to be in PCM (raw) mono format instead. Audacity is a nice open source tool to convert audio files to PCM.

  3. Hi treinio,
    thank you so much for talking back!

    Should I submit the changes you made to forum nokia?

    All the best
    Tam Hanna

  4. It’s worth pointing out that the low-level QtMultimedia audio APIs (QAudioOutput and QAudioInput) have now been implemented for Symbian. This backend was written after the Qt 4.6.2 release; to use these APIs now, you therefore need to build Qt from source. It will be available in Qt 4.6.3 and Qt 4.7 releases however.

    These Qt APIs are largely functionally equivalent to CMMFDevSound. They are therefore similar in functionality to CMdaAudioOutputStream / CMdaAudioInputStream, but do not incur the extra layer of buffering used by these two APIs.

    At present, QtMultimedia does not provide any PCM mixing capabilities, so this still needs to be done by the application. This code could, however, be easily written in a cross-platform manner; using QAudioOutput in place of CMdaAudioOutputStream would then mean that the application could target all of the Qt platforms, rather than just Symbian.

  5. Hi Gareth,
    thank you so much for talking back!

    Would you be willing to contribute a sample implementation?


  6. Would you be willing to contribute a sample implementation?

    If I get the time, I’d love to, but I wouldn’t like to commit to when that would be.

    I have written a demo app which uses the QtMultimedia APIs however. This will go into the Qt source tree shortly, and therefore should be in the next release. It doesn’t do any mixing, but it does use QAudioInput and QAudioOutput, and may therefore be of interest to readers of this post.

  7. Hi Gareth,
    just send me an email when your done or have anything you want to see here!


    P.S. Just look at the updating frequency. On the TCN, nobody commits to anything except to having fun and dieing one day ;) .

  8. The demo application I mentioned is now available in the Qt git repository.

    I have also published a couple of posts on the Qt Labs blog: one which describes the QtMultimedia audio APIs, and a second which describes the implementation of the demo application.

  9. Hi Gareth,
    ok – will try to mention you today!

    All the best, and hear from you again soon
    Tam Hanna

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting