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

📄 csndmixer.cpp

📁 在symbian中
💻 CPP
字号:
/*
 * ============================================================================
 *  Name     : CSndMixer.cpp
 *  Part of  : SoundMixer
 *  Created  : 03/30/2006 by Forum Nokia
 *  Description:
 *     This is the project specification file for SoundMixer.
 *     Initial content was generated by Series 60 AppWizard.
 *  Version  : 2.0.0
 *  Copyright: Forum Nokia
 * ============================================================================
 */

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

_LIT(KMixer, "Mixer");


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( iShared.iAliveMutex.CreateLocal( 1 ) );
  User::LeaveIfError( iShared.iMutex.CreateLocal() );
  User::LeaveIfError( iMixerThread.Create( KMixer,
        CMixerThread::ThreadFunction,
        KDefaultStackSize,
        KMinHeapSize, 
        KMinHeapSize+1000000, 
        &iShared));
  
  // Give all possible priority to audio
  iMixerThread.SetPriority( EPriorityRealTime );
  iMixerThread.Resume();
  iPaused = ETrue;
  }


CSndMixer::CSndMixer()
  {
  }


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


void CSndMixer::Pause()
  {
  RDebug::Print( _L("CSndMixer::Pause") );

  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();
  iShared.iExc = EExcUserInterrupt;
    
  TRequestStatus* status = iShared.iStatusPtr;
  if(status->Int() == KRequestPending )
    {
    iMixerThread.RequestComplete(status, KErrNone);
    }
  }

// End of File

⌨️ 快捷键说明

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