PlayAudio.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * PlayAudio.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Audio play source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #pragma hdrstop
- #ifndef _PLAYAUDIO_H_
- #include "PlayAudio.h"
- #endif
- #ifndef _MAN_ACTIVE_H_
- #include "man_active.h"
- #endif
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- static CPLAYAUDIO* play_audio_ptr;
- static bool g_bIsRunning;
- extern bool IsStopButtonPressed;
- //============================= static function ==============================
- static void REQ_TimeOut( void )
- { play_audio_ptr->REQ_TimeOut();
- }
- //----------------------------------------------------------------------------
- static void REQ_Finish( void )
- { play_audio_ptr->REQ_Finish();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Set_Volume( void )
- { play_audio_ptr->Req_Audio_Set_Volume();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Play_IMY_ByBuf( void )
- { play_audio_ptr->Req_Audio_Play_IMY_ByBuf();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Stop( void )
- { play_audio_ptr->Req_Audio_Stop();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Play_ByName( void )
- { play_audio_ptr->Req_Audio_Play_ByName();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Query_ID( void )
- { play_audio_ptr->Req_Audio_Query_ID();
- }
- //---------------------------------------------------------------------------
- static void Req_Audio_Play( void )
- { play_audio_ptr->Req_Audio_Play();
- }
- //----------------------------------------------------------------------------
- static void __stdcall CNF_AudioSetVolume(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioSetVolume(status, token, usrData);
- }
- //----------------------------------------------------------------------------
- static void __stdcall CNF_AudioStop(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioStop(status, token, usrData);
- }
- //----------------------------------------------------------------------------
- static void __stdcall IND_AudioPlayOver(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->IND_AudioPlayOver(status, token, usrData);
- }
- //--------------------------------------- play iMelody by buf ----------------
- static void __stdcall CNF_AudioPlayIMYBybuf(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioPlayIMYBybuf(status, token, usrData);
- }
- //--------------------------------------- play by name -----------------------
- static void __stdcall CNF_AudioPlayByName(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioPlayByName(status, token, usrData);
- }
- //--------------------------------------- play ID ----------------------------
- static void __stdcall CNF_AudioQueryID(const Audio_Query_ID_Cnf *cnf, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioQueryID(cnf, token, usrData);
- }
- //----------------------------------------------------------------------------
- static void __stdcall CNF_AudioPlay(const AUDIO_RESULT status, const short token, void *usrData)
- { play_audio_ptr->CNF_AudioPlay(status, token, usrData);
- }
- //===========================================================================
- CPLAYAUDIO::CPLAYAUDIO( void )
- {
- g_bIsRunning = false;
- play_audio_ptr = this;
- ConfirmCallback = 0;
- }
- //---------------------------------------------------------------------------
- CPLAYAUDIO::~CPLAYAUDIO( )
- {
- g_bIsRunning = false;
- //ConfirmCallback = 0;
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::Confirm( int confirm_state )
- {
- if(!g_bIsRunning) return;
- if(ConfirmCallback==0) return;
- m_iConfirmState = confirm_state;
- g_bIsRunning = false;
- ActiveMan->SetActiveFunction( ConfirmCallback );
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::REQ_Finish( void )
- {
- if(!g_bIsRunning) return;
- Confirm( STATE_AUDIO_OK );
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::REQ_Stop( void )
- {
- if(!g_bIsRunning) return;
- META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), m_sSPID_PLAYAUDIO );
- Confirm( STATE_AUDIO_STOP );
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::REQ_TimeOut( void )
- {
- if(!g_bIsRunning) return;
- META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), m_sSPID_PLAYAUDIO );
- Confirm( STATE_AUDIO_TIMEOUT );
- }
- //==============================================================================================
- void CPLAYAUDIO::Req_Audio_Play_IMY_ByBuf_Start(char *iMelodyBuf, unsigned int buf_len, unsigned char imy_instrument, int play_style)
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- m_sAudioPlayImyByBufReq.imy_buf = iMelodyBuf;
- m_sAudioPlayImyByBufReq.imy_buf_len = buf_len;
- m_sAudioPlayImyByBufReq.imy_instrument = imy_instrument;
- m_sAudioPlayImyByBufReq.play_style = (AUDIO_PLAY_STYLE) play_style;
- ActiveMan->SetActiveFunction( ::Req_Audio_Play_IMY_ByBuf );
- }
- //--------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Play_IMY_ByBuf( void )
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Play_IMY_ByBuf_r( m_META_HANDLE_Obj.Get_MainHandle(), &m_sAudioPlayImyByBufReq, ::CNF_AudioPlayIMYBybuf, ::IND_AudioPlayOver, &m_sSPID_PLAYAUDIO, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //--------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioPlayIMYBybuf(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status != AUD_RES_OK)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //--------------------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::IND_AudioPlayOver(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status == AUD_RES_END_OF_FILE)
- { Confirm( STATE_AUDIO_OVER ); return; }
- else
- {
- if(IsStopButtonPressed == false)
- {
- Confirm( STATE_AUDIO_FAIL ); return;
- }
- }
- }
- //===========================================================================
- void CPLAYAUDIO::Req_Audio_Stop_Start( void )
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- ActiveMan->SetActiveFunction( ::Req_Audio_Stop );
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Stop( void )
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Stop_r( m_META_HANDLE_Obj.Get_MainHandle(), ::CNF_AudioStop, &m_sSPID_STOPAUDIO, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //---------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioStop(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status != AUD_RES_OK)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- else
- { Confirm( STATE_AUDIO_OK ); return; }
- }
- //==============================================================================
- void CPLAYAUDIO::Req_Audio_Play_ByName_Start(char *FAT_fileinfo, int play_style)
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- m_sAudioPlayByNameReq.fat_filepath = FAT_fileinfo;
- m_sAudioPlayByNameReq.play_style = (AUDIO_PLAY_STYLE)play_style;
- ActiveMan->SetActiveFunction( ::Req_Audio_Play_ByName );
- }
- //--------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Play_ByName( void )
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Play_ByName_r( m_META_HANDLE_Obj.Get_MainHandle(), &m_sAudioPlayByNameReq, ::CNF_AudioPlayByName, ::IND_AudioPlayOver, &m_sSPID_PLAYAUDIO, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //--------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioPlayByName(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status != STATUS_ADUIO_OK)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //=============================================================================
- void CPLAYAUDIO::Req_Audio_Set_Volume_Start(int volume)
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- m_sAudioSetVolReq.volume = volume;
- ActiveMan->SetActiveFunction( ::Req_Audio_Set_Volume );
- }
- //--------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Set_Volume( void )
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Set_Volume_r( m_META_HANDLE_Obj.Get_MainHandle(), &m_sAudioSetVolReq, ::CNF_AudioSetVolume, &m_sSPID_SETVOLUME, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- ActiveMan->SetActiveFunction( ::REQ_Finish );
- }
- //--------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioSetVolume(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status != AUD_RES_OK)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //=============================================================================
- //////////////////////////// Play song using ID ///////////////////////////////
- //=============================================================================
- void CPLAYAUDIO::Req_Audio_Query_ID_Start(void)
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- ActiveMan->SetActiveFunction( ::Req_Audio_Query_ID );
- }
- //--------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Query_ID(void)
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Query_ID_r( m_META_HANDLE_Obj.Get_MainHandle(), ::CNF_AudioQueryID, &m_sSPID_QUERY, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //-------------------------------------- play by ID -------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioQueryID(const Audio_Query_ID_Cnf *cnf, const short token, void *usrData)
- {
- if( ! g_bIsRunning ) return;
- if( STATUS_ADUIO_OK == cnf->status )
- {
- m_AudioQueryIDCnf.MinRingTone_ID = cnf->MinRingTone_ID;
- m_AudioQueryIDCnf.MaxRingTone_ID = cnf->MaxRingTone_ID;
- m_AudioQueryIDCnf.MinMIDI_ID = cnf->MinMIDI_ID;
- m_AudioQueryIDCnf.MaxMIDI_ID = cnf->MaxMIDI_ID;
- m_AudioQueryIDCnf.MinSound_ID = cnf->MinSound_ID;
- m_AudioQueryIDCnf.MaxSound_ID = cnf->MaxSound_ID;
- Confirm( STATE_AUDIO_OK );
- return;
- }
- else
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CPLAYAUDIO::Req_Audio_Play_Start(int audio_id, int play_style)
- {
- play_audio_ptr = this;
- g_bIsRunning = true;
- m_sAudioPlayReq.audio_id = audio_id;
- m_sAudioPlayReq.play_style = (AUDIO_PLAY_STYLE)play_style;
- ActiveMan->SetActiveFunction( ::Req_Audio_Play );
- }
- //---------------------------------------------------------------------------
- void CPLAYAUDIO::Req_Audio_Play( void )
- {
- if( ! g_bIsRunning ) return;
- META_RESULT MetaResult = META_Audio_Play_r(m_META_HANDLE_Obj.Get_MainHandle(), &m_sAudioPlayReq, ::CNF_AudioPlay, ::IND_AudioPlayOver, &m_sSPID_PLAYAUDIO, NULL);
- if(MetaResult!=META_SUCCESS)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //---------------------------------------------------------------------------
- void __stdcall CPLAYAUDIO::CNF_AudioPlay(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if(status != STATUS_ADUIO_OK)
- { Confirm( STATE_AUDIO_FAIL ); return; }
- }
- //===========================================================================
- //////////////////////////// Global information ///////////////////////////
- //===========================================================================
- int CPLAYAUDIO::Get_ConfirmState( void )
- {
- return m_iConfirmState;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Audio_Query_ID_Cnf CPLAYAUDIO::Get_AudioQueryIDCnf( void )
- { return m_AudioQueryIDCnf;
- }