First public contribution.
1 // Copyright (c) 2006-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.
18 #include "audiogaincontrol.h"
19 #include <a3f/audioprocessingunittypeuids.h>
21 // ======== LOCAL FUNCTIONS ========
22 void Panic(TInt aPanicCode)
24 _LIT(KAudioGainControlPanicCategory, "audiogaincontrol");
25 User::Panic(KAudioGainControlPanicCategory, aPanicCode);
28 // ======== MEMBER FUNCTIONS ========
30 // ---------------------------------------------------------------------------
32 // ---------------------------------------------------------------------------
33 CAudioGainControl::CAudioGainControl()
36 DP_CONTEXT(CAudioGainControl::CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
44 EXPORT_C CAudioGainControl* CAudioGainControl::NewL()
46 DP_STATIC_CONTEXT(CAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
48 CAudioGainControl* self = new(ELeave)CAudioGainControl();
49 CleanupStack::PushL(self);
51 CleanupStack::Pop(self);
52 DP0_RET(self, "0x%x");
55 // ---------------------------------------------------------------------------
56 // Second phase constructor
57 // ---------------------------------------------------------------------------
58 void CAudioGainControl::ConstructL()
60 DP_CONTEXT(CAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
68 CAudioGainControl::~CAudioGainControl()
70 DP_CONTEXT(CAudioGainControl::~CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
72 iGainObservers.Close();
76 EXPORT_C void CAudioGainControl::SetHelper(MGainHelper &aHelper)
80 // ---------------------------------------------------------------------------
81 // CAudioGainControl::IssueGainChangedCallBack
82 // ---------------------------------------------------------------------------
83 EXPORT_C void CAudioGainControl::IssueGainChangedCallBack(TInt aError)
85 DP_CONTEXT(CAudioGainControl::IssueGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
87 TUint count = iGainObservers.Count();
88 for(TUint i(0); i<count; i++)
90 iGainObservers[i]->GainChanged(*this, aError);
95 // ---------------------------------------------------------------------------
96 // CAudioGainControl::IssueMaxGainChangedCallBack
97 // ---------------------------------------------------------------------------
98 void CAudioGainControl::IssueMaxGainChangedCallBack()
100 DP_CONTEXT(CAudioGainControl::IssueMaxGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
102 TUint count = iGainObservers.Count();
103 for(TUint i(0); i<count; i++)
105 iGainObservers[i]->MaxGainChanged(*this);
110 // ---------------------------------------------------------------------------
111 // CAudioGainControl::IssueMaxRampTimeGainChangedCallBack
112 // ---------------------------------------------------------------------------
113 void CAudioGainControl::IssueMaxRampTimeChangedCallBack()
115 DP_CONTEXT(CAudioGainControl::IssueMaxRampTimeChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
117 TUint count = iGainObservers.Count();
118 for(TUint i(0); i<count; i++)
120 iGainObservers[i]->MaxRampTimeChanged(*this);
125 // ---------------------------------------------------------------------------
126 // CAudioGainControl::ConfigureRamp
127 // ---------------------------------------------------------------------------
128 EXPORT_C TInt CAudioGainControl::ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
130 DP_CONTEXT(CAudioGainControl::ConfigureRamp *CD1*, CtxDevSound, DPLOCAL);
137 err = iHelper->ConfigureRamp(aRampOperation, aRampDuration);
143 // ---------------------------------------------------------------------------
144 // from class MAudioGainControl
145 // CAudioGainControl::GetMaxGain
146 // ---------------------------------------------------------------------------
147 TInt CAudioGainControl::GetMaxGain(TInt& aMaxGain) const
149 DP_CONTEXT(CAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
152 aMaxGain = KDefaultMaxGain;
156 // ---------------------------------------------------------------------------
157 // from class MAudioGainControl
158 // CAudioGainControl::GetMaxRampTime
159 // ---------------------------------------------------------------------------
160 TInt CAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
162 DP_CONTEXT(CAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
164 aMaxRampTime = KDefaultMaxRampTime;
165 DP0_RET(KErrNone, "%d");
168 // ---------------------------------------------------------------------------
169 // from class MAudioGainControl
170 // CAudioGainControl::GetGain
171 // ---------------------------------------------------------------------------
172 TInt CAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
174 DP_CONTEXT(CAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
179 TInt count = iGains.Count();
181 for (TUint i(0); i < count; i++)
183 err = aChannels.Append(iGains[i]);
193 // ---------------------------------------------------------------------------
194 // from class MAudioGainControl
195 // CAudioGainControl::SetGain
196 // ---------------------------------------------------------------------------
197 TInt CAudioGainControl::SetGain( RArray<TAudioChannelGain>& /*aChannels*/, TUid /*aRampOperation*/,
198 const TTimeIntervalMicroSeconds& /*aRampDuration*/)
200 DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
202 __ASSERT_DEBUG(EFalse, Panic(EAdaptationOldSetGainCalledPanic));
203 DP0_RET(KErrNone, "%d");
206 // ---------------------------------------------------------------------------
207 // from class MAudioGainControl
208 // CAudioGainControl::SetGain
209 // ---------------------------------------------------------------------------
210 TInt CAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
212 DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
218 TUint count = aChannels.Count();
219 for (TUint i(0); i < count; i++)
221 err = iGains.Append(aChannels[i]);
229 if(iHelper && err == KErrNone)
231 err = iHelper->SetGain(aChannels);
233 DP0_RET(KErrNone, "%d");
236 // ---------------------------------------------------------------------------
237 // from class MAudioGainControl
238 // CAudioGainControl::RegisterAudioGainControlObserver
239 // ---------------------------------------------------------------------------
240 TInt CAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
242 DP_CONTEXT(CAudioGainControl::RegisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
244 TInt err = iGainObservers.Find(&aObserver);
245 if(err == KErrNotFound)
247 err = iGainObservers.Append(&aObserver);
251 err = KErrAlreadyExists;
256 // ---------------------------------------------------------------------------
257 // from class MAudioGainControl
258 // CAudioGainControl::UnregisterAudioGainControlObserver
259 // ---------------------------------------------------------------------------
260 void CAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
262 DP_CONTEXT(CAudioGainControl::UnregisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
264 TInt idxOrErr = iGainObservers.Find(&aObserver);
265 if( idxOrErr != KErrNotFound )
267 iGainObservers.Remove(idxOrErr);