1 /* |
|
2 * Copyright (c) 2005 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: Manipulates the doppler effect of the SoundSource3D. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 #include <e32math.h> |
|
22 #include "cammsemcaudiodopplercontrol.h" |
|
23 |
|
24 // ============================ MEMBER FUNCTIONS =============================== |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CAMMSEMCAudioDopplerControl::NewLC |
|
28 // Two-phased constructor. |
|
29 // ----------------------------------------------------------------------------- |
|
30 CAMMSEMCAudioDopplerControl* CAMMSEMCAudioDopplerControl::NewLC(CMMAPlayer* aPlayer) |
|
31 { |
|
32 CAMMSEMCAudioDopplerControl* self = |
|
33 new(ELeave) CAMMSEMCAudioDopplerControl(aPlayer); |
|
34 |
|
35 CleanupStack::PushL(self); |
|
36 |
|
37 return self; |
|
38 } |
|
39 |
|
40 // Destructor |
|
41 CAMMSEMCAudioDopplerControl::~CAMMSEMCAudioDopplerControl() |
|
42 { |
|
43 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::~CAMMSEMCAudioDopplerControl"); |
|
44 // Perform DeallocateControl, if the state change has not yet performed it. |
|
45 DeallocateControl(); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CAMMSEMCAudioDopplerControl::PrepareControlL |
|
50 // Function which is called after the correct state is set in Player. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CAMMSEMCAudioDopplerControl::PrepareControlL() |
|
54 { |
|
55 // Perform the action only for the first time, skip if called afterwards |
|
56 if (!iMSourceDopplerControl) |
|
57 { |
|
58 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::PrepareControlL"); |
|
59 //Create Doppler Effect Control |
|
60 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
61 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
62 //Check the state of stream control ,it must be INITIALIZED |
|
63 TInt state = iStreamControl->GetState(); |
|
64 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::PrepareControlL: Stream state = %d,",state); |
|
65 |
|
66 MEffectControl* temp(NULL); |
|
67 User::LeaveIfError(iFactory->CreateEffectControl(KSourceDopplerEffectControl, temp)); |
|
68 iMSourceDopplerControl = static_cast<MSourceDopplerControl*>(temp); |
|
69 User::LeaveIfError(iStreamControl->AddEffect(*iMSourceDopplerControl)); |
|
70 iMSourceDopplerControl->Enable(); |
|
71 } |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CAMMSEMCAudioDopplerControl::DeallocateControl |
|
76 // Function which is called after the correct state is set in Player. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CAMMSEMCAudioDopplerControl::DeallocateControl() |
|
80 { |
|
81 if (iMSourceDopplerControl) |
|
82 { |
|
83 |
|
84 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::DeallocateControl"); |
|
85 |
|
86 // Doppler for Audio can be disabled or enabled |
|
87 if (Enabled()) |
|
88 { |
|
89 iMSourceDopplerControl->Disable(); |
|
90 } |
|
91 //return the control to factory |
|
92 MEffectControl* temp = iMSourceDopplerControl; |
|
93 iStreamControl->RemoveEffect(*temp); |
|
94 // Delete the Effect |
|
95 MEffectControl* tempCtrl = iMSourceDopplerControl; |
|
96 iFactory->DeleteEffectControl(tempCtrl); |
|
97 iMSourceDopplerControl = NULL; |
|
98 |
|
99 } |
|
100 |
|
101 } |
|
102 |
|
103 const TDesC& CAMMSEMCAudioDopplerControl::ClassName() const |
|
104 { |
|
105 return KAMMSEMCAudioDopplerControl; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 void CAMMSEMCAudioDopplerControl::SetEnabledL(TBool aDopplerEnabled) |
|
111 { |
|
112 |
|
113 if (aDopplerEnabled) |
|
114 { |
|
115 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::SetEnabledL(true)"); |
|
116 iMSourceDopplerControl->Enable(); |
|
117 } |
|
118 else |
|
119 { |
|
120 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::SetEnabledL(false)"); |
|
121 iMSourceDopplerControl->Disable(); |
|
122 } |
|
123 |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CAMMSEMCDopplerControl::Enabled |
|
129 // Returns whether this Doppler effect is currently active. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TBool CAMMSEMCAudioDopplerControl::Enabled() |
|
133 { |
|
134 TBool temp; |
|
135 iMSourceDopplerControl->IsEnabled(temp); |
|
136 return temp; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CAMMSEMCDopplerControl::SetVelocityCartesianL |
|
141 // Sets the velocity, used in calculations for the Doppler effect. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CAMMSEMCAudioDopplerControl::SetVelocityCartesianL( |
|
145 TInt aX, |
|
146 TInt aY, |
|
147 TInt aZ) |
|
148 { |
|
149 |
|
150 LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::SetVelocityCartesianL: X=%d, Y=%d, Z=%d", |
|
151 aX, aY, aZ); |
|
152 //Check the state of stream control ,it must be INITIALIZED |
|
153 TInt state = iStreamControl->GetState(); |
|
154 |
|
155 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::SetVelocityCartesianL: Stream state = %d,",state); |
|
156 TInt err = iMSourceDopplerControl->SetCartesianVelocity(aX, aY, aZ); |
|
157 |
|
158 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCAudioDopplerControl::SetVelocityCartesianL: err = %d,",err); |
|
159 |
|
160 |
|
161 // Apply updated settings to Effect API. |
|
162 iMSourceDopplerControl->Apply(); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CAMMSEMCDopplerControl::VelocityCartesian |
|
167 // Returns the current velocity, used in calculations for the Doppler effect. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CAMMSEMCAudioDopplerControl::VelocityCartesian( |
|
171 TInt& aX, TInt& aY, TInt& aZ) |
|
172 { |
|
173 // Get the velocity's cartesian settings |
|
174 // aX, aY and aZ are velocities in format mm/s |
|
175 TInt err = iMSourceDopplerControl->CartesianVelocity(aX,aY,aZ); |
|
176 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCAudioDopplerControl::VelocityCartesian: err = %d,",err); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CAMMSEMCDopplerControl::SetVelocitySphericalL |
|
181 // Sets the velocity, used in calculations for the Doppler effect. |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CAMMSEMCAudioDopplerControl::SetVelocitySphericalL( |
|
185 TInt aAzimuth, |
|
186 TInt aElevation, |
|
187 TInt aRadius) |
|
188 { |
|
189 // Parameters are thousandths of radians |
|
190 |
|
191 LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioDopplerControl::SetVelocitySphericalL %d, %d, %d", |
|
192 aAzimuth, aElevation, aRadius); |
|
193 |
|
194 TInt32 convertedAzimuth = (TInt32)(aAzimuth * KDegToRad * |
|
195 1000); // CSI: 47 Effect API uses thousands of radians # |
|
196 |
|
197 TInt32 convertedElevation = (TInt32)(aElevation * KDegToRad * |
|
198 1000); // CSI: 47 Effect API uses thousands of radians # |
|
199 |
|
200 LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEMCDopplerControl::SetVelocitySphericalL %d, %d", |
|
201 convertedAzimuth, convertedElevation); |
|
202 |
|
203 TInt err = iMSourceDopplerControl->SetSphericalVelocity( |
|
204 convertedAzimuth, convertedElevation, aRadius); |
|
205 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCAudioDopplerControl::SetVelocitySphericalL: err = %d,",err); |
|
206 // Apply updated settings to EMC API. |
|
207 iMSourceDopplerControl->Apply(); |
|
208 |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CAMMSEMCAudioDopplerControl::CAMMSEMCAudioDopplerControl |
|
214 // C++ default constructor can NOT contain any code, that |
|
215 // might leave. |
|
216 // ----------------------------------------------------------------------------- |
|
217 CAMMSEMCAudioDopplerControl::CAMMSEMCAudioDopplerControl( |
|
218 CMMAPlayer* aPlayer) |
|
219 : CAMMSDopplerControl(aPlayer) |
|
220 { |
|
221 iMMAPlayer = aPlayer; |
|
222 } |
|
223 // End of File |
|