⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voicelist.c

📁 好记星的控件,包括button,list,对文件操作
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*                                                                          */
/*              Copyright (C) 2002-2003 SHENZHEN MEIJIN CO.LTD              */
/*                                                                          */
/*  FILE NAME   : VoiceList.C                                                     */
/*  MODULE NAME : VoiceList模块(VoiceList.MOD)                                          */
/*  DESCRIPTION : VoiceList Manager                                               */
/*                                                                          */
/****************************************************************************/
/*  DATE        AUTHOR      VERSION     REMARKS                             */
/*  ==========  ========    =======     ==============================      */
/*  2003-04-04  黄小明       VER1.00     创建                               */
/****************************************************************************/
#define __OS_SOURCE_FILE__

/* 包含所需头文件 */
#include "kernel.h"
//#include "SysWatch.h"

#include "VoiceIn.h"

// 定义内部全局变量

    //播放列表与参数等相关
static  VoiceList           g_VoiceList;
static  VoiceListPlayParam  g_VoiceListPlayParam;
static  MVoiceEffect        g_VoiceEffect;

static    VoiceHandle       hVoiceListPlayHandle;
static    UINT8             g_VoiceListRandomStatus[VOICE_LIST_MAX_FILENUM];  

BOOL __VoiceListInitial()
{
    memset(&g_VoiceList, 0x0, sizeof(VoiceList));
    memset(&g_VoiceEffect, 0, sizeof(MVoiceEffect));

    memset(&g_VoiceListPlayParam, 0, sizeof(g_VoiceListPlayParam));
    g_VoiceListPlayParam.wPlayMode     = VOICE_LIST_PLAYMODE_NOCYCLE;    // 播放模式 - 非循环
    g_VoiceListPlayParam.wPlaySel      = VOICE_LIST_PLAYSEL_ORDER;       // 选曲方式 - 随机
    g_VoiceListPlayParam.wPlayStatus = VOICE_LIST_DEVICE_STOP;       /*默认播放设备状态*/
    g_VoiceListPlayParam.wPlayCur = 0;                /*默认播放第一个文件*/
	g_VoiceListPlayParam.pCallBackFunc = NULL;

    hVoiceListPlayHandle = -1;

	return TRUE;
}

BOOL VoiceGetEffect(MVoiceEffect *pVoiceEffect)
{
    memmove(pVoiceEffect, &g_VoiceEffect, sizeof(MVoiceEffect));
    return TRUE;
}

BOOL __VoiceSetEffect(UINT param)
{
    NU_DRIVER           *pAudioDrv;
    NU_DRIVER_REQUEST	request;
    MVoiceEffect        *pVoiceEffect;
    
    pVoiceEffect = &g_VoiceEffect;
    pAudioDrv = GetIODriverFromName((UINT8*)DRV_NAME_AUDIO);
    memset((UINT8*)&request, 0, sizeof(NU_DRIVER_REQUEST));
    request.nu_function = NU_STATUS;

    if (param & VOICE_SET_BASS) {
        request.nu_supplemental_ptr = "Bassset";
        request.nu_supplemental = pVoiceEffect->bass;
        if (NU_Request_Driver(pAudioDrv, &request) != NU_SUCCESS)
        {
            return FALSE;
        }
    }
    
    if (param & VOICE_SET_EQ) {
        request.nu_supplemental_ptr = "EQset";
        request.nu_supplemental = pVoiceEffect->byEQ;
        if (NU_Request_Driver(pAudioDrv, &request) != NU_SUCCESS)
        {
            return FALSE;
        }
    }
    
    if (param & VOICE_SET_3D) {
        request.nu_supplemental_ptr = "3Dset";
        request.nu_supplemental = pVoiceEffect->by3D;
        if (NU_Request_Driver(pAudioDrv, &request) != NU_SUCCESS)
        {
            return FALSE;
        }
    }

    return TRUE;
}

BOOL VoiceSetEffect(MVoiceEffect *pVoiceEffect)
{
    VoiceListPlayParam  playParam;
    UINT                param;

    if (memcmp(pVoiceEffect, &g_VoiceEffect, sizeof(MVoiceEffect)) != 0)
    {
        if (VoiceListPlayParamGet(&playParam))
        {
            param = 0;
            if (pVoiceEffect->bass != g_VoiceEffect.bass) {
                param |= VOICE_SET_BASS;
            }
            if (pVoiceEffect->byEQ != g_VoiceEffect.byEQ) {
                param |= VOICE_SET_EQ;
            }
            if (pVoiceEffect->by3D != g_VoiceEffect.by3D) {
                param |= VOICE_SET_3D;
            }
            memmove(&g_VoiceEffect, pVoiceEffect, sizeof(MVoiceEffect));
            __VoiceSetEffect(param);
        }
        else {
            memmove(&g_VoiceEffect, pVoiceEffect, sizeof(MVoiceEffect));
        }
    }
    
    return TRUE;
}

VOID __VoiceListGetFileName(UINT16 wFileSel, UINT8* pFileName)
{
    UINT16  wStart, wEnd;

    wStart = g_VoiceList.wFileNameTable[wFileSel];
    wEnd = g_VoiceList.wFileNameTable[wFileSel + 1];

    memcpy(pFileName, g_VoiceList.szListPath, FILE_MAX_NAMELEN);
    strncat((char *)pFileName, (char *)&g_VoiceList.FileNameBuf[wStart], wEnd - wStart);
}


VOID	__VoiceListPlayCallBack(UINT16 wParam, UINT32 dwParam)
{
	switch(wParam)
	{
    case VOICE_NOTIFY_PLAY_STOP:
        __VoiceSendCommand(NULL, VOICE_LIST_COMMAND_PLAYCYCLE, 0, 0);
        break;

	case VOICE_NOTIFY_PLAY_BREAK:
		break;

	default:
		if(g_VoiceListPlayParam.pCallBackFunc)
		    ((VOICECALLBACKPROC)g_VoiceListPlayParam.pCallBackFunc)(wParam, 0);
		break;
	}
}


BOOL __VoiceListFileExist(UINT8 *pVoiceListFile)
{
	DSTAT  stat;
	STATUS status;

	status = FileGetFirst(&stat, (INT8 *)pVoiceListFile);
	if (status == NU_SUCCESS)
	{
		FileDone(&stat);
		return TRUE;
	}
	else
		return FALSE;
}


BOOL __VoiceListOpen()
{
    UINT8   szFileName[FILE_MAX_NAMELEN];

	if (hVoiceListPlayHandle != -1)
		return TRUE;
	
    if (g_VoiceList.wFileNum == 0) {
        return FALSE;
    }
	
	__VoiceListGetFileName(g_VoiceListPlayParam.wPlayCur, szFileName);
    if (__VoiceListFileExist(szFileName))
    {
        g_VoiceListPlayParam.voicePlayParam.pDataSource = szFileName;
        g_VoiceListPlayParam.voicePlayParam.playType = VOICE_TYPE_DEFAULT;
        g_VoiceListPlayParam.voicePlayParam.playMode = (VOICE_MODE_FILENAME | VOICE_MODE_BACKGROUND);
        g_VoiceListPlayParam.voicePlayParam.dwPlayCycles = 1;
        g_VoiceListPlayParam.voicePlayParam.dwPlayStart = 0;
        g_VoiceListPlayParam.voicePlayParam.dwPlayLength = 0;
        g_VoiceListPlayParam.voicePlayParam.pCallBackFunc = (VOID*)__VoiceListPlayCallBack;
        
        __VoiceStop(VOICE_NOTIFY_STOP);
        
        __VoiceSetEffect(VOICE_SET_BASS | VOICE_SET_EQ | VOICE_SET_3D);
        hVoiceListPlayHandle = __VoiceOpen(&g_VoiceListPlayParam.voicePlayParam);
        if (hVoiceListPlayHandle >= 0) {
            MVoicePlayParam *temp = &g_VoiceListPlayParam.voicePlayParam;
            UINT32  dwBakOffset = temp->dwRetOffset;

            //处理挂起
            if (g_VoiceListPlayParam.wPlayStatus & VOICE_LIST_DEVICE_SUSPEND) {
                temp->dwPlayOffset = dwBakOffset;
                VoiceSetParam(hVoiceListPlayHandle, temp);
            }
            return TRUE;
        }
    }

	return FALSE;
}


/****************************************************************************/
/* FUNCTION:   VoiceListSet                                                */
/* DESCRIPTION:设置播放文件列表                                            */
/* INPUTS:     pNewVoiceList - 文件表                                      */
/* OUTPUTS:    NONE                                                        */
/* RETURN:     设置成功则返回TRUE,否则返回FALSE                           */
/****************************************************************************/
/*  NAME           DATE               REMARKS                               */
/* ==========  ============   ==============================================*/
/*  HuangXM     2003-04-09     创建                                         */
/*   谢永良     2003-04-24     修改,删除临时操作                           */
/****************************************************************************/
BOOL VoiceListSet(VoiceList *pNewVoiceList)
{
    UINT16	i;
    BOOL	bIsOpen, bPlaying, bPause;
    UINT16	wPlayCur;
    
    //判断传入参数的合法性
    if( (pNewVoiceList == NULL) || (pNewVoiceList->wFileNum > VOICE_LIST_MAX_FILENUM))
        return FALSE;
    
    if (pNewVoiceList->wFileNum == 0) {
        VoiceListClose();
        g_VoiceList.wFileNum = 0;
        return TRUE;
    }
    
    //检查新旧列表是否相同
    if (stricmp(g_VoiceList.szListPath, pNewVoiceList->szListPath) == 0
        && g_VoiceList.wFileNum == pNewVoiceList->wFileNum
        && memcmp(g_VoiceList.FileNameBuf, pNewVoiceList->FileNameBuf,
        pNewVoiceList->wFileNameTable[pNewVoiceList->wFileNum]) == 0)
    {
        return TRUE;
    }
    
    //记录当前正在播放的文件
    bPause = FALSE;
    wPlayCur = 0;
    if (stricmp(g_VoiceList.szListPath, pNewVoiceList->szListPath) == 0)
    {
        UINT8   *pCurFile, *pFile;

        pCurFile = &g_VoiceList.FileNameBuf
            [g_VoiceList.wFileNameTable[g_VoiceListPlayParam.wPlayCur]];
        for(i = 0; i < pNewVoiceList->wFileNum; i ++)
        {
            //比较每个文件
            pFile = &pNewVoiceList->FileNameBuf[pNewVoiceList->wFileNameTable[i]];
            if (strcmp(pCurFile, pFile) == 0)
            {
                wPlayCur = i;
                bPause = TRUE;
                break; 
            }
        }
    }
    
    if(g_VoiceListPlayParam.wPlayStatus == VOICE_LIST_DEVICE_PLAY)
        //当前处于播放状态,停止播放,做标志稍后还要继续
    {
        bPlaying = TRUE;
        if(bPause == TRUE)
            VoiceListPause();
        else
            VoiceListStop();
    }
    else
        bPlaying = FALSE;
    
    if(hVoiceListPlayHandle != -1 && bPause == FALSE)
    {
        bIsOpen = TRUE;
        VoiceListClose();
    }
    else
        bIsOpen = FALSE;
    
    __VoiceProtect();
    
    memmove(&g_VoiceList, pNewVoiceList, sizeof(VoiceList));
    
    g_VoiceListPlayParam.wPlayCur = wPlayCur;
    
    //清除随机播放记录
    memset(g_VoiceListRandomStatus, 0, g_VoiceList.wFileNum);
    if (!bPause) {
        g_VoiceListPlayParam.wPlayStatus = VOICE_LIST_DEVICE_STOP;
    }
    
    __VoiceUnprotect();
    
    if(bIsOpen && bPause == FALSE)
    {
        VoiceListOpen();
    }
    
    if(bPlaying)
    {
        //继续播放
        if(bPause == TRUE)
            return VoiceListResume();
        else
            return VoiceListPlayBack();
    }
    
    return TRUE;
}

/****************************************************************************/
/* FUNCTION:   VoiceListGet                                                  */
/* DESCRIPTION:得到(获取)播放文件列表                                 */
/* INPUTS:     NONE                                                        */
/* OUTPUTS:    pVoiceList - 文件表                                       */
/* RETURN:     获取成功则返回TRUE,否则返回FALSE                           */
/****************************************************************************/
/*  NAME           DATE               REMARKS                               */
/* ==========  ============   ==============================================*/
/*  HuangXM     2003-04-09     创建                                         */
/*   谢永良     2003-04-24     修改,删除临时操作                           */
/****************************************************************************/
BOOL VoiceListGet(VoiceList **pVoiceList)
{
    *pVoiceList = &g_VoiceList;

    return TRUE;
}


/****************************************************************************/
/* FUNCTION:   VoiceListPlayParamSet                                       */
/* DESCRIPTION:设置当前的播放参数                                          */
/* INPUTS:     pPlayParam - 要设置的播放参数结构                           */
/*             dwMask - 设置屏蔽位                                          */
/* OUTPUTS:    NONE                                                        */
/* RETURN:     设置成功则返回TRUE,否则返回FALSE                           */
/****************************************************************************/
/*  NAME           DATE               REMARKS                               */
/* ==========  ============   ==============================================*/
/*  HuangXM     2003-04-09     创建                                         */
/*   谢永良     2003-04-24     修改,删除临时操作                           */
/****************************************************************************/
BOOL VoiceListPlayParamSet(VoiceListPlayParam *pPlayParam, UINT32 dwMask)
{
    //设置播放模式
    if( dwMask & VOICE_LIST_SET_PLAYMOD )
        g_VoiceListPlayParam.wPlayMode = pPlayParam->wPlayMode;
    //设置选曲方式
    if( dwMask & VOICE_LIST_SET_PLAYORDER )
    {
        if(g_VoiceListPlayParam.wPlaySel != pPlayParam->wPlaySel)
        {
            g_VoiceListPlayParam.wPlaySel = pPlayParam->wPlaySel;
            
            __VoiceProtect();
            //清除随机播放记录
            memset(g_VoiceListRandomStatus, 0, VOICE_LIST_MAX_FILENUM);
		    if(g_VoiceListPlayParam.wPlayStatus != VOICE_LIST_DEVICE_STOP)
				g_VoiceListRandomStatus[g_VoiceListPlayParam.wPlayCur] = 1;
            __VoiceUnprotect();
        }
    }

    //设置当前播放时间
    if( dwMask & VOICE_LIST_SET_PLAYOFFSET )
	{
		if(g_VoiceListPlayParam.wPlayStatus == VOICE_LIST_DEVICE_PAUSE)
			VoiceListStop();

        __VoiceProtect();

		g_VoiceListPlayParam.voicePlayParam.dwPlayOffset = pPlayParam->voicePlayParam.dwPlayOffset;

        __VoiceUnprotect();

	    VoiceSetParam(hVoiceListPlayHandle, &g_VoiceListPlayParam.voicePlayParam);
	}
	if(dwMask & VOICE_LIST_SET_CALLBACK)
		g_VoiceListPlayParam.pCallBackFunc = pPlayParam->pCallBackFunc;

    return TRUE;
}

/****************************************************************************/
/* FUNCTION:   VoiceListPlayParamGet                                       */
/* DESCRIPTION:得到当前的播放参数                                          */
/* INPUTS:     NONE                                                        */
/* OUTPUTS:    pPlayParam - 返回当前的播放参数                             */
/* RETURN:     获取成功则返回TRUE,否则返回FALSE                           */
/****************************************************************************/
/*  NAME           DATE               REMARKS                               */
/* ==========  ============   ==============================================*/
/*  HuangXM     2003-04-09     创建                                         */
/*   谢永良     2003-04-24     修改,删除临时操作                           */
/****************************************************************************/
BOOL VoiceListPlayParamGet(VoiceListPlayParam *pPlayParam)
{
    BOOL    bRet;

    bRet = VoiceGetParam(hVoiceListPlayHandle, &g_VoiceListPlayParam.voicePlayParam);

    memcpy((VOID *)pPlayParam, (VOID *)&g_VoiceListPlayParam, sizeof(VoiceListPlayParam));

    return bRet;
}


BOOL __VoiceListPlay(VOID)
{
	//只有在停止或者打断状态下才可以播放
    if( (g_VoiceListPlayParam.wPlayStatus != VOICE_LIST_DEVICE_STOP)
		&& (g_VoiceListPlayParam.wPlayStatus & VOICE_LIST_DEVICE_SUSPEND) == 0)
    {
        return FALSE;
    }

    if( g_VoiceList.wFileNum == 0 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -