os/mm/mmhais/refacladapt/src/audiogaincontrol/audiogaincontrol.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 
    18 #include "audiogaincontrol.h"
    19 #include <a3f/audioprocessingunittypeuids.h>
    20 
    21 // ======== LOCAL FUNCTIONS ========
    22 void Panic(TInt aPanicCode)
    23 	{
    24 	_LIT(KAudioGainControlPanicCategory, "audiogaincontrol");
    25 	User::Panic(KAudioGainControlPanicCategory, aPanicCode);
    26 	}
    27 
    28 // ======== MEMBER FUNCTIONS ========
    29 
    30 // ---------------------------------------------------------------------------
    31 // Constructor
    32 // ---------------------------------------------------------------------------
    33 CAudioGainControl::CAudioGainControl()
    34 	{
    35 	TRACE_CREATE();
    36 	DP_CONTEXT(CAudioGainControl::CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
    37 	DP_IN();
    38 	DP_OUT();
    39 	}
    40 
    41 // ---------------------------------------------------------------------------
    42 // Factory method
    43 // ---------------------------------------------------------------------------
    44 EXPORT_C CAudioGainControl* CAudioGainControl::NewL()
    45 	{
    46 	DP_STATIC_CONTEXT(CAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
    47 	DP_IN();
    48 	CAudioGainControl* self = new(ELeave)CAudioGainControl();
    49 	CleanupStack::PushL(self);
    50 	self->ConstructL();
    51 	CleanupStack::Pop(self);
    52 	DP0_RET(self, "0x%x");
    53 	}
    54 
    55 // ---------------------------------------------------------------------------
    56 // Second phase constructor
    57 // ---------------------------------------------------------------------------
    58 void CAudioGainControl::ConstructL()
    59 	{
    60 	DP_CONTEXT(CAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
    61 	DP_IN();
    62 	DP_OUT();
    63 	}
    64 
    65 // ---------------------------------------------------------------------------
    66 // Destructor
    67 // ---------------------------------------------------------------------------
    68 CAudioGainControl::~CAudioGainControl()
    69 	{
    70 	DP_CONTEXT(CAudioGainControl::~CAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
    71 	DP_IN();
    72 	iGainObservers.Close();
    73 	DP_OUT();
    74 	}
    75 
    76 EXPORT_C void CAudioGainControl::SetHelper(MGainHelper &aHelper)
    77 	{
    78 	iHelper = &aHelper;
    79 	}
    80 // ---------------------------------------------------------------------------
    81 // CAudioGainControl::IssueGainChangedCallBack
    82 // ---------------------------------------------------------------------------
    83 EXPORT_C void CAudioGainControl::IssueGainChangedCallBack(TInt aError)
    84 	{
    85 	DP_CONTEXT(CAudioGainControl::IssueGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
    86 	DP_IN();
    87 	TUint count = iGainObservers.Count();
    88 	for(TUint i(0); i<count; i++)
    89 		{
    90 		iGainObservers[i]->GainChanged(*this, aError);
    91 		}
    92 	DP_OUT();
    93 	}
    94 
    95 // ---------------------------------------------------------------------------
    96 // CAudioGainControl::IssueMaxGainChangedCallBack
    97 // ---------------------------------------------------------------------------
    98 void CAudioGainControl::IssueMaxGainChangedCallBack()
    99 	{
   100 	DP_CONTEXT(CAudioGainControl::IssueMaxGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
   101 	DP_IN();
   102 	TUint count = iGainObservers.Count();
   103 	for(TUint i(0); i<count; i++)
   104 		{
   105 		iGainObservers[i]->MaxGainChanged(*this);
   106 		}
   107 	DP_OUT();
   108 	}
   109 
   110 // ---------------------------------------------------------------------------
   111 // CAudioGainControl::IssueMaxRampTimeGainChangedCallBack
   112 // ---------------------------------------------------------------------------
   113 void CAudioGainControl::IssueMaxRampTimeChangedCallBack()
   114 	{
   115 	DP_CONTEXT(CAudioGainControl::IssueMaxRampTimeChangedCallBack *CD1*, CtxDevSound, DPLOCAL);
   116 	DP_IN();
   117 	TUint count = iGainObservers.Count();
   118 	for(TUint i(0); i<count; i++)
   119 		{
   120 		 iGainObservers[i]->MaxRampTimeChanged(*this);
   121 		}
   122 	DP_OUT();
   123 	}
   124 
   125 // ---------------------------------------------------------------------------
   126 // CAudioGainControl::ConfigureRamp
   127 // ---------------------------------------------------------------------------
   128 EXPORT_C TInt CAudioGainControl::ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
   129 	{
   130 	DP_CONTEXT(CAudioGainControl::ConfigureRamp *CD1*, CtxDevSound, DPLOCAL);
   131 	DP_IN();
   132 
   133 	TInt err = KErrNone;
   134 	// Apply ramp
   135 	if(iHelper)
   136 		{
   137 		err = iHelper->ConfigureRamp(aRampOperation, aRampDuration);
   138 		}
   139 		
   140 	DP0_RET(err, "%d");
   141 	}
   142 
   143 // ---------------------------------------------------------------------------
   144 // from class MAudioGainControl
   145 // CAudioGainControl::GetMaxGain
   146 // ---------------------------------------------------------------------------
   147 TInt CAudioGainControl::GetMaxGain(TInt& aMaxGain) const
   148 	{
   149 	DP_CONTEXT(CAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
   150 	DP_IN();
   151 	TInt err = KErrNone;
   152 	aMaxGain = KDefaultMaxGain;
   153 	DP0_RET(err, "%d");
   154 	}
   155 
   156 // ---------------------------------------------------------------------------
   157 // from class MAudioGainControl
   158 // CAudioGainControl::GetMaxRampTime
   159 // ---------------------------------------------------------------------------
   160 TInt CAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
   161 	{
   162 	DP_CONTEXT(CAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
   163 	DP_IN();
   164 	aMaxRampTime = KDefaultMaxRampTime;
   165 	DP0_RET(KErrNone, "%d");
   166 	} 
   167 
   168 // ---------------------------------------------------------------------------
   169 // from class MAudioGainControl
   170 // CAudioGainControl::GetGain
   171 // ---------------------------------------------------------------------------
   172 TInt CAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
   173 	{
   174 	DP_CONTEXT(CAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
   175 	DP_IN();
   176 	TInt err = KErrNone;
   177 
   178 	aChannels.Reset();
   179 	TInt count = iGains.Count();
   180 
   181 	for (TUint i(0); i < count; i++)
   182 		{
   183 		err = aChannels.Append(iGains[i]);
   184 		if(err != KErrNone)
   185 			{
   186 			break;
   187 			}
   188 		}
   189 	
   190 	DP0_RET(err, "%d");
   191 	}
   192 
   193 // ---------------------------------------------------------------------------
   194 // from class MAudioGainControl
   195 // CAudioGainControl::SetGain
   196 // ---------------------------------------------------------------------------
   197 TInt CAudioGainControl::SetGain( RArray<TAudioChannelGain>& /*aChannels*/, TUid /*aRampOperation*/, 
   198 	const TTimeIntervalMicroSeconds& /*aRampDuration*/)
   199 	{
   200 	DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
   201 	DP_IN();
   202 	__ASSERT_DEBUG(EFalse, Panic(EAdaptationOldSetGainCalledPanic));
   203 	DP0_RET(KErrNone, "%d");
   204 	}
   205 
   206 // ---------------------------------------------------------------------------
   207 // from class MAudioGainControl
   208 // CAudioGainControl::SetGain
   209 // ---------------------------------------------------------------------------
   210 TInt CAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
   211 	{
   212 	DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
   213 	DP_IN();
   214 	TInt err = KErrNone;
   215 
   216 	// Keep array cache
   217 	iGains.Reset();
   218 	TUint count = aChannels.Count();
   219 	for (TUint i(0); i < count; i++)
   220 		{
   221 		err = iGains.Append(aChannels[i]);
   222 		if(err != KErrNone)
   223 			{
   224 			break;
   225 			}
   226 		}
   227 
   228 	// Apply gain
   229 	if(iHelper && err == KErrNone)
   230 		{
   231 		err = iHelper->SetGain(aChannels);
   232 		}
   233 	DP0_RET(KErrNone, "%d");
   234 	}
   235 
   236 // ---------------------------------------------------------------------------
   237 // from class MAudioGainControl
   238 // CAudioGainControl::RegisterAudioGainControlObserver
   239 // ---------------------------------------------------------------------------
   240 TInt CAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
   241 	{
   242 	DP_CONTEXT(CAudioGainControl::RegisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
   243 	DP_IN();
   244 	TInt err = iGainObservers.Find(&aObserver);
   245 	if(err == KErrNotFound)
   246 		{
   247 		err = iGainObservers.Append(&aObserver);
   248 		}
   249 	else
   250 		{
   251 		err = KErrAlreadyExists;
   252 		}
   253 	DP0_RET(err, "%d");
   254 	}
   255 
   256 // ---------------------------------------------------------------------------
   257 // from class MAudioGainControl
   258 // CAudioGainControl::UnregisterAudioGainControlObserver
   259 // ---------------------------------------------------------------------------
   260 void CAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
   261 	{
   262 	DP_CONTEXT(CAudioGainControl::UnregisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL);
   263 	DP_IN();
   264 	TInt idxOrErr = iGainObservers.Find(&aObserver);
   265 	if( idxOrErr != KErrNotFound )
   266 		{
   267 		iGainObservers.Remove(idxOrErr);
   268 		}
   269 	DP_OUT();
   270 	}
   271 
   272 // end of file