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

📄 sound.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
字号:
#include "winav.h"
#include "w99av.h"
#include "osd.h"
#include "hal.h"
#include "sound.h"
#include "cc.h"
#include "cdinfo.h"
#include "utl.h"

#define SYNC_PLAY_TIME_OUT  COUNT_1_SEC
// DVD_274Micky, add copyright. Don't remove it!!!!
BYTE    Copyright_CHEERTEK_INC_2002_SOUND=0;

#ifndef NO_SOUND_EFFECT

// DVD_275Micky, share the same variable.
#define __bSoundRepeatRemains   Copyright_CHEERTEK_INC_2002_SOUND
//BYTE __bSoundRepeatRemains=0;   // global, can be access by other modules
BYTE _bSoundState = SOUND_UNINITIALIZE;
// brian.171, improve speed with code *ptr
WORD code * _pwCurrentPlayId;    // pointer to the start position of the sound ID xxx.
#if  IO == IO_PCI
BYTE * _pW; // data pointer, yes, it is a pointer to BYTE
#else
WORD code *_pW; // brian.171, improve speed with code *ptr
#endif

WORD _wlength;  // data count remains in the "buffer". It is in WORD unit.
 

WORD code _wSoundData[]=
{
#include "sound.txt"
};

WORD _wOldDiscType;
extern WORD DATA __wDiscType;

#else
// must declare a dummy code variable, or will have link error
WORD code _wSoundData[]=
{
0
};

#endif

//WORD __wMonitorCount;
//**************************************************************************
// Function         : SOUND_Init()
// Description  : This function initializes the sound environment and the
//                        current sound state is set to SOUND_INIT_MP3/MP2. 
// Arguments    : bInit // don't care, only exist here for spec. compatible purpose
// Return           : None
// Side Effect  : Reset Audio
// Notes            : 
//**************************************************************************

void SOUND_Init (BYTE bInit)
{
#ifndef NO_SOUND_EFFECT

    //WORD   wTemp;
        
    //__wMonitorCount = 0;

    _wOldDiscType = __wDiscType; // keep the original Disc Type, restore it back when SOUND_Exit

    switch (_wSoundData[3])
    {
        case SOUND_MP3: //MP3
            // LLY2.78b-3, re-adjust the control flow to fix no sound effect from 2.74
            // Because, F/W don't change parser code again within HAL_SetDiscType() from 2.74
            // Set disc type as CDROM title
            __wDiscType = CDROM_M1;
            HAL_SetDiscType(__wDiscType);
            // Set Audio DAC for MP3 source
            //Kevin1.26, modify
            //HAL_SetAudioDAC (HAL_AUDIO_16BIT_44K); 
            HAL_SetAudioDAC (AUDIO_FREQ_44K); 

            // Set play MP3 audio
            __bAttrPlayNew=ATTR_MP3;
            UTL_SetPlayMode(MODE_PLAYAUDIO);
            // Set input path as Host interface
            HAL_SetInputPath(HAL_INPUT_PATH_HOSTIF);
            // Set BSFORMATR for audio only stream
            __wW99AVBSFORMATR &= 0x02F0;  // clear bit[3:0] & bit[8]
            __wW99AVBSFORMATR |= 0x0007;  // set bit[2:0] to 111 for audio only stream
            W99AV_WriteRegW ( BSFORMATR, __wW99AVBSFORMATR );
            _bSoundState = SOUND_INIT_MP3;
        break;
        case SOUND_MPEG:        //MPEG2
            _bSoundState = SOUND_INIT_MP2;
        break;
        case SOUND_AC3: //AC3
        break;
    }

    // Brian2.78b-3, push IFIFO data or the audio is incorrect at the beginning
    HAL_PushFIFOData(HAL_PUSHDATA_IFIFO, 32);
    HAL_Reset(HAL_RESET_AUDIO);
 
    //__wW99AVPCRLow = 0x6800; //   &= 0xFBFF ;
    //__wW99AVPCRHigh = 0x04;
    //W99AV_WriteRegDW(PCR,__wW99AVPCRLow,__wW99AVPCRHigh);  //ATAPI DMA enable & Byte Swap

    //_ShowDebug();
    //scanf("%c", &c);
    __btMute=FALSE;
        
    //CHIPS_OpenAudio(TRUE); // no effect

    // tune volume
    /*
    __dwW99AVCmdArg[0]=2; // number of the ARG0~ARG15
    __dwW99AVCmdArg[1]=CMDARG_SAVCR;
    __dwW99AVCmdArg[2]=0x6000; // volume
    W99AV_CommandN(COMMAND_SAVCR) ;
    */
    //Kevin1.10, write PCMSCALE register instead of macro command (RISC IRAM code jumper table is contaminated by somebody unknown) 
    W99AV_WriteRegDW (PCMSCALER, LOWORD(0x6000), HIWORD(0x6000)); 

    //__wDiscType = _wOldDiscType;  
    

#endif
}

//**************************************************************************
// Function         : SOUND_Configure ()
// Description  : This function reads the sound stream type from _wSoundData 
//                array and set the decoder according to the type.
// Arguments    : bSoundId          : Specifies ID of the selected sound. 
//                        bRepeatTime   : Specifies the repeat times. 
// Return           : None
// Side Effect  :
// Notes            : Calling to this function will automatically stop the playing
//                of current sound, and put the sound state to SOUND_READY 
//**************************************************************************

void SOUND_Configure (BYTE bSoundId, BYTE bRepeatTime)
{
#ifndef NO_SOUND_EFFECT

  // Stop Sound first
  SOUND_DoCommand(SOUND_STOP);
  // Brian2.78b-3, push IFIFO data or the audio is incorrect at the beginning
  HAL_PushFIFOData(HAL_PUSHDATA_IFIFO, 32);
  HAL_Reset(HAL_RESET_AUDIO); // clear IFIFI and audio buffer
  //_ShowDebug();   
  __bSoundRepeatRemains = bRepeatTime;
  if (_wSoundData[1] > (WORD) bSoundId)
  {
    BYTE i;
    for(i=0,_pwCurrentPlayId=_wSoundData+2;i<bSoundId;i++)
    {
        _pwCurrentPlayId = _pwCurrentPlayId+_pwCurrentPlayId[2]+3;
    }
#if  IO == IO_PCI   // just for type conversion warning in DOS
    _pW = (BYTE*) (_pwCurrentPlayId+3);
#else
    _pW = _pwCurrentPlayId+3;
#endif

    _wlength = _pwCurrentPlayId[2];
    _bSoundState = SOUND_READY;
  }


#endif
}

//**************************************************************************
// Function         : SOUND_DoCommand ()
// Description  : This function plays sound, pauses, resumes and stops the 
//                playing.
// Arguments    : bCmd          : SOUND_PLAY,  SOUND_STOP, SOUND_PAUSE,
//                                SOUND_RESUME, SOUND_PLAY_SYNC
// Return           : None                
// Side Effect  :
// Notes            : Just issue the command, the bitstream has not fed yet.
//**************************************************************************

void SOUND_DoCommand (BYTE bCmd)
{
#ifndef NO_SOUND_EFFECT
    switch (bCmd)
    {
        case  SOUND_PLAY:
            if (_bSoundState==SOUND_READY)
            {
                W99AV_Command1(COMMAND_PLAY,0xFFFF);
                // parser must be enable after normal play command
                // this comment is from HAL_SetDiscType
                __wW99AVPCRLow|=0x2000; // enable parser
                W99AV_WriteRegDW (PCR, __wW99AVPCRLow, __wW99AVPCRHigh) ;
                _bSoundState = SOUND_PLAY;
            }
            break;
        case  SOUND_STOP:
            W99AV_Command1(COMMAND_STOP,0xFFFF);
            _bSoundState = SOUND_STOP;
            break;
        case    SOUND_PAUSE:
            if (_bSoundState==SOUND_PLAY)
            {
                W99AV_Command1(COMMAND_PAUSE,0xFFFF);
                _bSoundState = SOUND_PAUSE;
            }
            break;
        case    SOUND_RESUME:
            if (_bSoundState==SOUND_PAUSE)
            {
                W99AV_Command1(COMMAND_PLAY,0xFFFF);
                _bSoundState = SOUND_PLAY;
            }
            break;
        case    SOUND_PLAY_SYNC:
            if (_bSoundState==SOUND_READY)
            {
                DWORD dwCount;

                _bSoundState = SOUND_PLAY;
                W99AV_Command1(COMMAND_PLAY,0xFFFF);
                dwCount = __dwCountSystem;
        
                
                while (SOUND_Monitor() != SOUND_STOP && 
                       ((__dwCountSystem - dwCount) < SYNC_PLAY_TIME_OUT));

                W99AV_Command1(COMMAND_STOP,0xFFFF);
                _bSoundState=SOUND_STOP;
            }
            break;      
    }
#endif

}

//**************************************************************************
// Function         : SOUND_Monitor ()
// Description  : The function monitors the sound data sending from host and
//                        provides the current sound state in return value. 
// Arguments    : None
// Return           : The current sound state.
// Side Effect  : 
// Notes            : 
//**************************************************************************

BYTE SOUND_Monitor (void)
{
#ifndef NO_SOUND_EFFECT

    WORD   wTemp1;
    BYTE    i;
    DWORD dwTemp;

    switch (_bSoundState)
    {
      case  SOUND_PLAY:

          //__wMonitorCount++;

        if (_wlength < 2) 
        {
            // data has been sent out and audio buffer is (almost) empty
            // this means the sound is stopped
          
            W99AV_ReadInfo (W99AV_INFO_AUDIO_REMAIN, &dwTemp);
            if (dwTemp <=32)
            {
                /*if (__bSoundRepeatRemains != 0)
                {
                    //W99AV_Command1(COMMAND_STOP,0xFFFF);
                    HAL_Reset(HAL_RESET_AUDIO);
                    //_ShowDebug();
                    W99AV_Command1(COMMAND_PLAY,0xFFFF);
                    if (__bSoundRepeatRemains!=0xff) // check loop forever 
                        --__bSoundRepeatRemains;
                    _pW = _pwCurrentPlayId+3;
                    _wlength = _pwCurrentPlayId[2];
                    
                }
                else
                */
                {
                    W99AV_Command1(COMMAND_STOP,0xFFFF);
                    _bSoundState=SOUND_STOP;
                    break;
                }
            }
            
        } 
        else
        for ( wTemp1= 0; wTemp1< 30; wTemp1++ )
        {
            //W99AV_ReadInfo(W99AV_INFO_IFIFO_REMAIN,&dwTemp);
                              
            //if (dwTemp <= 32)
            {
                if (_wlength >= 16) // 16 WORD ==> 32 bytes
                {
                for ( i= 0; i< 8; i++ )
                {
#if  IO == IO_PCI
                    
                    // hight byte and low byte switch
                    dwTemp=MAKELONG(MAKEWORD(*(_pW+2),*(_pW+3)),
                                    MAKEWORD(*(_pW),*(_pW+1)));
                    W99AV_OutIFIFO(dwTemp);
                    _pW = _pW + 4;
                    //_wlength = _wlength-2;
#else
                    
                    /*
                    W99AV_OutIFIFO( *(_pW++) );
                    W99AV_OutIFIFO( *(_pW++) );
                    W99AV_OutIFIFO( *(_pW++) );
                    W99AV_OutIFIFO( *(_pW++) );
                    */
                    
                    __wTemp = *_pW++;
                    OUTB(IBDPR0,HIBYTE(__wTemp));
                    OUTB(IBDPR0,LOBYTE(__wTemp));
                    __wTemp = *_pW++;
                    OUTB(IBDPR0,HIBYTE(__wTemp));
                    OUTB(IBDPR0,LOBYTE(__wTemp));
                 

                    //_wlength = _wlength-2;
#endif
               
                }  // for loop - put stream into InputFIFO
                    _wlength = _wlength-16;
                }
                else //_wlength < 16
                {
#if  IO == IO_PCI
                    dwTemp = _wlength/2;
                    for (i=0; i<dwTemp ; i++)
                    {
                        // hight byte and low byte switch
                        dwTemp=MAKELONG(MAKEWORD(*(_pW+2),*(_pW+3)),
                                    MAKEWORD(*(_pW),*(_pW+1)));
                        W99AV_OutIFIFO(dwTemp);
                        _pW = _pW + 4;
                        _wlength = _wlength-2;
                    }
                    if (_wlength != 0)
                    {
                        // padding two bytes 0
                        // hight byte and low byte switch
                        dwTemp=MAKELONG(MAKEWORD(0,0),
                                    MAKEWORD(*(_pW),*(_pW+1)));
                        W99AV_OutIFIFO(dwTemp);
                        _pW = _pW + 2;
                        _wlength = 0;
                    }

#else

                    for ( i= 0; i< _wlength; i++ )
                    {
                        
                        //W99AV_OutIFIFO( *(_pW++) );
                        //W99AV_OutIFIFO( *(_pW++) );
                        __wTemp = *_pW++;
                        OUTB(IBDPR0,HIBYTE(__wTemp));
                        OUTB(IBDPR0,LOBYTE(__wTemp));
                        

                    }
                    _wlength = 0;
#endif
                }

                if (_wlength==0)
                {
                    if (__bSoundRepeatRemains != 0)
                    {
                
                        if (__bSoundRepeatRemains!=0xff) // check loop forever 
                            --__bSoundRepeatRemains;
#if  IO == IO_PCI       // just for type conversion warning in DOS
                        _pW = (BYTE*) (_pwCurrentPlayId+3);
#else
                        _pW = _pwCurrentPlayId+3;
#endif

                        _wlength = _pwCurrentPlayId[2];
                
                    }
                    else
                    //if (__bSoundRepeatRemains == 0)
                    {
                        //_wlength = 0;
                        return SOUND_PLAY;
                    }
                    
                } // if (_wlength<=0) 

            }  // end if                
        }  // for loop

        break;
    default:
        break;
  }
  return _bSoundState;

#else
  return SOUND_UNINITIALIZE;
#endif
}

//**************************************************************************
// Function         : SOUND_Exit ()
// Description  : The function should stops playing and does the cleanup work 
//                when the sound environment is no longer needed. 
// Arguments    : None
// Return           : None
// Side Effect  : 
// Notes            : 
//**************************************************************************

void SOUND_Exit (void)
{
#ifndef NO_SOUND_EFFECT

  SOUND_DoCommand(SOUND_STOP);
  // Brian2.78b-3, push IFIFO data or the audio is incorrect at the beginning
  HAL_PushFIFOData(HAL_PUSHDATA_IFIFO, 32);
  HAL_Reset(HAL_RESET_AUDIO); // clear IFIFI and audio buffer
  _bSoundState = SOUND_UNINITIALIZE;
  __wDiscType = _wOldDiscType;
  HAL_SetInputPath(HAL_INPUT_PATH_DEFAULTIF);

#endif

}

⌨️ 快捷键说明

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