First public contribution.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : audiogaincontrol.cpp
15 // Part of : ACL Logical layer
20 #include "logicalaudiogaincontrol.h"
21 #include <a3f/audioprocessingunittypeuids.h>
22 #include <ecom/implementationproxy.h> // For making it ECom plugin
24 // ======== LOCAL FUNCTIONS ========
25 // __________________________________________________________________________
26 // Exported proxy for instantiation method resolution
27 // Define the interface UIDs
30 const TInt KDefaultMaxRampTime = 10;
32 const TImplementationProxy ImplementationTable[] =
34 IMPLEMENTATION_PROXY_ENTRY(KAudioGainControlUid, CLogicalAudioGainControl::NewL)
37 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
39 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
40 return ImplementationTable;
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 CLogicalAudioGainControl::CLogicalAudioGainControl(TAny* aParam) : CAudioProcessingUnit(aParam)
50 DP_CONTEXT(CLogicalAudioGainControl::CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
53 iMaxRampTime = KDefaultMaxRampTime;
58 // ---------------------------------------------------------------------------
60 // ---------------------------------------------------------------------------
62 CLogicalAudioGainControl* CLogicalAudioGainControl::NewL(TAny* aParam)
64 DP_STATIC_CONTEXT(CLogicalAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
66 CLogicalAudioGainControl* self = new(ELeave)CLogicalAudioGainControl(aParam);
67 CleanupStack::PushL(self);
69 CleanupStack::Pop(self);
70 DP0_RET(self, "0x%x");
73 // ---------------------------------------------------------------------------
74 // Second phase constructor
75 // ---------------------------------------------------------------------------
77 void CLogicalAudioGainControl::ConstructL()
79 DP_CONTEXT(CLogicalAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
81 TAudioChannelGain left;
82 TAudioChannelGain right;
83 left.iLocation = TAudioChannelGain::ELeft;
84 right.iLocation = TAudioChannelGain::ERight;
85 iDesiredChannels.AppendL(left);
86 iDesiredChannels.AppendL(right);
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 CLogicalAudioGainControl::~CLogicalAudioGainControl()
96 DP_CONTEXT(CLogicalAudioGainControl::~CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
98 iActiveChannels.Close();
99 iDesiredChannels.Close();
100 iGainObservers.Close();
104 // ---------------------------------------------------------------------------
105 // from class MAudioGainControl
106 // CLogicalAudioGainControl::GetMaxGain
107 // ---------------------------------------------------------------------------
109 TInt CLogicalAudioGainControl::GetMaxGain(TInt& aMaxGain) const
111 DP_CONTEXT(CLogicalAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
113 // TODO: Fix this when the MMRC server is available
114 // This adaptationGain pointer will be replaced by the a pointer gotten from
115 // the "control mechanism" provided by the real MMRC server
116 TInt err = KErrNotReady;
119 err = iAdaptationGain->GetMaxGain(aMaxGain);
124 // ---------------------------------------------------------------------------
125 // from class MAudioGainControl
126 // CLogicalAudioGainControl::GetMaxRampTime
127 // ---------------------------------------------------------------------------
129 TInt CLogicalAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
131 DP_CONTEXT(CLogicalAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
134 aMaxRampTime = KDefaultMaxRampTime;
137 err = iAdaptationGain->GetMaxRampTime(aMaxRampTime);
142 // ---------------------------------------------------------------------------
143 // from class MAudioGainControl
144 // CLogicalAudioGainControl::GetGain
145 // ---------------------------------------------------------------------------
147 TInt CLogicalAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
149 DP_CONTEXT(CLogicalAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
152 TInt count = iDesiredChannels.Count();
154 for (TUint i(0); i < count; i++)
156 TInt err = aChannels.Append(iDesiredChannels[i]);
161 // ---------------------------------------------------------------------------
162 // from class MAudioGainControl
163 // CLogicalAudioGainControl::SetGain
164 // ---------------------------------------------------------------------------
166 TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels, TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
168 DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
172 iDesiredRampTime = static_cast<TInt>(aRampDuration.Int64());
173 iDesiredRampOperation = aRampOperation;
175 // The gain values are clippped to MaxGain.
179 err = iAdaptationGain->GetMaxGain(a3fMaxGain);
184 iDesiredChannels.Reset();
185 TUint count = aChannels.Count();
186 TAudioChannelGain gainChannel;
187 for (TUint i(0); i < count; i++)
189 gainChannel = aChannels[i];
191 if(gainChannel.iGain > a3fMaxGain)
193 gainChannel.iGain = a3fMaxGain;
195 else if(gainChannel.iGain < 0)
201 err = iDesiredChannels.Append( gainChannel );
211 if(iSettingsObserver)
213 iSettingsObserver->ReceiveComponentSettingsChange(iType, EComponentAlterationGain);
220 // ---------------------------------------------------------------------------
221 // from class MAudioGainControl
222 // CLogicalAudioGainControl::SetGain
223 // ---------------------------------------------------------------------------
225 TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
227 DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
230 err = SetGain(aChannels, KNullUid, 0);
234 // ---------------------------------------------------------------------------
235 // from class MAudioGainControl
236 // CLogicalAudioGainControl::RegisterAudioGainControlObserver
237 // ---------------------------------------------------------------------------
239 TInt CLogicalAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
241 DP_CONTEXT(CLogicalAudioGainControl::RegisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL);
243 TInt err = iGainObservers.Find(&aObserver);
244 if( err != KErrNotFound )
246 err = KErrAlreadyExists;
250 err = iGainObservers.Append(&aObserver);
255 // ---------------------------------------------------------------------------
256 // from class MAudioGainControl
257 // CLogicalAudioGainControl::UnregisterAudioGainControlObserver
258 // ---------------------------------------------------------------------------
260 void CLogicalAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
262 DP_CONTEXT(CLogicalAudioGainControl::UnregisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL);
264 TInt idxOrErr = iGainObservers.Find(&aObserver);
265 if( idxOrErr != KErrNotFound )
267 iGainObservers.Remove(idxOrErr);
272 // ---------------------------------------------------------------------------
273 // from class MAudioProcessingUnit
274 // CLogicalAudioGainControl::IsTypeOf
275 // ---------------------------------------------------------------------------
276 TBool CLogicalAudioGainControl::IsTypeOf(TUid aTypeId) const
278 DP_CONTEXT(CLogicalAudioGainControl::IsTypeOf *CD1*, CtxDevSound, DPLOCAL);
280 TBool result = EFalse;
281 if (iType == aTypeId)
285 DP0_RET(result, "%d");
288 // ---------------------------------------------------------------------------
289 // from class MAudioProcessingUnit
290 // CLogicalAudioGainControl::Interface
291 // ---------------------------------------------------------------------------
292 TAny* CLogicalAudioGainControl::Interface(TUid aType)
294 DP_CONTEXT(CLogicalAudioGainControl::GetInterface *CD1*, CtxDevSound, DPLOCAL);
296 MAudioGainControl* ptr = NULL;
297 if(aType==KUidAudioGainControl)
305 // ---------------------------------------------------------------------------
306 // from class MAudioGainControlObserver
307 // CLogicalAudioGainControl::MaxRampTimeChanged
308 // ---------------------------------------------------------------------------
309 void CLogicalAudioGainControl::MaxRampTimeChanged(MAudioGainControl& /*aGain*/)
311 DP_CONTEXT(CLogicalAudioGainControl::MaxRampTimeChanged *CD1*, CtxDevSound, DPLOCAL);
313 TUint count = iGainObservers.Count();
314 for ( TUint idx(0); idx < count; idx++ )
316 iGainObservers[idx]->MaxRampTimeChanged(*this);
321 // ---------------------------------------------------------------------------
322 // from class MAudioGainControlObserver
323 // CLogicalAudioGainControl::MaxGainChanged
324 // ---------------------------------------------------------------------------
325 void CLogicalAudioGainControl::MaxGainChanged(MAudioGainControl& /*aGain*/)
327 DP_CONTEXT(CLogicalAudioGainControl::MaxGainChanged *CD1*, CtxDevSound, DPLOCAL);
329 TUint count = iGainObservers.Count();
330 for ( TUint idx(0); idx < count; idx++ )
332 iGainObservers[idx]->MaxGainChanged(*this);
337 // ---------------------------------------------------------------------------
338 // from class MAudioGainControlObserver
339 // CLogicalAudioGainControl::GainChanged
340 // ---------------------------------------------------------------------------
341 void CLogicalAudioGainControl::GainChanged(MAudioGainControl& /*aGain*/, TInt aError)
343 DP_CONTEXT(CLogicalAudioGainControl::GainChanged *CD1*, CtxDevSound, DPLOCAL);
345 TUint count = iDesiredChannels.Count();
346 iActiveChannels.Reset();
347 for(TUint i=0; i<count; i++)
349 iActiveChannels.Append(iDesiredChannels[i]);
351 count = iGainObservers.Count();
352 for ( TUint idx(0); idx < count; idx++ )
354 iGainObservers[idx]->GainChanged(*this, aError);