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

📄 dspinterface.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
*
*  Module:         DSPInterface.c
*
*  Description:    DSP Interface routines
*
*  Author:         Craig L. Mahananey
*
*  Copyright 1999, Lucent Technologies, Inc., All rights reserved
*
*
*  Change Log:
*
*  Date        By      Description
*  ========    ===     ====================================================
*  11/11/99    CLM     Created
*  09/01/2000  RFG     When a tone is played (not counting DTMF tones), the
*                      input source is forced to be the handset, even if the
*                      speakerphone mode is on.  This is required so tones
*                      do not pass through the AEC.  When the tone is stopped
*                      the input source is switched back to whatever it should be.
*  09/11/2000  RFG     Removed dead code that will not be used with the multi-port
*                      DSP API
*  11/06/2000  mwb     Added INTERFACE_TERSE for quieter output
*
***************************************************************************/



/*
 * Application layer include files
 */

#include "DSPInterface.h"
// #include "NetworkInterface.h"
// #include "TradeShowApp.h"

/*
 * Driver layer include files
 */
#include <vxWorks.h>
#include <logLib.h>
#include <Platform.h>
#include <dspManager.h>
#include "../config/ipt_arm/ipt_arm.h"


/*
 * Standard include files
 */

#include <string.h>
#include <stdio.h>

extern "C"
{
unsigned long sysGetCPUVer(void);
}

/*
 * File-scope variables
 */

static int              volume        = 0;
static int              voice_enabled = FALSE;
int                     tone_enabled  = FALSE;
static int              input_source  = DSP_INPUT_HANDSET;
static int              output_dest   = DSP_AUDIO_TO_HANDSET;
static int				backup_input_source = DSP_INPUT_HANDSET;
static CdspManager      *dspMgr;
int                     muted = FALSE;
/* speaker-handset-tone-switching
 * Stores the current active tone*/
static tone_type cur_tone = null_tone;

/* Type of ring tone */
static unsigned short ring_type = 0;

/* Volume of ring tone */
static unsigned short ring_volume = 10;

//chenguoyin
extern int on_speakerphone;
extern int isPlayRing;
/*
 * External variables
 */
extern tone_type tone_playing;
extern unsigned short gDSPhstvolumeMap[];
extern unsigned short gDSPspkvolumeMap[];

int cadenceOn;

#ifdef CHECKDSP
extern "C"
{
void checkDSP(int sid);
}
#endif

#ifdef PPA
/* PPA Port Numer */
int port0CadOn = 0;
int port1CadOn = 0;
int port2CadOn = 0;
int port3CadOn = 0;
unsigned short  ppaChannelNum = 0x0000;
static void ppaCandenceSwitch (unsigned short ppaPortNumber, unsigned short cadenceEnable);
#endif

/***************************************************************************
 *
 *  InitDSP()
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Create the dsp managers
 *
 **************************************************************************/

void InitDSP()
{
    /* set dsp Clock */
    setDSPClock();

    CError::CreateErrorObject();

    dspMgr = CdspManager::Instance();

    if( dspMgr == NULLPOINTER ){
        fprintf( stderr, "InitDSP: Failure creating DSP manager.\n" );
        return;
    }
}

/***************************************************************************
 *
 *  StartVoice()
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Set voice_enabled = TRUE
 *
 **************************************************************************/

void StartVoice()
{
    voice_enabled = TRUE;
}
unsigned int isVoiceStart()
{
	return voice_enabled;
}
/***************************************************************************
 *
 *  StopVoice()
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *
 **************************************************************************/

void StopVoice()
{
    voice_enabled = FALSE;
}

/***************************************************************************
 *
 *  PlayTone( tone_type tone )
 *
 *  Arguments
 *      Input: tone to play
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Send control message to DSP to play requested tone
 *
 **************************************************************************/

void PlayTone( tone_type tone )
{
    ushort dsp_tone;
    ushort dsp_audio_out;
		
    ushort gst1 = 0x1c97;
    ushort gst2 = 0x1c97;
	
	/*
    ushort gst1 = 0x8000;
    ushort gst2 = 0x8000;
    */
    ushort gnet = 0x0000;
    if(tone == ringback_tone)
    {
   	cur_tone = tone;
    	return;
   }
	
    
    printf("PlayTone(%d)\n",tone);	
  
#ifdef CHECKDSP
checkDSP(-1);
#endif

    cadenceOn = 1;
    switch( tone ){ 
        case dial_tone:
            dsp_tone = DSP_TONE_DIAL;
            break;
        case busy_tone:
            dsp_tone = DSP_TONE_BUSY;
            break;
        case ringback_tone:
            /* @@@CLM: What tone goes here??? */
            dsp_tone = DSP_TONE_ALERT_RING;
            break;
        case receiver_off_hook_tone:
            /* @@@CLM: What tone goes here??? */
            dsp_tone = DSP_TONE_COVERAGE;
            break;
        case congestion_tone:
            /* @@@CLM: What tone goes here??? */
            /*WAS: dsp_tone = DSP_TONE_COVERAGE; GTC */
            /* TRY THIS ONE - GTC: */
            dsp_tone = DSP_TONE_REORDER;
            break;
        default:
#ifndef INTERFACE_TERSE
            fprintf( stderr, "PlayTone: Bad tone.\n" );
#endif /* INTERFACE_TERSE */
            return;
            break;
    }
#ifdef PPA
	ppaCandenceSwitch (ppaChannelNum, 1);
	dspMgr->ppaPlayTone( dsp_tone, ppaChannelNum, gst1, gnet);
#else
    if( (input_source == DSP_INPUT_HANDSET) || (input_source == DSP_INPUT_MUTE) ){
		input_source = DSP_INPUT_HANDSET;
        dsp_audio_out = DSP_AUDIO_TO_HANDSET;
		dspMgr->setAudioOutput(DSP_AUDIO_TO_HANDSET);
        dspMgr->setAudioSource(DSP_INPUT_HANDSET);
    }
#ifdef SECONDARY_AUDIO_ARM
	else if( (input_source == DSP_INPUT_SIO) || (input_source == DSP_INPUT_MUTE) ){
		input_source = DSP_INPUT_SIO;
        dsp_audio_out = DSP_AUDIO_TO_SIO;
		dspMgr->setAudioOutput(DSP_AUDIO_TO_SIO);
        dspMgr->setAudioSource(DSP_INPUT_SIO);
    }
#endif
    else {
		/* If we play a tone while the input source is the speakerphone mic., the tone
		   will not sound correct since it will be going through the AEC.  We need to set
		   the input source to be the handset if we are in speakerphone mode */
       dspMgr->setAudioSource(DSP_INPUT_HANDSET);
       dsp_audio_out = DSP_AUDIO_TO_SPEAKERPHONE;
    }

	/* currently we are using default gain value, to select value refer to */
	/* dsptabel.h, right now we have no mechanism (button)to increase gain */
    dspMgr->playTone( dsp_tone, DSP_TONE_TO_STATION, dsp_audio_out, gst1, gst2, gnet);
    /* Store the current active tone.
     * speaker-handset-tone-switching */
#endif /* #ifdef PPA */
    cur_tone = tone;
    tone_enabled = TRUE;
}


//chenguoyin
void firstSetAudio( void )
{
    
   dspMgr->setAudioOutput(DSP_AUDIO_TO_HANDSET);
        
		dspMgr->setAudioDestination( DSP_AUDIO_TO_HANDSET );
        dspMgr->setAudioSource( DSP_INPUT_HANDSET );
		return;
 
}





/***************************************************************************
 *
 *  StopTone()
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Send control message to DSP to stop tone
 *
 **************************************************************************/

void StopTone()
{
	int error;
	ushort gst1 = 0x1c97;
	ushort gst2 = 0x1c97;
	ushort gnet = 0x0000;
       ushort dsp_audio_out;
	if(cur_tone == ringback_tone)
	{	
		cur_tone = null_tone;
		return;
	}
#ifdef CHECKDSP
checkDSP(-1);
#endif

#ifdef PPA
    dspMgr->ppaPlayTone(DSP_TONE_OFF, ppaChannelNum,gst1,gnet);
	ppaCandenceSwitch (ppaChannelNum, 0);
#else
    if( ((input_source == DSP_INPUT_HANDSET) || (input_source == DSP_INPUT_MUTE)) && (muted==FALSE) ){
        dsp_audio_out = DSP_AUDIO_TO_HANDSET;
		input_source = DSP_INPUT_HANDSET;
        dspMgr->setAudioSource(DSP_INPUT_HANDSET);
    }
    else if( (input_source == DSP_INPUT_SPEAKERPHONE) && (muted==FALSE) ) {
		/* Set the audio source back to the speakerphone */
        dspMgr->setAudioSource( DSP_INPUT_SPEAKERPHONE );
        dsp_audio_out = DSP_AUDIO_TO_SPEAKERPHONE;
    }
#ifdef SECONDARY_AUDIO_ARM
	else if( ((input_source == DSP_INPUT_SIO) || (input_source == DSP_INPUT_MUTE)) && (muted==FALSE) ){
        dsp_audio_out = DSP_AUDIO_TO_SIO;
		input_source = DSP_INPUT_SIO;
        dspMgr->setAudioSource(DSP_INPUT_SIO);
    }
#endif

/*    error = dspMgr->playTone( DSP_TONE_OFF, DSP_TONE_TO_STATION, dsp_audio_out ); */
    error = dspMgr->playTone( DSP_TONE_OFF, DSP_TONE_TO_STATION, DSP_AUDIO_TO_MUTE, gst1, gst2, gnet);

    /* speaker-handset-tone-switching
     * reset the cur_tone when tone is stopped.*/
#endif /* #ifdef PPA */
    cur_tone = null_tone;
    tone_enabled = FALSE;
    tone_playing = null_tone;   /* added GTC - when stopping the tone, make sure it doesn't resume! */
    cadenceOn = 0;
}

/***************************************************************************
 *
 *  PlayDTMF( dtmf_tone_type tone )
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Send control message to DSP to stop tone
 *
 **************************************************************************/

void PlayDTMF( dtmf_tone_type tone )
{
    ushort  dsp_tone;
    ushort  dsp_tone_dir;
    ushort  dsp_audio_out;
	
    ushort gst1 = 0x1c97;
    ushort gst2 = 0x1c97;
    ushort gnet = 0x0000;
    
#ifdef CHECKDSP
checkDSP(-1);
#endif

    switch( tone ){
        case dtmf_0:
            dsp_tone = DSP_DTMF_0;
            break;
        case dtmf_1:
            dsp_tone = DSP_DTMF_1;
            break;
        case dtmf_2:
            dsp_tone = DSP_DTMF_2;
            break;
        case dtmf_3:
            dsp_tone = DSP_DTMF_3;
            break;
        case dtmf_4:
            dsp_tone = DSP_DTMF_4;
            break;
        case dtmf_5:
            dsp_tone = DSP_DTMF_5;
            break;
        case dtmf_6:
            dsp_tone = DSP_DTMF_6;
            break;
        case dtmf_7:
            dsp_tone = DSP_DTMF_7;
            break;
        case dtmf_8:
            dsp_tone = DSP_DTMF_8;
            break;
        case dtmf_9:
            dsp_tone = DSP_DTMF_9;
            break;
        case dtmf_star:
            dsp_tone = DSP_DTMF_STAR;
            break;
        case dtmf_hash:
            dsp_tone = DSP_DTMF_POUND;
            break;
        case dtmf_a:
            dsp_tone = DSP_DTMF_A;
            break;
        case dtmf_b:
            dsp_tone = DSP_DTMF_B;
            break;
        case dtmf_c:
            dsp_tone = DSP_DTMF_C;
            break;
        case dtmf_d:
            dsp_tone = DSP_DTMF_D;
            break;
        case dtmf_e:
            dsp_tone = DSP_DTMF_E;
            break;
        case dtmf_f:
            dsp_tone = DSP_DTMF_F;
            break;
        default:
#ifndef INTERFACE_TERSE
            printf(" PlayDTMF: Bad tone.\n" );
#endif /* INTERFACE_TERSE */
            return;
    }

    if( voice_enabled ){
        dsp_tone_dir = DSP_TONE_TO_BOTH;
/* slm: MR7049 remove bogus pragma
/* #pragma "Missing DSP_TONE_TO_BOTH in DSP API" */
    }
    else {
        dsp_tone_dir = DSP_TONE_TO_STATION;
    }

    if( (input_source == DSP_INPUT_HANDSET) || (input_source == DSP_INPUT_MUTE) ){
		input_source = DSP_INPUT_HANDSET;
        dsp_audio_out = DSP_AUDIO_TO_HANDSET;
    }
#ifdef SECONDARY_AUDIO_ARM
	else if ( (input_source == DSP_INPUT_SIO) || (input_source == DSP_INPUT_MUTE) ){
		input_source = DSP_INPUT_SIO;

⌨️ 快捷键说明

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