os/mm/mmhais/a3facl/src/audiogaincontrol/logicalaudiogaincontrol.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-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
// Name        : audiogaincontrol.cpp
sl@0
    15
// Part of     : ACL Logical layer
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
#include "logicalaudiogaincontrol.h"
sl@0
    21
#include <a3f/audioprocessingunittypeuids.h>
sl@0
    22
#include <ecom/implementationproxy.h> // For making it ECom plugin
sl@0
    23
sl@0
    24
// ======== LOCAL FUNCTIONS ========
sl@0
    25
// __________________________________________________________________________
sl@0
    26
// Exported proxy for instantiation method resolution
sl@0
    27
// Define the interface UIDs
sl@0
    28
sl@0
    29
// Moved from header 
sl@0
    30
const TInt KDefaultMaxRampTime = 10;
sl@0
    31
sl@0
    32
const TImplementationProxy ImplementationTable[] = 
sl@0
    33
	{
sl@0
    34
	IMPLEMENTATION_PROXY_ENTRY(KAudioGainControlUid, CLogicalAudioGainControl::NewL)
sl@0
    35
	};
sl@0
    36
sl@0
    37
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
    38
	{
sl@0
    39
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
    40
	return ImplementationTable;
sl@0
    41
	}
sl@0
    42
sl@0
    43
// ---------------------------------------------------------------------------
sl@0
    44
// Constructor
sl@0
    45
// ---------------------------------------------------------------------------
sl@0
    46
//
sl@0
    47
CLogicalAudioGainControl::CLogicalAudioGainControl(TAny* aParam) : CAudioProcessingUnit(aParam)
sl@0
    48
	{
sl@0
    49
	TRACE_CREATE();
sl@0
    50
	DP_CONTEXT(CLogicalAudioGainControl::CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
sl@0
    51
	DP_IN();
sl@0
    52
	
sl@0
    53
	iMaxRampTime = KDefaultMaxRampTime;
sl@0
    54
	
sl@0
    55
	DP_OUT();
sl@0
    56
	}
sl@0
    57
sl@0
    58
// ---------------------------------------------------------------------------
sl@0
    59
// Factory method
sl@0
    60
// ---------------------------------------------------------------------------
sl@0
    61
//
sl@0
    62
CLogicalAudioGainControl* CLogicalAudioGainControl::NewL(TAny* aParam)
sl@0
    63
	{
sl@0
    64
	DP_STATIC_CONTEXT(CLogicalAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL);
sl@0
    65
	DP_IN();
sl@0
    66
	CLogicalAudioGainControl* self = new(ELeave)CLogicalAudioGainControl(aParam);
sl@0
    67
	CleanupStack::PushL(self);
sl@0
    68
	self->ConstructL();
sl@0
    69
	CleanupStack::Pop(self);
sl@0
    70
	DP0_RET(self, "0x%x");
sl@0
    71
	}
sl@0
    72
sl@0
    73
// ---------------------------------------------------------------------------
sl@0
    74
// Second phase constructor
sl@0
    75
// ---------------------------------------------------------------------------
sl@0
    76
//
sl@0
    77
void CLogicalAudioGainControl::ConstructL()
sl@0
    78
	{
sl@0
    79
	DP_CONTEXT(CLogicalAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
sl@0
    80
	DP_IN();
sl@0
    81
	TAudioChannelGain left;
sl@0
    82
	TAudioChannelGain right;
sl@0
    83
	left.iLocation = TAudioChannelGain::ELeft;
sl@0
    84
	right.iLocation = TAudioChannelGain::ERight;
sl@0
    85
	iDesiredChannels.AppendL(left);
sl@0
    86
	iDesiredChannels.AppendL(right);
sl@0
    87
	DP_OUT();
sl@0
    88
	}
sl@0
    89
sl@0
    90
// ---------------------------------------------------------------------------
sl@0
    91
// Destructor
sl@0
    92
// ---------------------------------------------------------------------------
sl@0
    93
//
sl@0
    94
CLogicalAudioGainControl::~CLogicalAudioGainControl()
sl@0
    95
	{
sl@0
    96
	DP_CONTEXT(CLogicalAudioGainControl::~CLogicalAudioGainControl *CD1*, CtxDevSound, DPLOCAL);
sl@0
    97
	DP_IN();
sl@0
    98
	iActiveChannels.Close();
sl@0
    99
	iDesiredChannels.Close();
sl@0
   100
	iGainObservers.Close();
sl@0
   101
	DP_OUT();
sl@0
   102
	}
sl@0
   103
sl@0
   104
// ---------------------------------------------------------------------------
sl@0
   105
// from class MAudioGainControl
sl@0
   106
// CLogicalAudioGainControl::GetMaxGain
sl@0
   107
// ---------------------------------------------------------------------------
sl@0
   108
//
sl@0
   109
TInt CLogicalAudioGainControl::GetMaxGain(TInt& aMaxGain) const
sl@0
   110
	{
sl@0
   111
	DP_CONTEXT(CLogicalAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL);
sl@0
   112
	DP_IN();
sl@0
   113
	// TODO: Fix this when the MMRC server is available
sl@0
   114
	// This adaptationGain pointer will be replaced by the a pointer gotten from 
sl@0
   115
	// the "control mechanism" provided by the real MMRC server
sl@0
   116
	TInt err = KErrNotReady;
sl@0
   117
	if(iAdaptationGain)
sl@0
   118
		{
sl@0
   119
		err = iAdaptationGain->GetMaxGain(aMaxGain);
sl@0
   120
		}
sl@0
   121
	DP0_RET(err, "%d");
sl@0
   122
	}
sl@0
   123
sl@0
   124
// ---------------------------------------------------------------------------
sl@0
   125
// from class MAudioGainControl
sl@0
   126
// CLogicalAudioGainControl::GetMaxRampTime
sl@0
   127
// ---------------------------------------------------------------------------
sl@0
   128
//
sl@0
   129
TInt CLogicalAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const
sl@0
   130
	{
sl@0
   131
	DP_CONTEXT(CLogicalAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL);
sl@0
   132
	DP_IN();
sl@0
   133
	TInt err = KErrNone;
sl@0
   134
	aMaxRampTime = KDefaultMaxRampTime;
sl@0
   135
	if(iAdaptationGain)
sl@0
   136
		{
sl@0
   137
		err = iAdaptationGain->GetMaxRampTime(aMaxRampTime);
sl@0
   138
		}
sl@0
   139
	DP0_RET(err, "%d");
sl@0
   140
	} 
sl@0
   141
sl@0
   142
// ---------------------------------------------------------------------------
sl@0
   143
// from class MAudioGainControl
sl@0
   144
// CLogicalAudioGainControl::GetGain
sl@0
   145
// ---------------------------------------------------------------------------
sl@0
   146
//
sl@0
   147
TInt CLogicalAudioGainControl::GetGain(RArray<TAudioChannelGain>& aChannels) const
sl@0
   148
	{
sl@0
   149
	DP_CONTEXT(CLogicalAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL);
sl@0
   150
	DP_IN();
sl@0
   151
	TInt err = KErrNone;
sl@0
   152
	TInt count = iDesiredChannels.Count();
sl@0
   153
	aChannels.Reset();
sl@0
   154
	for (TUint i(0); i < count; i++)
sl@0
   155
		{
sl@0
   156
		TInt err = aChannels.Append(iDesiredChannels[i]);
sl@0
   157
		}
sl@0
   158
	DP0_RET(err, "%d");
sl@0
   159
	}
sl@0
   160
sl@0
   161
// ---------------------------------------------------------------------------
sl@0
   162
// from class MAudioGainControl
sl@0
   163
// CLogicalAudioGainControl::SetGain
sl@0
   164
// ---------------------------------------------------------------------------
sl@0
   165
//
sl@0
   166
TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels, TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration)
sl@0
   167
	{
sl@0
   168
	DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
sl@0
   169
	DP_IN();
sl@0
   170
	TInt err = KErrNone;
sl@0
   171
sl@0
   172
	iDesiredRampTime = static_cast<TInt>(aRampDuration.Int64());
sl@0
   173
	iDesiredRampOperation = aRampOperation;
sl@0
   174
sl@0
   175
	// The gain values are clippped to MaxGain. 
sl@0
   176
	TInt a3fMaxGain = 0;
sl@0
   177
	if(iAdaptationGain)
sl@0
   178
		{
sl@0
   179
		err = iAdaptationGain->GetMaxGain(a3fMaxGain);
sl@0
   180
		}
sl@0
   181
sl@0
   182
	if(err == KErrNone)
sl@0
   183
		{
sl@0
   184
		iDesiredChannels.Reset();
sl@0
   185
		TUint count = aChannels.Count();
sl@0
   186
		TAudioChannelGain gainChannel;
sl@0
   187
		for (TUint i(0); i < count; i++)
sl@0
   188
			{
sl@0
   189
			gainChannel = aChannels[i];
sl@0
   190
			// 
sl@0
   191
			if(gainChannel.iGain > a3fMaxGain)
sl@0
   192
				{
sl@0
   193
				gainChannel.iGain = a3fMaxGain;
sl@0
   194
				}
sl@0
   195
			else if(gainChannel.iGain < 0)
sl@0
   196
				{
sl@0
   197
				err = KErrArgument;
sl@0
   198
				break;
sl@0
   199
				}
sl@0
   200
			
sl@0
   201
			err = iDesiredChannels.Append( gainChannel );
sl@0
   202
			if(err != KErrNone)
sl@0
   203
				{
sl@0
   204
				break;
sl@0
   205
				}
sl@0
   206
			}
sl@0
   207
		}
sl@0
   208
sl@0
   209
	if(err == KErrNone)
sl@0
   210
		{
sl@0
   211
		if(iSettingsObserver)
sl@0
   212
			{
sl@0
   213
			iSettingsObserver->ReceiveComponentSettingsChange(iType, EComponentAlterationGain);
sl@0
   214
			}
sl@0
   215
		}
sl@0
   216
sl@0
   217
	DP0_RET(err, "%d");
sl@0
   218
	}
sl@0
   219
sl@0
   220
// ---------------------------------------------------------------------------
sl@0
   221
// from class MAudioGainControl
sl@0
   222
// CLogicalAudioGainControl::SetGain
sl@0
   223
// ---------------------------------------------------------------------------
sl@0
   224
//
sl@0
   225
TInt CLogicalAudioGainControl::SetGain(RArray<TAudioChannelGain>& aChannels)
sl@0
   226
	{
sl@0
   227
	DP_CONTEXT(CLogicalAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL);
sl@0
   228
	DP_IN();
sl@0
   229
	TInt err = KErrNone;
sl@0
   230
	err = SetGain(aChannels, KNullUid, 0);
sl@0
   231
	DP0_RET(err, "%d");
sl@0
   232
	}
sl@0
   233
sl@0
   234
// ---------------------------------------------------------------------------
sl@0
   235
// from class MAudioGainControl
sl@0
   236
// CLogicalAudioGainControl::RegisterAudioGainControlObserver
sl@0
   237
// ---------------------------------------------------------------------------
sl@0
   238
//
sl@0
   239
TInt CLogicalAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
sl@0
   240
	{
sl@0
   241
	DP_CONTEXT(CLogicalAudioGainControl::RegisterAudioGainControlObserver *CD1*, CtxDevSound, DPLOCAL);
sl@0
   242
	DP_IN();
sl@0
   243
	TInt err = iGainObservers.Find(&aObserver);
sl@0
   244
	if( err != KErrNotFound )
sl@0
   245
		{
sl@0
   246
		err = KErrAlreadyExists;
sl@0
   247
		}
sl@0
   248
	else
sl@0
   249
		{
sl@0
   250
		err = iGainObservers.Append(&aObserver);
sl@0
   251
		}
sl@0
   252
	DP0_RET(err, "%d");
sl@0
   253
	}
sl@0
   254
sl@0
   255
// ---------------------------------------------------------------------------
sl@0
   256
// from class MAudioGainControl
sl@0
   257
// CLogicalAudioGainControl::UnregisterAudioGainControlObserver
sl@0
   258
// ---------------------------------------------------------------------------
sl@0
   259
//
sl@0
   260
void CLogicalAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver)
sl@0
   261
	{
sl@0
   262
	DP_CONTEXT(CLogicalAudioGainControl::UnregisterAudioGainControlObserver *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
// ---------------------------------------------------------------------------
sl@0
   273
// from class MAudioProcessingUnit
sl@0
   274
// CLogicalAudioGainControl::IsTypeOf
sl@0
   275
// ---------------------------------------------------------------------------
sl@0
   276
TBool CLogicalAudioGainControl::IsTypeOf(TUid aTypeId) const
sl@0
   277
	{
sl@0
   278
	DP_CONTEXT(CLogicalAudioGainControl::IsTypeOf *CD1*, CtxDevSound, DPLOCAL);
sl@0
   279
	DP_IN();
sl@0
   280
	TBool result = EFalse;
sl@0
   281
	if (iType == aTypeId)
sl@0
   282
		{
sl@0
   283
		result = ETrue;
sl@0
   284
		}
sl@0
   285
	DP0_RET(result, "%d");
sl@0
   286
	}
sl@0
   287
sl@0
   288
// ---------------------------------------------------------------------------
sl@0
   289
// from class MAudioProcessingUnit
sl@0
   290
// CLogicalAudioGainControl::Interface
sl@0
   291
// ---------------------------------------------------------------------------
sl@0
   292
TAny* CLogicalAudioGainControl::Interface(TUid aType)
sl@0
   293
	{
sl@0
   294
	DP_CONTEXT(CLogicalAudioGainControl::GetInterface *CD1*, CtxDevSound, DPLOCAL);
sl@0
   295
	DP_IN();
sl@0
   296
	MAudioGainControl* ptr = NULL;
sl@0
   297
	if(aType==KUidAudioGainControl)
sl@0
   298
		{
sl@0
   299
		ptr = this;
sl@0
   300
		}
sl@0
   301
	DP_OUT();
sl@0
   302
	return ptr;
sl@0
   303
	}
sl@0
   304
sl@0
   305
// ---------------------------------------------------------------------------
sl@0
   306
// from class MAudioGainControlObserver
sl@0
   307
// CLogicalAudioGainControl::MaxRampTimeChanged
sl@0
   308
// ---------------------------------------------------------------------------
sl@0
   309
void CLogicalAudioGainControl::MaxRampTimeChanged(MAudioGainControl& /*aGain*/)
sl@0
   310
	{
sl@0
   311
	DP_CONTEXT(CLogicalAudioGainControl::MaxRampTimeChanged *CD1*, CtxDevSound, DPLOCAL);
sl@0
   312
	DP_IN();
sl@0
   313
	TUint count = iGainObservers.Count();
sl@0
   314
	for ( TUint idx(0); idx < count; idx++ )
sl@0
   315
		{
sl@0
   316
		iGainObservers[idx]->MaxRampTimeChanged(*this);
sl@0
   317
		}
sl@0
   318
	DP_OUT();
sl@0
   319
	}
sl@0
   320
sl@0
   321
// ---------------------------------------------------------------------------
sl@0
   322
// from class MAudioGainControlObserver
sl@0
   323
// CLogicalAudioGainControl::MaxGainChanged
sl@0
   324
// ---------------------------------------------------------------------------
sl@0
   325
void CLogicalAudioGainControl::MaxGainChanged(MAudioGainControl& /*aGain*/)
sl@0
   326
	{
sl@0
   327
	DP_CONTEXT(CLogicalAudioGainControl::MaxGainChanged *CD1*, CtxDevSound, DPLOCAL);
sl@0
   328
	DP_IN();
sl@0
   329
	TUint count = iGainObservers.Count();
sl@0
   330
	for ( TUint idx(0); idx < count; idx++ )
sl@0
   331
		{
sl@0
   332
		iGainObservers[idx]->MaxGainChanged(*this);
sl@0
   333
		}
sl@0
   334
	DP_OUT();
sl@0
   335
	}
sl@0
   336
sl@0
   337
// ---------------------------------------------------------------------------
sl@0
   338
// from class MAudioGainControlObserver
sl@0
   339
// CLogicalAudioGainControl::GainChanged
sl@0
   340
// ---------------------------------------------------------------------------
sl@0
   341
void CLogicalAudioGainControl::GainChanged(MAudioGainControl& /*aGain*/, TInt aError)
sl@0
   342
	{
sl@0
   343
	DP_CONTEXT(CLogicalAudioGainControl::GainChanged *CD1*, CtxDevSound, DPLOCAL);
sl@0
   344
	DP_IN();
sl@0
   345
	TUint count = iDesiredChannels.Count();
sl@0
   346
	iActiveChannels.Reset();
sl@0
   347
	for(TUint i=0; i<count; i++)
sl@0
   348
		{
sl@0
   349
		iActiveChannels.Append(iDesiredChannels[i]);
sl@0
   350
		}
sl@0
   351
	count = iGainObservers.Count();
sl@0
   352
	for ( TUint idx(0); idx < count; idx++ )
sl@0
   353
		{
sl@0
   354
		iGainObservers[idx]->GainChanged(*this, aError);
sl@0
   355
		}
sl@0
   356
	DP_OUT();
sl@0
   357
	}