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 virtual location of the SoundSource3D. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 #include <e32math.h> |
|
22 #include "cammsemcaudiolocationcontrol.h" |
|
23 |
|
24 #ifdef _DEBUG |
|
25 // CONSTANTS |
|
26 const TInt KAMMSMinRadius = 0; |
|
27 #endif // _DEBUG |
|
28 |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CAMMSEMCAudioLocationControl::NewLC |
|
34 // Two-phased constructor. |
|
35 // ----------------------------------------------------------------------------- |
|
36 CAMMSEMCAudioLocationControl* CAMMSEMCAudioLocationControl::NewLC( |
|
37 CMMAPlayer* aPlayer) |
|
38 { |
|
39 CAMMSEMCAudioLocationControl* self = |
|
40 new(ELeave) CAMMSEMCAudioLocationControl(aPlayer); |
|
41 |
|
42 CleanupStack::PushL(self); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 // Destructor |
|
48 CAMMSEMCAudioLocationControl::~CAMMSEMCAudioLocationControl() |
|
49 { |
|
50 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::~CAMMSEMCAudioLocationControl"); |
|
51 // Perform DeallocateControl, if the state change has not yet performed it. |
|
52 DeallocateControl(); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CAMMSEMCAudioLocationControl::PrepareControlL |
|
57 // Function which is called after the correct state is set in Player. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CAMMSEMCAudioLocationControl::PrepareControlL() |
|
61 { |
|
62 // Perform the action only for the first time, skip if called afterwards |
|
63 if (!iMSourceLocationControl) |
|
64 { |
|
65 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::PrepareControlL"); |
|
66 //Create Location Effect Control |
|
67 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
68 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
69 MEffectControl* temp(NULL); |
|
70 User::LeaveIfError(iFactory->CreateEffectControl(KSourceLocationEffectControl, temp)); |
|
71 iMSourceLocationControl = static_cast<MSourceLocationControl*>(temp); |
|
72 User::LeaveIfError(iStreamControl->AddEffect(*iMSourceLocationControl)); |
|
73 iMSourceLocationControl->Enable(); |
|
74 } |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CAMMSEMCAudioLocationControl::DeallocateControl |
|
79 // Function which is called after the correct state is set in Player. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CAMMSEMCAudioLocationControl::DeallocateControl() |
|
83 { |
|
84 if (iMSourceLocationControl) |
|
85 { |
|
86 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::DeallocateControl"); |
|
87 |
|
88 // Location for Audio can be disabled or enabled |
|
89 TRAPD(err,iMSourceLocationControl->Disable()); |
|
90 if (err != KErrNone) |
|
91 { |
|
92 // some EMC Error |
|
93 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCAudioLocationControl::DeallocateControl err = %d",err); |
|
94 } |
|
95 //return the control to factory |
|
96 MEffectControl* temp = iMSourceLocationControl; |
|
97 iStreamControl->RemoveEffect(*temp); |
|
98 // Delete the Effect |
|
99 MEffectControl* tempCtrl = iMSourceLocationControl; |
|
100 iFactory->DeleteEffectControl(tempCtrl); |
|
101 iMSourceLocationControl = NULL; |
|
102 } |
|
103 } |
|
104 |
|
105 const TDesC& CAMMSEMCAudioLocationControl::ClassName() const |
|
106 { |
|
107 return KAMMSEMCAudioLocationControl; |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CAMMSEMCAudioLocationControl::SetLocationCartesianL |
|
113 // Moves the object to the new location. |
|
114 // ----------------------------------------------------------------------------- |
|
115 void CAMMSEMCAudioLocationControl::SetLocationCartesianL( |
|
116 TInt& aX, |
|
117 TInt& aY, |
|
118 TInt& aZ) |
|
119 { |
|
120 // Sets the cartesian coordinates for the source location. |
|
121 |
|
122 LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::SetLocationCartesianL: %d, %d, %d", |
|
123 aX, aY, aZ); |
|
124 |
|
125 iMSourceLocationControl->SetLocationCartesian(aX, aY, aZ); |
|
126 |
|
127 // Apply updated settings to EMC API. |
|
128 iMSourceLocationControl->Apply(); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CAMMSEMCAudioLocationControl::LocationCartesian |
|
133 // Gets the coordinates of the current location. |
|
134 // ----------------------------------------------------------------------------- |
|
135 void CAMMSEMCAudioLocationControl::LocationCartesian( |
|
136 TInt& aX, TInt& aY, TInt& aZ) |
|
137 { |
|
138 // Gets the cartesian coordinates for the location of the source position. |
|
139 // The coordinates of the positions are in millimeters. |
|
140 iMSourceLocationControl->LocationCartesian(aX, aY, aZ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CAMMSEMCAudioLocationControl::SetLocationSphericalL |
|
145 // Moves the object to the new location. |
|
146 // ----------------------------------------------------------------------------- |
|
147 void CAMMSEMCAudioLocationControl::SetLocationSphericalL( |
|
148 TInt& aAzimuth, |
|
149 TInt& aElevation, |
|
150 TInt& aRadius) |
|
151 { |
|
152 // Check in debug build that aRadius is within valid range. |
|
153 __ASSERT_DEBUG(aRadius >= KAMMSMinRadius, User::Invariant()); |
|
154 |
|
155 // Sets the spherical coordinates for the location of the source position. |
|
156 // The parameters are thousandths of radians |
|
157 |
|
158 LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::SetLocationSphericalL: %d, %d, %d", |
|
159 aAzimuth, aElevation, aRadius); |
|
160 |
|
161 TInt32 convertedAzimuth = (TInt32)(aAzimuth * |
|
162 KDegToRad * 1000); |
|
163 |
|
164 TInt32 convertedElevation = (TInt32)(aElevation * |
|
165 KDegToRad * 1000); |
|
166 |
|
167 LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioLocationControl::SetLocationSphericalL: %d, %d", |
|
168 convertedAzimuth, convertedElevation); |
|
169 |
|
170 iMSourceLocationControl->SetLocationSpherical( |
|
171 convertedAzimuth, convertedElevation, (TInt32&)aRadius); |
|
172 |
|
173 // Apply updated settings to EMC API. |
|
174 iMSourceLocationControl->Apply(); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CAMMSEMCAudioLocationControl::CAMMSEMCAudioLocationControl |
|
179 // C++ default constructor can NOT contain any code, that |
|
180 // might leave. |
|
181 // ----------------------------------------------------------------------------- |
|
182 CAMMSEMCAudioLocationControl::CAMMSEMCAudioLocationControl(CMMAPlayer* aPlayer) |
|
183 : CAMMSLocationControl(aPlayer) |
|
184 { |
|
185 iMMAPlayer = aPlayer; |
|
186 } |
|
187 |
|
188 // End of File |
|