📄 aphearsaysndplay.c
字号:
/****************************************************************************/
/* */
/* Copyright (C) 2005 SHENZHEN MEIJIN CO.LTD */
/* */
/* FILE NAME: ApHearSaySndPlay.c */
/* MODULE NAME: AP应用程序 */
/* DESCRIPTION: Hearsay Sound File */
/* */
/* FUNCTIONS: */
/* */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* DennyHan 2006-03-14 V1.00B */
/****************************************************************************/
// 包含必要的头文件
#include "Ap.h"
#include "ApHearSay.h"
extern RrParam g_RrParam;
//==================================================================================
//==================================================================================
//
// Play Sound Part
//
//===========================================================================
//===========================================================================
/****************************************************************************/
/* FUNCTION: void __RrPlayCallBack(UINT16 wParam, UINT32 dwParam) */
/* DESCRIPTION: */
/* INPUTS: NULL */
/* OUTPUTS: NONE */
/* RETURN: TURE OR FAULSE */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Poul 2005-04-19 创建 */
/****************************************************************************/
// Here must use POST Message
static void __RrPlayCallBack(UINT16 wParam, UINT32 dwParam)
{
switch (wParam)
{
case VOICE_NOTIFY_PLAY_FAIL: // 播放失败
case VOICE_NOTIFY_OPEN_FAIL: // 打开失败
MsgPost(NULL,(UINT)EVENT_COMMAND,CMD_HS_OPENFAIL);
break;
case VOICE_NOTIFY_PLAY_BREAK: // 播放被打断
MsgPost(NULL,(UINT)EVENT_COMMAND,CMD_HS_BREAK);
break;
case VOICE_NOTIFY_BUFFER_USEUP: //播放buffer里的数据已经取完
break;
default:
case VOICE_NOTIFY_PLAY_STOP: // 自动播放结束
#if 0
{
#ifdef _WIN32
#define APHS_VOICE_STOP_CNT 1000
#else
#define APHS_VOICE_STOP_CNT 500
#endif
int i;
for (i=(APHS_VOICE_STOP_CNT*0x400);i>0;i--){}
}
#endif
MsgPost(NULL,(UINT)EVENT_COMMAND,CMD_HS_STOP);
break;
}
}
//==================================================================
//
// Time Stamp
//
//------------
INT ApHsClrPlayTm(INT nMode)
{
nMode &= 1;
g_RrParam.aPlay[nMode].dwPlayTm=0;
g_RrParam.aPlay[nMode].dwTotalTm=0;
ApHsClrPlayTmBar(nMode);
return TRUE;
}
//---------------
// Get Time
INT ApHsGetPlayTm(INT nMode)
{
VoiceHandle hVoice;
MVoicePlayParam *pPlay;
if (nMode>1)
{
return FALSE;
}
nMode &= 1;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if (hVoice>=0)
{
pPlay=g_RrParam.pPlayParam;
VoiceGetParam(hVoice,pPlay);
// total time : to 0.5s
g_RrParam.aPlay[nMode].dwTotalTm= 1000* pPlay->dwTimeLength; // To 1ms
// Current Play Time // To 1ms
// g_RrParam.aPlay[nMode].dwPlayTm =1000 * pPlay->dwRetOffset
// / pPlay->dwLengthPerSec;
g_RrParam.aPlay[nMode].dwPlayTm = (UINT32)((double)pPlay->dwRetOffset
*(double)g_RrParam.aPlay[nMode].dwTotalTm
/ (double)pPlay->dwPlayEnd);
g_RrParam.aPlay[nMode].dwPlayTm =((g_RrParam.aPlay[nMode].dwPlayTm+50)/100)*100 ;
/*----------------------------------------------------------------/
if(g_RrParam.aPlay[nMode].dwPlayTm>500)
g_RrParam.aPlay[nMode].dwPlayTm-=500;
/-----------------------------------------------------------------*/
if ( g_RrParam.aPlay[nMode].dwPlayTm > g_RrParam.aPlay[nMode].dwTotalTm )
{
g_RrParam.aPlay[nMode].dwPlayTm=g_RrParam.aPlay[nMode].dwTotalTm;
}
ApHsSetPlayTmBar(nMode);
return TRUE;
}
return FALSE;
}
//-----------------
// Set Play TIme
INT ApHsSetPlayTm(INT nMode)
{
VoiceHandle hVoice;
MVoicePlayParam *pPlay;
if (nMode>1)
{
return FALSE;
}
nMode &= 1;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if ( hVoice >=0 )
{
pPlay=g_RrParam.pPlayParam;
// to S
// pPlay->dwPlayOffset = g_RrParam.aPlay[nMode].dwPlayTm
// *pPlay->dwLengthPerSec/1000;
pPlay->dwPlayOffset = (UINT32)( (double)(g_RrParam.aPlay[nMode].dwPlayTm)
*(double) (pPlay->dwPlayEnd)
/(double)g_RrParam.aPlay[nMode].dwTotalTm);
if (pPlay->dwPlayOffset > pPlay->dwPlayEnd)
{
pPlay->dwPlayOffset = pPlay->dwPlayEnd;
}
VoiceSetParam(hVoice,pPlay);
ApHsSetPlayTmBar(nMode);
return TRUE;
}
return FALSE;
}
//---------------
// Set Time
INT ApHsSetCurrentPlayTm(INT nMode,UINT32 Tm)
{
if (nMode>1)
{
return FALSE;
}
if (Tm>g_RrParam.aPlay[nMode&1].dwTotalTm)
{
Tm=g_RrParam.aPlay[nMode&1].dwTotalTm;
}
g_RrParam.aPlay[nMode&1].dwPlayTm=Tm;
return TRUE;
}
/****************************************************************************/
/* FUNCTION: INT ApHsStartPlay(VOID) */
/* DESCRIPTION: */
/* INPUTS: NULL */
/* OUTPUTS: NONE */
/* RETURN: TURE OR FAULSE */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* DennyHan 2006.3.14 V1.00B */
/****************************************************************************/
// nMode=0, Play
// nMode=1, Record
//----------
INT ApHsOpenPlay(INT nMode)
{
UINT8 *pFile;
INT nRet;
VoiceHandle hVoice;
MVoicePlayParam *pPlyParam;
if (nMode>1)
{
return FALSE;
}
//------------------
if (g_RrParam.aPlay[nMode].hPlay>=0)
{
ApHsClosePlay(nMode);
}
ApHsClrPlayTm(nMode);
g_RrParam.aPlay[nMode].hPlay=-1;
if (nMode==0)
{
pFile=(UINT8*)g_RrParam.pFile;
}
else
{
pFile=(UINT8*)(APHS_DEF_REC_FILE);
}
pPlyParam=g_RrParam.pPlayParam;
pPlyParam->playType = VOICE_TYPE_DEFAULT;
pPlyParam->playMode = VOICE_MODE_FILENAME;
pPlyParam->pDataSource = pFile;
pPlyParam->dwPlayCycles = 1;
pPlyParam->dwPlayStart = 0;
pPlyParam->dwPlayLength = 0;
pPlyParam->pCallBackFunc = (void*)__RrPlayCallBack;
nRet=TRUE;
hVoice = VoiceOpen(g_RrParam.pPlayParam);
if (hVoice == (VoiceHandle)-1)
{
nRet=FALSE;
}
if (nRet)
{
g_RrParam.aPlay[nMode].hPlay=hVoice;
ApHsGetPlayTm(nMode);
// it is close, backup current play time
if (!g_RrParam.aPlay[nMode].bOpen)
{
APHsRestorePlay0SndTm();
ApHsSetPlayTm(nMode);
g_RrParam.aPlay[nMode].bOpen=TRUE;
}
}
return nRet;
}
INT ApHsStartPlay(INT nMode)
{
INT nRet;
VoiceHandle hVoice;
if (nMode>1)
{
return FALSE;
}
nRet=FALSE;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if (hVoice>=0)
{
ApHsGetPlayTm(nMode);
ApHsSetPlayTm(nMode);
if (VoicePlay(hVoice))
{
nRet=TRUE;
}
}
return nRet;
}
//===================================
// Pause
INT ApHsPausePlay(INT nMode)
{
INT nRet;
VoiceHandle hVoice;
if (nMode>1)
{
return FALSE;
}
nRet=FALSE;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if (hVoice>=0)
{
ApHsGetPlayTm(nMode);
if (VoicePause(hVoice))
{
nRet=TRUE;
}
}
return nRet;
}
//===================================
// Continue
//------------
INT ApHsContinuePlay(INT nMode)
{
INT nRet;
VoiceHandle hVoice;
if (nMode>1)
{
return FALSE;
}
nRet=FALSE;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if (hVoice>=0)
{
ApHsGetPlayTm(nMode);
if (VoiceResume(hVoice))
{
nRet=TRUE;
}
}
return nRet;
}
//===================================
//Stop
INT ApHsStopPlay(INT nMode)
{
INT nRet;
VoiceHandle hVoice;
if (nMode>1)
{
return FALSE;
}
nRet=FALSE;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if ( (hVoice>=0)
&& (VoiceStop(hVoice)) )
{
nRet=TRUE;
}
return nRet;
}
//==============================
// Close
INT ApHsClosePlay(INT nMode)
{
INT nRet;
VoiceHandle hVoice;
if (nMode>1)
{
return FALSE;
}
// it is close, backup current play time
if (g_RrParam.aPlay[nMode].bOpen)
{
APHsBackupPlay0SndTm();
}
nRet=FALSE;
hVoice=g_RrParam.aPlay[nMode].hPlay;
if ( (hVoice>=0)
&& (VoiceClose(hVoice)) )
{
UINT32 dwTotalTm;
nRet=TRUE;
dwTotalTm = g_RrParam.aPlay[nMode].dwTotalTm; // Back up for display baub
ApHsClrPlayTm(nMode);
g_RrParam.aPlay[nMode].dwTotalTm = dwTotalTm;
g_RrParam.aPlay[nMode].hPlay=-1;
// Clear
g_RrParam.aPlay[nMode].bOpen=FALSE;
}
return nRet;
}
/****************************************************************************/
/* FUNCTION: BOOL APHSReturn(VOID) */
/* DESCRIPTION: */
/* INPUTS: NULL */
/* OUTPUTS: NONE */
/* RETURN: TURE OR FAULSE */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* DennyHan 2006.3.14 V1.00B */
/****************************************************************************/
BOOL APHSSndReturn(VOID)
{
ApHsStopPlay(1);
ApHsStopRecord();
ApHsStopPlay(0);
ApHsClosePlay(0);
ApHsClosePlay(1);
g_RrParam.wRptMode &= ~(RR_MODE_NOMST | RR_MODE_NOTEXT);
return TRUE;
}
/****************************************************************************/
/* FUNCTION: BOOL APHSReturn(VOID) */
/* DESCRIPTION: */
/* INPUTS: NULL */
/* OUTPUTS: NONE */
/* RETURN: TURE OR FAULSE */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* DennyHan 2006.3.14 V1.00B */
/****************************************************************************/
BOOL APHsStopCurrentSound(VOID)
{
if (g_RrParam.wSndMode&APHS_SOUND_REC)
{
ApHsStopRecord();
g_RrParam.wSndMode&=(~APHS_SOUND_REC);
}
else if (g_RrParam.wSndMode&APHS_SOUND_PLAY)
{
ApHsStopPlay(0);
g_RrParam.wSndMode&=(~APHS_SOUND_PLAY);
}
else if (g_RrParam.wSndMode&APHS_SOUND_PLAYREC)
{
ApHsStopPlay(1);
g_RrParam.wSndMode&=(~APHS_SOUND_PLAYREC);
}
else
{
return FALSE;
}
return TRUE;
}
// Get Sound Busy mode
// 0= No Sound
// 1=
BOOL ApHsSndIsBusy(VOID)
{
if (g_RrParam.wSndMode&(APHS_SOUND_PLAY|APHS_SOUND_PLAYREC|APHS_SOUND_REC))
{
return TRUE;
}
return FALSE;
}
//===========================================================================
// for backup tim
//=======
VOID APHsBackupPlay0SndTm(VOID)
{
g_RrParam.aPlay[0].dwCurTm=g_RrParam.aPlay[0].dwPlayTm; // BackUp the time
}
VOID APHsRestorePlay0SndTm(VOID)
{
g_RrParam.aPlay[0].dwPlayTm=g_RrParam.aPlay[0].dwCurTm; // restore the time
}
//---------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -