00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <eikenv.h>
00021 #include "AudioTonePlayer.h"
00022
00023
00024 const TInt KVolumeDenominator = 2;
00025
00026
00027
00028 CAudioTonePlayer::CAudioTonePlayer()
00029 {
00030 }
00031
00032 CAudioTonePlayer::~CAudioTonePlayer()
00033 {
00034 delete iTonePlayer;
00035 }
00036
00037 CAudioTonePlayer* CAudioTonePlayer::NewLC()
00038 {
00039 CAudioTonePlayer* self = new (ELeave)CAudioTonePlayer();
00040 CleanupStack::PushL(self);
00041 self->ConstructL();
00042 return self;
00043 }
00044
00045 CAudioTonePlayer* CAudioTonePlayer::NewL()
00046 {
00047 CAudioTonePlayer* self=CAudioTonePlayer::NewLC();
00048 CleanupStack::Pop(self);
00049 return self;
00050 }
00051
00052 void CAudioTonePlayer::ConstructL()
00053 {
00054 iTonePlayer = CMdaAudioToneUtility::NewL(*this);
00055 }
00056
00057 void CAudioTonePlayer::PlayTone(TInt aFrequency,
00058 TTimeIntervalMicroSeconds aDuration)
00059 {
00060 Stop();
00061 iTonePlayer->PrepareToPlayTone(aFrequency, aDuration);
00062 }
00063
00064 void CAudioTonePlayer::PlayDualTone(TInt aFrequency1, TInt aFrequency2,
00065 TTimeIntervalMicroSeconds aDuration)
00066 {
00067 Stop();
00068 iTonePlayer->PrepareToPlayDualTone(aFrequency1, aFrequency2,
00069 aDuration);
00070 }
00071
00072 void CAudioTonePlayer::Stop()
00073 {
00074 iTonePlayer->CancelPlay();
00075 }
00076
00077 void CAudioTonePlayer::MatoPrepareComplete(TInt aError)
00078 {
00079 if (KErrNone == aError)
00080 {
00081 iTonePlayer->SetVolume(iTonePlayer->MaxVolume()
00082 / KVolumeDenominator);
00083 iTonePlayer->Play();
00084 }
00085 else
00086 {
00087
00088 DisplayErrorMessage(aError);
00089 }
00090 }
00091
00092 void CAudioTonePlayer::MatoPlayComplete(TInt aError)
00093 {
00094 if (KErrNone == aError)
00095 {
00096 }
00097 else
00098 {
00099
00100 DisplayErrorMessage(aError);
00101 }
00102 }
00103
00104 void CAudioTonePlayer::DisplayErrorMessage(TInt aError)
00105 {
00106 const TInt KMaxBuffer = 15;
00107 _LIT(KErrorMessage, "Error: %d");
00108 TBuf<KMaxBuffer> buffer;
00109 buffer.AppendFormat(KErrorMessage, aError);
00110 TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(KNullDesC, buffer));
00111 }
00112
00113