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