sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\multimedia\t_soundwav.cpp
|
sl@0
|
15 |
// Record wav to a file "t_soundwav filename [rate] [channels] [seconds]" where filename does not exist.
|
sl@0
|
16 |
// Play a wav file "t_soundwav filename" where filename exists.
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file Shared chunk sound driver WAV file player and recorder utility.
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <e32test.h>
|
sl@0
|
25 |
#include <e32def.h>
|
sl@0
|
26 |
#include <e32def_private.h>
|
sl@0
|
27 |
#include "t_soundutils.h"
|
sl@0
|
28 |
#include <f32file.h>
|
sl@0
|
29 |
|
sl@0
|
30 |
#define CHECK(aValue) {Test(aValue);}
|
sl@0
|
31 |
#define CHECK_NOERROR(aValue) { TInt v=(aValue); if(v) { Test.Printf(_L("Error value = %d\n"),v); Test(EFalse,__LINE__); }}
|
sl@0
|
32 |
#define CHECK_EQUAL(aValue1,aValue2) { TInt v1=(aValue1); TInt v2=(aValue2); if(v1!=v2) { Test.Printf(_L("Error value = %d\n"),v1); Test(EFalse,__LINE__); }}
|
sl@0
|
33 |
|
sl@0
|
34 |
_LIT(KSndLddFileName,"ESOUNDSC.LDD");
|
sl@0
|
35 |
_LIT(KSndPddFileName,"SOUNDSC.PDD");
|
sl@0
|
36 |
|
sl@0
|
37 |
RTest Test(_L("T_SOUNDWAV"));
|
sl@0
|
38 |
RSoundSc TxSoundDevice;
|
sl@0
|
39 |
RSoundSc RxSoundDevice;
|
sl@0
|
40 |
|
sl@0
|
41 |
TSoundFormatsSupportedV02Buf RecordCapsBuf;
|
sl@0
|
42 |
TSoundFormatsSupportedV02Buf PlayCapsBuf;
|
sl@0
|
43 |
TCurrentSoundFormatV02Buf PlayFormatBuf;
|
sl@0
|
44 |
TCurrentSoundFormatV02Buf RecordFormatBuf;
|
sl@0
|
45 |
|
sl@0
|
46 |
TBuf<256> CommandLine;
|
sl@0
|
47 |
RFs Fs;
|
sl@0
|
48 |
|
sl@0
|
49 |
//
|
sl@0
|
50 |
// This is the WAV header structure used for playing and recording files
|
sl@0
|
51 |
//
|
sl@0
|
52 |
struct WAVEheader
|
sl@0
|
53 |
{
|
sl@0
|
54 |
char ckID[4]; // chunk id 'RIFF'
|
sl@0
|
55 |
TUint32 ckSize; // chunk size
|
sl@0
|
56 |
char wave_ckID[4]; // wave chunk id 'WAVE'
|
sl@0
|
57 |
char fmt_ckID[4]; // format chunk id 'fmt '
|
sl@0
|
58 |
TUint32 fmt_ckSize; // format chunk size
|
sl@0
|
59 |
TUint16 formatTag; // format tag currently pcm
|
sl@0
|
60 |
TUint16 nChannels; // number of channels
|
sl@0
|
61 |
TUint32 nSamplesPerSec; // sample rate in hz
|
sl@0
|
62 |
TUint32 nAvgBytesPerSec; // average bytes per second
|
sl@0
|
63 |
TUint16 nBlockAlign; // number of bytes per sample
|
sl@0
|
64 |
TUint16 nBitsPerSample; // number of bits in a sample
|
sl@0
|
65 |
char data_ckID[4]; // data chunk id 'data'
|
sl@0
|
66 |
TUint32 data_ckSize; // length of data chunk
|
sl@0
|
67 |
};
|
sl@0
|
68 |
|
sl@0
|
69 |
LOCAL_C TInt SamplesPerSecondToRate(TInt aRateInSamplesPerSecond,TSoundRate& aRate)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
switch (aRateInSamplesPerSecond)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
case 7350: aRate=ESoundRate7350Hz; break;
|
sl@0
|
74 |
case 8000: aRate=ESoundRate8000Hz; break;
|
sl@0
|
75 |
case 8820: aRate=ESoundRate8820Hz; break;
|
sl@0
|
76 |
case 9600: aRate=ESoundRate9600Hz; break;
|
sl@0
|
77 |
case 11025: aRate=ESoundRate11025Hz; break;
|
sl@0
|
78 |
case 12000: aRate=ESoundRate12000Hz; break;
|
sl@0
|
79 |
case 14700: aRate=ESoundRate14700Hz; break;
|
sl@0
|
80 |
case 16000: aRate=ESoundRate16000Hz; break;
|
sl@0
|
81 |
case 22050: aRate=ESoundRate22050Hz; break;
|
sl@0
|
82 |
case 24000: aRate=ESoundRate24000Hz; break;
|
sl@0
|
83 |
case 29400: aRate=ESoundRate29400Hz; break;
|
sl@0
|
84 |
case 32000: aRate=ESoundRate32000Hz; break;
|
sl@0
|
85 |
case 44100: aRate=ESoundRate44100Hz; break;
|
sl@0
|
86 |
case 48000: aRate=ESoundRate48000Hz; break;
|
sl@0
|
87 |
default: return(KErrArgument);
|
sl@0
|
88 |
};
|
sl@0
|
89 |
return(KErrNone);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
LOCAL_C TInt RecordBufferSizeInBytes(TCurrentSoundFormatV02& aFormat)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
switch (aFormat.iRate)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
case ESoundRate7350Hz: return(8192);
|
sl@0
|
97 |
case ESoundRate8000Hz: return(8192);
|
sl@0
|
98 |
case ESoundRate8820Hz: return(12288);
|
sl@0
|
99 |
case ESoundRate9600Hz: return(12288);
|
sl@0
|
100 |
case ESoundRate11025Hz: return(12288);
|
sl@0
|
101 |
case ESoundRate12000Hz: return(12288);
|
sl@0
|
102 |
case ESoundRate14700Hz: return(12288);
|
sl@0
|
103 |
case ESoundRate16000Hz: return(12288);
|
sl@0
|
104 |
case ESoundRate22050Hz: return(16384);
|
sl@0
|
105 |
case ESoundRate24000Hz: return(16384);
|
sl@0
|
106 |
case ESoundRate29400Hz: return(24576);
|
sl@0
|
107 |
case ESoundRate32000Hz: return(24576);
|
sl@0
|
108 |
case ESoundRate44100Hz: return(32768);
|
sl@0
|
109 |
case ESoundRate48000Hz: return(32768);
|
sl@0
|
110 |
default: return(32768);
|
sl@0
|
111 |
};
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
LOCAL_C TInt Load()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TInt r;
|
sl@0
|
117 |
|
sl@0
|
118 |
Test.Start(_L("Load sound PDD"));
|
sl@0
|
119 |
r=User::LoadPhysicalDevice(KSndPddFileName);
|
sl@0
|
120 |
if (r==KErrNotFound)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
Test.End();
|
sl@0
|
123 |
return(r);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
CHECK(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
126 |
|
sl@0
|
127 |
Test.Next(_L("Load sound LDD"));
|
sl@0
|
128 |
r=User::LoadLogicalDevice(KSndLddFileName);
|
sl@0
|
129 |
CHECK(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
130 |
|
sl@0
|
131 |
Test.End();
|
sl@0
|
132 |
return(KErrNone);
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
LOCAL_C TInt WavPlay()
|
sl@0
|
136 |
{
|
sl@0
|
137 |
RChunk chunk;
|
sl@0
|
138 |
|
sl@0
|
139 |
// Parse the commandline and get a filename to use
|
sl@0
|
140 |
TLex l(CommandLine);
|
sl@0
|
141 |
TFileName thisfile=RProcess().FileName();
|
sl@0
|
142 |
TPtrC token=l.NextToken();
|
sl@0
|
143 |
if (token.MatchF(thisfile)==0)
|
sl@0
|
144 |
token.Set(l.NextToken());
|
sl@0
|
145 |
|
sl@0
|
146 |
if (token.Length()==0)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
// No args, skip to end
|
sl@0
|
149 |
Test.Printf(_L("Invalid configuration\r\n"));
|
sl@0
|
150 |
return(KErrArgument);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
Test.Next(_L("Play Wav file"));
|
sl@0
|
154 |
|
sl@0
|
155 |
// Assume that the argument is a WAV filename
|
sl@0
|
156 |
TFileName wavFilename=token;
|
sl@0
|
157 |
TInt r;
|
sl@0
|
158 |
RFile source;
|
sl@0
|
159 |
r = source.Open(Fs,wavFilename,EFileRead);
|
sl@0
|
160 |
if (r!=KErrNone)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
Test.Printf(_L("Open failed(%d)\r\n"), r);
|
sl@0
|
163 |
return(r);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
// Read the pcm header
|
sl@0
|
167 |
WAVEheader header;
|
sl@0
|
168 |
TPtr8 headerDes((TUint8 *)&header,sizeof(struct WAVEheader),sizeof(struct WAVEheader));
|
sl@0
|
169 |
r = source.Read(headerDes);
|
sl@0
|
170 |
if (r!=KErrNone)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
source.Close();
|
sl@0
|
173 |
return(r);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
Test.Printf(_L("Header Read %d bytes\r\n"),headerDes.Size());
|
sl@0
|
176 |
|
sl@0
|
177 |
if (headerDes.Size() != sizeof(struct WAVEheader)) // EOF
|
sl@0
|
178 |
{
|
sl@0
|
179 |
Test.Printf(_L("Couldn't read a header(%d bytes)\r\n"),headerDes.Size());
|
sl@0
|
180 |
source.Close();
|
sl@0
|
181 |
return(KErrCorrupt);
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\n"),
|
sl@0
|
185 |
header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample,
|
sl@0
|
186 |
header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize);
|
sl@0
|
187 |
|
sl@0
|
188 |
if (header.formatTag != 1) // not pcm
|
sl@0
|
189 |
{
|
sl@0
|
190 |
Test.Printf(_L("Format not PCM(%d)\r\n"),header.formatTag);
|
sl@0
|
191 |
source.Close();
|
sl@0
|
192 |
return(KErrNotSupported);
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
if (header.nBitsPerSample != 16) // not 16 bit
|
sl@0
|
196 |
{
|
sl@0
|
197 |
Test.Printf(_L("Format not 16 bit PCM(%d bits)\r\n"),header.nBitsPerSample);
|
sl@0
|
198 |
source.Close();
|
sl@0
|
199 |
return(KErrNotSupported);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
TSoundRate rate;
|
sl@0
|
203 |
if (SamplesPerSecondToRate(header.nSamplesPerSec,rate)!=KErrNone)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
Test.Printf(_L("Format specifies a rate not supported(%d)\r\n"),header.nSamplesPerSec);
|
sl@0
|
206 |
source.Close();
|
sl@0
|
207 |
return(KErrNotSupported);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
TxSoundDevice.AudioFormat(PlayFormatBuf); // Read back the current setting which must be valid.
|
sl@0
|
211 |
PlayFormatBuf().iChannels = header.nChannels;
|
sl@0
|
212 |
PlayFormatBuf().iRate = rate;
|
sl@0
|
213 |
PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
|
sl@0
|
214 |
|
sl@0
|
215 |
// Set the play buffer configuration.
|
sl@0
|
216 |
TInt bufSize=BytesPerSecond(PlayFormatBuf())/8; // Large enough to hold 1/8th second of data.
|
sl@0
|
217 |
bufSize&=~(header.nBlockAlign-1); // Keep the buffer length a multiple of the bytes per sample (assumes 16bitPCM, 1 or 2 chans).
|
sl@0
|
218 |
if (PlayCapsBuf().iRequestMinSize)
|
sl@0
|
219 |
bufSize&=~(PlayCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver.
|
sl@0
|
220 |
TTestSharedChunkBufConfig bufferConfig;
|
sl@0
|
221 |
bufferConfig.iNumBuffers=3;
|
sl@0
|
222 |
bufferConfig.iBufferSizeInBytes=bufSize;
|
sl@0
|
223 |
bufferConfig.iFlags=0;
|
sl@0
|
224 |
PrintBufferConf(bufferConfig,Test);
|
sl@0
|
225 |
TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
|
sl@0
|
226 |
r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
|
sl@0
|
227 |
if (r!=KErrNone)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r);
|
sl@0
|
230 |
source.Close();
|
sl@0
|
231 |
return(r);
|
sl@0
|
232 |
}
|
sl@0
|
233 |
TxSoundDevice.GetBufferConfig(bufferConfigBuf); // Read back the configuration - to get the buffer offsets
|
sl@0
|
234 |
CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
|
sl@0
|
235 |
|
sl@0
|
236 |
// Set the audio play configuration.
|
sl@0
|
237 |
TxSoundDevice.SetVolume(KSoundMaxVolume - (KSoundMaxVolume / 4)); // set volume to 75%
|
sl@0
|
238 |
PrintConfig(PlayFormatBuf(),Test);
|
sl@0
|
239 |
r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
|
sl@0
|
240 |
if (r!=KErrNone)
|
sl@0
|
241 |
{
|
sl@0
|
242 |
Test.Printf(_L("Format not supported\r\n"));
|
sl@0
|
243 |
source.Close();
|
sl@0
|
244 |
chunk.Close();
|
sl@0
|
245 |
return(r);
|
sl@0
|
246 |
}
|
sl@0
|
247 |
TxSoundDevice.ResetBytesTransferred();
|
sl@0
|
248 |
|
sl@0
|
249 |
TInt32 bytesToPlay = header.data_ckSize;
|
sl@0
|
250 |
TTime starttime;
|
sl@0
|
251 |
starttime.HomeTime();
|
sl@0
|
252 |
|
sl@0
|
253 |
TRequestStatus stat[3];
|
sl@0
|
254 |
TPtr8* tPtr[3];
|
sl@0
|
255 |
TInt i;
|
sl@0
|
256 |
for (i=0;i<3;i++)
|
sl@0
|
257 |
tPtr[i]=new TPtr8(NULL,0);
|
sl@0
|
258 |
|
sl@0
|
259 |
TTime startTime;
|
sl@0
|
260 |
startTime.HomeTime();
|
sl@0
|
261 |
|
sl@0
|
262 |
// Start off by issuing a play request for each buffer (assuming that the file is long enough). Use the full size
|
sl@0
|
263 |
// of each buffer.
|
sl@0
|
264 |
TInt stillToRead=bytesToPlay;
|
sl@0
|
265 |
TInt stillNotPlayed=bytesToPlay;
|
sl@0
|
266 |
TUint flags;
|
sl@0
|
267 |
for (i=0 ; i<3 ; i++)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
// Setup the descriptor for reading in the data from the file.
|
sl@0
|
270 |
tPtr[i]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[i],0,bufSize);
|
sl@0
|
271 |
|
sl@0
|
272 |
// If there is still data to read to play then read this into the descriptor
|
sl@0
|
273 |
// and then write it to the driver.
|
sl@0
|
274 |
if (stillToRead)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
r=source.Read(*tPtr[i],Min(stillToRead,bufSize));
|
sl@0
|
277 |
if (r!=KErrNone)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
Test.Printf(_L("Initial file read error(%d)\r\n"),r);
|
sl@0
|
280 |
source.Close();
|
sl@0
|
281 |
chunk.Close();
|
sl@0
|
282 |
return(r);
|
sl@0
|
283 |
}
|
sl@0
|
284 |
stillToRead-=tPtr[i]->Length();
|
sl@0
|
285 |
flags=(stillToRead>0)?0:KSndFlagLastSample;
|
sl@0
|
286 |
TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],tPtr[i]->Length(),flags);
|
sl@0
|
287 |
}
|
sl@0
|
288 |
else
|
sl@0
|
289 |
stat[i]=KRequestPending;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
FOREVER
|
sl@0
|
293 |
{
|
sl@0
|
294 |
// Wait for any one of the outstanding play requests to complete.
|
sl@0
|
295 |
User::WaitForAnyRequest();
|
sl@0
|
296 |
|
sl@0
|
297 |
TTime currentTime;
|
sl@0
|
298 |
currentTime.HomeTime();
|
sl@0
|
299 |
TInt64 elapsedTime = currentTime.Int64()-startTime.Int64(); // us
|
sl@0
|
300 |
TTimeIntervalMicroSecondsBuf timePlayedBuf;
|
sl@0
|
301 |
if(TxSoundDevice.TimePlayed(timePlayedBuf) == KErrNone)
|
sl@0
|
302 |
{
|
sl@0
|
303 |
// Compare TimePlayed with the actual elapsed time. They should be different, but not drift apart too badly...
|
sl@0
|
304 |
TInt32 offset = TInt32(elapsedTime - timePlayedBuf().Int64());
|
sl@0
|
305 |
Test.Printf(_L("\telapsedTime - TimePlayed = %d ms\n"), offset/1000);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
|
sl@0
|
308 |
// Work out which buffer this applies to
|
sl@0
|
309 |
for (i=0 ; i<3 ; i++)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
if (stat[i]!=KRequestPending)
|
sl@0
|
312 |
break;
|
sl@0
|
313 |
}
|
sl@0
|
314 |
if (i>=3)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
Test.Printf(_L("I/O error\r\n"));
|
sl@0
|
317 |
source.Close();
|
sl@0
|
318 |
chunk.Close();
|
sl@0
|
319 |
return(KErrGeneral);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
// Check that the transfer was succesful and whether we have now played all the file.
|
sl@0
|
323 |
if (stat[i]!=KErrNone)
|
sl@0
|
324 |
{
|
sl@0
|
325 |
Test.Printf(_L("Play error(%d)\r\n"),stat[i].Int());
|
sl@0
|
326 |
source.Close();
|
sl@0
|
327 |
chunk.Close();
|
sl@0
|
328 |
return(stat[i].Int());
|
sl@0
|
329 |
}
|
sl@0
|
330 |
Test.Printf(_L("Played %d bytes(%d) - %d\r\n"),tPtr[i]->Length(),i,stat[i].Int());
|
sl@0
|
331 |
stillNotPlayed-=tPtr[i]->Length();
|
sl@0
|
332 |
CHECK(stillNotPlayed>=0);
|
sl@0
|
333 |
if (!stillNotPlayed)
|
sl@0
|
334 |
break;
|
sl@0
|
335 |
|
sl@0
|
336 |
// Still more to be played so read the next part of the file into the descriptor for this
|
sl@0
|
337 |
// buffer and then write it to the driver.
|
sl@0
|
338 |
if (stillToRead)
|
sl@0
|
339 |
{
|
sl@0
|
340 |
TInt len=Min(stillToRead,bufSize);
|
sl@0
|
341 |
|
sl@0
|
342 |
// If we've got to the end of the file and the driver is particular about the request length then
|
sl@0
|
343 |
// zero fill the entire buffer so we can play extra zeros after the last sample from the file.
|
sl@0
|
344 |
if (len<bufSize && PlayCapsBuf().iRequestMinSize)
|
sl@0
|
345 |
tPtr[i]->FillZ(bufSize);
|
sl@0
|
346 |
|
sl@0
|
347 |
// Read the next part of the file
|
sl@0
|
348 |
r=source.Read(*tPtr[i],len); // This will alter the length of the descriptor
|
sl@0
|
349 |
if (r!=KErrNone)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
Test.Printf(_L("File read error(%d)\r\n"),r);
|
sl@0
|
352 |
source.Close();
|
sl@0
|
353 |
chunk.Close();
|
sl@0
|
354 |
return(r);
|
sl@0
|
355 |
}
|
sl@0
|
356 |
stillToRead-=tPtr[i]->Length();
|
sl@0
|
357 |
|
sl@0
|
358 |
// If we've got to the end of the file and the driver is particular about the request length then
|
sl@0
|
359 |
// round up the length to the next valid boundary. This is OK since we zero filled.
|
sl@0
|
360 |
if (tPtr[i]->Length() < bufSize && PlayCapsBuf().iRequestMinSize)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
TUint m=PlayCapsBuf().iRequestMinSize-1;
|
sl@0
|
363 |
len=(tPtr[i]->Length() + m) & ~m;
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
// Write it to the driver.
|
sl@0
|
367 |
flags=(stillToRead>0)?0:KSndFlagLastSample;
|
sl@0
|
368 |
TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],len,flags);
|
sl@0
|
369 |
}
|
sl@0
|
370 |
else
|
sl@0
|
371 |
stat[i]=KRequestPending;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
// Delete all the variables again.
|
sl@0
|
375 |
for (i=0 ; i<3 ; i++)
|
sl@0
|
376 |
delete tPtr[i];
|
sl@0
|
377 |
|
sl@0
|
378 |
TTime endtime;
|
sl@0
|
379 |
endtime.HomeTime();
|
sl@0
|
380 |
|
sl@0
|
381 |
Test.Printf(_L("Done playing\r\n"));
|
sl@0
|
382 |
Test.Printf(_L("Bytes played = %d\r\n"),TxSoundDevice.BytesTransferred());
|
sl@0
|
383 |
Test.Printf(_L("Delta time = %d\r\n"),endtime.Int64()-starttime.Int64());
|
sl@0
|
384 |
|
sl@0
|
385 |
chunk.Close();
|
sl@0
|
386 |
source.Close();
|
sl@0
|
387 |
return(KErrNone);
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
LOCAL_C TInt WavRecord()
|
sl@0
|
391 |
{
|
sl@0
|
392 |
// Parse the commandline and get a filename to use
|
sl@0
|
393 |
TLex l(CommandLine);
|
sl@0
|
394 |
TParse destinationName;
|
sl@0
|
395 |
if (destinationName.SetNoWild(l.NextToken(),0,0)!=KErrNone)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
Test.Printf(_L("No arg, skipping\r\n"));
|
sl@0
|
398 |
return(KErrArgument);
|
sl@0
|
399 |
}
|
sl@0
|
400 |
Test.Next(_L("Record Wav file"));
|
sl@0
|
401 |
|
sl@0
|
402 |
// Open the file for writing
|
sl@0
|
403 |
TInt r;
|
sl@0
|
404 |
RFile destination;
|
sl@0
|
405 |
r = destination.Replace(Fs,destinationName.FullName(),EFileWrite);
|
sl@0
|
406 |
if (r!=KErrNone)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
Test.Printf(_L("Open file for write failed(%d)\n"), r);
|
sl@0
|
409 |
return(r);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
Test.Printf(_L("File opened for write\r\n"));
|
sl@0
|
412 |
|
sl@0
|
413 |
Test.Next(_L("Preparing to record"));
|
sl@0
|
414 |
|
sl@0
|
415 |
// Get the rate
|
sl@0
|
416 |
TLex cl(l.NextToken());
|
sl@0
|
417 |
TUint32 tmpRate;
|
sl@0
|
418 |
TSoundRate rate;
|
sl@0
|
419 |
r = cl.Val(tmpRate,EDecimal);
|
sl@0
|
420 |
if (r == KErrNone && (r=SamplesPerSecondToRate(tmpRate,rate))==KErrNone)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
Test.Printf(_L("Parsed rate: %d\r\n"), tmpRate);
|
sl@0
|
423 |
RecordFormatBuf().iRate = rate;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
else
|
sl@0
|
426 |
{
|
sl@0
|
427 |
Test.Printf(_L("Parse rate failed(%d)\r\n"),r);
|
sl@0
|
428 |
RecordFormatBuf().iRate = ESoundRate32000Hz;
|
sl@0
|
429 |
}
|
sl@0
|
430 |
|
sl@0
|
431 |
// Get number of channels
|
sl@0
|
432 |
TLex cl_chan(l.NextToken());
|
sl@0
|
433 |
TUint32 tmpChannels;
|
sl@0
|
434 |
r = cl_chan.Val(tmpChannels,EDecimal);
|
sl@0
|
435 |
if (r == KErrNone)
|
sl@0
|
436 |
{
|
sl@0
|
437 |
Test.Printf(_L("Parsed %d channels\r\n"),tmpChannels);
|
sl@0
|
438 |
RecordFormatBuf().iChannels = tmpChannels;
|
sl@0
|
439 |
}
|
sl@0
|
440 |
else
|
sl@0
|
441 |
{
|
sl@0
|
442 |
Test.Printf(_L("Parse channels failed(%d)\r\n"), r);
|
sl@0
|
443 |
RecordFormatBuf().iChannels = 2;
|
sl@0
|
444 |
}
|
sl@0
|
445 |
|
sl@0
|
446 |
RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
|
sl@0
|
447 |
|
sl@0
|
448 |
// Set the record buffer configuration.
|
sl@0
|
449 |
RChunk chunk;
|
sl@0
|
450 |
TTestSharedChunkBufConfig bufferConfig;
|
sl@0
|
451 |
bufferConfig.iNumBuffers=4;
|
sl@0
|
452 |
bufferConfig.iBufferSizeInBytes=RecordBufferSizeInBytes(RecordFormatBuf());
|
sl@0
|
453 |
if (RecordCapsBuf().iRequestMinSize)
|
sl@0
|
454 |
bufferConfig.iBufferSizeInBytes&=~(RecordCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver.
|
sl@0
|
455 |
bufferConfig.iFlags=0;
|
sl@0
|
456 |
PrintBufferConf(bufferConfig,Test);
|
sl@0
|
457 |
TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
|
sl@0
|
458 |
r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
|
sl@0
|
459 |
if (r!=KErrNone)
|
sl@0
|
460 |
{
|
sl@0
|
461 |
Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r);
|
sl@0
|
462 |
return(r);
|
sl@0
|
463 |
}
|
sl@0
|
464 |
|
sl@0
|
465 |
// Set the audio record configuration.
|
sl@0
|
466 |
RxSoundDevice.SetVolume(KSoundMaxVolume);
|
sl@0
|
467 |
PrintConfig(RecordFormatBuf(),Test);
|
sl@0
|
468 |
r=RxSoundDevice.SetAudioFormat(RecordFormatBuf);
|
sl@0
|
469 |
if (r!=KErrNone)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
Test.Printf(_L("Format not supported\r\n"));
|
sl@0
|
472 |
return(r);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
|
sl@0
|
475 |
// Get length in seconds
|
sl@0
|
476 |
TLex cl_seconds(l.NextToken());
|
sl@0
|
477 |
TUint32 tmpSeconds;
|
sl@0
|
478 |
r = cl_seconds.Val(tmpSeconds,EDecimal);
|
sl@0
|
479 |
if (r == KErrNone)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
Test.Printf(_L("Parsed %d seconds\r\n"),tmpSeconds);
|
sl@0
|
482 |
}
|
sl@0
|
483 |
else
|
sl@0
|
484 |
{
|
sl@0
|
485 |
Test.Printf(_L("Parse seconds failed(%d)\r\n"),r);
|
sl@0
|
486 |
tmpSeconds=10;
|
sl@0
|
487 |
}
|
sl@0
|
488 |
TInt bytesToRecord = BytesPerSecond(RecordFormatBuf())*tmpSeconds;
|
sl@0
|
489 |
|
sl@0
|
490 |
Test.Next(_L("Recording..."));
|
sl@0
|
491 |
|
sl@0
|
492 |
// Lay down a file header
|
sl@0
|
493 |
WAVEheader header;
|
sl@0
|
494 |
TPtr8 headerDes((TUint8 *)&header, sizeof(struct WAVEheader), sizeof(struct WAVEheader));
|
sl@0
|
495 |
|
sl@0
|
496 |
// "RIFF"
|
sl@0
|
497 |
header.ckID[0] = 'R'; header.ckID[1] = 'I';
|
sl@0
|
498 |
header.ckID[2] = 'F'; header.ckID[3] = 'F';
|
sl@0
|
499 |
// "WAVE"
|
sl@0
|
500 |
header.wave_ckID[0] = 'W'; header.wave_ckID[1] = 'A';
|
sl@0
|
501 |
header.wave_ckID[2] = 'V'; header.wave_ckID[3] = 'E';
|
sl@0
|
502 |
// "fmt "
|
sl@0
|
503 |
header.fmt_ckID[0] = 'f'; header.fmt_ckID[1] = 'm';
|
sl@0
|
504 |
header.fmt_ckID[2] = 't'; header.fmt_ckID[3] = ' ';
|
sl@0
|
505 |
// "data"
|
sl@0
|
506 |
header.data_ckID[0] = 'd'; header.data_ckID[1] = 'a';
|
sl@0
|
507 |
header.data_ckID[2] = 't'; header.data_ckID[3] = 'a';
|
sl@0
|
508 |
|
sl@0
|
509 |
header.nChannels = (TUint16)RecordFormatBuf().iChannels;
|
sl@0
|
510 |
header.nSamplesPerSec = RateInSamplesPerSecond(RecordFormatBuf().iRate);
|
sl@0
|
511 |
header.nBitsPerSample = 16;
|
sl@0
|
512 |
header.nBlockAlign = TUint16((RecordFormatBuf().iChannels == 2) ? 4 : 2);
|
sl@0
|
513 |
header.formatTag = 1; // type 1 is PCM
|
sl@0
|
514 |
header.fmt_ckSize = 16;
|
sl@0
|
515 |
header.nAvgBytesPerSec = BytesPerSecond(RecordFormatBuf());
|
sl@0
|
516 |
header.data_ckSize = bytesToRecord;
|
sl@0
|
517 |
header.ckSize = bytesToRecord + sizeof(struct WAVEheader) - 8;
|
sl@0
|
518 |
|
sl@0
|
519 |
Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\r\n"),
|
sl@0
|
520 |
header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample,
|
sl@0
|
521 |
header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize, sizeof(struct WAVEheader));
|
sl@0
|
522 |
|
sl@0
|
523 |
r = destination.Write(headerDes);
|
sl@0
|
524 |
|
sl@0
|
525 |
TRequestStatus stat;
|
sl@0
|
526 |
TInt length;
|
sl@0
|
527 |
TPtrC8 buf;
|
sl@0
|
528 |
|
sl@0
|
529 |
TTime startTime;
|
sl@0
|
530 |
startTime.HomeTime();
|
sl@0
|
531 |
|
sl@0
|
532 |
// Start off by issuing a record request.
|
sl@0
|
533 |
TTime starttime;
|
sl@0
|
534 |
starttime.HomeTime();
|
sl@0
|
535 |
TInt bytesRecorded = 0;
|
sl@0
|
536 |
RxSoundDevice.RecordData(stat,length);
|
sl@0
|
537 |
|
sl@0
|
538 |
TInt pausesToDo = 10;
|
sl@0
|
539 |
pausesToDo = 0;
|
sl@0
|
540 |
FOREVER
|
sl@0
|
541 |
{
|
sl@0
|
542 |
// Wait for the outstanding record request to complete.
|
sl@0
|
543 |
User::After(6000);
|
sl@0
|
544 |
|
sl@0
|
545 |
User::WaitForAnyRequest();
|
sl@0
|
546 |
if (stat==KRequestPending)
|
sl@0
|
547 |
return(KErrGeneral);
|
sl@0
|
548 |
|
sl@0
|
549 |
TTime currentTime;
|
sl@0
|
550 |
currentTime.HomeTime();
|
sl@0
|
551 |
TInt64 elapsedTime = currentTime.Int64()-startTime.Int64(); // us
|
sl@0
|
552 |
TTimeIntervalMicroSecondsBuf timeRecordedBuf;
|
sl@0
|
553 |
if(RxSoundDevice.TimeRecorded(timeRecordedBuf) == KErrNone)
|
sl@0
|
554 |
{
|
sl@0
|
555 |
// Compare TimeRecorded with the actual elapsed time. They should be different, but not drift apart too badly...
|
sl@0
|
556 |
TInt32 offset = TInt32(elapsedTime - timeRecordedBuf().Int64());
|
sl@0
|
557 |
Test.Printf(_L("\telapsedTime - TimeRecorded = %d ms\n"), offset/1000);
|
sl@0
|
558 |
}
|
sl@0
|
559 |
|
sl@0
|
560 |
// Check whether the record request was succesful.
|
sl@0
|
561 |
TInt retOffset=stat.Int();
|
sl@0
|
562 |
if (retOffset<0)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
Test.Printf(_L("Record failed(%d)\r\n"),retOffset);
|
sl@0
|
565 |
return(retOffset);
|
sl@0
|
566 |
}
|
sl@0
|
567 |
|
sl@0
|
568 |
// Successfully recorded another buffer so write the recorded data to the record file and release the buffer.
|
sl@0
|
569 |
buf.Set((const TUint8*)(chunk.Base()+retOffset),length);
|
sl@0
|
570 |
r=destination.Write(buf);
|
sl@0
|
571 |
if (r!=KErrNone)
|
sl@0
|
572 |
{
|
sl@0
|
573 |
Test.Printf(_L("File write failed(%d)\r\n"),r);
|
sl@0
|
574 |
return(r);
|
sl@0
|
575 |
}
|
sl@0
|
576 |
r=RxSoundDevice.ReleaseBuffer(retOffset);
|
sl@0
|
577 |
if (r!=KErrNone)
|
sl@0
|
578 |
{
|
sl@0
|
579 |
Test.Printf(_L("Release buffer failed(%d)\r\n"),r);
|
sl@0
|
580 |
return(r);
|
sl@0
|
581 |
}
|
sl@0
|
582 |
|
sl@0
|
583 |
Test.Printf(_L("Recorded %d more bytes - %d\r\n"),length,retOffset);
|
sl@0
|
584 |
|
sl@0
|
585 |
if((pausesToDo > 0) && (bytesRecorded > bytesToRecord/2))
|
sl@0
|
586 |
{
|
sl@0
|
587 |
--pausesToDo;
|
sl@0
|
588 |
Test.Printf(_L("Pause\r\n"));
|
sl@0
|
589 |
RxSoundDevice.Pause();
|
sl@0
|
590 |
Test.Printf(_L("Paused, sleeping for 0.5 seconds\r\n"));
|
sl@0
|
591 |
User::After(500*1000);
|
sl@0
|
592 |
Test.Printf(_L("Resume\r\n"));
|
sl@0
|
593 |
RxSoundDevice.Resume();
|
sl@0
|
594 |
}
|
sl@0
|
595 |
|
sl@0
|
596 |
// Check whether we have now recorded all the data. If more to record then queue a further request
|
sl@0
|
597 |
bytesRecorded+=length;
|
sl@0
|
598 |
if (bytesRecorded<bytesToRecord)
|
sl@0
|
599 |
{
|
sl@0
|
600 |
Test.Printf(_L("RecordData\r\n"));
|
sl@0
|
601 |
RxSoundDevice.RecordData(stat,length);
|
sl@0
|
602 |
}
|
sl@0
|
603 |
else
|
sl@0
|
604 |
break;
|
sl@0
|
605 |
}
|
sl@0
|
606 |
|
sl@0
|
607 |
RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
|
sl@0
|
608 |
|
sl@0
|
609 |
TTime endtime;
|
sl@0
|
610 |
endtime.HomeTime();
|
sl@0
|
611 |
|
sl@0
|
612 |
TInt64 elapsedTime = endtime.Int64()-starttime.Int64(); // us
|
sl@0
|
613 |
Test.Printf(_L("Delta time = %d\r\n"),I64LOW(elapsedTime));
|
sl@0
|
614 |
Test.Printf(_L("Seconds in buffer: %d (%d)\r\n"), bytesRecorded / header.nAvgBytesPerSec, (bytesRecorded / header.nAvgBytesPerSec)*1000000);
|
sl@0
|
615 |
|
sl@0
|
616 |
if (I64LOW(elapsedTime) <= (bytesRecorded / header.nAvgBytesPerSec)*1000000)
|
sl@0
|
617 |
{
|
sl@0
|
618 |
Test.Printf(_L("Time travelling; record took less time than it should have done\r\n"));
|
sl@0
|
619 |
return(KErrGeneral);
|
sl@0
|
620 |
}
|
sl@0
|
621 |
|
sl@0
|
622 |
chunk.Close();
|
sl@0
|
623 |
destination.Close();
|
sl@0
|
624 |
|
sl@0
|
625 |
Test.Printf(_L("Record finished\r\n"));
|
sl@0
|
626 |
return(KErrNone);
|
sl@0
|
627 |
}
|
sl@0
|
628 |
|
sl@0
|
629 |
// Quick test block to write the output of the signal generator to a file.
|
sl@0
|
630 |
// You'll need to comment out the reference to playdata in writetone and link
|
sl@0
|
631 |
// the function into the command line processing (search on this function name).
|
sl@0
|
632 |
/*
|
sl@0
|
633 |
LOCAL_C void TestWaveformGenerator()
|
sl@0
|
634 |
{
|
sl@0
|
635 |
|
sl@0
|
636 |
Test.Next(_L("Testing waveform generator"));
|
sl@0
|
637 |
// Parse the commandline and get a filename to use
|
sl@0
|
638 |
TLex l(CommandLine);
|
sl@0
|
639 |
TParse destinationName;
|
sl@0
|
640 |
if (destinationName.SetNoWild(l.NextToken(),0,0)!=KErrNone)
|
sl@0
|
641 |
{
|
sl@0
|
642 |
Test.Printf(_L("No arg, skipping\r\n"));
|
sl@0
|
643 |
return;
|
sl@0
|
644 |
}
|
sl@0
|
645 |
|
sl@0
|
646 |
// Open the file for writing
|
sl@0
|
647 |
TInt r;
|
sl@0
|
648 |
RFile destination;
|
sl@0
|
649 |
r = destination.Replace(Fs,destinationName.FullName(),EFileWrite);
|
sl@0
|
650 |
if (r!=KErrNone)
|
sl@0
|
651 |
{
|
sl@0
|
652 |
Test.Printf(_L("Open file for write failed(%d)\r\n"), r);
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
Test.Printf(_L("File opened for write\r\n"));
|
sl@0
|
656 |
Test.Next(_L("Preparing to record data"));
|
sl@0
|
657 |
|
sl@0
|
658 |
// Get the rate
|
sl@0
|
659 |
TLex cl(l.NextToken());
|
sl@0
|
660 |
TUint32 tmpRate;
|
sl@0
|
661 |
TSoundRate rate;
|
sl@0
|
662 |
r = cl.Val(tmpRate,EDecimal);
|
sl@0
|
663 |
if (r == KErrNone && (r=SamplesPerSecondToRate(tmpRate,rate))==KErrNone)
|
sl@0
|
664 |
{
|
sl@0
|
665 |
Test.Printf(_L("Parsed rate: %d\r\n"), tmpRate);
|
sl@0
|
666 |
PlayFormatBuf().iRate = rate;
|
sl@0
|
667 |
}
|
sl@0
|
668 |
else
|
sl@0
|
669 |
{
|
sl@0
|
670 |
Test.Printf(_L("Parse rate failed(%d)\r\n"),r);
|
sl@0
|
671 |
PlayFormatBuf().iRate = ESoundRate32000Hz;
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
// Get number of channels
|
sl@0
|
675 |
TLex cl_chan(l.NextToken());
|
sl@0
|
676 |
TUint32 tmpChannels;
|
sl@0
|
677 |
r = cl_chan.Val(tmpChannels,EDecimal);
|
sl@0
|
678 |
if (r == KErrNone)
|
sl@0
|
679 |
{
|
sl@0
|
680 |
Test.Printf(_L("Parsed %d channels\r\n"),tmpChannels);
|
sl@0
|
681 |
PlayFormatBuf().iChannels = tmpChannels;
|
sl@0
|
682 |
}
|
sl@0
|
683 |
else
|
sl@0
|
684 |
{
|
sl@0
|
685 |
Test.Printf(_L("Parse channels failed(%d)\r\n"), r);
|
sl@0
|
686 |
PlayFormatBuf().iChannels = 2;
|
sl@0
|
687 |
}
|
sl@0
|
688 |
|
sl@0
|
689 |
PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
|
sl@0
|
690 |
PrintConfig(PlayFormatBuf(),Test);
|
sl@0
|
691 |
|
sl@0
|
692 |
TInt bufferSize=BytesPerSecond(PlayFormatBuf())/8;
|
sl@0
|
693 |
TUint8* buffer = (TUint8*)User::Alloc(bufferSize*sizeof(TUint8));
|
sl@0
|
694 |
if (buffer==NULL)
|
sl@0
|
695 |
{
|
sl@0
|
696 |
Test.Printf(_L("Out of memory\r\n"));
|
sl@0
|
697 |
return;
|
sl@0
|
698 |
}
|
sl@0
|
699 |
TPtr8 bufferDes(buffer,bufferSize,bufferSize);
|
sl@0
|
700 |
|
sl@0
|
701 |
Test.Next(_L("Recording..."));
|
sl@0
|
702 |
TInt i = BytesPerSecond(PlayFormatBuf())*10/bufferSize;
|
sl@0
|
703 |
TInt bytesToRecord = i * bufferSize;
|
sl@0
|
704 |
|
sl@0
|
705 |
// Lay down a file header
|
sl@0
|
706 |
WAVEheader header;
|
sl@0
|
707 |
TPtr8 headerDes((TUint8 *)&header, sizeof(struct WAVEheader), sizeof(struct WAVEheader));
|
sl@0
|
708 |
|
sl@0
|
709 |
// "RIFF"
|
sl@0
|
710 |
header.ckID[0] = 'R'; header.ckID[1] = 'I';
|
sl@0
|
711 |
header.ckID[2] = 'F'; header.ckID[3] = 'F';
|
sl@0
|
712 |
// "WAVE"
|
sl@0
|
713 |
header.wave_ckID[0] = 'W'; header.wave_ckID[1] = 'A';
|
sl@0
|
714 |
header.wave_ckID[2] = 'V'; header.wave_ckID[3] = 'E';
|
sl@0
|
715 |
// "fmt "
|
sl@0
|
716 |
header.fmt_ckID[0] = 'f'; header.fmt_ckID[1] = 'm';
|
sl@0
|
717 |
header.fmt_ckID[2] = 't'; header.fmt_ckID[3] = ' ';
|
sl@0
|
718 |
// "data"
|
sl@0
|
719 |
header.data_ckID[0] = 'd'; header.data_ckID[1] = 'a';
|
sl@0
|
720 |
header.data_ckID[2] = 't'; header.data_ckID[3] = 'a';
|
sl@0
|
721 |
|
sl@0
|
722 |
header.nChannels = PlayFormatBuf().iChannels;
|
sl@0
|
723 |
header.nSamplesPerSec = RateInSamplesPerSecond(PlayFormatBuf().iRate);
|
sl@0
|
724 |
header.nBitsPerSample = 16;
|
sl@0
|
725 |
header.nBlockAlign = 4;
|
sl@0
|
726 |
header.formatTag = 1;
|
sl@0
|
727 |
header.fmt_ckSize = 16;
|
sl@0
|
728 |
header.nAvgBytesPerSec = BytesPerSecond(PlayFormatBuf());
|
sl@0
|
729 |
header.data_ckSize = bytesToRecord;
|
sl@0
|
730 |
header.ckSize = bytesToRecord + sizeof(struct WAVEheader) - 8;
|
sl@0
|
731 |
|
sl@0
|
732 |
Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\r\n"),
|
sl@0
|
733 |
header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample,
|
sl@0
|
734 |
header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize);
|
sl@0
|
735 |
|
sl@0
|
736 |
r = destination.Write(headerDes);
|
sl@0
|
737 |
|
sl@0
|
738 |
MakeSineTable(PlayFormatBuf());
|
sl@0
|
739 |
SetToneFrequency(440,PlayFormatBuf()); // 'A'
|
sl@0
|
740 |
|
sl@0
|
741 |
while(--i>0)
|
sl@0
|
742 |
{
|
sl@0
|
743 |
WriteTone(bufferDes,PlayFormatBuf());
|
sl@0
|
744 |
r = destination.Write(bufferDes);
|
sl@0
|
745 |
if (r!=KErrNone)
|
sl@0
|
746 |
{
|
sl@0
|
747 |
Test.Printf(_L("Write failed(%d)\r\n"),r);
|
sl@0
|
748 |
break;
|
sl@0
|
749 |
}
|
sl@0
|
750 |
}
|
sl@0
|
751 |
Test.Printf(_L("Finished\r\n"));
|
sl@0
|
752 |
|
sl@0
|
753 |
delete buffer;
|
sl@0
|
754 |
destination.Close();
|
sl@0
|
755 |
}
|
sl@0
|
756 |
*/
|
sl@0
|
757 |
LOCAL_C void TestUnloadDrivers()
|
sl@0
|
758 |
{
|
sl@0
|
759 |
TInt r=User::FreeLogicalDevice(KDevSoundScName);
|
sl@0
|
760 |
Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
|
sl@0
|
761 |
CHECK_NOERROR(r);
|
sl@0
|
762 |
|
sl@0
|
763 |
TName pddName(KDevSoundScName);
|
sl@0
|
764 |
_LIT(KPddWildcardExtension,".*");
|
sl@0
|
765 |
pddName.Append(KPddWildcardExtension);
|
sl@0
|
766 |
TFindPhysicalDevice findPD(pddName);
|
sl@0
|
767 |
TFullName findResult;
|
sl@0
|
768 |
r=findPD.Next(findResult);
|
sl@0
|
769 |
while (r==KErrNone)
|
sl@0
|
770 |
{
|
sl@0
|
771 |
r=User::FreePhysicalDevice(findResult);
|
sl@0
|
772 |
Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
|
sl@0
|
773 |
CHECK_NOERROR(r);
|
sl@0
|
774 |
findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
|
sl@0
|
775 |
r=findPD.Next(findResult);
|
sl@0
|
776 |
}
|
sl@0
|
777 |
}
|
sl@0
|
778 |
|
sl@0
|
779 |
TInt E32Main()
|
sl@0
|
780 |
{
|
sl@0
|
781 |
TInt r;
|
sl@0
|
782 |
|
sl@0
|
783 |
__UHEAP_MARK;
|
sl@0
|
784 |
|
sl@0
|
785 |
Test.Title();
|
sl@0
|
786 |
|
sl@0
|
787 |
Test.Start(_L("Load"));
|
sl@0
|
788 |
if (Load()==KErrNotFound)
|
sl@0
|
789 |
{
|
sl@0
|
790 |
Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
|
sl@0
|
791 |
Test.End();
|
sl@0
|
792 |
Test.Close();
|
sl@0
|
793 |
__UHEAP_MARKEND;
|
sl@0
|
794 |
return(KErrNone);
|
sl@0
|
795 |
}
|
sl@0
|
796 |
|
sl@0
|
797 |
__KHEAP_MARK;
|
sl@0
|
798 |
|
sl@0
|
799 |
Test.Next(_L("Open playback channel"));
|
sl@0
|
800 |
r = TxSoundDevice.Open(KSoundScTxUnit0);
|
sl@0
|
801 |
if (r!=KErrNone)
|
sl@0
|
802 |
{
|
sl@0
|
803 |
Test.Printf(_L("Open playback channel error(%d)\r\n"),r);
|
sl@0
|
804 |
Test(0);
|
sl@0
|
805 |
}
|
sl@0
|
806 |
|
sl@0
|
807 |
Test.Next(_L("Open record channel"));
|
sl@0
|
808 |
r = RxSoundDevice.Open(KSoundScRxUnit0);
|
sl@0
|
809 |
if (r!=KErrNone)
|
sl@0
|
810 |
{
|
sl@0
|
811 |
Test.Printf(_L("Open record channel error(%d)\r\n"),r);
|
sl@0
|
812 |
Test(0);
|
sl@0
|
813 |
}
|
sl@0
|
814 |
|
sl@0
|
815 |
Test.Next(_L("Query play formats supported"));
|
sl@0
|
816 |
TxSoundDevice.Caps(PlayCapsBuf);
|
sl@0
|
817 |
TSoundFormatsSupportedV02 playCaps=PlayCapsBuf();
|
sl@0
|
818 |
PrintCaps(playCaps,Test);
|
sl@0
|
819 |
|
sl@0
|
820 |
Test.Next(_L("Query record formats supported"));
|
sl@0
|
821 |
RxSoundDevice.Caps(RecordCapsBuf);
|
sl@0
|
822 |
TSoundFormatsSupportedV02 recordCaps=RecordCapsBuf();
|
sl@0
|
823 |
PrintCaps(recordCaps,Test);
|
sl@0
|
824 |
|
sl@0
|
825 |
Test.Next(_L("Connect to the file server"));
|
sl@0
|
826 |
r = Fs.Connect();
|
sl@0
|
827 |
if (r!=KErrNone)
|
sl@0
|
828 |
{
|
sl@0
|
829 |
Test.Printf(_L("Connect to the file server error(%d)\r\n"),r);
|
sl@0
|
830 |
Test(0);
|
sl@0
|
831 |
}
|
sl@0
|
832 |
|
sl@0
|
833 |
if (User::CommandLineLength())
|
sl@0
|
834 |
{
|
sl@0
|
835 |
User::CommandLine(CommandLine);
|
sl@0
|
836 |
TLex l(CommandLine);
|
sl@0
|
837 |
TPtrC token=l.NextToken();
|
sl@0
|
838 |
|
sl@0
|
839 |
TInt count=0;
|
sl@0
|
840 |
while (token.Length()!=0)
|
sl@0
|
841 |
{
|
sl@0
|
842 |
++count;
|
sl@0
|
843 |
token.Set(l.NextToken());
|
sl@0
|
844 |
}
|
sl@0
|
845 |
Test.Printf(_L("Command line %d parameters\r\n"),count);
|
sl@0
|
846 |
|
sl@0
|
847 |
if (count==1) // If 1 parameter try playing a file
|
sl@0
|
848 |
r=WavPlay();
|
sl@0
|
849 |
else if (count) // If there is more than 1 parameter, try recording
|
sl@0
|
850 |
r=WavRecord();
|
sl@0
|
851 |
|
sl@0
|
852 |
//TestWaveformGenerator();
|
sl@0
|
853 |
|
sl@0
|
854 |
}
|
sl@0
|
855 |
|
sl@0
|
856 |
Fs.Close();
|
sl@0
|
857 |
|
sl@0
|
858 |
Test.Next(_L("Close channels"));
|
sl@0
|
859 |
RxSoundDevice.Close();
|
sl@0
|
860 |
TxSoundDevice.Close();
|
sl@0
|
861 |
|
sl@0
|
862 |
__KHEAP_MARKEND;
|
sl@0
|
863 |
|
sl@0
|
864 |
// Now that both the channels are closed, unload the LDD and the PDDs.
|
sl@0
|
865 |
TestUnloadDrivers();
|
sl@0
|
866 |
|
sl@0
|
867 |
Test(r==KErrNone);
|
sl@0
|
868 |
|
sl@0
|
869 |
Test.End();
|
sl@0
|
870 |
Test.Close();
|
sl@0
|
871 |
|
sl@0
|
872 |
Cleanup();
|
sl@0
|
873 |
|
sl@0
|
874 |
__UHEAP_MARKEND;
|
sl@0
|
875 |
|
sl@0
|
876 |
return(KErrNone);
|
sl@0
|
877 |
}
|