1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmhais/a3facl/src/audiogaincontrol/logicalaudiogaincontrol.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,357 @@
1.4 +// Copyright (c) 2004-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 +// Name : audiogaincontrol.cpp
1.18 +// Part of : ACL Logical layer
1.19 +//
1.20 +
1.21 +
1.22 +
1.23 +#include "logicalaudiogaincontrol.h"
1.24 +#include <a3f/audioprocessingunittypeuids.h>
1.25 +#include <ecom/implementationproxy.h> // For making it ECom plugin
1.26 +
1.27 +// ======== LOCAL FUNCTIONS ========
1.28 +// __________________________________________________________________________
1.29 +// Exported proxy for instantiation method resolution
1.30 +// Define the interface UIDs
1.31 +
1.32 +// Moved from header
1.33 +const TInt KDefaultMaxRampTime = 10;
1.34 +
1.35 +const TImplementationProxy ImplementationTable[] =
1.36 + {
1.37 + IMPLEMENTATION_PROXY_ENTRY(KAudioGainControlUid, CLogicalAudioGainControl::NewL)
1.38 + };
1.39 +
1.40 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
1.41 + {
1.42 + aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
1.43 + return ImplementationTable;
1.44 + }
1.45 +
1.46 +// ---------------------------------------------------------------------------
1.47 +// Constructor
1.48 +// ---------------------------------------------------------------------------
1.49 +//
1.50 +CLogicalAudioGainControl::CLogicalAudioGainControl(TAny* aParam) : CAudioProcessingUnit(aParam)
1.51 + {
1.52 + TRACE_CREATE();
1.53 + DP_CONTEXT(CLogicalAudioGainControl::CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
1.54 + DP_IN();
1.55 +
1.56 + iMaxRampTime = KDefaultMaxRampTime;
1.57 +
1.58 + DP_OUT();
1.59 + }
1.60 +
1.61 +// ---------------------------------------------------------------------------
1.62 +// Factory method
1.63 +// ---------------------------------------------------------------------------
1.64 +//
1.65 +CLogicalAudioGainControl* CLogicalAudioGainControl::NewL(TAny* aParam)
1.66 + {
1.67 + DP_STATIC_CONTEXT(CLogicalAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
1.68 + DP_IN();
1.69 + CLogicalAudioGainControl* self = new(ELeave)CLogicalAudioGainControl(aParam);
1.70 + CleanupStack::PushL(self);
1.71 + self->ConstructL();
1.72 + CleanupStack::Pop(self);
1.73 + DP0_RET(self, "0x%x");
1.74 + }
1.75 +
1.76 +// ---------------------------------------------------------------------------
1.77 +// Second phase constructor
1.78 +// ---------------------------------------------------------------------------
1.79 +//
1.80 +void CLogicalAudioGainControl::ConstructL()
1.81 + {
1.82 + DP_CONTEXT(CLogicalAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
1.83 + DP_IN();
1.84 + TAudioChannelGain left;
1.85 + TAudioChannelGain right;
1.86 + left.iLocation = TAudioChannelGain::ELeft;
1.87 + right.iLocation = TAudioChannelGain::ERight;
1.88 + iDesiredChannels.AppendL(left);
1.89 + iDesiredChannels.AppendL(right);
1.90 + DP_OUT();
1.91 + }
1.92 +
1.93 +// ---------------------------------------------------------------------------
1.94 +// Destructor
1.95 +// ---------------------------------------------------------------------------
1.96 +//
1.97 +CLogicalAudioGainControl::~CLogicalAudioGainControl()
1.98 + {
1.99 + DP_CONTEXT(CLogicalAudioGainControl::~CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
1.100 + DP_IN();
1.101 + iActiveChannels.Close();
1.102 + iDesiredChannels.Close();
1.103 + iGainObservers.Close();
1.104 + DP_OUT();
1.105 + }
1.106 +
1.107 +// ---------------------------------------------------------------------------
1.108 +// from class MAudioGainControl
1.109 +// CLogicalAudioGainControl::GetMaxGain
1.110 +// ---------------------------------------------------------------------------
1.111 +//
1.112 +TInt CLogicalAudioGainControl::GetMaxGain(TInt& aMaxGain) const
1.113 + {
1.114 + DP_CONTEXT(CLogicalAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
1.115 + DP_IN();
1.116 + // TODO: Fix this when the MMRC server is available
1.117 + // This adaptationGain pointer will be replaced by the a pointer gotten from
1.118 + // the "control mechanism" provided by the real MMRC server
1.119 + TInt err = KErrNotReady;
1.120 + if(iAdaptationGain)
1.121 + {
1.122 + err = iAdaptationGain->GetMaxGain(aMaxGain);
1.123 + }
1.124 + DP0_RET(err, "%d");
1.125 + }
1.126 +
1.127 +// ---------------------------------------------------------------------------
1.128 +// from class MAudioGainControl
1.129 +// CLogicalAudioGainControl::GetMaxRampTime
1.130 +// ---------------------------------------------------------------------------
1.131 +//
1.132 +TInt CLogicalAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
1.133 + {
1.134 + DP_CONTEXT(CLogicalAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
1.135 + DP_IN();
1.136 + TInt err = KErrNone;
1.137 + aMaxRampTime = KDefaultMaxRampTime;
1.138 + if(iAdaptationGain)
1.139 + {
1.140 + err = iAdaptationGain->GetMaxRampTime(aMaxRampTime);
1.141 + }
1.142 + DP0_RET(err, "%d");
1.143 + }
1.144 +
1.145 +// ---------------------------------------------------------------------------
1.146 +// from class MAudioGainControl
1.147 +// CLogicalAudioGainControl::GetGain
1.148 +// ---------------------------------------------------------------------------
1.149 +//
1.150 +TInt CLogicalAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
1.151 + {
1.152 + DP_CONTEXT(CLogicalAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
1.153 + DP_IN();
1.154 + TInt err = KErrNone;
1.155 + TInt count = iDesiredChannels.Count();
1.156 + aChannels.Reset();
1.157 + for (TUint i(0); i < count; i++)
1.158 + {
1.159 + TInt err = aChannels.Append(iDesiredChannels[i]);
1.160 + }
1.161 + DP0_RET(err, "%d");
1.162 + }
1.163 +
1.164 +// ---------------------------------------------------------------------------
1.165 +// from class MAudioGainControl
1.166 +// CLogicalAudioGainControl::SetGain
1.167 +// ---------------------------------------------------------------------------
1.168 +//
1.169 +TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels, TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
1.170 + {
1.171 + DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
1.172 + DP_IN();
1.173 + TInt err = KErrNone;
1.174 +
1.175 + iDesiredRampTime = static_cast<TInt>(aRampDuration.Int64());
1.176 + iDesiredRampOperation = aRampOperation;
1.177 +
1.178 + // The gain values are clippped to MaxGain.
1.179 + TInt a3fMaxGain = 0;
1.180 + if(iAdaptationGain)
1.181 + {
1.182 + err = iAdaptationGain->GetMaxGain(a3fMaxGain);
1.183 + }
1.184 +
1.185 + if(err == KErrNone)
1.186 + {
1.187 + iDesiredChannels.Reset();
1.188 + TUint count = aChannels.Count();
1.189 + TAudioChannelGain gainChannel;
1.190 + for (TUint i(0); i < count; i++)
1.191 + {
1.192 + gainChannel = aChannels[i];
1.193 + //
1.194 + if(gainChannel.iGain > a3fMaxGain)
1.195 + {
1.196 + gainChannel.iGain = a3fMaxGain;
1.197 + }
1.198 + else if(gainChannel.iGain < 0)
1.199 + {
1.200 + err = KErrArgument;
1.201 + break;
1.202 + }
1.203 +
1.204 + err = iDesiredChannels.Append( gainChannel );
1.205 + if(err != KErrNone)
1.206 + {
1.207 + break;
1.208 + }
1.209 + }
1.210 + }
1.211 +
1.212 + if(err == KErrNone)
1.213 + {
1.214 + if(iSettingsObserver)
1.215 + {
1.216 + iSettingsObserver->ReceiveComponentSettingsChange(iType, EComponentAlterationGain);
1.217 + }
1.218 + }
1.219 +
1.220 + DP0_RET(err, "%d");
1.221 + }
1.222 +
1.223 +// ---------------------------------------------------------------------------
1.224 +// from class MAudioGainControl
1.225 +// CLogicalAudioGainControl::SetGain
1.226 +// ---------------------------------------------------------------------------
1.227 +//
1.228 +TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
1.229 + {
1.230 + DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
1.231 + DP_IN();
1.232 + TInt err = KErrNone;
1.233 + err = SetGain(aChannels, KNullUid, 0);
1.234 + DP0_RET(err, "%d");
1.235 + }
1.236 +
1.237 +// ---------------------------------------------------------------------------
1.238 +// from class MAudioGainControl
1.239 +// CLogicalAudioGainControl::RegisterAudioGainControlObserver
1.240 +// ---------------------------------------------------------------------------
1.241 +//
1.242 +TInt CLogicalAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
1.243 + {
1.244 + DP_CONTEXT(CLogicalAudioGainControl::RegisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL);
1.245 + DP_IN();
1.246 + TInt err = iGainObservers.Find(&aObserver);
1.247 + if( err != KErrNotFound )
1.248 + {
1.249 + err = KErrAlreadyExists;
1.250 + }
1.251 + else
1.252 + {
1.253 + err = iGainObservers.Append(&aObserver);
1.254 + }
1.255 + DP0_RET(err, "%d");
1.256 + }
1.257 +
1.258 +// ---------------------------------------------------------------------------
1.259 +// from class MAudioGainControl
1.260 +// CLogicalAudioGainControl::UnregisterAudioGainControlObserver
1.261 +// ---------------------------------------------------------------------------
1.262 +//
1.263 +void CLogicalAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
1.264 + {
1.265 + DP_CONTEXT(CLogicalAudioGainControl::UnregisterAudioGainControlObserver *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 +// ---------------------------------------------------------------------------
1.276 +// from class MAudioProcessingUnit
1.277 +// CLogicalAudioGainControl::IsTypeOf
1.278 +// ---------------------------------------------------------------------------
1.279 +TBool CLogicalAudioGainControl::IsTypeOf(TUid aTypeId) const
1.280 + {
1.281 + DP_CONTEXT(CLogicalAudioGainControl::IsTypeOf *CD1*, CtxDevSound, DPLOCAL);
1.282 + DP_IN();
1.283 + TBool result = EFalse;
1.284 + if (iType == aTypeId)
1.285 + {
1.286 + result = ETrue;
1.287 + }
1.288 + DP0_RET(result, "%d");
1.289 + }
1.290 +
1.291 +// ---------------------------------------------------------------------------
1.292 +// from class MAudioProcessingUnit
1.293 +// CLogicalAudioGainControl::Interface
1.294 +// ---------------------------------------------------------------------------
1.295 +TAny* CLogicalAudioGainControl::Interface(TUid aType)
1.296 + {
1.297 + DP_CONTEXT(CLogicalAudioGainControl::GetInterface *CD1*, CtxDevSound, DPLOCAL);
1.298 + DP_IN();
1.299 + MAudioGainControl* ptr = NULL;
1.300 + if(aType==KUidAudioGainControl)
1.301 + {
1.302 + ptr = this;
1.303 + }
1.304 + DP_OUT();
1.305 + return ptr;
1.306 + }
1.307 +
1.308 +// ---------------------------------------------------------------------------
1.309 +// from class MAudioGainControlObserver
1.310 +// CLogicalAudioGainControl::MaxRampTimeChanged
1.311 +// ---------------------------------------------------------------------------
1.312 +void CLogicalAudioGainControl::MaxRampTimeChanged(MAudioGainControl& /*aGain*/)
1.313 + {
1.314 + DP_CONTEXT(CLogicalAudioGainControl::MaxRampTimeChanged *CD1*, CtxDevSound, DPLOCAL);
1.315 + DP_IN();
1.316 + TUint count = iGainObservers.Count();
1.317 + for ( TUint idx(0); idx < count; idx++ )
1.318 + {
1.319 + iGainObservers[idx]->MaxRampTimeChanged(*this);
1.320 + }
1.321 + DP_OUT();
1.322 + }
1.323 +
1.324 +// ---------------------------------------------------------------------------
1.325 +// from class MAudioGainControlObserver
1.326 +// CLogicalAudioGainControl::MaxGainChanged
1.327 +// ---------------------------------------------------------------------------
1.328 +void CLogicalAudioGainControl::MaxGainChanged(MAudioGainControl& /*aGain*/)
1.329 + {
1.330 + DP_CONTEXT(CLogicalAudioGainControl::MaxGainChanged *CD1*, CtxDevSound, DPLOCAL);
1.331 + DP_IN();
1.332 + TUint count = iGainObservers.Count();
1.333 + for ( TUint idx(0); idx < count; idx++ )
1.334 + {
1.335 + iGainObservers[idx]->MaxGainChanged(*this);
1.336 + }
1.337 + DP_OUT();
1.338 + }
1.339 +
1.340 +// ---------------------------------------------------------------------------
1.341 +// from class MAudioGainControlObserver
1.342 +// CLogicalAudioGainControl::GainChanged
1.343 +// ---------------------------------------------------------------------------
1.344 +void CLogicalAudioGainControl::GainChanged(MAudioGainControl& /*aGain*/, TInt aError)
1.345 + {
1.346 + DP_CONTEXT(CLogicalAudioGainControl::GainChanged *CD1*, CtxDevSound, DPLOCAL);
1.347 + DP_IN();
1.348 + TUint count = iDesiredChannels.Count();
1.349 + iActiveChannels.Reset();
1.350 + for(TUint i=0; i<count; i++)
1.351 + {
1.352 + iActiveChannels.Append(iDesiredChannels[i]);
1.353 + }
1.354 + count = iGainObservers.Count();
1.355 + for ( TUint idx(0); idx < count; idx++ )
1.356 + {
1.357 + iGainObservers[idx]->GainChanged(*this, aError);
1.358 + }
1.359 + DP_OUT();
1.360 + }