Symbian S60 MP3 decoding & sound mixing solution.
Official website: http://www.wanwann.com/2010/02/21/symbian-s60-mp3-decoding-sound-mixing-solution/
preamble:
As we might know, It is not workable to play mutiple music file all at once on the symbian s60 platform, for the latter would preempt the audio device of the previous one(However, It’s workable if we have a music file player and another stream player, here, I mean music file player by playing some music by using the CMdaAudioPlayerUtility::de>OpenFileL() de>, or some similiar operation, stream player by playing some music by using the CMdaAudioInputStream::de>Open() de> or some operation like that.)
So what if we wanna play multiple music or sound at the some time? What if we wanna play some background music, and at this moment, we wanna have some sound effect in our game? If you try by using several music file player, I bet, you would have to stop the others while some is playing. This sounds no good, as it might be too difficult to control and also, the effect would be not as good as you expect.
Well, here provides a solution to you, that you can decode your mp3 to raw music datas, and then mixing then play(by using a single streamming player) these decoded raw datas. However, this solution is an opensource project which is licenced under the GPL licence, please agree to the license before you use the sourcecodes.
How did it work?
We use an open-sourced mp3 decoding library, madlib for mp3 decoding. For mixing play, we register an channel everytime we’d like to play one music(sound).
How do I get started?
We provide a demo here, so you can learn how to use it.
For decoding, just create an instance of class CMp3ToRawdataDecoder, then set your resample rate, then decode.
iDecoder1 = CMp3ToRawdataDecoder::NewL(iObserver); // The observer to observe this decoding process
iDecoder1->SetResampleRate(44100);
TFileName srcFile = KSrcFilePath; // The source mp3 file to be decoded
TFileName destFile = KDestFilePath; // The file path where the decoded raw datas will be saved
iDecoder1->StartDecode(srcFile, destFile);
If the decoding process succeeds, the DecodeComplete(const TFileName& aSrcFileName, const TFileName& aDestFileName) of the observer class will be called, otherwise, the ReportError(const TFileName& aSrcFile, const TFileName& aDestFileName, TInt aErrorCode) of the observer class would be called.
For mixing play , just create an instance of class CMixingPlayer, then play.
iMixingPlayer = CMixingPlayer::NewL();
iMixingPlayer->play(aDestFileName1, 100, FALSE);
If you wanna play another music, easy, just call play again.
iMixingPlayer->play(aDestFileName2, 100, FALSE);
Downloads
The Solution Library is downloadable here .
The Solution Demo is downloadable here .