sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : audiogaincontrol.cpp sl@0: // Part of : ACL Logical layer sl@0: // sl@0: sl@0: sl@0: sl@0: #include "logicalaudiogaincontrol.h" sl@0: #include sl@0: #include // For making it ECom plugin sl@0: sl@0: // ======== LOCAL FUNCTIONS ======== sl@0: // __________________________________________________________________________ sl@0: // Exported proxy for instantiation method resolution sl@0: // Define the interface UIDs sl@0: sl@0: // Moved from header sl@0: const TInt KDefaultMaxRampTime = 10; sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: IMPLEMENTATION_PROXY_ENTRY(KAudioGainControlUid, CLogicalAudioGainControl::NewL) sl@0: }; sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: return ImplementationTable; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CLogicalAudioGainControl::CLogicalAudioGainControl(TAny* aParam) : CAudioProcessingUnit(aParam) sl@0: { sl@0: TRACE_CREATE(); sl@0: DP_CONTEXT(CLogicalAudioGainControl::CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: iMaxRampTime = KDefaultMaxRampTime; sl@0: sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Factory method sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CLogicalAudioGainControl* CLogicalAudioGainControl::NewL(TAny* aParam) sl@0: { sl@0: DP_STATIC_CONTEXT(CLogicalAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: CLogicalAudioGainControl* self = new(ELeave)CLogicalAudioGainControl(aParam); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: DP0_RET(self, "0x%x"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Second phase constructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CLogicalAudioGainControl::ConstructL() sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TAudioChannelGain left; sl@0: TAudioChannelGain right; sl@0: left.iLocation = TAudioChannelGain::ELeft; sl@0: right.iLocation = TAudioChannelGain::ERight; sl@0: iDesiredChannels.AppendL(left); sl@0: iDesiredChannels.AppendL(right); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Destructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CLogicalAudioGainControl::~CLogicalAudioGainControl() sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::~CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: iActiveChannels.Close(); sl@0: iDesiredChannels.Close(); sl@0: iGainObservers.Close(); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::GetMaxGain sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::GetMaxGain(TInt& aMaxGain) const sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: // TODO: Fix this when the MMRC server is available sl@0: // This adaptationGain pointer will be replaced by the a pointer gotten from sl@0: // the "control mechanism" provided by the real MMRC server sl@0: TInt err = KErrNotReady; sl@0: if(iAdaptationGain) sl@0: { sl@0: err = iAdaptationGain->GetMaxGain(aMaxGain); sl@0: } sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::GetMaxRampTime sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: aMaxRampTime = KDefaultMaxRampTime; sl@0: if(iAdaptationGain) sl@0: { sl@0: err = iAdaptationGain->GetMaxRampTime(aMaxRampTime); sl@0: } sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::GetGain sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::GetGain(RArray& aChannels) const sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: TInt count = iDesiredChannels.Count(); sl@0: aChannels.Reset(); sl@0: for (TUint i(0); i < count; i++) sl@0: { sl@0: TInt err = aChannels.Append(iDesiredChannels[i]); sl@0: } sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::SetGain sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::SetGain(RArray& aChannels, TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: sl@0: iDesiredRampTime = static_cast(aRampDuration.Int64()); sl@0: iDesiredRampOperation = aRampOperation; sl@0: sl@0: // The gain values are clippped to MaxGain. sl@0: TInt a3fMaxGain = 0; sl@0: if(iAdaptationGain) sl@0: { sl@0: err = iAdaptationGain->GetMaxGain(a3fMaxGain); sl@0: } sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: iDesiredChannels.Reset(); sl@0: TUint count = aChannels.Count(); sl@0: TAudioChannelGain gainChannel; sl@0: for (TUint i(0); i < count; i++) sl@0: { sl@0: gainChannel = aChannels[i]; sl@0: // sl@0: if(gainChannel.iGain > a3fMaxGain) sl@0: { sl@0: gainChannel.iGain = a3fMaxGain; sl@0: } sl@0: else if(gainChannel.iGain < 0) sl@0: { sl@0: err = KErrArgument; sl@0: break; sl@0: } sl@0: sl@0: err = iDesiredChannels.Append( gainChannel ); sl@0: if(err != KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: if(iSettingsObserver) sl@0: { sl@0: iSettingsObserver->ReceiveComponentSettingsChange(iType, EComponentAlterationGain); sl@0: } sl@0: } sl@0: sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::SetGain sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::SetGain(RArray& aChannels) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: err = SetGain(aChannels, KNullUid, 0); sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::RegisterAudioGainControlObserver sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CLogicalAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::RegisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = iGainObservers.Find(&aObserver); sl@0: if( err != KErrNotFound ) sl@0: { sl@0: err = KErrAlreadyExists; sl@0: } sl@0: else sl@0: { sl@0: err = iGainObservers.Append(&aObserver); sl@0: } sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CLogicalAudioGainControl::UnregisterAudioGainControlObserver sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CLogicalAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::UnregisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt idxOrErr = iGainObservers.Find(&aObserver); sl@0: if( idxOrErr != KErrNotFound ) sl@0: { sl@0: iGainObservers.Remove(idxOrErr); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioProcessingUnit sl@0: // CLogicalAudioGainControl::IsTypeOf sl@0: // --------------------------------------------------------------------------- sl@0: TBool CLogicalAudioGainControl::IsTypeOf(TUid aTypeId) const sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::IsTypeOf *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TBool result = EFalse; sl@0: if (iType == aTypeId) sl@0: { sl@0: result = ETrue; sl@0: } sl@0: DP0_RET(result, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioProcessingUnit sl@0: // CLogicalAudioGainControl::Interface sl@0: // --------------------------------------------------------------------------- sl@0: TAny* CLogicalAudioGainControl::Interface(TUid aType) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::GetInterface *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: MAudioGainControl* ptr = NULL; sl@0: if(aType==KUidAudioGainControl) sl@0: { sl@0: ptr = this; sl@0: } sl@0: DP_OUT(); sl@0: return ptr; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControlObserver sl@0: // CLogicalAudioGainControl::MaxRampTimeChanged sl@0: // --------------------------------------------------------------------------- sl@0: void CLogicalAudioGainControl::MaxRampTimeChanged(MAudioGainControl& /*aGain*/) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::MaxRampTimeChanged *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iGainObservers.Count(); sl@0: for ( TUint idx(0); idx < count; idx++ ) sl@0: { sl@0: iGainObservers[idx]->MaxRampTimeChanged(*this); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControlObserver sl@0: // CLogicalAudioGainControl::MaxGainChanged sl@0: // --------------------------------------------------------------------------- sl@0: void CLogicalAudioGainControl::MaxGainChanged(MAudioGainControl& /*aGain*/) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::MaxGainChanged *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iGainObservers.Count(); sl@0: for ( TUint idx(0); idx < count; idx++ ) sl@0: { sl@0: iGainObservers[idx]->MaxGainChanged(*this); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControlObserver sl@0: // CLogicalAudioGainControl::GainChanged sl@0: // --------------------------------------------------------------------------- sl@0: void CLogicalAudioGainControl::GainChanged(MAudioGainControl& /*aGain*/, TInt aError) sl@0: { sl@0: DP_CONTEXT(CLogicalAudioGainControl::GainChanged *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iDesiredChannels.Count(); sl@0: iActiveChannels.Reset(); sl@0: for(TUint i=0; iGainChanged(*this, aError); sl@0: } sl@0: DP_OUT(); sl@0: }