⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csoundmixer.cpp

📁 手机游戏:Symbian S60俄罗斯方块(Tetris)的源代码
💻 CPP
字号:
#include "CSoundMixer.h"
#include "CMixerThread.h"
#include <e32svr.h>


CSoundMixer* CSoundMixer::NewL()
{
	CSoundMixer* self = new( ELeave )CSoundMixer();
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop( self );
	return self;
}

void CSoundMixer::ConstructL()
{
	iShared.iMainVolume = 64;	// default main volume

	User::LeaveIfError( iMixerThread.Create( _L("Mixer"),
											 CMixerThread::ThreadFunction,
											 KDefaultStackSize,
											 NULL,
											 NULL) );

	// Give all possible priority to audio
	iMixerThread.SetPriority( EPriorityRealTime );
	RThread().SetPriority( EPriorityAbsoluteLow );
	
	User::LeaveIfError( iShared.iAliveMutex.CreateLocal( 1 ) );
	User::LeaveIfError( iShared.iMutex.CreateLocal() );
	iMixerThread.SetInitialParameter( &iShared );
	iMixerThread.Resume();
	iPaused = ETrue;
}

CSoundMixer::CSoundMixer()
{
}

CSoundMixer::~CSoundMixer()
{
	if( iPaused )
		SendCmd( ECmdStartMixer );			// maybe there's bug here

	SendCmd( ECmdDestroyMixer );
	//
	iShared.iAliveMutex.Wait();
	iShared.iAliveMutex.Close();
	iShared.iMutex.Close();

}

void CSoundMixer::Pause()
{
	//RDebug::Print( _L("CSndMixer::Pause") );
	// check if mutex is already in wait ( pause mode )
	if( iPaused )
	{
		return;
	}

	iPaused = ETrue;

	SendCmd( ECmdStopMixer );
}

void CSoundMixer::Resume()
{
	//RDebug::Print( _L("CSoundMixer::Resume") );
	if( !iPaused )
	{
		return;
	}
	iPaused = EFalse;

	SendCmd( ECmdStartMixer );
}

void CSoundMixer::Play( const TSample& aSample, TInt aChannel, TInt aFrequency, TInt aVolume )
{
	iShared.iMutex.Wait();
	iShared.iPlayStarted[ aChannel ] = ETrue;
	iShared.iSample[ aChannel ] = aSample;
	iShared.iFrequency[ aChannel ] = aFrequency;
	iShared.iVolume[ aChannel ] = aVolume;
	iShared.iMutex.Signal();
}


void CSoundMixer::Stop( TInt aChannel )
{
	iShared.iMutex.Wait();
	iShared.iPlayStarted[ aChannel ] = ETrue;
	iShared.iSample[ aChannel ] = iEmptySample;
	iShared.iMutex.Signal();	
}


void CSoundMixer::SetVolume( TInt aVolume )
{
	iShared.iMutex.Wait();
	iShared.iMainVolume = aVolume;
	iShared.iMutex.Signal();	
}


TInt CSoundMixer::Volume()
{
	return iShared.iMainVolume;
}


void CSoundMixer::SendCmd( TMixerCmd aCmd )
{
	iShared.iMutex.Wait();
	iShared.iCmd = aCmd;
	iShared.iMutex.Signal();
	iMixerThread.RaiseException( EExcUserInterrupt );
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -