os/mm/mmhais/refacladapt/src/audiogaincontrol/audiogaincontrol.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmhais/refacladapt/src/audiogaincontrol/audiogaincontrol.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,272 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +
    1.20 +
    1.21 +#include "audiogaincontrol.h"
    1.22 +#include <a3f/audioprocessingunittypeuids.h>
    1.23 +
    1.24 +// ======== LOCAL FUNCTIONS ========
    1.25 +void Panic(TInt aPanicCode)
    1.26 +	{
    1.27 +	_LIT(KAudioGainControlPanicCategory, "audiogaincontrol");
    1.28 +	User::Panic(KAudioGainControlPanicCategory, aPanicCode);
    1.29 +	}
    1.30 +
    1.31 +// ======== MEMBER FUNCTIONS ========
    1.32 +
    1.33 +// ---------------------------------------------------------------------------
    1.34 +// Constructor
    1.35 +// ---------------------------------------------------------------------------
    1.36 +CAudioGainControl::CAudioGainControl()
    1.37 +	{
    1.38 +	TRACE_CREATE();
    1.39 +	DP_CONTEXT(CAudioGainControl::CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
    1.40 +	DP_IN();
    1.41 +	DP_OUT();
    1.42 +	}
    1.43 +
    1.44 +// ---------------------------------------------------------------------------
    1.45 +// Factory method
    1.46 +// ---------------------------------------------------------------------------
    1.47 +EXPORT_C CAudioGainControl* CAudioGainControl::NewL()
    1.48 +	{
    1.49 +	DP_STATIC_CONTEXT(CAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
    1.50 +	DP_IN();
    1.51 +	CAudioGainControl* self = new(ELeave)CAudioGainControl();
    1.52 +	CleanupStack::PushL(self);
    1.53 +	self->ConstructL();
    1.54 +	CleanupStack::Pop(self);
    1.55 +	DP0_RET(self, "0x%x");
    1.56 +	}
    1.57 +
    1.58 +// ---------------------------------------------------------------------------
    1.59 +// Second phase constructor
    1.60 +// ---------------------------------------------------------------------------
    1.61 +void CAudioGainControl::ConstructL()
    1.62 +	{
    1.63 +	DP_CONTEXT(CAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
    1.64 +	DP_IN();
    1.65 +	DP_OUT();
    1.66 +	}
    1.67 +
    1.68 +// ---------------------------------------------------------------------------
    1.69 +// Destructor
    1.70 +// ---------------------------------------------------------------------------
    1.71 +CAudioGainControl::~CAudioGainControl()
    1.72 +	{
    1.73 +	DP_CONTEXT(CAudioGainControl::~CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
    1.74 +	DP_IN();
    1.75 +	iGainObservers.Close();
    1.76 +	DP_OUT();
    1.77 +	}
    1.78 +
    1.79 +EXPORT_C void CAudioGainControl::SetHelper(MGainHelper &aHelper)
    1.80 +	{
    1.81 +	iHelper = &aHelper;
    1.82 +	}
    1.83 +// ---------------------------------------------------------------------------
    1.84 +// CAudioGainControl::IssueGainChangedCallBack
    1.85 +// ---------------------------------------------------------------------------
    1.86 +EXPORT_C void CAudioGainControl::IssueGainChangedCallBack(TInt aError)
    1.87 +	{
    1.88 +	DP_CONTEXT(CAudioGainControl::IssueGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
    1.89 +	DP_IN();
    1.90 +	TUint count = iGainObservers.Count();
    1.91 +	for(TUint i(0); i<count; i++)
    1.92 +		{
    1.93 +		iGainObservers[i]->GainChanged(*this, aError);
    1.94 +		}
    1.95 +	DP_OUT();
    1.96 +	}
    1.97 +
    1.98 +// ---------------------------------------------------------------------------
    1.99 +// CAudioGainControl::IssueMaxGainChangedCallBack
   1.100 +// ---------------------------------------------------------------------------
   1.101 +void CAudioGainControl::IssueMaxGainChangedCallBack()
   1.102 +	{
   1.103 +	DP_CONTEXT(CAudioGainControl::IssueMaxGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
   1.104 +	DP_IN();
   1.105 +	TUint count = iGainObservers.Count();
   1.106 +	for(TUint i(0); i<count; i++)
   1.107 +		{
   1.108 +		iGainObservers[i]->MaxGainChanged(*this);
   1.109 +		}
   1.110 +	DP_OUT();
   1.111 +	}
   1.112 +
   1.113 +// ---------------------------------------------------------------------------
   1.114 +// CAudioGainControl::IssueMaxRampTimeGainChangedCallBack
   1.115 +// ---------------------------------------------------------------------------
   1.116 +void CAudioGainControl::IssueMaxRampTimeChangedCallBack()
   1.117 +	{
   1.118 +	DP_CONTEXT(CAudioGainControl::IssueMaxRampTimeChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
   1.119 +	DP_IN();
   1.120 +	TUint count = iGainObservers.Count();
   1.121 +	for(TUint i(0); i<count; i++)
   1.122 +		{
   1.123 +		 iGainObservers[i]->MaxRampTimeChanged(*this);
   1.124 +		}
   1.125 +	DP_OUT();
   1.126 +	}
   1.127 +
   1.128 +// ---------------------------------------------------------------------------
   1.129 +// CAudioGainControl::ConfigureRamp
   1.130 +// ---------------------------------------------------------------------------
   1.131 +EXPORT_C TInt CAudioGainControl::ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
   1.132 +	{
   1.133 +	DP_CONTEXT(CAudioGainControl::ConfigureRamp *CD1*, CtxDevSound, DPLOCAL);
   1.134 +	DP_IN();
   1.135 +
   1.136 +	TInt err = KErrNone;
   1.137 +	// Apply ramp
   1.138 +	if(iHelper)
   1.139 +		{
   1.140 +		err = iHelper->ConfigureRamp(aRampOperation, aRampDuration);
   1.141 +		}
   1.142 +		
   1.143 +	DP0_RET(err, "%d");
   1.144 +	}
   1.145 +
   1.146 +// ---------------------------------------------------------------------------
   1.147 +// from class MAudioGainControl
   1.148 +// CAudioGainControl::GetMaxGain
   1.149 +// ---------------------------------------------------------------------------
   1.150 +TInt CAudioGainControl::GetMaxGain(TInt& aMaxGain) const
   1.151 +	{
   1.152 +	DP_CONTEXT(CAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
   1.153 +	DP_IN();
   1.154 +	TInt err = KErrNone;
   1.155 +	aMaxGain = KDefaultMaxGain;
   1.156 +	DP0_RET(err, "%d");
   1.157 +	}
   1.158 +
   1.159 +// ---------------------------------------------------------------------------
   1.160 +// from class MAudioGainControl
   1.161 +// CAudioGainControl::GetMaxRampTime
   1.162 +// ---------------------------------------------------------------------------
   1.163 +TInt CAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
   1.164 +	{
   1.165 +	DP_CONTEXT(CAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
   1.166 +	DP_IN();
   1.167 +	aMaxRampTime = KDefaultMaxRampTime;
   1.168 +	DP0_RET(KErrNone, "%d");
   1.169 +	} 
   1.170 +
   1.171 +// ---------------------------------------------------------------------------
   1.172 +// from class MAudioGainControl
   1.173 +// CAudioGainControl::GetGain
   1.174 +// ---------------------------------------------------------------------------
   1.175 +TInt CAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
   1.176 +	{
   1.177 +	DP_CONTEXT(CAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
   1.178 +	DP_IN();
   1.179 +	TInt err = KErrNone;
   1.180 +
   1.181 +	aChannels.Reset();
   1.182 +	TInt count = iGains.Count();
   1.183 +
   1.184 +	for (TUint i(0); i < count; i++)
   1.185 +		{
   1.186 +		err = aChannels.Append(iGains[i]);
   1.187 +		if(err != KErrNone)
   1.188 +			{
   1.189 +			break;
   1.190 +			}
   1.191 +		}
   1.192 +	
   1.193 +	DP0_RET(err, "%d");
   1.194 +	}
   1.195 +
   1.196 +// ---------------------------------------------------------------------------
   1.197 +// from class MAudioGainControl
   1.198 +// CAudioGainControl::SetGain
   1.199 +// ---------------------------------------------------------------------------
   1.200 +TInt CAudioGainControl::SetGain( RArray<TAudioChannelGain>& /*aChannels*/, TUid /*aRampOperation*/, 
   1.201 +	const TTimeIntervalMicroSeconds& /*aRampDuration*/)
   1.202 +	{
   1.203 +	DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
   1.204 +	DP_IN();
   1.205 +	__ASSERT_DEBUG(EFalse, Panic(EAdaptationOldSetGainCalledPanic));
   1.206 +	DP0_RET(KErrNone, "%d");
   1.207 +	}
   1.208 +
   1.209 +// ---------------------------------------------------------------------------
   1.210 +// from class MAudioGainControl
   1.211 +// CAudioGainControl::SetGain
   1.212 +// ---------------------------------------------------------------------------
   1.213 +TInt CAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
   1.214 +	{
   1.215 +	DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
   1.216 +	DP_IN();
   1.217 +	TInt err = KErrNone;
   1.218 +
   1.219 +	// Keep array cache
   1.220 +	iGains.Reset();
   1.221 +	TUint count = aChannels.Count();
   1.222 +	for (TUint i(0); i < count; i++)
   1.223 +		{
   1.224 +		err = iGains.Append(aChannels[i]);
   1.225 +		if(err != KErrNone)
   1.226 +			{
   1.227 +			break;
   1.228 +			}
   1.229 +		}
   1.230 +
   1.231 +	// Apply gain
   1.232 +	if(iHelper && err == KErrNone)
   1.233 +		{
   1.234 +		err = iHelper->SetGain(aChannels);
   1.235 +		}
   1.236 +	DP0_RET(KErrNone, "%d");
   1.237 +	}
   1.238 +
   1.239 +// ---------------------------------------------------------------------------
   1.240 +// from class MAudioGainControl
   1.241 +// CAudioGainControl::RegisterAudioGainControlObserver
   1.242 +// ---------------------------------------------------------------------------
   1.243 +TInt CAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
   1.244 +	{
   1.245 +	DP_CONTEXT(CAudioGainControl::RegisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
   1.246 +	DP_IN();
   1.247 +	TInt err = iGainObservers.Find(&aObserver);
   1.248 +	if(err == KErrNotFound)
   1.249 +		{
   1.250 +		err = iGainObservers.Append(&aObserver);
   1.251 +		}
   1.252 +	else
   1.253 +		{
   1.254 +		err = KErrAlreadyExists;
   1.255 +		}
   1.256 +	DP0_RET(err, "%d");
   1.257 +	}
   1.258 +
   1.259 +// ---------------------------------------------------------------------------
   1.260 +// from class MAudioGainControl
   1.261 +// CAudioGainControl::UnregisterAudioGainControlObserver
   1.262 +// ---------------------------------------------------------------------------
   1.263 +void CAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
   1.264 +	{
   1.265 +	DP_CONTEXT(CAudioGainControl::UnregisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
   1.266 +	DP_IN();
   1.267 +	TInt idxOrErr = iGainObservers.Find(&aObserver);
   1.268 +	if( idxOrErr != KErrNotFound )
   1.269 +		{
   1.270 +		iGainObservers.Remove(idxOrErr);
   1.271 +		}
   1.272 +	DP_OUT();
   1.273 +	}
   1.274 +
   1.275 +// end of file