📄 soundhandler.h
字号:
#ifndef SOUNDHANDLER
#define SOUNDHANDLER
#define KNumberOfChannels 4
#include <e32base.h>
#include <Mda\Common\Audio.h>
#include <mdaaudiooutputstream.h>
class CMdaAudioOutputStream;
/**
* Class that stores an sample, loaded from a wav file
*/
class CSoundSample:public CBase
{
public:
static CSoundSample* NewL(const TFileName& aFileName);
~CSoundSample();
CSoundSample();
void ConstructL(const TFileName& aFileName);
TInt iSampleLength;
TInt iSampleRate;
TInt16 iNoChannels;
TInt16 iNoBits;
TInt16 iStepRate;
HBufC8* iSampleData;
TPtr8 iSamplePtr;
};
/**
* Class that defines a sound channel playing, and an associated sample
*/
class CSoundChannel:public CBase
{
public:
CSoundChannel();
~CSoundChannel();
CSoundSample* iSample;
TBool iIsPlaying;
TTime iStartedPlayAt;
TReal iPlayPosition;
TBool iIsLooping;
TReal iStepRate;
};
class CSoundHandler;
class CSoundThreadWatcher:public CActive
{
public:
CSoundThreadWatcher(RThread* aSndThread,CSoundHandler* aSoundHandler);
~CSoundThreadWatcher();
void RunL();
void DoCancel();
private:
RThread* iSndThread;
CSoundHandler* iSoundHandler;
};
class MSoundEventObserver
{
public:
virtual void ChannelStopped(TInt aChannelIndex)=0;
};
class CSoundHandler:public CBase,public MMdaAudioOutputStreamCallback
{
public:
static CSoundHandler* NewL(TInt aNoOfSoundChannels=4,TInt aMixFreq = 11025,TInt aChannels = 1,const TDesC& aDefaultMusicZip = KNullDesC());
~CSoundHandler();
TInt AddSoundSampleL(const TFileName& aSampleName);
/**
* @returns Channel Index
*/
TInt PlaySampleL(TInt aSampleIndex,TReal aFactor = 1,TBool aIsLooping = EFalse);
void StopPlayingChannelL(TInt aChannelIndex);
void StopAll();
void StartSound();
void SuspendSound();
void SetObserver(MSoundEventObserver* aObserver);
TBool PlayingSample();
inline TBool SoundOn(){return iSoundOn;};
inline void SetSoundOn(TBool aBool){
if(aBool)
StartSound();
else
{
SuspendSound();
}
};
// Sets the volume 0-100 in %
void SetVolume(TInt aVolume);
/**
* Returns volume in %
*/
TInt Volume();
void SoundThreadDiedL();
protected:
void MixChannels();
void InitThreadL();
static TInt ThreadStart(TAny* aSoundHandler);
private:
CSoundHandler(TInt aNoOfSoundChannels,TInt aMixFreq,TInt aChannels);
void ConstructL(const TDesC& aDefaultMusicZip = KNullDesC());
void StartSoundL();
virtual void MaoscOpenComplete(TInt aError) ;
virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) ;
virtual void MaoscPlayComplete(TInt aError);
void UpdateSoundL();
private:
RPointerArray<CSoundChannel>* iSoundChannels;
RPointerArray<CSoundSample>* iSoundSamples;
TInt iNoOfSoundChannels;
HBufC8* iMixBuffer;
TInt iSampleFreq;
TInt iChannels;
TInt iBufferLength;
RThread* iSndThread;
CActiveScheduler* iScheduler;
CMdaAudioOutputStream* iAudioStream;
TMdaAudioDataSettings iAudioSettings;
CSoundSample* iMusicSample;
RCriticalSection iThreadMutex;
CSoundThreadWatcher* iThreadWatcher;
TBool iSoundOn;
TInt iVolume;
TInt iNewVolume;
TBool iSchedStarted;
TInt64 iBytesWritten;
TInt64 iChunkSize;
MSoundEventObserver* iObserver;
public:
TBool iExitSnd;
TBool iReconfigureSound;
TBool iSoundInitOk;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -