| 1 | /*******************************************************************\r |
| 2 | *\r |
| 3 | * File: Audio_mediaserver.h\r |
| 4 | *\r |
| 5 | * Author: Peter van Sebille (peter@yipton.net)\r |
| 6 | *\r |
| 7 | * Modified/adapted for picodriveN by notaz, 2006\r |
| 8 | *\r |
| 9 | * (c) Copyright 2006, notaz\r |
| 10 | * (c) Copyright 2001, Peter van Sebille\r |
| 11 | * All Rights Reserved\r |
| 12 | *\r |
| 13 | *******************************************************************/\r |
| 14 | \r |
| 15 | #ifndef __AUDIO_MEDIASERVER_H\r |
| 16 | #define __AUDIO_MEDIASERVER_H\r |
| 17 | \r |
| 18 | #include <Mda\Common\Audio.h>\r |
| 19 | #include <MdaAudioOutputStream.h>\r |
| 20 | \r |
| 21 | #include "audio.h"\r |
| 22 | #include "polledas.h"\r |
| 23 | \r |
| 24 | const TInt KSoundBuffers = 4;\r |
| 25 | const TInt KBlockTime = 1000000 / 5; // hardcoded: 5 updates/sec\r |
| 26 | const TInt KMaxLag = 260000; // max sound lag, lower values increase chanse of underflow\r |
| 27 | const TInt KMaxUnderflows = 50; // max underflows/API errors we are going allow in a row (to prevent lockups)\r |
| 28 | \r |
| 29 | \r |
| 30 | class TGameAudioEventListener : public MMdaAudioOutputStreamCallback\r |
| 31 | {\r |
| 32 | public: // implements MMdaAudioOutputStreamCallback\r |
| 33 | void MaoscOpenComplete(TInt aError);\r |
| 34 | void MaoscBufferCopied(TInt aError, const TDesC8& );\r |
| 35 | void MaoscPlayComplete(TInt aError);\r |
| 36 | \r |
| 37 | TBool iIsOpen;\r |
| 38 | // TBool iHasCopied;\r |
| 39 | TInt iUnderflowed;\r |
| 40 | };\r |
| 41 | \r |
| 42 | \r |
| 43 | class CGameAudioMS : public IGameAudio // IGameAudio MUST be specified first!\r |
| 44 | {\r |
| 45 | public: // implements IGameAudio\r |
| 46 | TInt16 *NextFrameL();\r |
| 47 | TInt16 *DupeFrameL(TInt &aUnderflowed);\r |
| 48 | TInt16 *ResumeL();\r |
| 49 | void Pause();\r |
| 50 | void ChangeVolume(TInt aUp);\r |
| 51 | \r |
| 52 | public:\r |
| 53 | ~CGameAudioMS();\r |
| 54 | CGameAudioMS(TInt aRate, TBool aStereo, TInt aPcmFrames, TInt aBufferedFrames);\r |
| 55 | void ConstructL();\r |
| 56 | EXPORT_C static CGameAudioMS* NewL(TInt aRate, TBool aStereo, TInt aPcmFrames, TInt aBufferedFrames);\r |
| 57 | \r |
| 58 | protected:\r |
| 59 | void WriteBlockL();\r |
| 60 | void UnderflowedL();\r |
| 61 | \r |
| 62 | protected:\r |
| 63 | void WaitForOpenToCompleteL();\r |
| 64 | // void WaitForCopyToCompleteL();\r |
| 65 | \r |
| 66 | TInt iRate;\r |
| 67 | TBool iStereo;\r |
| 68 | \r |
| 69 | CMdaAudioOutputStream *iMdaAudioOutputStream;\r |
| 70 | TMdaAudioDataSettings iMdaAudioDataSettings;\r |
| 71 | \r |
| 72 | TGameAudioEventListener iListener;\r |
| 73 | \r |
| 74 | CPolledActiveScheduler *iScheduler;\r |
| 75 | \r |
| 76 | HBufC8* iSoundBuffers[KSoundBuffers+1];\r |
| 77 | TInt iBufferedFrames;\r |
| 78 | TInt16* iCurrentPosition;\r |
| 79 | TInt iCurrentBuffer;\r |
| 80 | TInt iFrameCount;\r |
| 81 | TInt iPcmFrames;\r |
| 82 | CMdaServer* iServer;\r |
| 83 | \r |
| 84 | TInt64 iTime;\r |
| 85 | };\r |
| 86 | \r |
| 87 | #endif /* __AUDIO_MEDIASERVER_H */\r |