sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: sl@0: #include "audiogaincontrol.h" sl@0: #include sl@0: sl@0: // ======== LOCAL FUNCTIONS ======== sl@0: void Panic(TInt aPanicCode) sl@0: { sl@0: _LIT(KAudioGainControlPanicCategory, "audiogaincontrol"); sl@0: User::Panic(KAudioGainControlPanicCategory, aPanicCode); sl@0: } sl@0: sl@0: // ======== MEMBER FUNCTIONS ======== sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructor sl@0: // --------------------------------------------------------------------------- sl@0: CAudioGainControl::CAudioGainControl() sl@0: { sl@0: TRACE_CREATE(); sl@0: DP_CONTEXT(CAudioGainControl::CAudioGainControl *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Factory method sl@0: // --------------------------------------------------------------------------- sl@0: EXPORT_C CAudioGainControl* CAudioGainControl::NewL() sl@0: { sl@0: DP_STATIC_CONTEXT(CAudioGainControl::NewL *CD0*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: CAudioGainControl* self = new(ELeave)CAudioGainControl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: DP0_RET(self, "0x%x"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Second phase constructor sl@0: // --------------------------------------------------------------------------- sl@0: void CAudioGainControl::ConstructL() sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::ConstructL *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Destructor sl@0: // --------------------------------------------------------------------------- sl@0: CAudioGainControl::~CAudioGainControl() sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::~CAudioGainControl *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: iGainObservers.Close(); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: EXPORT_C void CAudioGainControl::SetHelper(MGainHelper &aHelper) sl@0: { sl@0: iHelper = &aHelper; sl@0: } sl@0: // --------------------------------------------------------------------------- sl@0: // CAudioGainControl::IssueGainChangedCallBack sl@0: // --------------------------------------------------------------------------- sl@0: EXPORT_C void CAudioGainControl::IssueGainChangedCallBack(TInt aError) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::IssueGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iGainObservers.Count(); sl@0: for(TUint i(0); iGainChanged(*this, aError); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // CAudioGainControl::IssueMaxGainChangedCallBack sl@0: // --------------------------------------------------------------------------- sl@0: void CAudioGainControl::IssueMaxGainChangedCallBack() sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::IssueMaxGainChangedCallBack *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iGainObservers.Count(); sl@0: for(TUint i(0); iMaxGainChanged(*this); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // CAudioGainControl::IssueMaxRampTimeGainChangedCallBack sl@0: // --------------------------------------------------------------------------- sl@0: void CAudioGainControl::IssueMaxRampTimeChangedCallBack() sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::IssueMaxRampTimeChangedCallBack *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TUint count = iGainObservers.Count(); sl@0: for(TUint i(0); iMaxRampTimeChanged(*this); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // CAudioGainControl::ConfigureRamp sl@0: // --------------------------------------------------------------------------- sl@0: EXPORT_C TInt CAudioGainControl::ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::ConfigureRamp *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err = KErrNone; sl@0: // Apply ramp sl@0: if(iHelper) sl@0: { sl@0: err = iHelper->ConfigureRamp(aRampOperation, aRampDuration); sl@0: } sl@0: sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::GetMaxGain sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::GetMaxGain(TInt& aMaxGain) const sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::GetMaxGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: aMaxGain = KDefaultMaxGain; sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::GetMaxRampTime sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::GetMaxRampTime(TTimeIntervalMicroSeconds& aMaxRampTime) const sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::GetMaxRampTime *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: aMaxRampTime = KDefaultMaxRampTime; sl@0: DP0_RET(KErrNone, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::GetGain sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::GetGain(RArray& aChannels) const sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::GetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: sl@0: aChannels.Reset(); sl@0: TInt count = iGains.Count(); sl@0: sl@0: for (TUint i(0); i < count; i++) sl@0: { sl@0: err = aChannels.Append(iGains[i]); sl@0: if(err != KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::SetGain sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::SetGain( RArray& /*aChannels*/, TUid /*aRampOperation*/, sl@0: const TTimeIntervalMicroSeconds& /*aRampDuration*/) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: __ASSERT_DEBUG(EFalse, Panic(EAdaptationOldSetGainCalledPanic)); sl@0: DP0_RET(KErrNone, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::SetGain sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::SetGain(RArray& aChannels) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::SetGain *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = KErrNone; sl@0: sl@0: // Keep array cache sl@0: iGains.Reset(); sl@0: TUint count = aChannels.Count(); sl@0: for (TUint i(0); i < count; i++) sl@0: { sl@0: err = iGains.Append(aChannels[i]); sl@0: if(err != KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // Apply gain sl@0: if(iHelper && err == KErrNone) sl@0: { sl@0: err = iHelper->SetGain(aChannels); sl@0: } sl@0: DP0_RET(KErrNone, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::RegisterAudioGainControlObserver sl@0: // --------------------------------------------------------------------------- sl@0: TInt CAudioGainControl::RegisterAudioGainControlObserver(MAudioGainControlObserver& aObserver) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::RegisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt err = iGainObservers.Find(&aObserver); sl@0: if(err == KErrNotFound) sl@0: { sl@0: err = iGainObservers.Append(&aObserver); sl@0: } sl@0: else sl@0: { sl@0: err = KErrAlreadyExists; sl@0: } sl@0: DP0_RET(err, "%d"); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // from class MAudioGainControl sl@0: // CAudioGainControl::UnregisterAudioGainControlObserver sl@0: // --------------------------------------------------------------------------- sl@0: void CAudioGainControl::UnregisterAudioGainControlObserver(MAudioGainControlObserver& aObserver) sl@0: { sl@0: DP_CONTEXT(CAudioGainControl::UnregisterAudioStreamObserver *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: TInt idxOrErr = iGainObservers.Find(&aObserver); sl@0: if( idxOrErr != KErrNotFound ) sl@0: { sl@0: iGainObservers.Remove(idxOrErr); sl@0: } sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // end of file