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.
19 #include <mmf/server/sounddevice.h>
20 #include "sounddevicebody.h"
23 * Default Constructor.
25 CMMFDevSound::CMMFDevSound()
32 EXPORT_C CMMFDevSound::~CMMFDevSound()
40 * Constructs and returns a pointer to a new CMMFDevSound object.
42 EXPORT_C CMMFDevSound* CMMFDevSound::NewL()
44 CMMFDevSound* self = new (ELeave) CMMFDevSound;
45 CleanupStack::PushL(self);
47 CleanupStack::Pop(self);
52 * CMMFDevSound::ConstructL
54 * Second phase constructor.
56 void CMMFDevSound::ConstructL()
58 iBody = CBody::NewL();
62 * CMMFDevSound::InitializeL
64 * Initializes CMMFDevSound object. On completion of Initialization will
65 * call InitializeComplete() on aDevSoundObserver.
67 * @param aDevSoundObserver. A reference to the DevSound Observer instance.
68 * @param aMode. A mode for which this object will be used.
70 EXPORT_C void CMMFDevSound::InitializeL(MDevSoundObserver& aDevSoundObserver,TMMFState aMode)
73 iBody->InitializeL(aDevSoundObserver,aMode);
77 * CMMFDevSound::InitializeL
79 * Initializes CMMFDevSound object with hardware device aHWDev. On completion
80 * of Initialization will call InitializeComplete() on aDevSoundObserver.
82 * Method is deprecated from OS release 9.5
84 * @param aDevSoundObserver. A reference to the DevSound Observer instance.
85 * @param aHWDev. CMMFHwDevice implementation identifier.
86 * @param aMode. A mode for which this object will be used.
88 EXPORT_C void CMMFDevSound::InitializeL(
89 MDevSoundObserver& /*aDevSoundObserver*/,
93 User::Leave(KErrNotSupported);
97 * CMMFDevSound::InitializeL
99 * Initializes CMMFDevSound object with hardware device with hardware
100 * device's FourCC code. On completion of Initialization will call
101 * InitializeComplete() on aDevSoundObserver.
103 * @param aDevSoundObserver. A reference to the DevSound Observer instance.
104 * @param aDesiredFourCC. CMMFHwDevice implementation FourCC.
105 * @param aMode. A mode for which this object will be used.
107 EXPORT_C void CMMFDevSound::InitializeL(
108 MDevSoundObserver& aDevSoundObserver,
109 TFourCC aDesiredFourCC,
112 iBody->InitializeL(aDevSoundObserver, aDesiredFourCC, aMode);
116 * CMMFDevSound::Capabilities
118 * Returns supported Audio settings.
120 * @return TMMFCapabilities device settings.
122 EXPORT_C TMMFCapabilities CMMFDevSound::Capabilities()
124 return iBody->Capabilities();
128 * CMMFDevSound::Config
130 * Returns current audio settings.
132 * @return TMMFCapabilities device settings.
134 EXPORT_C TMMFCapabilities CMMFDevSound::Config() const
136 return iBody->Config();
140 * CMMFDevSound::SetConfigL
142 * ConfigureS CMMFDevSound object with the settings in aConfig.
144 * Use this to set sampling rate, Encoding and Mono/Stereo.
146 * @param aConfig. CMMFDevSound configuration settings.
148 EXPORT_C void CMMFDevSound::SetConfigL(const TMMFCapabilities& aConfig)
150 iBody->SetConfigL(aConfig);
154 * CMMFDevSound::MaxVolume
156 * Returns an integer representing the maximum volume.
158 * This is the maximum volume which can be passed to CMMFDevSound::SetVolume.
161 * The maximum volume. This value is platform dependent but is always
162 * greater than or equal to one.
164 EXPORT_C TInt CMMFDevSound::MaxVolume()
166 return iBody->MaxVolume();
170 * CMMFDevSound::Volume
172 * Returns an integer representing current volume level.
175 * Current volume level.
177 EXPORT_C TInt CMMFDevSound::Volume()
179 return iBody->Volume();
183 * CMMFDevSound::SetVolume
185 * Changes current volume level to the specified value.
187 * The volume can be changed before or during playback and is effective
191 * The volume setting. This can be any value between zero and the
192 * value returned by the call to CMMFDevSound::MaxVolume(). If the
193 * volume is out of range, it is automatically set to the minimum or
194 * maximum level closest to the value being passed in. Setting a zero
195 * value mutes the sound.
197 EXPORT_C void CMMFDevSound::SetVolume(TInt aVolume)
199 iBody->SetVolume(aVolume);
203 * CMMFDevSound::MaxGain
205 * Returns an integer representing the maximum microphone gain.
207 * This is the maximum value which can be passed to CMMFDevSound::SetGain.
210 * The maximum gain. This value is platform dependent but is always
211 * greater than or equal to one.
213 EXPORT_C TInt CMMFDevSound::MaxGain()
215 return iBody->MaxGain();
221 * Returns an integer representing current gain.
224 * The current gain level.
226 EXPORT_C TInt CMMFDevSound::Gain()
228 return iBody->Gain();
232 * CMMFDevSound::SetGain
234 * Changes current recording gain to a specified value.
236 * The gain can be changed before or during recording and is effective
239 * @param aGain. This can be any value between zero and the
240 * value returned by the call to CMMFDevSound::MaxGain(). If the
241 * gain is out of range, it is automatically set to minimum or maximum
242 * value closest to the value that is being passed.
243 * Setting a zero value mutes the microphone.
245 EXPORT_C void CMMFDevSound::SetGain(TInt aGain)
247 iBody->SetGain(aGain);
251 * CMMFDevSound::GetPlayBalanceL
253 * Returns the speaker balance set for playing.
255 * @param aLeftPercentage. On return contains the left speaker volume percentage.
256 * @param aRightPercentage. On return contains the left speaker volume percentage.
258 EXPORT_C void CMMFDevSound::GetPlayBalanceL(TInt& aLeftPercentage,TInt& aRightPercentage)
260 iBody->GetPlayBalanceL(aLeftPercentage, aRightPercentage);
264 * CMMFDevSound::SetPlayBalanceL
266 * Sets the speaker balance for playing.
268 * The speaker balance can be changed before or during playback and is
269 * effective immediately.
271 * @param aLeftPercentage. Left speaker volume perecentage. This can be any value between
272 * zero and 100. Setting a zero value mutes the sound on the left
274 * @param aRightPercentage. Right speaker volume perecentage. This can be any value between
275 * zero and 100. Setting a zero value mutes the sound on the right
278 EXPORT_C void CMMFDevSound::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
280 iBody->SetPlayBalanceL(aLeftPercentage, aRightPercentage);
284 * CMMFDevSound::GetRecordBalanceL
286 * Returns the microphone gain balance set for recording.
288 * @param aLeftPercentage. On return contains the left microphone gain percentage.
289 * @param aRightPercentage. On return contains the right microphone gain percentage.
291 EXPORT_C void CMMFDevSound::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
293 iBody->GetRecordBalanceL(aLeftPercentage, aRightPercentage);
297 * CMMFDevSound::SetRecordBalanceL
299 * Sets the microphone gain balance for recording.
301 * The microphone gain balance can be changed before or during recording and
302 * is effective immediately.
304 * @param aLeftPercentage. Left microphone gain precentage. This can be any value between zero
305 * and 100. Setting a zero value mutes the gain on the left microphone.
306 * @param aRightPercentage. Right microphone gain precentage. This can be any value between zero
307 * and 100. Setting a zero value mutes the gain on the right microphone
309 EXPORT_C void CMMFDevSound::SetRecordBalanceL(TInt aLeftPercentage,TInt aRightPercentage)
311 iBody->SetRecordBalanceL(aLeftPercentage, aRightPercentage);
315 * CMMFDevSound::PlayInitL
317 * Initializes audio device and starts the playback. Before playback can be
318 * started, its current client's access priority is first verified by the
319 * audio policy. In case of an error during the policy initialization, the
320 * PlayError() method will be called on the observer with KErrAccessDenied
321 * error code, otherwise BufferToBeFilled() method will be called with a
322 * buffer reference. After filling the buffer with the data, the client
323 * should call PlayData() to start playback.
325 * The amount of data that can be played is specified in
326 * CMMFBuffer::RequestSize(). Any data that is read into the buffer beyond
327 * this size will be ignored.
330 EXPORT_C void CMMFDevSound::PlayInitL()
336 * CMMFDevSound::RecordInitL
338 * Initializes audio device and starts the recording. Before recording can be
339 * started, its current client's access priority is first verified by the
340 * audio policy. In case of an error during the policy initialization, the
341 * RecordError() method will be called on the observer with KErrAccessDenied
342 * error code, otherwise BufferToBeEmptied() method will be called with a
343 * buffer reference. This buffer contains recorded or encoded data. After
344 * processing the data in the buffer, the client should call RecordData()
345 * to continue recording process.
347 * The amount of data that is available is specified in
348 * CMMFBuffer::RequestSize().
351 EXPORT_C void CMMFDevSound::RecordInitL()
353 iBody->RecordInitL();
357 * CMMFDevSound::PlayData
359 * Plays data in the buffer. The client should fill the buffer with a stream
360 * of sampled audio data before calling this method. The observer gets the
361 * reference to the buffer along with BufferToBeFilled() callback. When
362 * playing of the audio sample is complete, with success or not, the
363 * PlayError() method is called on the observer.
365 EXPORT_C void CMMFDevSound::PlayData()
371 * CMMFDevSound::RecordData
373 * Records audio data. Once the buffer is filled with recorded sampled audio
374 * data, the observer gets reference to the buffer along with
375 * BufferToBeEmptied() callback. After processing of the buffer (copying over
376 * to a different buffer or writing to a file) the client should call this
377 * method again to continue recording process.
379 EXPORT_C void CMMFDevSound::RecordData()
387 * Stops the ongoing operation (Play, Record, TonePlay)
389 EXPORT_C void CMMFDevSound::Stop()
395 * CMMFDevSound::Pause
397 * Temporarily suspends the ongoing operation (Play, Record, TonePlay)
399 EXPORT_C void CMMFDevSound::Pause()
405 * CMMFDevSound::SamplesRecorded
407 * Returns the number of recorded samples up to this point.
410 * Value representing recorded samples.
412 EXPORT_C TInt CMMFDevSound::SamplesRecorded()
414 return iBody->SamplesRecorded();
418 * CMMFDevSound::SamplesPlayed
420 * Returns the number of played samples up to this point.
423 * Value representing played samples.
425 EXPORT_C TInt CMMFDevSound::SamplesPlayed()
427 return iBody->SamplesPlayed();
431 * CMMFDevSound::PlayToneL
433 * Initializes audio device and starts playing a single tone according with
434 * the specified frequency and duration attributes.
436 * @param aFrequency. Frequency at with the tone will be played.
437 * @param aDuration. The period over which the tone will be played. A zero value causes
438 * no tone to be played.
440 EXPORT_C void CMMFDevSound::PlayToneL(TInt aFrequency,const TTimeIntervalMicroSeconds& aDuration)
442 iBody->PlayToneL(aFrequency, aDuration);
446 * CMMFDevSound::PlayDualToneL
448 * Initializes audio device and starts playing a dual tone.
449 * The tone consists of two sine waves of different frequencies summed
450 * together. Both frequencies and the duration are specified in the passed
453 * @param aFrequencyOne. Value representing first frequency of the dual tone.
455 * @param aFrequencyTwo. Value representing second frequency of the dual tone.
457 * @param aDuration. The period over which the tone will be played. A zero value causes
458 * no tone to be played.
460 EXPORT_C void CMMFDevSound::PlayDualToneL(
463 const TTimeIntervalMicroSeconds& aDuration)
465 iBody->PlayDualToneL(aFrequencyOne, aFrequencyTwo, aDuration);
469 * CMMFDevSound::PlayDTMFStringL
471 * Initializes audio device and starts playing DTMF string.
473 * @param aDTMFString. DTMF sequence in a descriptor.
475 EXPORT_C void CMMFDevSound::PlayDTMFStringL(const TDesC& aDTMFString)
477 iBody->PlayDTMFStringL(aDTMFString);
481 * CMMFDevSound::PlayToneSequenceL
483 * Initializes audio device and starts playing tone sequence.
485 * @param aData. Tone sequence in a descriptor.
487 EXPORT_C void CMMFDevSound::PlayToneSequenceL(const TDesC8& aData)
489 iBody->PlayToneSequenceL(aData);
493 * CMMFDevSound::PlayFixedSequenceL
495 * Initializes audio device and starts playing the specified tone sequence.
497 * Method is deprecated from OS release 9.5
499 * @param aSequenceNumber. The index identifying the specific pre-defined tone sequence. The
500 * index values are relative to zero. This can be any value between
501 * zero and the value returned by the call to
502 * CMdaAudioPlayerUtility::FixedSequenceCount() - 1. The function
503 * raises a panic if sequence number is out of range.
505 EXPORT_C void CMMFDevSound::PlayFixedSequenceL(TInt /*aSequenceNumber*/)
507 User::Leave(KErrNotSupported);
511 * CMMFDevSound::SetToneRepeats
513 * Defines the number of times the audio is to be repeated during the tone
514 * playback operation.
516 * A period of silence can follow each playing of tone. The tone playing can
517 * be repeated indefinitely.
519 * @param aRepeatCount. The number of times the tone, together with the trailing silence,
520 * is to be repeated. If this is set to KMdaRepeatForever, then the
521 * tone, together with the trailing silence, is repeated indefinitely
522 * or until Stop() is called. If this is set to zero, then the tone is
523 * not repeated. Supported only during the tone playing.
525 * @param aRepeatTrailingSilence. The duration of the trailing silence.
527 EXPORT_C void CMMFDevSound::SetToneRepeats(TInt aRepeatCount,const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
529 iBody->SetToneRepeats(aRepeatCount, aRepeatTrailingSilence);
533 * CMMFDevSound::SetDTMFLengths
535 * Defines the duration of 'tone on/tone off' and 'tone pause' to be used
536 * during the DTMF playback.
538 * Supported only during tone playing.
540 * @param aToneOnLength. The period over which the tone will be played. If this is set to
541 * zero, then the tone is not played.
543 * @param aToneOffLength. The period over which 'no tone' will be played.
545 * @param aPauseLength. The period over which the tone playing will be paused.
547 EXPORT_C void CMMFDevSound::SetDTMFLengths(
548 TTimeIntervalMicroSeconds32& aToneOnLength,
549 TTimeIntervalMicroSeconds32& aToneOffLength,
550 TTimeIntervalMicroSeconds32& aPauseLength)
552 iBody->SetDTMFLengths(aToneOnLength, aToneOffLength, aPauseLength);
556 * CMMFDevSound::SetVolumeRamp
558 * Defines the period over which the volume level will rise smoothly from
559 * mute to the normal volume level.
561 * @param aRampDuration. The period over which the volume is to rise. A zero value causes
562 * the tone sample to be played at the normal level for the full duration of the
563 * playback. A value, which is longer than the duration
564 * of the tone sample, will result in the sample never reaching its
565 * normal volume level.
567 EXPORT_C void CMMFDevSound::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
569 iBody->SetVolumeRamp(aRampDuration);
573 * CMMFDevSound::SetPrioritySettings
575 * Defines the priority settings that should be used for this instance.
577 * @param aPrioritySettings. A structure representing client's priority, priority
578 * preference and the state.
580 EXPORT_C void CMMFDevSound::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
582 iBody->SetPrioritySettings(aPrioritySettings);
586 * CMMFDevSound::CustomInterface
588 * Sends request to the DevSound Server to start custom interface specified
589 * by the TUid attribute.
591 * @param aInterface. Unique ID of the custom interface
594 * Pointer to the custom interface object.
596 EXPORT_C TAny* CMMFDevSound::CustomInterface(TUid aInterface)
598 return iBody->CustomInterface(aInterface);
602 * CMMFDevSound::FixedSequenceCount
604 * Returns the number of available pre-defined tone sequences.
606 * Method is deprecated from OS release 9.5
608 * This is the number of fixed sequence supported by the DevSound by default.
611 * The fixed sequence count. This value is implementation dependent
612 * but is always greater than or equal to zero.
614 EXPORT_C TInt CMMFDevSound::FixedSequenceCount()
620 * CMMFDevSound::FixedSequenceName
622 * Returns the name assigned to a specific pre-defined tone sequence.
624 * Method is deprecated from OS release 9.5
626 * @param aSequenceNumber. The index identifying the specific pre-defined tone sequence.
627 * Index values are relative to zero. This can be any value between
628 * zero and the value returned by the call to
629 * CMdaAudioPlayerUtility::FixedSequenceCount() - 1. The function
630 * raises a panic if sequence number is out of range.
633 * A reference to a descriptor containing fixed sequence name
634 * indexed by aSequenceNumber.
636 EXPORT_C const TDesC& CMMFDevSound::FixedSequenceName(TInt /*aSequenceNumber*/)
642 * CMMFDevSound::GetSupportedInputDataTypesL
644 * Returns a list of supported input data types that can be sent to the
645 * DevSound for playing audio.
647 * @param aSupportedDataTypes. An array of supported data types.
648 * @param aPrioritySettings. Structure containing priority settings.
650 EXPORT_C void CMMFDevSound::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes,const TMMFPrioritySettings& aPrioritySettings) const
652 iBody->GetSupportedInputDataTypesL(aSupportedDataTypes,
657 * CMMFDevSound::GetSupportedOutputDataTypesL
659 * Returns a list of supported output data types that can be received from
660 * the DevSound for recording audio.
662 * @param aSupportedDataTypes. An array of supported data types.
663 * @param aPrioritySettings. Structure containing priority settings.
665 EXPORT_C void CMMFDevSound::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes,const TMMFPrioritySettings& aPrioritySettings) const
667 iBody->GetSupportedOutputDataTypesL(aSupportedDataTypes,aPrioritySettings);
670 /********************************************************************************
671 * Non Exported public functions ends here *
672 ********************************************************************************/
674 /******************************************************************************
675 * Function Name: E32Dll
677 * Description: Entry point for applications.
679 ******************************************************************************/
682 EXPORT_C TInt E32Dll(TDllReason /*aReason*/)
687 // CMMFDevSoundEventHandler::NewL() has been declared in export table
688 // but since it is the only class method to be so, and .h is in source
689 // it is not actually usable. Just declare the following to keep linker happy
691 // Need dummy abstract type - this is not the real class
692 class RMMFAudioPolicyProxy;
694 class CMMFDevSoundEventHandler : public CActive
697 IMPORT_C static CMMFDevSoundEventHandler* NewL(RMMFAudioPolicyProxy*);
699 CMMFDevSoundEventHandler();
702 EXPORT_C CMMFDevSoundEventHandler* CMMFDevSoundEventHandler::NewL(RMMFAudioPolicyProxy*)
704 _LIT(KModule, "DevSound");
705 User::Panic(KModule, 1000);
709 // default constructor - keep compilers happy
710 CMMFDevSoundEventHandler::CMMFDevSoundEventHandler():
711 CActive(EPriorityStandard)