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

📄 csndmixer.cpp

📁 SoundMixer example application is compatible with Series 60 Developer Platform v1.0 and v2.0. It
💻 CPP
字号:
   /*
    *
============================================================================
    *  Name     : CSndMixer.cpp
    *  Part of  : SoundMixer
    *  Created  : 03/01/2003 by Forum Nokia
    *  Description:
    *     This is the project specification file for SoundMixer.
    *     Initial content was generated by Series 60 AppWizard.
    *
    *  Version  : 1.0.0
    *  Copyright: Forum Nokia
    *
============================================================================
    */

#include "CSndMixer.h"
#include "CMixerThread.h"
#include <e32svr.h>

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

void CSndMixer::ConstructL()
	{
	iShared.iMainVolume = 256;	// 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;
	}

CSndMixer::CSndMixer()
	{

	}

CSndMixer::~CSndMixer()
	{
	if( iPaused )
		{
		SendCmd( ECmdStartMixer );
		}
	SendCmd( ECmdDestroyMixer );
	//
	iShared.iAliveMutex.Wait();
	iShared.iAliveMutex.Close();
	iShared.iMutex.Close();

	}

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

	iPaused = ETrue;

	SendCmd( ECmdStopMixer );
	}

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

	SendCmd( ECmdStartMixer );
	}

void CSndMixer::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 CSndMixer::Stop( TInt aChannel )
	{
	iShared.iMutex.Wait();
	iShared.iPlayStarted[ aChannel ] = ETrue;
	iShared.iSample[ aChannel ] = iEmptySample;
	iShared.iMutex.Signal();	
	}


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


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


void CSndMixer::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 + -