|
1 /* |
|
2 * Copyright (c) 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: AudioRecorder Test |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "PlayBalance.h" |
|
20 |
|
21 #include "MdaAudioSampleEditor.h" |
|
22 |
|
23 ////////////////////////////////////////////////////////////////////// |
|
24 // Construction/Destruction |
|
25 ////////////////////////////////////////////////////////////////////// |
|
26 |
|
27 |
|
28 CPlayBalance::CPlayBalance(CTestModuleIf *aConsole, CStifLogger *aLogger) |
|
29 { |
|
30 console = aConsole; |
|
31 logger = aLogger; |
|
32 } |
|
33 |
|
34 CPlayBalance::~CPlayBalance() |
|
35 { |
|
36 |
|
37 if (recorder) delete recorder; |
|
38 recorder = NULL; |
|
39 } |
|
40 |
|
41 |
|
42 void CPlayBalance::ConstructL(TFileName* fileName) |
|
43 { |
|
44 logger->Log(_L("Creating file: %S"),fileName); |
|
45 recorder = CMdaAudioRecorderUtility::NewL(*this); |
|
46 if (recorder) |
|
47 { |
|
48 TRAPD(err,recorder->OpenFileL(*fileName)); |
|
49 if (err != KErrNone) |
|
50 { |
|
51 logger->Log(_L("Error %d opening file: %S"),err,fileName); |
|
52 User::Leave(KErrRecOpenFile); |
|
53 } |
|
54 } |
|
55 } |
|
56 |
|
57 TInt CPlayBalance::RunTestL(CTestModuleIf *aConsole, CStifLogger *aLogger, CStifSectionParser *aParser, TInt* /*clipCounter*/) |
|
58 { |
|
59 TInt error = KErrNone; |
|
60 aLogger->Log(_L("Creating scheduler")); |
|
61 |
|
62 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
63 CleanupStack::PushL(scheduler); // push to clean-up stack |
|
64 CActiveScheduler::Install(scheduler); // install as active scheduler |
|
65 |
|
66 TFileName fileName; |
|
67 |
|
68 //Get file name |
|
69 TPtrC name; |
|
70 CStifItemParser* item = aParser->GetItemLineL(KFileName, ENoTag); |
|
71 if (!item) |
|
72 { |
|
73 CleanupStack::PopAndDestroy(); |
|
74 return KErrSyntax; |
|
75 } |
|
76 |
|
77 CleanupStack::PushL(item); |
|
78 if (item->GetString(KEmptyString,name) != KErrNone) |
|
79 { |
|
80 aLogger->Log(_L("Invalid file name")); |
|
81 CleanupStack::PopAndDestroy(2); |
|
82 return KErrSyntax; |
|
83 } |
|
84 CleanupStack::PopAndDestroy(); |
|
85 |
|
86 GetFileName(name,&fileName); |
|
87 |
|
88 |
|
89 //Obtain balances(s) from parser |
|
90 TInt expectedBalance1 = 0; |
|
91 item = aParser->GetNextItemLineL(KBalance); |
|
92 |
|
93 if (item) |
|
94 { |
|
95 CleanupStack::PushL(item); |
|
96 if (item->GetInt(KBalance,expectedBalance1) != KErrNone) |
|
97 { |
|
98 aLogger->Log(_L("expectedBalance syntax error")); |
|
99 } |
|
100 CleanupStack::PopAndDestroy(); // item |
|
101 } |
|
102 else |
|
103 { |
|
104 error = KErrSetPlayBalance; |
|
105 } |
|
106 |
|
107 |
|
108 if (error != KErrNone) |
|
109 { |
|
110 CleanupStack::PopAndDestroy(); //scheduler |
|
111 return error; |
|
112 } |
|
113 |
|
114 |
|
115 // create CPlayBalance |
|
116 aLogger->Log(_L("Creating CPlayBalance")); |
|
117 |
|
118 CPlayBalance* selfObj = CPlayBalance::NewL(aConsole, aLogger, &fileName); |
|
119 |
|
120 selfObj->expectedBalance = expectedBalance1; |
|
121 |
|
122 CleanupStack::PushL(selfObj); |
|
123 |
|
124 CActiveScheduler::Start(); |
|
125 |
|
126 // if (selfObj->windowStart != startPos) |
|
127 // { |
|
128 // aLogger->Log(_L("The window start position is not right after SetWindow: %d"),selfObj->windowStart); |
|
129 // error = KErrDiffVolume; |
|
130 // } |
|
131 |
|
132 |
|
133 // TTimeIntervalMicroSeconds expectedPlayTime(Abs(endPos.Int64() - startPos.Int64())); |
|
134 |
|
135 // LogTime(_L("expectedPlayTime:"),expectedPlayTime,aLogger); |
|
136 if (Abs(selfObj->expectedBalance - expectedBalance1)> 2) |
|
137 { |
|
138 aLogger->Log(_L("GetPlaybackBalance differs from SetPlaybackBalance")); |
|
139 error = KErrSetPlayBalance; |
|
140 } |
|
141 |
|
142 CleanupStack::PopAndDestroy(2); // schedule, selfObj |
|
143 |
|
144 return error; |
|
145 } |
|
146 |
|
147 |
|
148 CPlayBalance* CPlayBalance::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName) |
|
149 { |
|
150 CPlayBalance* self = new (ELeave) CPlayBalance(aConsole, aLogger); |
|
151 CleanupStack::PushL(self); |
|
152 |
|
153 // self->ConstructL(fileName); |
|
154 TRAPD(err, self->ConstructL(fileName)); |
|
155 if (err != KErrNone) |
|
156 { |
|
157 CleanupStack::PopAndDestroy(); |
|
158 return NULL; |
|
159 } |
|
160 |
|
161 CleanupStack::Pop(self); |
|
162 return self; |
|
163 } |
|
164 |
|
165 void CPlayBalance::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) |
|
166 { |
|
167 #ifdef _DEBUG |
|
168 RDebug::Print (_L ("CPlayBalance::MoscoStateChangeEvent")); |
|
169 #endif |
|
170 |
|
171 logger->Log(_L("MoscoStateChangeEvent called, error: %d prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState); |
|
172 |
|
173 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0) |
|
174 { |
|
175 // Initialize |
|
176 recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal); |
|
177 logger->Log(_L("Mode set")); |
|
178 recorder->SetGain(recorder->MaxGain()); |
|
179 logger->Log(_L("Gain set")); |
|
180 recorder->SetVolume(recorder->MaxVolume()); |
|
181 logger->Log(_L("Volume set")); |
|
182 recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0))); |
|
183 logger->Log(_L("Position set")); |
|
184 |
|
185 recorder->SetThreadPriorityPlayback(EPriorityNormal); |
|
186 logger->Log(_L("ThreadPriorityPlayback set")); |
|
187 recorder->SetThreadPriorityRecord(EPriorityNormal); |
|
188 logger->Log(_L("ThreadPriorityPlayRecord set")); |
|
189 |
|
190 recorder->ClearPlayWindow(); |
|
191 logger->Log(_L("ClearPlayWindow set")); |
|
192 |
|
193 recorder->CancelRegisterAudioResourceNotification(KUidInterfaceMMFController); |
|
194 logger->Log(_L("CancelRegisterAudioResourceNotification set")); |
|
195 |
|
196 |
|
197 |
|
198 // TInt expectedPlayTime; |
|
199 // TTimeIntervalMicroSeconds expectedPlayTime = Abs(windowEnd.Int64() - windowStart.Int64()); |
|
200 // LogTime(_L("Recorded clip duration:"),recorder->Duration()); |
|
201 logger->Log(_L("SetPlaybackBalance before playing: %d"),expectedBalance); |
|
202 recorder->SetPlaybackBalance(expectedBalance); |
|
203 |
|
204 |
|
205 // TTime time; |
|
206 // time.UniversalTime(); |
|
207 // startTime = time.Int64(); |
|
208 |
|
209 recorder->PlayL(); |
|
210 |
|
211 |
|
212 return; |
|
213 } |
|
214 |
|
215 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying) |
|
216 { |
|
217 //get position after play window, which should be start position |
|
218 // windowStart = recorder->Position(); |
|
219 |
|
220 // TTime time; |
|
221 // time.UniversalTime(); |
|
222 // endTime = time.Int64(); |
|
223 recorder->GetPlaybackBalance(expectedBalance); |
|
224 logger->Log(_L("GetPlaybackBalance. Get")); |
|
225 |
|
226 CActiveScheduler::Stop(); |
|
227 } |
|
228 |
|
229 return; |
|
230 |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 void CPlayBalance::GetFileName(TPtrC path, TFileName* fileName) |
|
236 { |
|
237 |
|
238 TParse p; |
|
239 p.Set(path,NULL,NULL); |
|
240 fileName->Append(p.DriveAndPath()); |
|
241 fileName->Append(p.Name()); |
|
242 |
|
243 fileName->Append(p.Ext()); |
|
244 } |