1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Controls how the sound is attenuated with its distance. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <logger.h> |
|
22 #include "cammsemcdistanceattenuationcontrol.h" |
|
23 |
|
24 // CONSTANTS |
|
25 namespace |
|
26 { |
|
27 const TInt KAMMSRoomRollOffFactor = 0; // The logical default value set to 0 |
|
28 // Rolloff factor 1000 in AMMS is 100 in EMC API |
|
29 const TInt KAMMSRolloffDivider = 10; |
|
30 |
|
31 #ifdef _DEBUG |
|
32 const TInt KAMMSMinDistance = 1; |
|
33 const TInt KAMMSMinRollofFactor = 0; |
|
34 #endif // _DEBUG |
|
35 } |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CAMMSEMCDistanceAttenuationControl::NewLC |
|
41 // Two-phased constructor. |
|
42 // ----------------------------------------------------------------------------- |
|
43 CAMMSEMCDistanceAttenuationControl* CAMMSEMCDistanceAttenuationControl::NewLC( |
|
44 CMMAPlayer* aPlayer) |
|
45 { |
|
46 CAMMSEMCDistanceAttenuationControl* self = |
|
47 new(ELeave)CAMMSEMCDistanceAttenuationControl(aPlayer); |
|
48 |
|
49 CleanupStack::PushL(self); |
|
50 |
|
51 return self; |
|
52 } |
|
53 |
|
54 // Destructor |
|
55 CAMMSEMCDistanceAttenuationControl::~CAMMSEMCDistanceAttenuationControl() |
|
56 { |
|
57 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCDistanceAttenuationControl::~CAMMSEMCDistanceAttenuationControl"); |
|
58 |
|
59 // Perform DeallocateControl, if the state change has not yet performed it. |
|
60 DeallocateControl(); |
|
61 |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CAMMSEMCDistanceAttenuationControl::SetParametersL |
|
66 // Sets all the 3D audio distance attenuation parameters simultaneously. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CAMMSEMCDistanceAttenuationControl::SetParametersL( |
|
70 TInt aMinDistance, |
|
71 TInt aMaxDistance, |
|
72 TBool aMuteAfterMax, |
|
73 TInt aRolloffFactor) |
|
74 { |
|
75 // Check in debug build that parameters are within valid range. |
|
76 __ASSERT_DEBUG( |
|
77 (aMaxDistance > aMinDistance) && |
|
78 (aMinDistance >= KAMMSMinDistance) && |
|
79 (aMaxDistance >= KAMMSMinDistance) && |
|
80 (aRolloffFactor >= KAMMSMinRollofFactor), |
|
81 User::Invariant()); |
|
82 |
|
83 // NOTE: Effect API uses hundreths (100 corresponds to 1.00), |
|
84 // but JSR234 uses thousandths (1000 represents a rolloff factor of 1.0) |
|
85 // |
|
86 LOG4( EJavaMMAPI, EInfo, "AMMS::CAMMSEMCDistanceAttenuationControl::SetParametersL %d, %d, %d, %d", |
|
87 aMinDistance, aMaxDistance, aMuteAfterMax, aRolloffFactor); |
|
88 |
|
89 TInt convertedRolloffFactor = aRolloffFactor / KAMMSRolloffDivider; |
|
90 |
|
91 iMDistanceAttenuationControl->SetDistanceAttenuation(aMinDistance, aMaxDistance, |
|
92 aMuteAfterMax, convertedRolloffFactor, KAMMSRoomRollOffFactor); |
|
93 |
|
94 // Apply updated settings to EMC API. |
|
95 iMDistanceAttenuationControl->Apply(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CAMMSEMCDistanceAttenuationControl::PrepareControlL |
|
100 // Function which is called after the correct state is set in Player. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CAMMSEMCDistanceAttenuationControl::PrepareControlL() |
|
104 { |
|
105 // Perform the action only for the first time, skip if called afterwards |
|
106 if (!iMDistanceAttenuationControl) |
|
107 { |
|
108 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCDistanceAttenuationControl::PrepareControlL"); |
|
109 //Create Orientation Effect Control |
|
110 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
111 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
112 |
|
113 MEffectControl* temp(NULL); |
|
114 User::LeaveIfError(iFactory->CreateEffectControl(KDistanceAttenuationEffectControl, temp)); |
|
115 iMDistanceAttenuationControl = static_cast<MDistanceAttenuationControl*>(temp); |
|
116 User::LeaveIfError(iStreamControl->AddEffect(*iMDistanceAttenuationControl)); |
|
117 iMDistanceAttenuationControl->Enable(); |
|
118 |
|
119 } |
|
120 |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CAMMSEMCDistanceAttenuationControl::DeallocateControl |
|
125 // Function which is called after the correct state is set in Player. |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CAMMSEMCDistanceAttenuationControl::DeallocateControl() |
|
129 { |
|
130 if (iMDistanceAttenuationControl) |
|
131 { |
|
132 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCDistanceAttenuationControl::DeallocateControl"); |
|
133 |
|
134 // Location for Audio can be disabled or enabled |
|
135 TRAPD(err,iMDistanceAttenuationControl->Disable()); |
|
136 if (err != KErrNone) |
|
137 { |
|
138 //Some EMC Error |
|
139 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCDistanceAttenuationControl::DeallocateControl err = %d",err); |
|
140 } |
|
141 //return the control to factory |
|
142 MEffectControl* temp = iMDistanceAttenuationControl; |
|
143 iStreamControl->RemoveEffect(*temp); |
|
144 // Delete the Effect |
|
145 MEffectControl* tempCtrl = iMDistanceAttenuationControl; |
|
146 iFactory->DeleteEffectControl(tempCtrl); |
|
147 iMDistanceAttenuationControl = NULL; |
|
148 } |
|
149 } |
|
150 |
|
151 const TDesC& CAMMSEMCDistanceAttenuationControl::ClassName() const |
|
152 { |
|
153 return KAMMSEMCDistanceAttenuationControl; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CAMMSEMCDistanceAttenuationControl::CAMMSEMCDistanceAttenuationControl |
|
158 // C++ default constructor can NOT contain any code, that |
|
159 // might leave. |
|
160 // ----------------------------------------------------------------------------- |
|
161 CAMMSEMCDistanceAttenuationControl::CAMMSEMCDistanceAttenuationControl( |
|
162 CMMAPlayer* aPlayer) |
|
163 : CAMMSBaseDistanceAttenuationControl(aPlayer) |
|
164 { |
|
165 iMMAPlayer = aPlayer; |
|
166 } |
|
167 |
|
168 // End of File |
|