Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\multimedia\t_sound2.cpp
19 @file General test code for the shared chunk sound driver - based on T_SOUND.
23 #include "t_soundutils.h"
26 #include <e32def_private.h>
30 const TSoundRate speedTable[] = {ESoundRate48000Hz,ESoundRate44100Hz,ESoundRate32000Hz,ESoundRate29400Hz,
31 ESoundRate24000Hz,ESoundRate22050Hz,ESoundRate16000Hz,ESoundRate14700Hz,
32 ESoundRate12000Hz,ESoundRate11025Hz,ESoundRate9600Hz,ESoundRate8820Hz,
33 ESoundRate8000Hz,ESoundRate7350Hz,(TSoundRate)-1}; // ALL RATES DECENDING
35 #define CHECK(aValue) {Test(aValue,__LINE__);}
36 #define CHECK_NOERROR(aValue) { TInt v=(aValue); if(v) { Test.Printf(_L("Error value = %d\n"),v); Test(EFalse,__LINE__); }}
37 #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__); }}
38 #define CHECK_POSITIVE(aOffset) { if(aOffset<0) { Test.Printf(_L("CHECK_POSITIVE(%d) failed\n"), aOffset); Test(EFalse,__LINE__); } }
40 _LIT(KSndLddFileName,"ESOUNDSC.LDD");
41 _LIT(KSndPddFileName,"SOUNDSC.PDD");
43 RTest Test(_L("T_SOUND2"));
44 RSoundSc TxSoundDevice;
45 RSoundSc RxSoundDevice;
47 TSoundFormatsSupportedV02Buf RecordCapsBuf;
48 TSoundFormatsSupportedV02Buf PlayCapsBuf;
49 TCurrentSoundFormatV02Buf PlayFormatBuf;
50 TCurrentSoundFormatV02Buf RecordFormatBuf;
56 Test.Start(_L("Load sound PDD"));
57 r=User::LoadPhysicalDevice(KSndPddFileName);
63 CHECK(r==KErrNone || r==KErrAlreadyExists);
64 r=User::LoadPhysicalDevice(KSndPddFileName);
65 CHECK(r==KErrAlreadyExists);
67 Test.Next(_L("Load sound LDD"));
68 r=User::LoadLogicalDevice(KSndLddFileName);
69 CHECK(r==KErrNone || r==KErrAlreadyExists);
70 r=User::LoadPhysicalDevice(KSndPddFileName);
71 CHECK(r==KErrAlreadyExists);
77 LOCAL_C void CheckConfig(const TCurrentSoundFormatV02& aConfig,const TSoundFormatsSupportedV02& aCaps)
79 if (!((1<<(aConfig.iChannels-1)) & aCaps.iChannels))
81 if (!((1<<aConfig.iRate) & aCaps.iRates))
83 if (!((1<<aConfig.iEncoding) & aCaps.iEncodings))
85 if (!((1<<aConfig.iDataFormat) & aCaps.iDataFormats))
90 ////////////////////////////////////////////////////////////////////////////////
93 const TInt KMaxLinearVolume=256;
94 const TInt KLinearTodB[KMaxLinearVolume+1] =
96 0 ,158,170,177,182,186,189,192,194,196,198,200,201,203,204,205,
97 206,207,208,209,210,211,212,213,213,214,215,215,216,217,217,218,
98 218,219,219,220,220,221,221,222,222,223,223,224,224,224,225,225,
99 225,226,226,226,227,227,227,228,228,228,229,229,229,230,230,230,
100 230,231,231,231,231,232,232,232,232,233,233,233,233,234,234,234,
101 234,235,235,235,235,235,236,236,236,236,236,237,237,237,237,237,
102 237,238,238,238,238,238,239,239,239,239,239,239,240,240,240,240,
103 240,240,240,241,241,241,241,241,241,241,242,242,242,242,242,242,
104 242,243,243,243,243,243,243,243,244,244,244,244,244,244,244,244,
105 245,245,245,245,245,245,245,245,245,246,246,246,246,246,246,246,
106 246,246,247,247,247,247,247,247,247,247,247,247,248,248,248,248,
107 248,248,248,248,248,248,249,249,249,249,249,249,249,249,249,249,
108 250,250,250,250,250,250,250,250,250,250,250,250,251,251,251,251,
109 251,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,
110 252,252,252,252,252,253,253,253,253,253,253,253,253,253,253,253,
111 253,253,254,254,254,254,254,254,254,254,254,254,254,254,254,254,255
114 LOCAL_C void TestBasicPlayFunctions()
116 TRequestStatus stat[2];
118 Test.Next(_L("Preparing to play..."));
119 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
120 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
121 PlayFormatBuf().iChannels = 1;
122 PrintConfig(PlayFormatBuf(),Test);
123 TInt r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
126 // Set the play buffer configuration, then read it back.
128 TInt bufSize=BytesPerSecond(PlayFormatBuf())/8; // Large enough to hold 1/8th second of data.
129 bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver.
130 TTestSharedChunkBufConfig bufferConfig;
131 bufferConfig.iNumBuffers=2;
132 bufferConfig.iBufferSizeInBytes=bufSize;
133 bufferConfig.iFlags=0; // All buffers will be contiguous
134 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
135 r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
137 TxSoundDevice.GetBufferConfig(bufferConfigBuf);
138 PrintBufferConf(bufferConfig,Test);
139 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
143 tPtr[i]=new TPtr8(chunk.Base()+bufferConfig.iBufferOffsetList[i],bufSize);
145 /** @SYMTestCaseID PBASE-T_SOUND2-249
146 @SYMTestCaseDesc Play pause / resume - pausing and resuming before playback has commenced.
147 @SYMTestPriority Critical
148 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer configuration.
149 1) Attempt to resume playback before playback has been started.
150 2) Attempt to pause playback before playback has been started.
151 @SYMTestExpectedResults 1) The resume request should complete with KErrNotReady.
152 2) The pause request should complete with KErrNotReady
153 @SYMREQ PREQ1073.4 */
155 Test.Printf(_L("Resume when not playing\r\n"));
156 r=TxSoundDevice.Resume();
157 CHECK(r==KErrNotReady)
159 Test.Printf(_L("Pause when not playing\r\n"));
160 r=TxSoundDevice.Pause();
161 CHECK(r==KErrNotReady)
163 /** @SYMTestCaseID PBASE-T_SOUND2-237
164 @SYMTestCaseDesc Play operation - with zero length.
165 @SYMTestPriority Critical
166 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer
167 configuration. Issue a transfer request from one of the buffers to play data specifying a
169 @SYMTestExpectedResults The play request should complete with KErrNone.
170 @SYMREQ PREQ1073.4 */
172 Test.Next(_L("Play empty buffer"));
173 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],0,KSndFlagLastSample); // Play length of zero
174 User::WaitForRequest(stat[0]);
175 CHECK_EQUAL(stat[0].Int(),KErrNone);
177 /** @SYMTestCaseID PBASE-T_SOUND2-238
178 @SYMTestCaseDesc Play operation - with a short transfer.
179 @SYMTestPriority Critical
180 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer configuration.
181 1) Issue a transfer requests from one of the buffers to play data, specifying a length equal to the
182 minimum request size that the device supports - i.e.
183 TSoundFormatsSupportedV02::iRequestMinSize, or 2 bytes, whichever is greater.
184 2) Issue a transfer requests from one of the buffers to play data, specifying a length equal
185 to twice the minimum request size that the device supports, or 34 bytes, whichever
187 @SYMTestExpectedResults 1) The play request should complete with KErrNone.
188 2) The play request should complete with KErrNone.
189 @SYMREQ PREQ1073.4 */
191 Test.Next(_L("Play short buffer"));
192 TInt len=Max(2,PlayCapsBuf().iRequestMinSize);
193 Test.Printf(_L("Play length is %d bytes\r\n"),len);
194 tPtr[0]->FillZ(bufSize);
196 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,0);
197 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],len,KSndFlagLastSample);
198 User::WaitForRequest(stat[0]);
199 CHECK_EQUAL(stat[0].Int(),KErrNone);
200 User::WaitForRequest(stat[1]);
201 CHECK_EQUAL(stat[1].Int(),KErrNone);
203 Test.Next(_L("Play a slightly longer buffer"));
204 len=Max(34,(PlayCapsBuf().iRequestMinSize<<1));
205 if (PlayCapsBuf().iRequestMinSize)
206 len&=~(PlayCapsBuf().iRequestMinSize-1);
207 Test.Printf(_L("Play length is %d bytes\r\n"),len);
208 tPtr[1]->FillZ(bufSize);
210 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[1],bufSize,0); // Play 2nd buffer 1st
211 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[0],len,KSndFlagLastSample);
212 User::WaitForRequest(stat[0]);
213 CHECK_EQUAL(stat[0].Int(),KErrNone);
214 User::WaitForRequest(stat[1]);
215 CHECK_EQUAL(stat[1].Int(),KErrNone);
217 /** @SYMTestCaseID PBASE-T_SOUND2-240
218 @SYMTestCaseDesc Play operation - altering the volume.
219 @SYMTestPriority Critical
220 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer configuration
221 so it contains multiple buffers. Using multiple simultaneous play requests, play 4 seconds
222 of continuous tone - with each individual play request consisting of 1/8th second of tone.
223 Each time a request completes, increase the volume slightly - starting at the minimum
224 and ending at maximum volume. (Ensure the last request is marked with the
225 KSndFlagLastSample flag).
226 @SYMTestExpectedResults The driver should successfully play 4 seconds of tone with all requests completing with
228 @SYMREQ PREQ1073.4 */
230 /** @SYMTestCaseID PBASE-T_SOUND2-250
231 @SYMTestCaseDesc Play pause / resume - pausing and resuming while playback is in progress.
232 @SYMTestPriority Critical
233 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer configuration
234 so it contains multiple buffers. Reset the channel's count of bytes transferred.
235 Using multiple simultaneous play requests, play 4 seconds of continuous tone - with
236 each individual play request consisting of 1/8th second of tone.
237 1) After 10 requests have completed, pause transfer for 2 seconds, then resume it.
238 2) After 20 requests have completed, attempt to resume playback while playback is not paused.
239 3) With only 0.25 second of tone still to play, pause transfer for 1 second, then resume it.
240 4) 10ms after resuming, pause transfer again for 1 second, then resume it.
241 5) Once transfer has completed, read back the count of bytes transferred.
242 @SYMTestExpectedResults 1) Playback of the tone should be interrupted for 2 seconds with the pause and resume requests
243 both completing with KErrNone.
244 2) The resume request should complete with KErrNotReady.
245 3) Playback of the tone should be interrupted for 1 second with the pause and resume requests
246 both completing with KErrNone.
247 4) Playback of the tone should be interrupted for 1 second with the pause and resume requests
248 both completing with KErrNone.
249 5) The count of bytes transferred should not be affected by pausing and resuming playback
250 (i.e. it should equal the value calculated for 4 seconds at the selected sampe rate and
252 @SYMREQ PREQ1073.4 */
254 Test.Next(_L("Playing..."));
255 r=MakeSineTable(PlayFormatBuf());
257 r=SetToneFrequency(440,PlayFormatBuf());
259 TxSoundDevice.ResetBytesTransferred();
260 TInt remainingPlayCount = BytesPerSecond(PlayFormatBuf())*4/bufSize;
262 // Set the initial value for the volume.
263 TInt bytesToPlay = remainingPlayCount*bufSize;
264 TInt bytesPlayed = 0;
265 TInt vol = I64LOW(TInt64(KMaxLinearVolume)*TInt64(bytesPlayed)/TInt64(bytesToPlay));
266 vol = KLinearTodB[vol]; // Rather than varying the volume logarithmically (in dB), vary it linearly (as done by MM).
267 TxSoundDevice.SetVolume(vol);
269 // Issue a pair of play requests.
270 WriteTone(*tPtr[0],PlayFormatBuf());
271 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize);
272 WriteTone(*tPtr[1],PlayFormatBuf());
273 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize);
277 while (remainingPlayCount>2)
279 // Wait for either of the outstanding play requests to complete.
280 User::WaitForAnyRequest();
281 remainingPlayCount--;
283 // Work out which request this applies to.
286 if (stat[i]!=KRequestPending)
290 CHECK_NOERROR(stat[i].Int());
292 // Issue a further play request using the buffer just made free.
293 WriteTone(*tPtr[i],PlayFormatBuf());
294 flags=(remainingPlayCount<=2)?KSndFlagLastSample:0;
295 TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],bufSize,flags);
298 bytesPlayed = TxSoundDevice.BytesTransferred();
299 vol = I64LOW(TInt64(KMaxLinearVolume)*TInt64(bytesPlayed)/TInt64(bytesToPlay));
300 vol = KLinearTodB[vol]; // Rather than varying the volume logarithmically (in dB), vary it linearly (as done by MM).
301 Test.Printf(_L("Bytes played = %d (vol = %d)\r\n"),bytesPlayed,vol);
302 TxSoundDevice.SetVolume(vol);
307 r=TxSoundDevice.Pause();
309 Test.Printf(_L("Pause 2 seconds\r\n"));
310 User::After(2000000);
311 Test.Printf(_L("Restart\r\n"));
312 r=TxSoundDevice.Resume();
317 Test.Printf(_L("Resume when playing\r\n"));
318 r=TxSoundDevice.Resume();
319 CHECK(r==KErrNotReady)
322 CHECK_EQUAL(TxSoundDevice.Volume(),vol);
323 CHECK_EQUAL(TxSoundDevice.SetAudioFormat(PlayFormatBuf),KErrInUse);
327 // Last 2 play requests still outstanding - do a pause/resume
328 r=TxSoundDevice.Pause();
330 Test.Printf(_L("Pause 1 second\r\n"));
331 User::After(1000000);
332 Test.Printf(_L("Restart\r\n"));
333 r=TxSoundDevice.Resume();
335 bytesPlayed = TxSoundDevice.BytesTransferred();
337 User::After(10000); // 10ms
339 r=TxSoundDevice.Pause();
340 Test.Printf(_L("Bytes played = %d\r\n"),bytesPlayed);
343 Test.Printf(_L("Pause 1 second\r\n"));
344 User::After(1000000);
345 Test.Printf(_L("Restart\r\n"));
346 r=TxSoundDevice.Resume();
348 bytesPlayed = TxSoundDevice.BytesTransferred();
349 Test.Printf(_L("Bytes played = %d\r\n"),bytesPlayed);
351 User::WaitForRequest(stat[0]);
352 CHECK_EQUAL(stat[0].Int(),KErrNone);
353 User::WaitForRequest(stat[1]);
354 CHECK_EQUAL(stat[1].Int(),KErrNone);
356 bytesPlayed = TxSoundDevice.BytesTransferred();
357 Test.Printf(_L("Bytes played = %d vs %d\n"),bytesPlayed, bytesToPlay);
358 CHECK_EQUAL(bytesToPlay,bytesPlayed);
360 TxSoundDevice.ResetBytesTransferred();
361 CHECK_EQUAL(TxSoundDevice.BytesTransferred(),0);
363 Test.Next(_L("Pause and resume when not playing"));
364 TxSoundDevice.Pause();
365 TxSoundDevice.Resume();
372 LOCAL_C void TestBasicRecordFunctions()
377 Test.Next(_L("Preparing to record..."));
379 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
380 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
381 RecordFormatBuf().iChannels = 2;
383 // find first supported rate and set the the audio configuration to use it
384 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
386 RecordFormatBuf().iRate = (TSoundRate)i;
387 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
388 if (RecordCapsBuf().iRates & (1<<i))
390 CHECK_NOERROR(r); // Caps reports it is supported
395 PrintConfig(RecordFormatBuf(),Test);
397 // Set the record buffer configuration, then read it back.
399 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
400 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
401 TTestSharedChunkBufConfig bufferConfig;
402 bufferConfig.iNumBuffers=3;
403 bufferConfig.iBufferSizeInBytes=bufSize;
404 bufferConfig.iFlags=0; // All buffers will be contiguous
405 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
406 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
408 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
409 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
411 Test.Next(_L("Test for record overflow"));
412 RxSoundDevice.SetVolume(KSoundMaxVolume);
413 RxSoundDevice.RecordData(stat,length);
414 User::WaitForRequest(stat);
415 TInt retOffset=stat.Int();
416 CHECK_POSITIVE(retOffset);
418 r=RxSoundDevice.ReleaseBuffer(retOffset);
421 User::After(500000); // Wait 1/2 second for data overflow.
423 RxSoundDevice.RecordData(stat,length);
424 User::WaitForRequest(stat);
425 retOffset=stat.Int();
426 CHECK(retOffset==KErrOverflow);
428 // Make sure we can issue a successful RecordData after recovering from overflow.
429 RxSoundDevice.RecordData(stat,length);
430 User::WaitForRequest(stat);
431 retOffset=stat.Int();
432 CHECK_POSITIVE(retOffset);
433 r=RxSoundDevice.ReleaseBuffer(retOffset);
436 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
440 /** @SYMTestCaseID PBASE-T_SOUND2-241
441 @SYMTestCaseDesc Play operation - playing all rates.
442 @SYMTestPriority Critical
443 @SYMTestActions 1) For each of the sample rates supported by the device, setup the audio configuration
444 on the playback channel for mono operation (i.e. 1 audio channel) and then setup
445 the buffer configuration so it contains multiple buffers. Using multiple simultaneous play requests,
446 play 4 seconds of continuous tone - with each individual play request consisting of 1/8th second of
447 tone. (Ensure the last request is marked with the KSndFlagLastSample flag).
448 2) Repeat the above with the driver configured for stereo operation (i.e. 2 audio channels).
449 @SYMTestExpectedResults 1) For each of the sample rates supported by the device, the driver should successfully play
450 4 seconds of tone, with no interruptions in the sound produced and with all requests
451 completing with KErrNone.
452 2) For each of the sample rates supported by the device, the driver should successfully play
453 4 seconds of tone, with no interruptions in the sound produced and with all requests
454 completing with KErrNone.
457 LOCAL_C void TestPlayAllRates(TInt aNumChannels,TInt aNumSeconds)
459 TRequestStatus stat[2];
463 tPtr[i]=new TPtr8(NULL,0);
465 Test.Next(_L("Play all rates test"));
466 Test.Printf(_L("Number of channels %d, duration %d seconds\n"), aNumChannels, aNumSeconds);
468 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
469 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
470 PlayFormatBuf().iChannels = aNumChannels;
471 TInt r=MakeSineTable(PlayFormatBuf());
474 TxSoundDevice.SetVolume(KSoundMaxVolume);
478 while (speedTable[speed]>=0)
480 PlayFormatBuf().iRate = speedTable[speed++];
481 PlayFormatBuf().iChannels = aNumChannels;
483 // Set the play format.
484 Test.Printf(_L("Testing playback rate %d...\r\n"),RateInSamplesPerSecond(PlayFormatBuf().iRate));
485 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
486 if (r==KErrNotSupported)
488 Test.Printf(_L("Sample rate not supported\r\n"));
493 // Set the play buffer configuration, then read it back.
494 TInt bufSize=BytesPerSecond(PlayFormatBuf())/4; // Large enough to hold 1/4th second of data.
495 bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver.
496 TTestSharedChunkBufConfig bufferConfig;
497 bufferConfig.iNumBuffers=2;
498 bufferConfig.iBufferSizeInBytes=bufSize;
499 bufferConfig.iFlags=0; // All buffers will be contiguous
500 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
501 r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
503 TxSoundDevice.GetBufferConfig(bufferConfigBuf);
504 PrintBufferConf(bufferConfig,Test);
505 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
506 tPtr[0]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[0],0,bufSize);
507 tPtr[1]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[1],0,bufSize);
509 r=SetToneFrequency(440,PlayFormatBuf());
511 TxSoundDevice.ResetBytesTransferred();
512 CHECK_EQUAL(TxSoundDevice.BytesTransferred(),0);
514 // Issue a pair of play requests.
515 WriteTone(*tPtr[0],PlayFormatBuf());
516 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize);
517 WriteTone(*tPtr[1],PlayFormatBuf());
518 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize);
520 TInt remainingPlayCount = BytesPerSecond(PlayFormatBuf())*aNumSeconds/bufSize;
521 TInt bytesToPlay = remainingPlayCount*bufSize;
522 TInt bytesPlayed = 0;
525 while(remainingPlayCount>2)
527 // Wait for either of the outstanding play requests to complete.
528 User::WaitForAnyRequest();
529 remainingPlayCount--;
531 // Work out which request this applies to.
534 if (stat[i]!=KRequestPending)
538 CHECK_NOERROR(stat[i].Int());
540 WriteTone(*tPtr[i],PlayFormatBuf());
541 flags=(remainingPlayCount<=2)?KSndFlagLastSample:0;
542 TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],bufSize,flags);
545 // Last 2 play requests still outstanding.
546 User::WaitForRequest(stat[0]);
547 CHECK_NOERROR(stat[0].Int());
548 User::WaitForRequest(stat[1]);
549 CHECK_NOERROR(stat[1].Int());
551 Test.Printf(_L("Sample rate successful\r\n"));
552 bytesPlayed = TxSoundDevice.BytesTransferred();
553 CHECK_EQUAL(bytesToPlay,bytesPlayed);
561 /** @SYMTestCaseID PBASE-T_SOUND2-254
562 @SYMTestCaseDesc Record operation - recording all rates.
563 @SYMTestPriority Critical
564 @SYMTestActions 1) For each of the sample rates supported by the device, setup the audio configuration on
565 the record channel for mono operation (i.e. 1 audio channel) and then setup the buffer
566 configuration so it contains multiple buffers. Using multiple simultaneous record
567 requests, record 4 seconds of audio data - with each individual record request being
568 for 1/8th second of data.
569 2) Repeat the above with the driver configured for stereo operation (i.e. 2 audio channels).
570 @SYMTestExpectedResults 1) For each of the sample rates supported by the device, the driver should successfully
571 record 4 seconds of data, with all requests completing with KErrNone.
572 2) For each of the sample rates supported by the device, the driver should successfully
573 record 4 seconds of data, with all requests completing with KErrNone
576 LOCAL_C void TestRecordAllRates(TInt aNumChannels,TInt aNumSeconds)
579 TRequestStatus stat[2];
582 Test.Next(_L("Record all rate test"));
583 Test.Printf(_L("Number of channels %d, duration %d seconds\n"), aNumChannels, aNumSeconds);
585 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
586 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
590 while (speedTable[speed]>=0)
592 RecordFormatBuf().iRate = speedTable[speed++];
593 RecordFormatBuf().iChannels = aNumChannels;
595 // Set the record format.
596 Test.Printf(_L("Testing record rate %d...\r\n"),RateInSamplesPerSecond(RecordFormatBuf().iRate));
597 TInt r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
598 if (r==KErrNotSupported)
600 Test.Printf(_L("Sample rate not supported\r\n"));
605 // Set the record buffer configuration, then read it back.
606 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
607 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
608 TTestSharedChunkBufConfig bufferConfig;
609 bufferConfig.iNumBuffers=4;
610 bufferConfig.iBufferSizeInBytes=bufSize;
611 bufferConfig.iFlags=0; // All buffers will be contiguous
612 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
613 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
615 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
616 PrintBufferConf(bufferConfig,Test);
617 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
619 TInt remainingRecordCount = BytesPerSecond(RecordFormatBuf())*aNumSeconds/bufSize;
620 TInt bytesToRecord = remainingRecordCount*bufSize;
621 TInt bytesRecorded = 0;
623 // The driver rounds up the buffer size to the nearest page meaning the total duration
624 // to complete this test won't be exactly equal to 'aNumSeconds' anymore. Hence, the
625 // predicted time is no longer simply: aNumSeconds * 1000000.
626 TInt64 predictedTime = (bufSize * remainingRecordCount);
627 predictedTime*=1000000;
628 predictedTime+=BytesPerSecond(RecordFormatBuf())>>1;
629 predictedTime/=BytesPerSecond(RecordFormatBuf());
631 starttime.HomeTime();
633 // Issue a pair of record requests.
634 TInt vol = I64LOW(TInt64(KSoundMaxVolume)*TInt64(bytesRecorded)/TInt64(bytesToRecord));
635 RxSoundDevice.SetVolume(vol);
636 RxSoundDevice.RecordData(stat[0],length[0]);
637 RxSoundDevice.RecordData(stat[1],length[1]);
643 // Wait for the next expected request to complete.
644 User::WaitForRequest(stat[currentReq]);
645 remainingRecordCount--;
646 retOffset=stat[currentReq].Int();
647 CHECK_POSITIVE(retOffset);
649 CHECK(length[currentReq]>0);
650 bytesRecorded += length[currentReq];
652 r=RxSoundDevice.ReleaseBuffer(retOffset);
654 CHECK_EQUAL(RxSoundDevice.Volume(),vol);
655 CHECK_EQUAL(RxSoundDevice.SetAudioFormat(RecordFormatBuf),KErrInUse);
657 vol = I64LOW(TInt64(KSoundMaxVolume)*TInt64(bytesRecorded)/TInt64(bytesToRecord));
658 RxSoundDevice.SetVolume(vol);
660 // Don't issue any further record requests on the last two loop passes - to allow for the
661 // two record requests made before the loop started.
662 if (remainingRecordCount>=2)
663 RxSoundDevice.RecordData(stat[currentReq],length[currentReq]);
665 currentReq^=0x01; // Toggle the current req. indicator
667 while(remainingRecordCount>0);
671 TInt64 elapsedTime = endtime.Int64()-starttime.Int64(); // us
672 Test.Printf(_L("Recorded %d bytes in %d us\n"),bytesRecorded, I64LOW(elapsedTime));
673 if (elapsedTime < predictedTime)
675 Test.Printf(_L("**** FAIL: time travelling; record took less time than it could have done\n"));
678 CHECK_EQUAL(bytesToRecord,bytesRecorded);
679 Test.Printf(_L("Sample rate successful\r\n"));
681 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
686 /** @SYMTestCaseID PBASE-T_SOUND2-253
687 @SYMTestCaseDesc Record operation - altering the record level.
688 @SYMTestPriority Critical
689 @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration
690 so it contains multiple buffers. Using multiple simultaneous record requests, record 10
691 seconds of audio data - with each individual record request being for 1/8th second of data.
692 Each time a request completes, increase the record level slightly - starting at the minimum
693 and ending at maximum record level.
694 @SYMTestExpectedResults The driver should successfully record 10 seconds of data - i.e. all requests should complete
698 LOCAL_C void TestRecordVolume(TInt aNumChannels,TInt aNumSeconds)
700 TRequestStatus stat[2];
704 Test.Next(_L("Preparing to test variable record levels..."));
706 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
707 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
709 RecordFormatBuf().iChannels = aNumChannels;
711 // find first supported rate and set the the audio configuration to use it
712 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
714 RecordFormatBuf().iRate = (TSoundRate)i;
715 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
716 if (RecordCapsBuf().iRates & (1<<i))
718 CHECK_NOERROR(r); // Caps reports it is supported
722 PrintConfig(RecordFormatBuf(),Test);
724 // Set the record buffer configuration, then read it back.
726 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
727 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
728 TTestSharedChunkBufConfig bufferConfig;
729 bufferConfig.iNumBuffers=8;
730 bufferConfig.iBufferSizeInBytes=bufSize;
731 bufferConfig.iFlags=0; // All buffers will be contiguous
732 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
733 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
735 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
736 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
738 Test.Next(_L("Recording..."));
739 TInt remainingRecordCount = BytesPerSecond(RecordFormatBuf())*aNumSeconds/bufSize;
740 TInt bytesToRecord = remainingRecordCount*bufSize;
741 TInt bytesRecorded = 0;
743 // Issue a pair of record requests.
744 RxSoundDevice.SetVolume(KSoundMaxVolume);
745 RxSoundDevice.RecordData(stat[0],length[0]);
746 RxSoundDevice.RecordData(stat[1],length[1]);
752 // Adjust the record level.
753 TInt vol = I64LOW(TInt64(KSoundMaxVolume)*TInt64(bytesRecorded)/TInt64(bytesToRecord));
754 r=RxSoundDevice.SetVolume(vol);
757 // Wait for the next expected request to complete.
758 User::WaitForRequest(stat[currentReq]);
759 remainingRecordCount--;
760 retOffset=stat[currentReq].Int();
761 CHECK_POSITIVE(retOffset);
763 // Check the length recorded and update bytes recorded.
764 CHECK(length[currentReq]>0);
765 bytesRecorded += length[currentReq];
766 Test.Printf(_L("."));
768 // Read back the record level / check we can't reconfig while recording.
769 CHECK_EQUAL(RxSoundDevice.Volume(),vol);
770 CHECK_EQUAL(RxSoundDevice.SetAudioFormat(RecordFormatBuf),KErrInUse);
772 // Now release the buffer and issue another record request.
773 r=RxSoundDevice.ReleaseBuffer(retOffset);
775 // Don't issue any further record requests on the last two loop passes - to allow for the
776 // two record requests made before the loop started.
777 if (remainingRecordCount>=2)
778 RxSoundDevice.RecordData(stat[currentReq],length[currentReq]);
780 currentReq^=0x01; // Toggle the current req. indicator
782 while(remainingRecordCount>0);
784 CHECK_EQUAL(bytesToRecord,bytesRecorded);
786 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
787 Test.Printf(_L("\nBytes recorded = %d\r\n"),bytesRecorded);
791 /** @SYMTestCaseID PBASE-T_SOUND2-245
792 @SYMTestCaseDesc Play operation - play cancellation.
793 @SYMTestPriority Critical
794 @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer configuration
795 so it contains two buffers.
796 1) Issue two simultaneous play requests, one from each buffer, each of 1/2 second of tone.
797 Wait for the first one to complete and issue a further play request from the same buffer.
798 Then immediately cancel all outstanding play requests (using CancelPlayData()).
799 2) Issue two simultaneous play requests, one from each buffer, each of 1/2 second of tone.
800 Wait for the first one to complete and issue a further play request from the same buffer.
801 Then immediately cancel the 2nd (i.e. now active) play request (using Cancel()).
802 @SYMTestExpectedResults 1) Both outstanding requests should complete, either with KErrNone or with KErrCancel.
803 2) The second request should complete, either with KErrNone or with KErrCancel whereas the
804 third should complete only with KErrNone.
807 LOCAL_C void TestPlayCancel()
809 TRequestStatus stat[2];
813 tPtr[i]=new TPtr8(NULL,0);
815 Test.Next(_L("Test play cancellation"));
817 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
818 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
819 PlayFormatBuf().iChannels = 2;
821 // find first supported rate and set the the audio configuration to use it
822 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
824 // check record channel
825 PlayFormatBuf().iRate = (TSoundRate)i;
826 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
827 if (PlayCapsBuf().iRates & (1 << i))
829 CHECK_NOERROR(r); // Caps reports it is supported
833 PrintConfig(PlayFormatBuf(),Test);
834 r=MakeSineTable(PlayFormatBuf());
837 // Set the play buffer configuration, then read it back.
839 TInt bufSize=BytesPerSecond(PlayFormatBuf())/2; // Large enough to hold 1/2 second of data.
840 bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver.
841 TTestSharedChunkBufConfig bufferConfig;
842 bufferConfig.iNumBuffers=2;
843 bufferConfig.iBufferSizeInBytes=bufSize;
844 bufferConfig.iFlags=0; // All buffers will be contiguous
845 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
846 r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
848 TxSoundDevice.GetBufferConfig(bufferConfigBuf);
849 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
850 tPtr[0]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[0],0,bufSize);
851 tPtr[1]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[1],0,bufSize);
853 Test.Next(_L("Test cancelling all outstanding requests"));
854 // Issue a pair of play requests.
855 r=SetToneFrequency(440,PlayFormatBuf());
857 WriteTone(*tPtr[0],PlayFormatBuf());
858 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize);
859 WriteTone(*tPtr[1],PlayFormatBuf());
860 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize);
862 // Wait for the 1st request to complete. Then, re-queue a further request but then
863 // immediately cancel both requests.
864 User::WaitForRequest(stat[0]);
865 CHECK_NOERROR(stat[0].Int());
866 WriteTone(*tPtr[0],PlayFormatBuf());
867 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize);
868 TxSoundDevice.CancelPlayData();
870 User::WaitForRequest(stat[1]);
871 if (stat[1]==KErrNone)
872 Test.Printf(_L("Note: 2nd request finished without cancel error\r\n"));
874 CHECK_EQUAL(stat[1].Int(),KErrCancel);
875 User::WaitForRequest(stat[0]);
876 if (stat[0]==KErrNone)
877 Test.Printf(_L("Note: 3rd request finished without cancel error\r\n"));
879 CHECK_EQUAL(stat[0].Int(),KErrCancel);
881 Test.Next(_L("Test cancelling an individual requests"));
882 // Issue a further pair of play requests.
883 r=SetToneFrequency(440,PlayFormatBuf());
885 WriteTone(*tPtr[0],PlayFormatBuf());
886 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,0);
887 WriteTone(*tPtr[1],PlayFormatBuf());
888 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize,0);
890 // Again, wait for the 1st request to complete. Then, re-queue a further request but then
891 // immediately cancel the 2nd request.
892 User::WaitForRequest(stat[0]);
893 CHECK_NOERROR(stat[0].Int());
894 WriteTone(*tPtr[0],PlayFormatBuf());
895 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
896 TxSoundDevice.Cancel(stat[1]);
898 User::WaitForRequest(stat[1]);
899 if (stat[1]==KErrNone)
900 Test.Printf(_L("Note: 2nd request finished without cancel error\r\n"));
902 CHECK_EQUAL(stat[1].Int(),KErrCancel);
903 User::WaitForRequest(stat[0]);
904 CHECK_NOERROR(stat[0].Int());
907 Test.Printf(_L("Cancel play test completed successful\r\n"));
913 /** @SYMTestCaseID PBASE-T_SOUND2-259
914 @SYMTestCaseDesc Record operation - record cancellation.
915 @SYMTestPriority Critical
916 @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration
917 so it contains multiple buffers.
918 1) Issue two simultaneous record requests requests, each for 1/2 second of data. Wait for
919 the first one to complete and issue a further record request. Then immediately cancel all
920 outstanding record requests (using CancelRecordData()).
921 2) Issue two simultaneous record requests, each for 1/2 second of data. Wait for the first
922 one to complete and issue a further record request. Then immediately cancel the 2nd (i.e.
923 now active) record request (using Cancel()).
924 @SYMTestExpectedResults 1) Both outstanding requests should complete, either with KErrNone or with KErrCancel.
925 2) The second requests should complete, either with KErrNone or with KErrCancel whereas the
926 third should complete only with KErrNone.
929 LOCAL_C void TestRecordCancel()
931 TRequestStatus stat[2];
936 tPtr[i]=new TPtr8(NULL,0);
938 Test.Next(_L("Test record cancellation"));
940 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
941 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
942 RecordFormatBuf().iChannels = 2;
944 // find first supported rate and set the the audio configuration to use it
945 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
947 RecordFormatBuf().iRate = (TSoundRate)i;
948 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
949 if (RecordCapsBuf().iRates & (1<<i))
951 CHECK_NOERROR(r); // Caps reports it is supported
956 PrintConfig(RecordFormatBuf(),Test);
958 // Set the record buffer configuration, then read it back.
960 TTestSharedChunkBufConfig bufferConfig;
961 bufferConfig.iNumBuffers=3;
962 bufferConfig.iBufferSizeInBytes=BytesPerSecond(RecordFormatBuf())/2; // Large enough to hold 1/2 second of data.
963 bufferConfig.iBufferSizeInBytes=ValidBufferSize(bufferConfig.iBufferSizeInBytes,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
964 bufferConfig.iFlags=0; // All buffers will be contiguous
965 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
966 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
968 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
970 Test.Next(_L("Test cancelling all outstanding requests"));
971 // Issue a pair of record requests.
972 RxSoundDevice.RecordData(stat[0],length[0]);
973 RxSoundDevice.RecordData(stat[1],length[1]);
975 // Wait for the 1st request to complete. Then, re-queue a further request but then
976 // immediately cancel both requests.
978 User::WaitForRequest(stat[0]);
979 retOffset=stat[0].Int();
980 CHECK_POSITIVE(retOffset);
982 r=RxSoundDevice.ReleaseBuffer(retOffset);
984 RxSoundDevice.RecordData(stat[0],length[0]);
985 RxSoundDevice.CancelRecordData();
987 User::WaitForRequest(stat[1]);
988 retOffset=stat[1].Int();
990 Test.Printf(_L("Note: 2nd request finished without cancel error\r\n"));
992 CHECK_EQUAL(retOffset,KErrCancel);
993 User::WaitForRequest(stat[0]);
994 retOffset=stat[0].Int();
996 Test.Printf(_L("Note: 3rd request finished without cancel error\r\n"));
998 CHECK_EQUAL(retOffset,KErrCancel);
1000 Test.Next(_L("Test cancelling an individual requests"));
1001 // Issue a further pair of record requests.
1002 RxSoundDevice.RecordData(stat[0],length[0]);
1003 RxSoundDevice.RecordData(stat[1],length[1]);
1005 // Again, wait for the 1st request to complete. Then, re-queue a further request but then
1006 // immediately cancel the 2nd request.
1007 User::WaitForRequest(stat[0]);
1008 retOffset=stat[0].Int();
1009 CHECK_POSITIVE(retOffset);
1011 r=RxSoundDevice.ReleaseBuffer(retOffset);
1013 RxSoundDevice.RecordData(stat[0],length[0]);
1014 RxSoundDevice.Cancel(stat[1]);
1016 User::WaitForRequest(stat[1]);
1017 retOffset=stat[1].Int();
1019 Test.Printf(_L("Note: 2nd request finished without cancel error\r\n"));
1021 CHECK_EQUAL(retOffset,KErrCancel);
1022 User::WaitForRequest(stat[0]);
1023 retOffset=stat[0].Int();
1024 CHECK_POSITIVE(retOffset);
1027 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
1029 Test.Printf(_L("Cancel record test completed successful\r\n"));
1035 /** @SYMTestCaseID PBASE-T_SOUND2-262
1036 @SYMTestCaseDesc Play pause / resume - pausing and resuming before playback has commenced.
1037 @SYMTestPriority Critical
1038 @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration.
1039 1) Attempt to resume recording before recording has been started.
1040 2) Attempt to pause recording before recording has been started.
1041 @SYMTestExpectedResults 1) The resume request should complete with KErrNotReady.
1042 2) The pause request should complete with KErrNotReady.
1046 /** @SYMTestCaseID PBASE-T_SOUND2-263
1047 @SYMTestCaseDesc Record pause / resume - pausing and resuming while recording is in progress.
1048 @SYMTestPriority Critical
1049 @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration
1050 so it contains multiple buffers. For the audio configuration selected, calculate the total
1051 number of bytes expected to be transferred in order record 4 seconds of data. Using multiple
1052 simultaneous record requests, record 4 seconds of audio data - with each individual record
1053 request being for 1/8th second of data. Increment a count of actual total bytes transferred
1054 by examining the count of bytes stored in the buffer for each request as it completes.
1055 1) After 10 requests have completed, pause transfer for 1 second, then resume it. If pausing
1056 causes a record request to complete with a shorter than requested length then reduce the
1057 count of expected total bytes transferred.
1058 2) Repeat step 1 when 20 requests have completed.
1059 3) Once transfer has completed, compare the counts of expected and actual total bytes
1061 @SYMTestExpectedResults 1) The pause and resume requests should both complete with KErrNone.
1062 2) The pause and resume requests should both complete with KErrNone.
1063 3) The counts should be equal.
1066 LOCAL_C void TestRecordPauseResume(TUint aChannels)
1068 TRequestStatus stat[2];
1071 Test.Next(_L("Test record pause and resume"));
1072 RecordFormatBuf().iRate = ESoundRate44100Hz;
1073 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
1074 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1075 RecordFormatBuf().iChannels = aChannels;
1076 PrintConfig(RecordFormatBuf(),Test);
1077 TInt r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
1080 // Set the record buffer configuration, then read it back.
1082 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
1083 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
1084 TTestSharedChunkBufConfig bufferConfig;
1085 bufferConfig.iNumBuffers=8;
1086 bufferConfig.iBufferSizeInBytes=bufSize;
1087 bufferConfig.iFlags=0; // All buffers will be contiguous
1088 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1089 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
1091 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
1092 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
1094 Test.Printf(_L("Resume when not recording\r\n"));
1095 r=RxSoundDevice.Resume();
1096 CHECK(r==KErrNotReady)
1098 Test.Printf(_L("Pause when not recording\r\n"));
1099 r=RxSoundDevice.Pause();
1100 CHECK(r==KErrNotReady)
1102 // Record for 4 seconds
1103 Test.Printf(_L("Record...\r\n"));
1104 TInt remainingRecordCount = BytesPerSecond(RecordFormatBuf())*4/bufSize;
1105 TInt bytesToRecord = remainingRecordCount*bufSize;
1106 TInt bytesRecorded = 0;
1108 // Issue a pair of record requests.
1109 RxSoundDevice.SetVolume(KSoundMaxVolume);
1111 RxSoundDevice.RecordData(stat[0],length[0]);
1113 RxSoundDevice.RecordData(stat[1],length[1]);
1120 // Do a pause / resume on 10th and 20th loop passes.
1121 if (lcount && !(lcount%10))
1123 // Do a pause/resume
1124 Test.Printf(_L("Pause 1 second\r\n"));
1125 r=RxSoundDevice.Pause();
1128 // Pausing record may result in the driver completing with a buffer not completely full. This isn't an error. Otherwise, all outstanding
1129 // requests should complete with KErrCancel. Wait for the 1st outstanding request to complete.
1130 User::WaitForRequest(stat[currentReq]);
1131 retOffset=stat[currentReq].Int();
1134 // Partially filled buffer. We need to adjust the bytes expected when an incomplete buffer arrives.
1135 remainingRecordCount--;
1137 CHECK_POSITIVE(length[currentReq]);
1138 CHECK(length[currentReq]<=bufSize);
1139 bytesRecorded += length[currentReq];
1140 if (length[currentReq]<bufSize)
1141 bytesToRecord-=(bufSize-length[currentReq]);
1142 Test.Printf(_L("1st outstanding req partially completed(len=%d)\r\n"),length[currentReq]);
1144 r=RxSoundDevice.ReleaseBuffer(retOffset); // Release the buffer ready for resuming
1149 CHECK(retOffset==KErrCancel);
1150 Test.Printf(_L("1st outstanding req cancelled\r\n"));
1152 currentReq^=0x01; // Toggle the current req. indicator
1154 // Wait for the 2nd outstanding request to complete
1155 User::WaitForRequest(stat[currentReq]);
1156 retOffset=stat[currentReq].Int();
1157 CHECK(retOffset==KErrCancel);
1158 Test.Printf(_L("2nd outstanding req cancelled\r\n"));
1160 // Idle for 1 second, resume and then re-issue a pair of record requests.
1161 User::After(1000000);
1162 Test.Printf(_L("Resume\r\n"));
1163 r=RxSoundDevice.Resume();
1165 RxSoundDevice.RecordData(stat[0],length[0]);
1166 RxSoundDevice.RecordData(stat[1],length[1]);
1170 // Wait for the next expected request to complete.
1171 User::WaitForRequest(stat[currentReq]);
1172 remainingRecordCount--;
1173 retOffset=stat[currentReq].Int();
1174 CHECK_POSITIVE(retOffset);
1175 CHECK(length[currentReq]>0);
1176 bytesRecorded += length[currentReq];
1178 // Now release the buffer and issue another record request
1179 r=RxSoundDevice.ReleaseBuffer(retOffset);
1181 // Don't issue any further record requests on the last two loop passes - to allow for the
1182 // two record requests made before the loop started.
1183 if (remainingRecordCount>=2)
1184 RxSoundDevice.RecordData(stat[currentReq],length[currentReq]);
1186 currentReq^=0x01; // Toggle the current req. indicator
1188 while(remainingRecordCount>0);
1190 CHECK_EQUAL(bytesToRecord,bytesRecorded);
1191 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
1192 Test.Printf(_L("Record pause/resume successful\r\n"));
1194 Test.Next(_L("Test record pause alone"));
1196 // Issue a single record request, wait for it to complete and then release it.
1197 RxSoundDevice.RecordData(stat[0],length[0]);
1198 User::WaitForRequest(stat[0]);
1199 retOffset=stat[0].Int();
1200 CHECK_POSITIVE(retOffset);
1201 CHECK(length[0]==bufSize);
1202 r=RxSoundDevice.ReleaseBuffer(retOffset);
1205 // Without issuing another record request, wait for a duration equal to one record buffer, then pause.
1206 User::After(150000); // Wait a bit longer than 1 buffer's worth (125000 is 1/8 second).
1207 Test.Printf(_L("Pause\r\n"));
1208 r=RxSoundDevice.Pause();
1211 // Check that there is at least 1 buffer's worth of record data available
1212 RxSoundDevice.RecordData(stat[0],length[0]);
1213 User::WaitForRequest(stat[0]);
1214 retOffset=stat[0].Int();
1215 CHECK_POSITIVE(retOffset);
1216 CHECK(length[0]==bufSize);
1217 Test.Printf(_L("1st req completed successfully\r\n"));
1218 r=RxSoundDevice.ReleaseBuffer(retOffset);
1221 // There's probably also a partially filled buffer
1222 RxSoundDevice.RecordData(stat[0],length[0]);
1223 User::WaitForRequest(stat[0]);
1224 retOffset=stat[0].Int();
1227 // Partially filled buffer.
1229 CHECK(length[0] <= bufSize);
1230 Test.Printf(_L("2nd req partially completed(len=%d)\r\n"),length[0]);
1231 r=RxSoundDevice.ReleaseBuffer(retOffset);
1236 CHECK(retOffset==KErrCancel);
1237 Test.Printf(_L("2nd req cancelled\r\n"));
1242 // Read all buffers until driver is empty. The RecordData call after that should immediately return with KErrCancel
1243 Test.Printf(_L("Draining driver\r\n"));
1244 RxSoundDevice.RecordData(stat[0],length[0]);
1245 User::WaitForRequest(stat[0]);
1246 retOffset=stat[0].Int();
1247 if(retOffset==KErrCancel)
1251 CHECK_NOERROR(retOffset);
1253 Test.Printf(_L("Driver empty\r\n"));
1255 r=RxSoundDevice.Resume(); // Don't leave it in paused state.
1257 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
1258 Test.Printf(_L("Record pause successful\r\n"));
1276 return iArray.Count();
1278 void PushL(const T &aItem)
1280 iArray.AppendL(aItem);
1284 if(iArray.Count() == 0)
1286 User::Leave(KErrUnderflow);
1288 const T ret = iArray[0];
1295 /** @SYMTestCaseID PBASE-T_SOUND2-248
1296 @SYMTestCaseDesc Play operation - simultaneous play and record on the same device, using a common shared chunk.
1297 @SYMTestPriority Critical
1298 @SYMTestActions Setup the audio configuration on the record channel and setup an identical audio
1299 configuration on the playback channel. On the record channel, create a shared chunk
1300 (i.e. using SetBufferChunkCreate()) with a buffer configuration containing multiple buffers.
1301 Open the same shared chunk on the playback channel (i.e. using SetBufferChunkOpen()).
1302 Set the volume to maximum level in both channels. Record 10 seconds of audio data - with
1303 each individual record request being for 1/8th second of data. As soon as each record request
1304 completes, issue a corresponding request on the playback channel to playback the
1305 1/8th second of data recorded. Only release each buffer for further recording once its
1306 contents have been played back. Continue until 10 seconds of audio data has been both
1307 recorded and played back. (Ensure the last play request is marked with the
1308 KSndFlagLastSample flag).
1309 @SYMTestExpectedResults The driver should successfully record and play 10 seconds of data - with all requests
1310 completing with KErrNone.
1313 void TestSimultaneousPlayRecord()
1315 Test.Next(_L("Preparing to record/play simultaneously..."));
1318 // Setup the same sound configuration for both - record and play channels
1319 if (RecordCapsBuf().iEncodings & KSoundEncoding16BitPCM)
1320 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1322 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
1323 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1325 RecordFormatBuf().iChannels = 2;
1326 PlayFormatBuf().iChannels = 2;
1328 // find first supported rate and set the the audio configuration to use it
1329 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
1331 // check record channel
1332 RecordFormatBuf().iRate = (TSoundRate)i;
1333 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
1334 if (RecordCapsBuf().iRates & (1 << i))
1336 CHECK_NOERROR(r); // Caps reports it is supported
1338 // ..and try the same bitrate for playback
1339 PlayFormatBuf().iRate = (TSoundRate)i;
1340 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
1341 if (PlayCapsBuf().iRates & (1 << i))
1343 CHECK_NOERROR(r); // Caps reports it is supported
1349 // both channels are set at this point, continue
1350 PrintConfig(RecordFormatBuf(),Test);
1351 PrintConfig(PlayFormatBuf(),Test);
1353 // Set the volume level in both channels
1354 RxSoundDevice.SetVolume(KSoundMaxVolume);
1355 TxSoundDevice.SetVolume(KSoundMaxVolume - 10);
1357 // Set the record buffer configuration, then read it back.
1359 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
1360 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
1361 TTestSharedChunkBufConfig bufferConfig;
1362 bufferConfig.iNumBuffers=7+7; // Must be able to use less than this
1363 bufferConfig.iBufferSizeInBytes=bufSize;
1364 bufferConfig.iFlags=0; // All buffers will be contiguous
1365 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1366 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
1368 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
1369 PrintBufferConf(bufferConfig,Test);
1370 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
1372 // Assign the same chunk to the play channel.
1373 r=TxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk);
1376 Test.Next(_L("Starting transfer..."));
1377 TInt remainingRecordCount = BytesPerSecond(RecordFormatBuf())*10/bufSize; // 10 seconds
1378 TInt remainingPlayCount = remainingRecordCount;
1379 TInt bytesToTransfer = remainingRecordCount*bufSize;
1380 TInt bytesRecorded = 0;
1381 TInt bytesPlayed = 0;
1383 TRequestStatus stat[3]; // 1 record + 2 play request statuses
1385 TInt activePlayOffset[2]; // To keep track of the buffer offset for each active play request.
1386 RQueue<TInt> playQueue; // A list containing the offsets for any buffer which is waiting to be played.
1388 // Issue three record requests and wait for them to complete.
1390 for (i=0 ; i<3 ; i++)
1392 RxSoundDevice.RecordData(stat[2],length);
1393 User::WaitForRequest(stat[2]);
1394 retOffset=stat[2].Int();
1395 // Test.Printf(_L("RECORD(%d)-Buf %d\r\n"),i,retOffset);
1396 CHECK_POSITIVE(retOffset);
1397 CHECK(length==bufSize);
1398 bytesRecorded += length;
1399 playQueue.PushL(retOffset);
1400 remainingRecordCount--;
1401 Test.Printf(_L("."));
1404 // Start playing first two buffers
1406 activePlayOffset[0]=playQueue.PopL();
1407 TxSoundDevice.PlayData(stat[0],activePlayOffset[0],bufSize,flags);
1408 activePlayOffset[1]=playQueue.PopL();
1409 TxSoundDevice.PlayData(stat[1],activePlayOffset[1],bufSize,flags);
1411 // Now queue the next record request.
1412 RxSoundDevice.RecordData(stat[2],length);
1416 // Wait for the next request to complete.
1417 User::WaitForAnyRequest();
1419 // Work out which request this applies to.
1422 if (stat[i]!=KRequestPending)
1429 // It is the record request that has completed
1430 remainingRecordCount--;
1431 retOffset=stat[2].Int();
1432 // Test.Printf(_L("RECORD(%d)-Buf %d\r\n"),remainingRecordCount,retOffset);
1433 CHECK_POSITIVE(retOffset);
1434 CHECK(length==bufSize);
1435 bytesRecorded += length;
1436 Test.Printf(_L("."));
1438 // Add the buffer to playQueue
1439 playQueue.PushL(retOffset);
1441 // If we haven't recorded enough data yet then record some more.
1442 if (remainingRecordCount>0)
1443 RxSoundDevice.RecordData(stat[2],length);
1446 Test.Printf(_L("***Disabling stat[2]\r\n"));
1447 stat[2]=KRequestPending;
1452 // Its one of the play requests that have completed
1453 if(stat[i].Int() >= 0)
1455 // release the buffer.
1456 // Test.Printf(_L("PLAY(%d) i%d CompBuf %d\r\n"),remainingPlayCount-1,i,activePlayOffset[i]);
1457 r=RxSoundDevice.ReleaseBuffer(activePlayOffset[i]);
1459 Test.Printf(_L("*"));
1463 // Play failed - but we ignore underflow because it often happens on WDP roms.
1464 CHECK(stat[i].Int() == KErrUnderflow);
1465 Test.Printf(_L("U"));
1468 remainingPlayCount--;
1469 bytesPlayed += bufSize;
1471 // If there are buffers available then issue a further play request and update the 'next to play' list.
1472 if (playQueue.Count() != 0)
1474 activePlayOffset[i]=playQueue.PopL();
1476 // Test.Printf(_L("PLAY(%d) i%d NextBuf%d\r\n"),remainingPlayCount,i,activePlayOffset[i]);
1477 flags=(remainingPlayCount<=2)?KSndFlagLastSample:0;
1478 TxSoundDevice.PlayData(stat[i],activePlayOffset[i],bufSize,flags);
1482 Test.Printf(_L("***Disabling stat[%d]\r\n"), i, stat[i].Int());
1483 stat[i]=KRequestPending;
1487 while (remainingRecordCount>0 || remainingPlayCount>0);
1489 CHECK_EQUAL(bytesToTransfer,bytesRecorded);
1490 CHECK_EQUAL(bytesToTransfer,bytesPlayed);
1492 RxSoundDevice.CancelRecordData(); // Stop the driver from recording.
1495 Test.Printf(_L("\nSimultaneous test ends\r\n"));
1501 Test.Next(_L("Preparing to measure record/playback speed..."));
1504 // Setup the same sound configuration for both - record and play channels
1505 if (RecordCapsBuf().iEncodings & KSoundEncoding16BitPCM)
1506 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1508 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
1509 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1511 RecordFormatBuf().iChannels = 2;
1512 PlayFormatBuf().iChannels = 2;
1514 // find first supported rate and set the the audio configuration to use it
1515 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
1517 // check record channel
1518 RecordFormatBuf().iRate = (TSoundRate)i;
1519 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
1520 if (RecordCapsBuf().iRates & (1 << i))
1522 CHECK_NOERROR(r); // Caps reports it is supported
1524 // ..and try the same bitrate for playback
1525 PlayFormatBuf().iRate = (TSoundRate)i;
1526 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
1527 if (PlayCapsBuf().iRates & (1 << i))
1529 CHECK_NOERROR(r); // Caps reports it is supported
1535 // both channels are set at this point, continue
1536 PrintConfig(RecordFormatBuf(),Test);
1537 PrintConfig(PlayFormatBuf(),Test);
1539 // Set the volume level in both channels
1540 RxSoundDevice.SetVolume(KSoundMaxVolume);
1541 TxSoundDevice.SetVolume(KSoundMaxVolume - 10);
1543 // Set the record buffer configuration, then read it back.
1545 TInt bufSize=BytesPerSecond(RecordFormatBuf())/8; // Large enough to hold 1/8th second of data.
1546 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
1547 TTestSharedChunkBufConfig bufferConfig;
1548 bufferConfig.iNumBuffers=7+7; // Must be able to use less than this
1549 bufferConfig.iBufferSizeInBytes=bufSize;
1550 bufferConfig.iFlags=0; // All buffers will be contiguous
1551 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1552 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
1554 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
1555 PrintBufferConf(bufferConfig,Test);
1556 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
1558 // Assign the same chunk to the play channel.
1559 r=TxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk);
1562 Test.Next(_L("Starting recording speed test..."));
1565 // Recording speed test
1566 TTime preTime, postTime;
1567 preTime.UniversalTime();
1568 for(i=0; i<100; ++i)
1573 TTime preBufTime, postBufTime;
1574 preBufTime.UniversalTime();
1575 RxSoundDevice.RecordData(s, length);
1576 User::WaitForRequest(s);
1578 postBufTime.UniversalTime();
1579 TTimeIntervalMicroSeconds elapsedBufTime = postBufTime.MicroSecondsFrom(preBufTime);
1580 Test.Printf(_L("\tElapsed buf (%d/100) recording time %d\n"), i, elapsedBufTime.Int64());
1581 CHECK(s.Int() >= 0);
1582 CHECK(RxSoundDevice.ReleaseBuffer(s.Int()) == KErrNone);
1583 CHECK(length == bufSize);
1585 postTime.UniversalTime();
1586 TTimeIntervalMicroSeconds elapsedRecordingTime = postTime.MicroSecondsFrom(preTime);
1587 Test.Printf(_L("Elapsed recording time %d\n"), elapsedRecordingTime.Int64());
1588 Test.Printf(_L("Record timing done\n"));
1594 TxSoundDevice.CancelPlayData();
1595 struct RequestInfo {
1599 RequestInfo requestA;
1600 RequestInfo requestB;
1602 // Get two buffers for playback speed test
1603 RxSoundDevice.RecordData(requestA.s_m, length);
1604 User::WaitForRequest(requestA.s_m);
1605 CHECK(requestA.s_m.Int() >= 0);
1606 requestA.bufOffset_m = requestA.s_m.Int();
1608 RxSoundDevice.RecordData(requestB.s_m, length);
1609 User::WaitForRequest(requestB.s_m);
1610 CHECK(requestB.s_m.Int() >= 0);
1611 requestB.bufOffset_m = requestB.s_m.Int();
1613 Test.Printf(_L("buf offsets %d %d\n"), requestA.bufOffset_m, requestB.bufOffset_m);
1615 RequestInfo *prevRequest = &requestA;
1616 RequestInfo *currRequest = &requestB;
1618 // Issue initial play request
1619 TxSoundDevice.PlayData(prevRequest->s_m, prevRequest->bufOffset_m, bufSize);
1621 preTime.UniversalTime();
1622 for(i=0; i<100; ++i)
1624 // Issue new request so we do not underflow....
1625 TxSoundDevice.PlayData(currRequest->s_m, currRequest->bufOffset_m, bufSize, (i==99)?(KSndFlagLastSample) : (0));
1627 // Wait for previous request to complete
1628 TTime preBufTime, postBufTime;
1629 preBufTime.UniversalTime();
1630 User::WaitForRequest(prevRequest->s_m);
1631 CHECK_NOERROR(prevRequest->s_m.Int());
1633 postBufTime.UniversalTime();
1634 TTimeIntervalMicroSeconds elapsedBufTime = postBufTime.MicroSecondsFrom(preBufTime);
1635 Test.Printf(_L("\tElapsed buf (%d/100) playback time %d\n"), i, elapsedBufTime.Int64());
1637 // Swap previous and current requests
1638 RequestInfo *p = prevRequest;
1639 prevRequest = currRequest;
1643 postTime.UniversalTime();
1644 TTimeIntervalMicroSeconds elapsedPlaybackTime = postTime.MicroSecondsFrom(preTime);
1645 Test.Printf(_L("Elapsed playback time = %d us\n"), elapsedPlaybackTime.Int64());
1646 Test.Printf(_L("Elapsed recording time = %d us\n"), elapsedRecordingTime.Int64());
1648 double play = (double) elapsedPlaybackTime.Int64();
1649 double record = (double) elapsedRecordingTime.Int64();
1650 Test.Printf(_L("difference %f%%\n"), (play*100)/record);
1652 User::WaitForRequest(prevRequest->s_m);
1653 CHECK_NOERROR(prevRequest->s_m.Int());
1655 // Free the two buffers
1656 CHECK(RxSoundDevice.ReleaseBuffer(requestA.bufOffset_m) == KErrNone);
1657 CHECK(RxSoundDevice.ReleaseBuffer(requestB.bufOffset_m) == KErrNone);
1659 Test.Printf(_L("Playback done\n"));
1660 TxSoundDevice.CancelPlayData();
1661 RxSoundDevice.CancelPlayData();
1668 void TestDefectDTWMM00678()
1670 // DTW-MM00678 RSoundSc::RecordData() returns recorded length > allocated buffer size
1671 TRequestStatus status[3];
1673 Test.Next(_L("DTW-MM00678 RSoundSc::RecordData() returns recorded length > allocated buffer size"));
1675 // Make sure recording is not in progress
1676 RxSoundDevice.CancelRecordData();
1680 // Setup the same sound configuration for both - record and play channels
1681 if (RecordCapsBuf().iEncodings & KSoundEncoding16BitPCM)
1682 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1684 RecordFormatBuf().iChannels = 2;
1686 // Find first supported rate and set the the audio configuration to use it
1687 for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
1689 // check record channel
1690 RecordFormatBuf().iRate = (TSoundRate)i;
1691 if (RecordCapsBuf().iRates & (1 << i))
1693 // Caps reports it is supported
1694 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
1699 // Check we found/set a valid format
1700 CHECK(i <= ESoundRate48000Hz);
1702 // Set recording format
1703 PrintConfig(RecordFormatBuf(),Test);
1705 // Set the volume level
1706 RxSoundDevice.SetVolume(KSoundMaxVolume);
1708 // Set the record buffer configuration, then read it back.
1710 TInt bufSize = 64 * 1024; // The defect is seen, on windows, when the buffer size is 64k and the LDD does 2x 32k transfers per buffer
1711 TTestSharedChunkBufConfig bufferConfig;
1712 bufferConfig.iNumBuffers=7;
1713 bufferConfig.iBufferSizeInBytes=bufSize;
1714 bufferConfig.iFlags=0;
1715 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1716 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
1718 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
1719 PrintBufferConf(bufferConfig,Test);
1720 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
1722 // Calculate time required to fill a single 64k byte buffer
1723 TUint32 durationOneBufferMsec = (1000 * bufSize) / BytesPerSecond(RecordFormatBuf());
1724 Test.Printf(_L("durationOneBufferMsec %d\n"), durationOneBufferMsec);
1726 // Start recording....
1727 Test.Printf(_L("Issue 3 RecordData requests then wait to pause during second internal 32k internal transfers of the second buffer...\n"));
1730 RxSoundDevice.RecordData(status[i], length[i]);
1733 // Wait for 1 3/4 64k buffers. In other words, wait for 3.75x32k byte internal transfers so we pause during the second transfer of the second buffer
1734 User::After(durationOneBufferMsec *1000 * (1 + 3/4) );
1736 CHECK_NOERROR(RxSoundDevice.Pause());
1737 Test.Printf(_L("Paused\n"));
1741 User::WaitForRequest(status[i]);
1742 Test.Printf(_L("status[%d].Int() = %d\n"), i, status[i].Int());
1743 Test.Printf(_L("length[%d] = %d\n"), i, length[i]);
1746 bool testValid = true;
1748 if((status[0].Int() < 0) || (length[0] != bufSize))
1751 Test.Printf(_L("Test invalid because pause hit first request\n"));
1754 if(testValid && (status[1].Int() == KErrCancel))
1757 Test.Printf(_L("Test invalid because pause hit before second request started\n"));
1760 if(testValid && (status[2].Int() != KErrCancel))
1763 Test.Printf(_L("Test invalid because pause missed all requests\n"));
1768 Test.Printf(_L("Appear to have issued pause at the correct time, check results\n"));
1769 // First request should have completed with a full buffer of data
1770 CHECK(status[0].Int() >= 0);
1771 CHECK(length[0] == bufSize);
1773 // second request should have been truncated
1774 CHECK(status[1].Int() >= 0);
1775 CHECK(length[1] < bufSize);
1777 // Last request should have been cancelled.
1778 CHECK(status[2].Int() == KErrCancel);
1780 Test.Printf(_L("DTW-MM00678 test done\r\n"));
1782 //CHECK_NOERROR(RxSoundDevice.Resume());
1784 // Make sure recording is not in progress
1785 RxSoundDevice.CancelRecordData();
1786 TxSoundDevice.CancelPlayData();
1793 LOCAL_C void TestUnloadDrivers()
1795 TInt r=User::FreeLogicalDevice(KDevSoundScName);
1796 Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
1799 TName pddName(KDevSoundScName);
1800 _LIT(KPddWildcardExtension,".*");
1801 pddName.Append(KPddWildcardExtension);
1802 TFindPhysicalDevice findPD(pddName);
1803 TFullName findResult;
1804 r=findPD.Next(findResult);
1807 r=User::FreePhysicalDevice(findResult);
1808 Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
1810 findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
1811 r=findPD.Next(findResult);
1815 void TestTimePlayed()
1817 TTimeIntervalMicroSecondsBuf timeIntervalBuf;
1819 // Don't try to do the tests if TimePlayed() is not supported
1820 TInt r = TxSoundDevice.TimePlayed(timeIntervalBuf);
1821 if (r == KErrNotSupported)
1823 Test.Printf(_L("TimePlayed() is not supported, skipping tests\n"));
1830 // Find first supported rate and set the the audio configuration to use it
1831 for (rate = 0; rate <= ESoundRate48000Hz; ++rate)
1833 if (PlayCapsBuf().iRates & (1 << rate))
1839 // Test mono and Stereo
1840 for (TInt channels=1; channels<=2; ++channels)
1842 TRequestStatus stat[2];
1844 Test.Next(_L("Preparing to play..."));
1845 if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
1846 PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
1847 PlayFormatBuf().iRate = (TSoundRate) rate;
1848 PlayFormatBuf().iChannels = channels;
1849 PrintConfig(PlayFormatBuf(),Test);
1850 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
1853 // Set the play buffer configuration, then read it back.
1855 TInt bufSize=BytesPerSecond(PlayFormatBuf()); // Large enough to hold 1 second of data.
1856 bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver.
1857 TTestSharedChunkBufConfig bufferConfig;
1858 bufferConfig.iNumBuffers=2;
1859 bufferConfig.iBufferSizeInBytes=bufSize;
1860 bufferConfig.iFlags=0; // All buffers will be contiguous
1861 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1862 r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
1864 TxSoundDevice.GetBufferConfig(bufferConfigBuf);
1865 PrintBufferConf(bufferConfig,Test);
1866 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
1870 tPtr[i]=new TPtr8(chunk.Base()+bufferConfig.iBufferOffsetList[i],bufSize);
1873 r=MakeSineTable(PlayFormatBuf());
1875 r=SetToneFrequency(440,PlayFormatBuf());
1878 WriteTone(*tPtr[0],PlayFormatBuf());
1879 WriteTone(*tPtr[1],PlayFormatBuf());
1881 // set up a timer to interrogate time played
1882 TRequestStatus timerStat;
1884 timer.CreateLocal();
1885 TTimeIntervalMicroSeconds32 timerInterval(50000);
1887 TInt64 currentTime, previousTime;
1889 Test.Next(_L("Time Played..."));
1891 currentTime = previousTime = MAKE_TINT64(0,0);
1893 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,0);
1894 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize,KSndFlagLastSample);
1896 // check requests are pending
1897 CHECK_EQUAL(stat[0].Int(),KRequestPending);
1898 CHECK_EQUAL(stat[1].Int(),KRequestPending);
1900 // check time recorded is not supported for play channel
1901 CHECK(TxSoundDevice.TimeRecorded(timeIntervalBuf)==KErrNotSupported);
1903 timer.After(timerStat,timerInterval);
1905 while (stat[0] == KRequestPending)
1907 User::WaitForRequest(stat[0],timerStat);
1908 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
1909 previousTime = currentTime;
1910 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
1912 currentTime = timeIntervalBuf().Int64();
1913 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
1915 // ensure time is increasing or function is not supported
1916 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
1918 if (timerStat != KRequestPending)
1920 timer.After(timerStat,timerInterval);
1925 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
1926 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
1928 currentTime = timeIntervalBuf().Int64();
1929 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
1931 CHECK_EQUAL(stat[0].Int(),KErrNone);
1933 timer.After(timerStat,timerInterval);
1935 while (stat[1] == KRequestPending)
1937 User::WaitForRequest(stat[1],timerStat);
1938 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
1939 previousTime = currentTime;
1940 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
1943 currentTime = timeIntervalBuf().Int64();
1944 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
1946 // ensure time is increasing or function is not supported
1947 if (stat[1] == KRequestPending) // still playing
1949 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
1952 if (timerStat != KRequestPending)
1954 timer.After(timerStat,timerInterval);
1960 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
1961 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
1964 currentTime = timeIntervalBuf().Int64();
1965 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(timeIntervalBuf().Int64()),I64LOW(timeIntervalBuf().Int64()));
1967 CHECK_EQUAL(stat[1].Int(),KErrNone);
1970 // Time Played with pause
1973 Test.Next(_L("Time Played with pause..."));
1975 TTimeIntervalMicroSeconds32 pauseInterval(2000000);
1976 TBool paused = EFalse;
1978 currentTime = previousTime = MAKE_TINT64(0,0);
1981 TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,0);
1982 TxSoundDevice.PlayData(stat[1],bufferConfig.iBufferOffsetList[1],bufSize,KSndFlagLastSample);
1984 // check requests are pending
1985 CHECK_EQUAL(stat[0].Int(),KRequestPending);
1986 CHECK_EQUAL(stat[1].Int(),KRequestPending);
1988 // check time recorded is not supported for play channel
1989 CHECK(TxSoundDevice.TimeRecorded(timeIntervalBuf)==KErrNotSupported);
1991 timer.After(timerStat,timerInterval);
1993 while (stat[0] == KRequestPending)
1995 User::WaitForRequest(stat[0],timerStat);
1996 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
1997 previousTime = currentTime;
1998 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2000 currentTime = timeIntervalBuf().Int64();
2001 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2003 // ensure time is increasing or function is not supported
2004 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2006 // Pause and resume ...
2007 if (paused == EFalse && I64LOW(currentTime) > 500000)
2010 TxSoundDevice.Pause();
2011 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2013 TInt64 pausedTime1 = timeIntervalBuf().Int64();
2014 Test.Printf(_L("Paused time_high %d, time_low %d\n"),I64HIGH(pausedTime1),I64LOW(pausedTime1));
2016 User::After(pauseInterval);
2018 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2020 TInt64 pausedTime2 = timeIntervalBuf().Int64();
2021 Test.Printf(_L("Resumed time_high %d, time_low %d\n"),I64HIGH(pausedTime2),I64LOW(pausedTime2));
2022 //CHECK(pausedTime1 == pausedTime2);
2023 TxSoundDevice.Resume();
2026 if (timerStat != KRequestPending)
2028 timer.After(timerStat,timerInterval);
2033 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2034 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2036 currentTime = timeIntervalBuf().Int64();
2037 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2039 CHECK_EQUAL(stat[0].Int(),KErrNone);
2041 timer.After(timerStat,timerInterval);
2043 while (stat[1] == KRequestPending)
2045 User::WaitForRequest(stat[1],timerStat);
2046 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
2047 previousTime = currentTime;
2048 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2051 currentTime = timeIntervalBuf().Int64();
2052 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2054 // ensure time is increasing or function is not supported
2055 if (stat[1] == KRequestPending) // still playing
2057 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2060 if (timerStat != KRequestPending)
2062 timer.After(timerStat,timerInterval);
2068 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
2069 r = TxSoundDevice.TimePlayed(timeIntervalBuf);
2072 currentTime = timeIntervalBuf().Int64();
2073 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(timeIntervalBuf().Int64()),I64LOW(timeIntervalBuf().Int64()));
2075 CHECK_EQUAL(stat[1].Int(),KErrNone);
2086 void TestTimeRecorded()
2088 TTimeIntervalMicroSecondsBuf timeIntervalBuf;
2090 TInt r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2091 if (r == KErrNotSupported)
2093 Test.Printf(_L("TimeRecorded() is not supported, skipping tests\n"));
2100 // Find first supported rate and set the the audio configuration to use it
2101 for (rate = 0; rate <= ESoundRate48000Hz; ++rate)
2103 if (PlayCapsBuf().iRates & (1 << rate))
2109 // Test mono and Stereo
2110 for (TInt channels=1; channels<=2; ++channels)
2112 TRequestStatus stat[2];
2114 Test.Next(_L("Preparing to record..."));
2115 if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
2116 RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
2117 RecordFormatBuf().iRate = (TSoundRate) rate;
2118 RecordFormatBuf().iChannels = channels;
2119 PrintConfig(RecordFormatBuf(),Test);
2120 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
2123 // Set the play buffer configuration, then read it back.
2125 TInt bufSize=BytesPerSecond(RecordFormatBuf()); // Large enough to hold 1 second of data.
2126 bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver.
2127 TTestSharedChunkBufConfig bufferConfig;
2128 bufferConfig.iNumBuffers=4;
2129 bufferConfig.iBufferSizeInBytes=bufSize;
2130 bufferConfig.iFlags=0; // All buffers will be contiguous
2131 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
2132 r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
2134 RxSoundDevice.GetBufferConfig(bufferConfigBuf);
2135 PrintBufferConf(bufferConfig,Test);
2136 CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
2138 // set up a timer to interrogate time played
2139 TRequestStatus timerStat;
2141 timer.CreateLocal();
2142 TTimeIntervalMicroSeconds32 timerInterval(50000);
2144 TInt64 currentTime, previousTime;
2146 Test.Next(_L("Time Recorded..."));
2148 currentTime = previousTime = MAKE_TINT64(0,0);
2150 TInt length1=0, length2=0;
2151 RxSoundDevice.RecordData(stat[0],length1);
2152 RxSoundDevice.RecordData(stat[1],length2);
2154 // check requests are pending
2155 CHECK_EQUAL(stat[0].Int(),KRequestPending);
2156 CHECK_EQUAL(stat[1].Int(),KRequestPending);
2158 // check time played is not supported for record channel
2159 CHECK(RxSoundDevice.TimePlayed(timeIntervalBuf)==KErrNotSupported);
2161 timer.After(timerStat,timerInterval);
2163 while (stat[0] == KRequestPending)
2165 User::WaitForRequest(stat[0],timerStat);
2166 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2167 previousTime = currentTime;
2168 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2170 currentTime = timeIntervalBuf().Int64();
2171 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2173 // ensure time is increasing or function is not supported
2174 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2176 if (timerStat != KRequestPending)
2178 timer.After(timerStat,timerInterval);
2183 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2184 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2186 currentTime = timeIntervalBuf().Int64();
2187 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2189 CHECK(stat[0].Int() == 0);
2191 timer.After(timerStat,timerInterval);
2193 while (stat[1] == KRequestPending)
2195 User::WaitForRequest(stat[1],timerStat);
2196 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
2197 previousTime = currentTime;
2198 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2200 currentTime = timeIntervalBuf().Int64();
2201 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2203 // ensure time is increasing or function is not supported
2204 if (stat[1] == KRequestPending) // still playing
2206 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2209 if (timerStat != KRequestPending)
2211 timer.After(timerStat,timerInterval);
2217 Test.Printf(_L("stat[1] %x, timerStat %x\n"),stat[1].Int(),timerStat.Int());
2218 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2220 currentTime = timeIntervalBuf().Int64();
2221 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(timeIntervalBuf().Int64()),I64LOW(timeIntervalBuf().Int64()));
2223 CHECK(stat[1].Int() > 0);
2225 // stop recording into the next buffer
2226 RxSoundDevice.CancelRecordData();
2228 // Release the buffers
2229 r = RxSoundDevice.ReleaseBuffer(stat[0].Int());
2230 CHECK_EQUAL(r, KErrNone);
2231 r = RxSoundDevice.ReleaseBuffer(stat[1].Int());
2232 CHECK_EQUAL(r, KErrNone);
2235 // Time Recorded with pause
2238 Test.Next(_L("Time Recorded with pause..."));
2240 TTimeIntervalMicroSeconds32 pauseInterval(2000000);
2241 TBool paused = EFalse;
2243 currentTime = previousTime = MAKE_TINT64(0,0);
2245 // Record and discard some data to make sure all testing is not within the first buffer...
2246 RxSoundDevice.RecordData(stat[0],length1);
2247 User::WaitForRequest(stat[0]);
2248 CHECK(stat[0].Int() >= 0);
2249 RxSoundDevice.ReleaseBuffer(stat[0].Int());
2251 RxSoundDevice.RecordData(stat[0],length1);
2252 RxSoundDevice.RecordData(stat[1],length2);
2254 // check requests are pending
2255 CHECK_EQUAL(stat[0].Int(),KRequestPending);
2257 // check time recorded is not supported for play channel
2258 CHECK(RxSoundDevice.TimePlayed(timeIntervalBuf)==KErrNotSupported);
2260 timer.After(timerStat,timerInterval);
2262 while (stat[0] == KRequestPending)
2264 User::WaitForRequest(stat[0],timerStat);
2265 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2266 previousTime = currentTime;
2267 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2269 currentTime = timeIntervalBuf().Int64();
2270 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2272 // ensure time is increasing or function is not supported
2273 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2275 // Pause and resume ...
2276 if (paused == EFalse && I64LOW(currentTime) > 500000)
2279 RxSoundDevice.Pause();
2280 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2282 TInt64 pausedTime1 = timeIntervalBuf().Int64();
2283 Test.Printf(_L("Paused time_high %d, time_low %d\n"),I64HIGH(pausedTime1),I64LOW(pausedTime1));
2284 // Check time is increasing
2285 CHECK((I64LOW(pausedTime1) >= I64LOW(currentTime)));
2287 User::After(pauseInterval);
2289 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2291 TInt64 pausedTime2 = timeIntervalBuf().Int64();
2292 Test.Printf(_L("Resumed time_high %d, time_low %d\n"),I64HIGH(pausedTime2),I64LOW(pausedTime2));
2293 // Check time is unchanged
2294 CHECK((I64LOW(pausedTime2) == I64LOW(pausedTime1)));
2297 if (timerStat != KRequestPending)
2299 timer.After(timerStat,timerInterval);
2305 // Buffer should complete normally or be empty (indicated by KErrCancel)
2306 CHECK((stat[0].Int() >= 0) || (stat[0].Int() == KErrCancel));
2307 // Release the first buffer, if it contained any data
2308 if (stat[0].Int() >= 0)
2310 r = RxSoundDevice.ReleaseBuffer(stat[0].Int());
2311 CHECK_EQUAL(r, KErrNone);
2313 // Check second buffer completed or cancelled
2314 User::WaitForRequest(stat[1]);
2315 CHECK_EQUAL(stat[1].Int(), KErrCancel);
2317 // Now resume the recording
2318 r = RxSoundDevice.Resume();
2319 CHECK_EQUAL(r, KErrNone);
2321 // Need to re-setup buffers
2322 RxSoundDevice.RecordData(stat[0],length1);
2323 RxSoundDevice.RecordData(stat[1],length2);
2325 timer.After(timerStat,timerInterval);
2327 while (stat[0] == KRequestPending)
2329 User::WaitForRequest(stat[0],timerStat);
2330 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2331 previousTime = currentTime;
2332 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2334 currentTime = timeIntervalBuf().Int64();
2335 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(currentTime),I64LOW(currentTime));
2337 // ensure time is increasing or function is not supported
2338 if (stat[0] == KRequestPending) // still recording
2340 CHECK((I64LOW(currentTime) >= I64LOW(previousTime)) || r == KErrNotSupported);
2343 if (timerStat != KRequestPending)
2345 timer.After(timerStat,timerInterval);
2351 Test.Printf(_L("stat[0] %x, timerStat %x\n"),stat[0].Int(),timerStat.Int());
2352 r = RxSoundDevice.TimeRecorded(timeIntervalBuf);
2354 currentTime = timeIntervalBuf().Int64();
2355 Test.Printf(_L("time_high %d, time_low %d\n"),I64HIGH(timeIntervalBuf().Int64()),I64LOW(timeIntervalBuf().Int64()));
2357 CHECK(stat[0].Int() > 0);
2359 // stop recording into the next buffer
2360 RxSoundDevice.CancelRecordData();
2362 // Release the buffers
2363 r = RxSoundDevice.ReleaseBuffer(stat[0].Int());
2364 CHECK_EQUAL(r, KErrNone);
2374 // User::SetDebugMask(0x10,1); // Enable KSOUND1
2381 Test.Start(_L("Load"));
2382 if (Load()==KErrNotFound)
2384 Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
2393 /** @SYMTestCaseID PBASE-T_SOUND2-223
2394 @SYMTestCaseDesc Opening the channel - normal
2395 @SYMTestPriority Critical
2396 @SYMTestActions 1) With the LDD and PDD installed and with all channels closed on the device,
2397 open a channel for playback on the device.
2398 2) Without closing the playback channel, open a channel for record on the device.
2399 3) Close the playback channel and then open it again.
2400 4) Close the record channel and then open it again.
2401 @SYMTestExpectedResults 1) KErrNone - Channel opens successfully.
2402 2) KErrNone - Channel opens successfully.
2403 3) KErrNone - Channel re-opens successfully.
2404 4) KErrNone - Channel re-opens successfully.
2405 @SYMREQ PREQ1073.4 */
2407 Test.Next(_L("Open playback channel"));
2408 r = TxSoundDevice.Open(KSoundScTxUnit0);
2411 Test.Next(_L("Open record channel"));
2412 r = RxSoundDevice.Open(KSoundScRxUnit0);
2415 Test.Next(_L("Query play formats supported"));
2416 TxSoundDevice.Caps(PlayCapsBuf);
2417 TSoundFormatsSupportedV02 playCaps=PlayCapsBuf();
2418 PrintCaps(playCaps,Test);
2420 Test.Next(_L("Close playback channel"));
2421 TxSoundDevice.Close();
2422 Test.Next(_L("Re-open playback channel"));
2423 r = TxSoundDevice.Open(KSoundScTxUnit0);
2425 Test.Next(_L("Close record channel"));
2426 RxSoundDevice.Close();
2427 Test.Next(_L("Re-open record channel"));
2428 r = RxSoundDevice.Open(KSoundScRxUnit0);
2431 Test.Next(_L("Query play formats supported"));
2432 TxSoundDevice.Caps(PlayCapsBuf);
2433 PrintCaps(playCaps,Test);
2435 Test.Next(_L("Query record formats supported"));
2436 RxSoundDevice.Caps(RecordCapsBuf);
2437 TSoundFormatsSupportedV02 recordCaps=RecordCapsBuf();
2438 PrintCaps(recordCaps,Test);
2440 Test.Next(_L("Query current play settings"));
2441 TxSoundDevice.AudioFormat(PlayFormatBuf);
2442 TCurrentSoundFormatV02 playFormat=PlayFormatBuf();
2443 PrintConfig(playFormat,Test);
2444 CheckConfig(playFormat,playCaps);
2446 Test.Next(_L("Query current record settings"));
2447 RxSoundDevice.AudioFormat(RecordFormatBuf);
2448 TCurrentSoundFormatV02 recordFormat=RecordFormatBuf();
2449 PrintConfig(recordFormat,Test);
2450 CheckConfig(recordFormat,recordCaps);
2452 Test.Next(_L("Set play format"));
2453 if (playCaps.iEncodings&KSoundEncoding16BitPCM)
2454 playFormat.iEncoding = ESoundEncoding16BitPCM;
2455 PrintConfig(playFormat,Test);
2456 r = TxSoundDevice.SetAudioFormat(PlayFormatBuf);
2459 Test.Next(_L("Set Record Format"));
2460 if (recordCaps.iEncodings&KSoundEncoding16BitPCM)
2461 recordFormat.iEncoding = ESoundEncoding16BitPCM;
2462 PrintConfig(recordFormat,Test);
2463 r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
2467 TInt freeRamInBytes=0;
2475 TestBasicPlayFunctions();
2476 TestBasicRecordFunctions();
2477 TestPlayAllRates(1,4);
2478 TestPlayAllRates(2,4);
2479 TestRecordAllRates(1,4);
2480 TestRecordAllRates(2,4);
2481 TestRecordVolume(2,10);
2484 TestRecordPauseResume(1);
2485 TestRecordPauseResume(2);
2486 TestSimultaneousPlayRecord();
2490 TestDefectDTWMM00678();
2492 //TestSpeed(); // Gives information which may help debug h4 FMM issues
2496 HAL::Get(HAL::EMemoryRAMFree,free);
2497 Test.Printf(_L("Free ram is %d bytes\r\n"),free);
2498 // if (freeRamInBytes)
2499 // CHECK(freeRamInBytes == free)
2500 freeRamInBytes=free;
2504 TTimeIntervalMinutes elapsed;
2505 r=ntim.MinutesFrom(stim,elapsed);
2507 Test.Printf(_L("Test has been running for %d minutes\r\n"),elapsed.Int());
2511 Test.Next(_L("Close channels"));
2512 RxSoundDevice.Close();
2513 TxSoundDevice.Close();
2517 // Now that both the channels are closed, unload the LDD and the PDDs.
2518 TestUnloadDrivers();
2525 User::Allocator().Check();