Update contrib.
1 // Copyright (c) 2006-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 "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.
21 #include "mmfdevsoundadaptationbody.h"
22 #include "cdevaudiocontrol.h"
23 #include "cdevaudio.h"
24 #include "a3ffourcclookup.h"
26 #include <a3f/audioformatuids.h>
28 #include "mglobalproperties.h"
30 const TInt KDefaultOnDTMFLength = 250000;
31 const TInt KDefaultOffDTMFLength = 50000;
32 const TInt KDefaultPauseDTMFLength = 250000;
33 const TInt KDefaultBufferSize = 4096;
35 // ============================ MEMBER FUNCTIONS =============================// -----------------------------------------------------------------------------
36 // CMMFDevSoundAdaptation::CBody::CBody
37 // C++ default constructor can NOT contain any code, that
39 // -----------------------------------------------------------------------------
41 CMMFDevSoundAdaptation::CBody::CBody(MDevSoundAdaptationObserver& aDevSoundObserver,
42 MGlobalProperties& aGlobalProperties)
43 :iDevSoundObserver(aDevSoundObserver)
46 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::CBody *CD1*, CtxDevSound, DPLOCAL);
49 iGlobalProperties = &aGlobalProperties;
51 iMode = EMMFStateIdle;
52 // Initialize default config for cases when the DevSound's client query using
53 // CMMDevSound::Config() before setting the configuration through
54 // CMMDevSound::SetConfigL(TMMFCappabilites aConfig)
55 iMmfConfig.iRate = EMMFSampleRate8000Hz;
56 iMmfConfig.iEncoding = EMMFSoundEncoding16BitPCM;
57 iMmfConfig.iChannels = EMMFMono;
58 iMmfConfig.iBufferSize = KDefaultBufferSize;
63 // -----------------------------------------------------------------------------
64 // CMMFDevSoundAdaptation::CBody::ConstructL
65 // Symbian 2nd phase constructor can leave.
66 // assumes that iParent has already been set up properly
67 // -----------------------------------------------------------------------------
69 void CMMFDevSoundAdaptation::CBody::ConstructL(MGlobalProperties& aGlobalProperties)
71 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::ConstructL *CD1*, CtxDevSound, DPLOCAL);
75 iDevAudio = CDevAudio::NewL(iDevSoundObserver, aGlobalProperties);
77 //Default values for DTMF tones
78 iToneData.SetDtmfLengths(KDefaultOnDTMFLength,KDefaultOffDTMFLength,KDefaultPauseDTMFLength);
83 // -----------------------------------------------------------------------------
84 // CMMFDevSoundAdaptation::CBody::NewL
85 // Two-phased constructor.
86 // -----------------------------------------------------------------------------
88 CMMFDevSoundAdaptation::CBody* CMMFDevSoundAdaptation::CBody::NewL(MDevSoundAdaptationObserver& aDevSoundObserver,
89 MGlobalProperties& aGlobalProperties)
91 DP_STATIC_CONTEXT(CMMFDevSoundAdaptation::CBody::NewL *CD0*, CtxDevSound, DPLOCAL);
93 CMMFDevSoundAdaptation::CBody* self = new (ELeave) CBody(aDevSoundObserver, aGlobalProperties);
94 CleanupStack::PushL(self);
95 self->ConstructL(aGlobalProperties);
96 CleanupStack::Pop(self);
97 DP0_RET(self, "0x%x");
100 // -----------------------------------------------------------------------------
101 // CMMFDevSoundAdaptation::CBody::~CBody
103 // -----------------------------------------------------------------------------
105 CMMFDevSoundAdaptation::CBody::~CBody()
107 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::~CBody *CD1*, CtxDevSound, DPLOCAL);
116 // CMMFDevSoundAdaptation:CBody::PostOpenL()
117 // 2nd phase post open - used to setup internal attributes asynchronously
119 void CMMFDevSoundAdaptation::CBody::PostOpenL()
121 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PostOpenL *CD1*, CtxDevSound, DPLOCAL);
123 User::LeaveIfError(iDevAudio->PostOpen());
127 // -----------------------------------------------------------------------------
128 // CMMFDevSoundAdaptation::CBody::InitializeL
129 // Initializes CMMFDevSoundProxy object to play and record PCM16 raw audio data
130 // with sampling rate of 8 KHz.
131 // On completion of Initialization, calls InitializeComplete() on
132 // aDevSoundObserver.
133 // Leaves on failure.
134 // (other items were commented in a header).
135 // -----------------------------------------------------------------------------
137 void CMMFDevSoundAdaptation::CBody::InitializeL(TMMFState aMode)
139 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::InitializeL *CD1*, CtxDevSound, DPLOCAL);
141 if (aMode == EMMFStateTonePlaying)
143 DoInitializeL(KUidFormatTone, aMode);
147 DoInitializeL(KUidFormatPCM16, aMode);
152 // -----------------------------------------------------------------------------
153 // CMMFDevSoundAdaptation::CBody::InitializeL
154 // Initializes DevSound object for the mode aMode for processing audio data
155 // with hardware device aHWDev.
156 // On completion of Initialization, the observer will be notified via call back
157 // InitializeComplete().
158 // Leaves on failure.
159 // (other items were commented in a header).
160 // -----------------------------------------------------------------------------
162 void CMMFDevSoundAdaptation::CBody::InitializeL(TUid /*aHWDev*/,
165 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::InitializeL *CD1*, CtxDevSound, DPLOCAL);
167 User::LeaveIfError(KErrNotSupported);
171 // -----------------------------------------------------------------------------
172 // CMMFDevSoundAdaptation::CBody::InitializeL
173 // Initializes DevSound object for the mode aMode for processing audio data
174 // with hardware device supporting FourCC aDesiredFourCC.
175 // On completion of Initialization, the observer will be notified via call back
176 // InitializeComplete().
177 // Leaves on failure.
178 // (other items were commented in a header).
179 // -----------------------------------------------------------------------------
181 void CMMFDevSoundAdaptation::CBody::InitializeL(
182 TFourCC aDesiredFourCC,
185 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::InitializeL *CD1*, CtxDevSound, DPLOCAL);
191 err = iGlobalProperties->GetFourCCConvertor().FourCCToFormat(aDesiredFourCC, format);
194 DoInitializeL(format, aMode);
198 User::LeaveIfError(KErrNotSupported);
203 // -----------------------------------------------------------------------------
204 // CMMFDevSoundAdaptation::CBody::DoInitializeL
205 // -----------------------------------------------------------------------------
207 void CMMFDevSoundAdaptation::CBody::DoInitializeL(
211 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::DoInitializeL *CD1*, CtxDevSound, DPLOCAL);
212 DP2_IN("format=0x%x, mode=%d",aFormat.iUid,aMode);
219 if ((aMode == EMMFStatePlaying) || (aMode == EMMFStateRecording)
220 || (aMode == EMMFStateTonePlaying))
222 err = iDevAudio->Initialize(aFormat, aMode);
226 err = KErrNotSupported;
228 User::LeaveIfError(err);
235 // -----------------------------------------------------------------------------
236 // CMMFDevSoundAdaptation::CBody::CancelInitialize
237 // Cancels the initialization of DevSound object
238 // returns an error code
239 // (other items were commented in a header).
240 // -----------------------------------------------------------------------------
242 TInt CMMFDevSoundAdaptation::CBody::CancelInitialize()
244 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::CancelInitialize *CD1*, CtxDevSound, DPLOCAL);
246 TInt err=iDevAudio->CancelInitialize();
251 // -----------------------------------------------------------------------------
252 // CMMFDevSoundAdaptation::CBody::Capabilities
253 // Returns the supported Audio settings.
254 // (other items were commented in a header).
255 // -----------------------------------------------------------------------------
257 TInt CMMFDevSoundAdaptation::CBody::Capabilities(TMMFCapabilities& aCap)
259 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Capabilities *CD1*, CtxDevSound, DPLOCAL);
261 // query real values, on error just return last known (default) values
262 TInt err = iDevAudio->GetAudioControl()->GetCapabilities(aCap);
266 // -----------------------------------------------------------------------------
267 // CMMFDevSoundAdaptation::CBody::Config()
268 // Returns the current audio settings.
269 // (other items were commented in a header).
270 // -----------------------------------------------------------------------------
272 TMMFCapabilities CMMFDevSoundAdaptation::CBody::Config() const
274 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Config *CD1*, CtxDevSound, DPLOCAL);
276 // Query real values, on error just return last known (default) values
277 TMMFCapabilities config;
278 TInt err = iDevAudio->GetAudioControl()->GetConfig(config);
279 // TBD: for now, just return set value for encoding - codec does not give this
280 config.iEncoding = iMmfConfig.iEncoding;
281 if ( err == KErrNone )
283 DP0_RET(config, "0");
285 DP0_RET(iMmfConfig, "0");
288 // -----------------------------------------------------------------------------
289 // CMMFDevSoundAdaptation::CBody::SetConfigL
290 // Configure device for the settings in aConfig.
291 // Use this to set sampling rate, Encoding and Mono/Stereo.
293 // (other items were commented in a header).
294 // -----------------------------------------------------------------------------
296 void CMMFDevSoundAdaptation::CBody::SetConfigL(const TMMFCapabilities& aConfig)
298 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetConfigL *CD1*, CtxDevSound, DPLOCAL);
299 DP3_IN("rate 0x%x, channels 0x%x, encoding 0x%x",
300 aConfig.iRate, aConfig.iChannels, aConfig.iEncoding);
301 User::LeaveIfError(iDevAudio->GetAudioControl()->SetConfig(aConfig));
302 // success, update local copy
303 iMmfConfig.iRate = aConfig.iRate;
304 iMmfConfig.iChannels = aConfig.iChannels;
305 iMmfConfig.iEncoding = aConfig.iEncoding;
309 // -----------------------------------------------------------------------------
310 // CMMFDevSoundAdaptation::CBody::MaxVolume
311 // Returns an integer representing the maximum volume.
312 // This is the maximum value which can be passed to CMMFDevSoundProxy::SetVolume
313 // (other items were commented in a header).
314 // -----------------------------------------------------------------------------
316 TInt CMMFDevSoundAdaptation::CBody::MaxVolume()
318 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::MaxVolume *CD1*, CtxDevSound, DPLOCAL);
320 DP0_RET(iDevAudio->DevSoundMaxVolume(), "%d");
323 // -----------------------------------------------------------------------------
324 // CMMFDevSoundAdaptation::CBody::Volume
325 // Returns an integer representing the current volume.
326 // (other items were commented in a header).
327 // -----------------------------------------------------------------------------
329 TInt CMMFDevSoundAdaptation::CBody::Volume()
331 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Volume *CD1*, CtxDevSound, DPLOCAL);
333 DP0_RET(iDevAudio->DevSoundVolume(), "%d");
336 // -----------------------------------------------------------------------------
337 // CMMFDevSoundAdaptation::CBody::SetVolume
338 // Changes the current playback volume to a specified value.
339 // The volume can be changed before or during playback and is effective
341 // (other items were commented in a header).
342 // -----------------------------------------------------------------------------
344 TInt CMMFDevSoundAdaptation::CBody::SetVolume(TInt aVolume, TBool& aAsyncCompletion)
346 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetVolume *CD1*, CtxDevSound, DPLOCAL);
347 DP1_IN("aVolume = %d", aVolume);
348 TInt error = iDevAudio->SetDevSoundVolume(aVolume, aAsyncCompletion);
349 DP0_RET(error, "%d");
352 // -----------------------------------------------------------------------------
353 // CMMFDevSoundAdaptation::CBody::MaxGain
354 // Returns an integer representing the maximum gain.
355 // This is the maximum value which can be passed to CMMFDevSoundProxy::SetGain.
356 // (other items were commented in a header).
357 // -----------------------------------------------------------------------------
359 TInt CMMFDevSoundAdaptation::CBody::MaxGain()
361 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::MaxGain *CD1*, CtxDevSound, DPLOCAL);
363 DP0_RET(iDevAudio->DevSoundMaxGain(), "%d");
366 // -----------------------------------------------------------------------------
367 // CMMFDevSoundAdaptation::CBody::Gain
368 // Returns an integer representing the current gain.
369 // (other items were commented in a header).
370 // -----------------------------------------------------------------------------
372 TInt CMMFDevSoundAdaptation::CBody::Gain()
374 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Gain *CD1*, CtxDevSound, DPLOCAL);
376 DP0_RET(iDevAudio->DevSoundGain(), "%d");
379 // -----------------------------------------------------------------------------
380 // CMMFDevSoundAdaptation::CBody::SetGain
381 // Changes the current recording gain to a specified value.
382 // The gain can be changed before or during recording and is effective
384 // (other items were commented in a header).
385 // -----------------------------------------------------------------------------
387 TInt CMMFDevSoundAdaptation::CBody::SetGain(TInt aGain, TBool& aAsyncCompletion)
389 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetGain *CD1*, CtxDevSound, DPLOCAL);
390 DP1_IN("aGain = %d", aGain);
391 TInt error = iDevAudio->SetDevSoundGain(aGain, aAsyncCompletion);
392 DP0_RET(error, "%d");
395 // -----------------------------------------------------------------------------
396 // CMMFDevSoundAdaptation::CBody::GetPlayBalanceL
397 // Returns the speaker balance set for playing.
398 // Leaves on failure.
399 // (other items were commented in a header).
400 // -----------------------------------------------------------------------------
402 void CMMFDevSoundAdaptation::CBody::GetPlayBalanceL(TInt& aLeftPercentage,
403 TInt& aRightPercentage)
405 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetPlayBalanceL *CD1*, CtxDevSound, DPLOCAL);
407 iDevAudio->GetDevSoundPlayBalance(aLeftPercentage, aRightPercentage);
411 // -----------------------------------------------------------------------------
412 // CMMFDevSoundAdaptation::CBody::SetPlayBalanceL
413 // Sets the speaker balance for playing.
414 // The speaker balance can be changed before or during playback and is
415 // effective immediately.
416 // (other items were commented in a header).
417 // -----------------------------------------------------------------------------
419 void CMMFDevSoundAdaptation::CBody::SetPlayBalanceL(TInt aLeftPercentage,
420 TInt aRightPercentage,
421 TBool& aAsyncCompletion)
423 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetPlayBalanceL *CD1*, CtxDevSound, DPLOCAL);
424 DP2_IN("aLeftPercentage = %d, aRightPercentage=%d", aLeftPercentage, aRightPercentage);
426 User::LeaveIfError(iDevAudio->SetDevSoundPlayBalance(aLeftPercentage, aRightPercentage, aAsyncCompletion));
431 // -----------------------------------------------------------------------------
432 // CMMFDevSoundAdaptation::CBody::GetRecordBalanceL
433 // Returns the microphone gain balance set for recording.
434 // Leaves on failure.
435 // (other items were commented in a header).
436 // -----------------------------------------------------------------------------
438 void CMMFDevSoundAdaptation::CBody::GetRecordBalanceL(TInt& aLeftPercentage,
439 TInt& aRightPercentage)
441 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetRecordBalanceL *CD1*, CtxDevSound, DPLOCAL);
444 iDevAudio->GetDevSoundRecordBalance(aLeftPercentage, aRightPercentage);
449 // -----------------------------------------------------------------------------
450 // CMMFDevSoundAdaptation::CBody::SetRecordBalanceL
451 // Sets the microphone gain balance for recording.
452 // The microphone gain balance can be changed before or during recording and
453 // is effective immediately.
454 // (other items were commented in a header).
455 // -----------------------------------------------------------------------------
457 void CMMFDevSoundAdaptation::CBody::SetRecordBalanceL(TInt aLeftPercentage,
458 TInt aRightPercentage,
459 TBool& aAsyncCompletion)
461 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetRecordBalanceL *CD1*, CtxDevSound, DPLOCAL);
462 DP2_IN("aLeftPercentage = %d, aRightPercentage=%d", aLeftPercentage, aRightPercentage);
464 User::LeaveIfError(iDevAudio->SetDevSoundRecordBalance(aLeftPercentage, aRightPercentage,aAsyncCompletion));
469 // -----------------------------------------------------------------------------
470 // CMMFDevSoundAdaptation::CBody::PlayInitL
471 // Initializes audio device and start play process. This method queries and
472 // acquires the audio policy before initializing audio device. If there was an
473 // error during policy initialization, PlayError() method will be called on
474 // the observer with error code KErrAccessDenied, otherwise BufferToBeFilled()
475 // method will be called with a buffer reference. After reading data into the
476 // buffer reference passed, the client should call PlayData() to play data.
478 // The amount of data that can be played is specified in
479 // CMMFBuffer::RequestSize(). Any data that is read into buffer beyond this
480 // size will be ignored.
482 // Leaves on failure.
483 // (other items were commented in a header).
484 // -----------------------------------------------------------------------------
486 void CMMFDevSoundAdaptation::CBody::PlayInitL()
488 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayInitL *CD1*, CtxDevSound, DPLOCAL);
491 if(iMode==EMMFStatePlaying)
493 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
497 DP1(DLERR,"Current mode is not EMMFStatePlaying! (iMode=%d)",iMode);
498 User::Leave(KErrNotReady);
503 // -----------------------------------------------------------------------------
504 // CMMFDevSoundAdaptation::CBody::RecordInitL
505 // Initializes audio device and start record process. This method queries and
506 // acquires the audio policy before initializing audio device. If there was an
507 // error during policy initialization, RecordError() method will be called on
508 // the observer with error code KErrAccessDenied, otherwise BufferToBeEmptied()
509 // method will be called with a buffer reference. This buffer contains recorded
510 // or encoded data. After processing data in the buffer reference passed, the
511 // client should call RecordData() to continue recording process.
513 // The amount of data that is available is specified in
514 // CMMFBuffer::RequestSize().
516 // Leaves on failure.
517 // (other items were commented in a header).
518 // -----------------------------------------------------------------------------
520 void CMMFDevSoundAdaptation::CBody::RecordInitL()
522 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::RecordInitL *CD1*, CtxDevSound, DPLOCAL);
524 if(iMode==EMMFStateRecording)
526 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
530 DP1(DLERR,"Current mode is not EMMFStateRecording! (iMode=%d)",iMode);
531 User::Leave(KErrNotReady);
536 // -----------------------------------------------------------------------------
537 // CMMFDevSoundAdaptation::CBody::PlayData
538 // Plays data in the buffer at the current volume. The client should fill
539 // the buffer with audio data before calling this method. The Observer gets
540 // reference to buffer along with callback BufferToBeFilled(). When playing of
541 // the audio sample is complete, successfully or otherwise, the method
542 // PlayError() on observer is called.
543 // (other items were commented in a header).
544 // -----------------------------------------------------------------------------
546 void CMMFDevSoundAdaptation::CBody::PlayData()
548 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayData *CD1*, CtxDevSound, DPLOCAL);
551 if(iMode==EMMFStatePlaying)
553 iDevAudio->GetAudioControl()->ProcessData();
557 DP1(DLERR,"Current mode is not EMMFStatePlaying! (iMode=%d)",iMode);
562 // -----------------------------------------------------------------------------
563 // CMMFDevSoundAdaptation::CBody::RecordData
564 // Contine the process of recording. Once the buffer is filled with recorded
565 // data, the Observer gets reference to buffer along with callback
566 // BufferToBeEmptied(). After processing the buffer (copying over to a
567 // different buffer or writing to file) the client should call this
568 // method to continue recording process.
569 // (other items were commented in a header).
570 // -----------------------------------------------------------------------------
572 void CMMFDevSoundAdaptation::CBody::RecordData()
574 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::RecordData *CD1*, CtxDevSound, DPLOCAL);
576 if(iMode==EMMFStateRecording)
578 iDevAudio->GetAudioControl()->ProcessData();
582 DP1(DLERR,"Current mode is not EMMFStateRecording! (iMode=%d)",iMode);
587 // -----------------------------------------------------------------------------
588 // CMMFDevSoundAdaptation::CBody::Stop
589 // Stops the ongoing operation (Play, Record, TonePlay)
590 // (other items were commented in a header).
591 // -----------------------------------------------------------------------------
593 TBool CMMFDevSoundAdaptation::CBody::Stop()
595 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Stop *CD1*, CtxDevSound, DPLOCAL);
597 TBool isCompleted = EFalse;
599 // Need for sequences when calling stop and is already stopped
600 TDevSoundAdaptorState state = iDevAudio->ActiveState();
601 if( (iMode != EMMFStateIdle) &&
602 (state == EDevSoundAdaptorActive_Active ||
603 state == EDevSoundAdaptorPaused_Primed ) )
605 TInt err = iDevAudio->GetAudioControl()->Stop();
619 // -----------------------------------------------------------------------------
620 // CMMFDevSoundAdaptation::CBody::Pause
621 // Temporarily Stops the ongoing operation (Play, Record, TonePlay)
622 // (other items were commented in a header).
623 // -----------------------------------------------------------------------------
625 TInt CMMFDevSoundAdaptation::CBody::Pause()
627 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::Pause *CD1*, CtxDevSound, DPLOCAL);
630 TInt err = iDevAudio->GetAudioControl()->Pause();
634 // -----------------------------------------------------------------------------
635 // CMMFDevSoundAdaptation::CBody::SamplesRecorded
636 // Returns the sample recorded so far.
637 // (other items were commented in a header).
638 // -----------------------------------------------------------------------------
640 TInt CMMFDevSoundAdaptation::CBody::SamplesRecorded()
642 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SamplesRecorded *CD1*, CtxDevSound, DPLOCAL);
645 if(iMode==EMMFStateRecording)
648 return(iDevAudio->GetAudioControl()->GetSamples());
652 DP1(DLERR,"Current mode is not EMMFStateRecording! (iMode=%d)",iMode);
657 // -----------------------------------------------------------------------------
658 // CMMFDevSoundAdaptation::CBody::SamplesPlayed
659 // Returns the sample played so far.
660 // (other items were commented in a header).
661 // -----------------------------------------------------------------------------
663 TInt CMMFDevSoundAdaptation::CBody::SamplesPlayed()
665 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SamplesPlayed *CD1*, CtxDevSound, DPLOCAL);
667 if(iMode==EMMFStatePlaying)
670 return(iDevAudio->GetAudioControl()->GetSamples());
674 DP1(DLERR,"Current mode is not EMMFStatePlaying! (iMode=%d)",iMode);
679 // -----------------------------------------------------------------------------
680 // CMMFDevSoundAdaptation::CBody::PlayToneL
681 // Initializes audio device and start playing tone. Tone is played with
682 // frequency and for duration specified.
683 // Leaves on failure.
684 // (other items were commented in a header).
685 // -----------------------------------------------------------------------------
687 void CMMFDevSoundAdaptation::CBody::PlayToneL(
689 const TTimeIntervalMicroSeconds& aDuration)
691 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayToneL *CD1*, CtxDevSound, DPLOCAL);
692 DP1_IN("aFrequency = %d", aFrequency);
694 if(iMode==EMMFStateTonePlaying)
696 iToneData.SetType(TToneData::ESimple);
697 iToneData.SetFrequencyOne(aFrequency);
698 iToneData.SetDuration(aDuration);
699 User::LeaveIfError(iDevAudio->GetAudioControl()->SetToneData(iToneData));
700 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
704 DP1(DLERR,"Current mode is not EMMFStateTonePlaying! (iMode=%d)",iMode);
705 User::Leave(KErrNotSupported);
711 // -----------------------------------------------------------------------------
712 // CMMFDevSoundAdaptation::CBody::PlayDualToneL
713 // Initializes audio device and start playing a dual tone.
714 // The tone consists of two sine waves of different frequencies summed together
715 // Dual Tone is played with specified frequencies and for specified duration.
716 // (other items were commented in a header).
717 // -----------------------------------------------------------------------------
719 void CMMFDevSoundAdaptation::CBody::PlayDualToneL(
722 const TTimeIntervalMicroSeconds& aDuration)
724 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayDualToneL *CD1*, CtxDevSound, DPLOCAL);
725 DP2_IN("aFrequencyOne = %d, aFrequencyTwo=%d", aFrequencyOne, aFrequencyTwo);
727 if(iMode==EMMFStateTonePlaying)
729 iToneData.SetType(TToneData::EDual);
730 iToneData.SetFrequencyOne(aFrequencyOne);
731 iToneData.SetFrequencyTwo(aFrequencyTwo);
732 iToneData.SetDuration(aDuration);
733 User::LeaveIfError(iDevAudio->GetAudioControl()->SetToneData(iToneData));
734 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
738 DP1(DLERR,"Current mode is not EMMFStateTonePlaying! (iMode=%d)",iMode);
739 User::Leave(KErrNotSupported);
744 // -----------------------------------------------------------------------------
745 // CMMFDevSoundAdaptation::CBody::PlayDTMFStringL
746 // Initializes audio device and start playing DTMF string aDTMFString.
747 // Leaves on failure.
748 // (other items were commented in a header).
749 // -----------------------------------------------------------------------------
751 void CMMFDevSoundAdaptation::CBody::PlayDTMFStringL(const TDesC& aDTMFString)
753 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayDTMFStringL *CD1*, CtxDevSound, DPLOCAL);
756 if(iMode==EMMFStateTonePlaying)
758 iToneData.SetType(TToneData::EDtmfString);
759 iToneData.SetDTMFString(const_cast<TDesC&>(aDTMFString));
760 User::LeaveIfError(iDevAudio->GetAudioControl()->SetToneData(iToneData));
761 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
765 DP1(DLERR,"Current mode is not EMMFStateTonePlaying! (iMode=%d)",iMode);
766 User::Leave(KErrNotSupported);
772 // -----------------------------------------------------------------------------
773 // CMMFDevSoundAdaptation::CBody::PlayToneSequenceL
774 // Initializes audio device and start playing tone sequence.
776 // Leaves on failure.
777 // (other items were commented in a header).
778 // -----------------------------------------------------------------------------
780 void CMMFDevSoundAdaptation::CBody::PlayToneSequenceL(const TDesC8& aData)
782 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayToneSequenceL *CD1*, CtxDevSound, DPLOCAL);
785 if(iMode==EMMFStateTonePlaying)
787 iToneData.SetType(TToneData::ESequence);
788 iToneData.SetSequenceData(const_cast<TDesC8&>(aData));
789 User::LeaveIfError(iDevAudio->GetAudioControl()->SetToneData(iToneData));
790 User::LeaveIfError(iDevAudio->GetAudioControl()->ProcessInit());
794 DP1(DLERR,"Current mode is not EMMFStateTonePlaying! (iMode=%d)",iMode);
795 User::Leave(KErrNotSupported);
801 // -----------------------------------------------------------------------------
802 // CMMFDevSoundAdaptation::CBody::PlayFixedSequenceL
803 // Initializes audio device and start playing the specified pre-defined tone
806 // Leaves on failure.
807 // (other items were commented in a header).
808 // -----------------------------------------------------------------------------
810 void CMMFDevSoundAdaptation::CBody::PlayFixedSequenceL(TInt /*aSequenceNumber*/)
812 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::PlayFixedSequenceL *CD1*, CtxDevSound, DPLOCAL);
814 User::Leave(KErrNotSupported);
818 // -----------------------------------------------------------------------------
819 // CMMFDevSoundAdaptation::CBody::SetToneRepeats
820 // Defines the number of times the audio is to be repeated during the tone
821 // playback operation. A period of silence can follow each playing of tone.
822 // The tone playing can be repeated indefinitely.
823 // Supported only during tone playing.
824 // (other items were commented in a header).
825 // -----------------------------------------------------------------------------
827 TInt CMMFDevSoundAdaptation::CBody::SetToneRepeats(
829 const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
831 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetToneRepeats *CD1*, CtxDevSound, DPLOCAL);
832 DP1_IN("aRepeatCount = %d", aRepeatCount);
835 iToneData.SetRepeatCount(aRepeatCount);
836 iToneData.SetRepeatTrailingSilence(aRepeatTrailingSilence);
841 // -----------------------------------------------------------------------------
842 // CMMFDevSoundAdaptation::CBody::SetDTMFLengths
843 // Defines the duration of tone on, tone off and tone pause to be used during
844 // the DTMF tone playback operation.
845 // Supported only during tone playing.
846 // (other items were commented in a header).
847 // -----------------------------------------------------------------------------
849 TInt CMMFDevSoundAdaptation::CBody::SetDTMFLengths(
850 TTimeIntervalMicroSeconds32& aToneOnLength,
851 TTimeIntervalMicroSeconds32& aToneOffLength,
852 TTimeIntervalMicroSeconds32& aPauseLength)
854 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetDTMFLengths *CD1*, CtxDevSound, DPLOCAL);
858 if (aToneOnLength.Int() < KMdaInfiniteDurationDTMFToneOnLength)
860 aToneOnLength = TTimeIntervalMicroSeconds32(0);
862 if (aToneOffLength.Int() < 0)
864 aToneOffLength = TTimeIntervalMicroSeconds32(0);
866 if (aPauseLength.Int() < 0)
868 aPauseLength = TTimeIntervalMicroSeconds32(0);
871 iToneData.SetDtmfLengths(aToneOnLength, aToneOffLength, aPauseLength);
876 // -----------------------------------------------------------------------------
877 // CMMFDevSoundAdaptation::CBody::SetVolumeRamp
878 // Defines the period over which the volume level is to rise smoothly from
879 // nothing to the normal volume level.
880 // (other items were commented in a header).
881 // -----------------------------------------------------------------------------
883 TInt CMMFDevSoundAdaptation::CBody::SetVolumeRamp(
884 const TTimeIntervalMicroSeconds& aRampDuration)
886 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetVolumeRamp *CD1*, CtxDevSound, DPLOCAL);
889 TInt err = iDevAudio->SetVolumeRamp(aRampDuration);
893 // -----------------------------------------------------------------------------
894 // CMMFDevSoundAdaptation::CBody::SetPrioritySettings
895 // Defines the priority settings that should be used for this instance.
896 // (other items were commented in a header).
897 // -----------------------------------------------------------------------------
899 TInt CMMFDevSoundAdaptation::CBody::SetPrioritySettings(
900 const TMMFPrioritySettings& aPrioritySettings)
902 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetPrioritySettings *CD1*, CtxDevSound, DPLOCAL);
905 TInt err = iDevAudio->SetPrioritySettings(aPrioritySettings);
908 iPrioritySettings = aPrioritySettings;
913 // -----------------------------------------------------------------------------
914 // CMMFDevSoundAdaptation::CBody::CustomInterface
915 // @see sounddevice.h
916 // (other items were commented in a header).
917 // -----------------------------------------------------------------------------
919 TAny* CMMFDevSoundAdaptation::CBody::CustomInterface(TUid aInterfaceId)
921 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::CustomInterface *CD1*, CtxDevSound, DPLOCAL);
926 return(iDevAudio->GetAudioControl()->CustomInterface(aInterfaceId));
934 // -----------------------------------------------------------------------------
935 // CMMFDevSoundAdaptation::CBody::FixedSequenceCount
936 // Returns the number of available pre-defined tone sequences.
937 // This is the number of fixed sequence supported by DevSound by default.
938 // (other items were commented in a header).
939 // -----------------------------------------------------------------------------
941 TInt CMMFDevSoundAdaptation::CBody::FixedSequenceCount()
943 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::FixedSequenceCount *CD1*, CtxDevSound, DPLOCAL);
948 // -----------------------------------------------------------------------------
949 // CMMFDevSoundAdaptation::CBody::FixedSequenceName
950 // Returns the name assigned to a specific pre-defined tone sequence.
951 // This is the number of fixed sequence supported by DevSound by default.
952 // The function raises a panic if sequence number specified invalid.
953 // (other items were commented in a header).
954 // -----------------------------------------------------------------------------
956 const TDesC& CMMFDevSoundAdaptation::CBody::FixedSequenceName(
957 TInt /*aSequenceNumber*/)
959 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::FixedSequenceName *CD1*, CtxDevSound, DPLOCAL);
961 DP0_RET(KNullDesC, "");
964 // -----------------------------------------------------------------------------
965 // CMMFDevSoundAdaptation::CBody::GetSupportedInputDataTypesL
966 // @see sounddevice.h
967 // (other items were commented in a header).
968 // -----------------------------------------------------------------------------
970 void CMMFDevSoundAdaptation::CBody::GetSupportedInputDataTypesL(
971 RArray<TFourCC>& aSupportedDataTypes,
972 const TMMFPrioritySettings& /*aPrioritySettings*/) const
974 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetSupportedInputDataTypesL *CD1*, CtxDevSound, DPLOCAL);
976 //aPrioritySettings not used on ref DevSound
977 //search for playing datatypes
978 iDevAudio->DevSoundSupportedDataTypesL(aSupportedDataTypes, KDataForPlay);
982 // -----------------------------------------------------------------------------
983 // CMMFDevSoundAdaptation::CBody::GetSupportedOutputDataTypesL
984 // @see sounddevice.h
985 // (other items were commented in a header).
986 // -----------------------------------------------------------------------------
988 void CMMFDevSoundAdaptation::CBody::GetSupportedOutputDataTypesL(
989 RArray<TFourCC>& aSupportedDataTypes,
990 const TMMFPrioritySettings& /*aPrioritySettings*/) const
992 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetSupportedOutputDataTypesL *CD1*, CtxDevSound, DPLOCAL);
994 //aPrioritySettings not used on ref DevSound
995 // search for recording datatypes
996 iDevAudio->DevSoundSupportedDataTypesL(aSupportedDataTypes, KDataForRecord);
1000 // -----------------------------------------------------------------------------
1001 // CMMFDevSoundAdaptation::CBody::SetClientConfig
1002 // Sets client capabilities for this instance of DevSound Adaptation.
1003 // (other items were commented in a header).
1004 // -----------------------------------------------------------------------------
1006 TInt CMMFDevSoundAdaptation::CBody::SetClientConfig(
1007 const TProcessId& aActualProcessId,
1008 const TProcessId& aProcessId)
1010 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
1013 TInt err = iDevAudio->SetClientConfig(aActualProcessId, aProcessId);
1017 TInt CMMFDevSoundAdaptation::CBody::SetClientConfig(
1018 const TProcessId& aProcessId)
1020 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
1023 TInt err = iDevAudio->SetClientConfig(aProcessId);
1027 TBool CMMFDevSoundAdaptation::CBody::CloseDevSound()
1029 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::CloseDevSound *CD1*, CtxDevSound, DPLOCAL);
1032 return iDevAudio->GetAudioControl()->DestroyChain();
1035 // -----------------------------------------------------------------------------
1036 // CMMFDevSoundAdaptation::CBody::ProcessingFinishedReceived
1037 // (other items were commented in a header).
1038 // -----------------------------------------------------------------------------
1040 TInt CMMFDevSoundAdaptation::CBody::ProcessingFinishedReceived(TBool& asyncOperation)
1042 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::ProcessingFinishedReceived *CD1*, CtxDevSound, DPLOCAL);
1045 return iDevAudio->GetAudioControl()->ProcessingFinishedReceived(asyncOperation);
1048 // -----------------------------------------------------------------------------
1049 // CMMFDevSoundAdaptation::CBody::ProcessingFinishedReceived
1050 // (other items were commented in a header).
1051 // -----------------------------------------------------------------------------
1053 TInt CMMFDevSoundAdaptation::CBody::ProcessingError(TBool& asyncOperation)
1055 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::ProcessingError *CD1*, CtxDevSound, DPLOCAL);
1058 return iDevAudio->GetAudioControl()->ProcessingError(asyncOperation);
1061 // -----------------------------------------------------------------------------
1062 // CMMFDevSoundAdaptation::CBody::EmptyBuffers
1063 // (other items were commented in a header).
1064 // -----------------------------------------------------------------------------
1066 TInt CMMFDevSoundAdaptation::CBody::EmptyBuffers()
1068 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::EmptyBuffers *CD1*, CtxDevSound, DPLOCAL);
1071 // Empty buffers is only supported on playing
1072 if (iMode == EMMFStateRecording || iMode == EMMFStateTonePlaying)
1074 err = KErrNotSupported;
1076 else if (!iDevAudio)
1082 TDevSoundAdaptorState state = iDevAudio->ActiveState();
1083 if (state == EDevSoundAdaptorActive_Active ||
1084 state == EDevSoundAdaptorPaused_Primed )
1086 err = iDevAudio->GetAudioControl()->RequestEmptyBuffers();
1099 // -----------------------------------------------------------------------------
1100 // CMMFDevSoundAdaptation::CBody::RegisterAsClient
1101 // (other items were commented in a header).
1102 // -----------------------------------------------------------------------------
1104 TInt CMMFDevSoundAdaptation::CBody::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
1106 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
1111 err = iDevAudio->RegisterAsClient(aEventType, aNotificationRegistrationData);
1124 // -----------------------------------------------------------------------------
1125 // CMMFDevSoundAdaptation::CBody::CancelRegisterAsClient
1126 // (other items were commented in a header).
1127 // -----------------------------------------------------------------------------
1129 TInt CMMFDevSoundAdaptation::CBody::CancelRegisterAsClient(TUid aEventType)
1131 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
1136 err = iDevAudio->CancelRegisterAsClient(aEventType);
1148 // -----------------------------------------------------------------------------
1149 // CMMFDevSoundAdaptation::CBody::GetResourceNotificationData
1150 // (other items were commented in a header).
1151 // -----------------------------------------------------------------------------
1153 TInt CMMFDevSoundAdaptation::CBody::GetResourceNotificationData(TUid /*aEventType*/, TDes8& aNotificationData)
1155 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetResourceNotificationData *CD1*, CtxDevSound, DPLOCAL);
1160 TMMFTimeIntervalMicroSecondsPckg pckg = TTimeIntervalMicroSeconds(SamplesPlayed());
1161 aNotificationData.Copy(pckg);
1173 // -----------------------------------------------------------------------------
1174 // CMMFDevSoundAdaptation::CBody::WillResumePlay
1175 // (other items were commented in a header).
1176 // -----------------------------------------------------------------------------
1178 TInt CMMFDevSoundAdaptation::CBody::WillResumePlay()
1180 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::WillResumePlay *CD1*, CtxDevSound, DPLOCAL);
1185 err = iDevAudio->WillResumePlay();
1194 // CMMFDevSoundAdaptation::CBody::GetTimePlayed
1195 // (other items were commented in a header).
1196 // -----------------------------------------------------------------------------
1198 TInt CMMFDevSoundAdaptation::CBody::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
1200 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::GetTimePlayed *CD1*, CtxDevSound, DPLOCAL);
1203 TInt err = iDevAudio->GetAudioControl()->GetTimePlayed(aTime);
1207 // -----------------------------------------------------------------------------
1208 // CMMFDevSoundAdaptation::CBody::IsResumeSupported
1209 // (other items were commented in a header).
1210 // -----------------------------------------------------------------------------
1212 TBool CMMFDevSoundAdaptation::CBody::IsResumeSupported()
1214 DP_CONTEXT(CMMFDevSoundAdaptation::IsResumeSupported *CD1*, CtxDevSound, DPLOCAL);
1216 TBool isSupported = iDevAudio->IsResumeSupported();
1217 DP0_RET(isSupported, "%d");
1220 // -----------------------------------------------------------------------------
1221 // CMMFDevSoundAdaptation::CBody::Resume
1222 // (other items were commented in a header).
1223 // -----------------------------------------------------------------------------
1225 TInt CMMFDevSoundAdaptation::CBody::Resume()
1227 DP_CONTEXT(CMMFDevSoundAdaptation::Resume *CD1*, CtxDevSound, DPLOCAL);
1229 TInt err = iDevAudio->GetAudioControl()->Resume();
1233 void CMMFDevSoundAdaptation::CBody::BufferErrorEvent()
1236 iDevAudio->GetAudioControl()->BufferErrorEvent();
1239 void CMMFDevSoundAdaptation::CBody::RollbackAdaptorActiveStateToBeforeCommit()
1241 DP_CONTEXT(CMMFDevSoundAdaptation::CBody::RollbackAdaptorActiveStateToBeforeCommit *CD1*, CtxDevSound, DPLOCAL);
1243 TDevSoundAdaptorState previousState = iDevAudio->PreviousState();
1244 // Set previous state to the active state set after state changing Commit call
1245 iDevAudio->SetPreviousState(iDevAudio->ActiveState());
1246 // Set active state to the previous state set before state changing Commit call
1247 iDevAudio->SetActiveState(previousState);