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

📄 melp.c

📁 It is source code for Melp2.4kps vocoder using dsp tms320vc55x of ti
💻 C
字号:
/*								    */
/*  melp.c: Mixed Excitation LPC speech coder			    */
/*								    */


/*  compiler include files  */
#include	<c50regs.h>

#include "melp.h"
#include "spbstd.h"
#include "mat.h"

/* Globals */
int saturation = 0;

/*  compiler constants */
#define ANA_SYN 0
#define ANALYSIS 1
#define SYNTHESIS 2

/* note: CHSIZE is shortest integer number of words in channel packet */
#define CHSIZE 9
#define NUM_CH_BITS 54

/*  external memory */
Shortword melpmode = ANA_SYN;
char in_name[80], out_name[80];

/* Used for timing code */
volatile unsigned int	 TCount = 0;
/* For timing analysis */
/* For timing synthsis */
/* General purpose timer */
volatile unsigned int tArray[3];

volatile unsigned int command;
extern void c_int0();
#define RESET	0x5555

/* Routine to initialize the DSP */

void main(int argc, char **argv)

{

    Shortword i;
    Longword length, frame;
    Shortword eof_reached;
    Longword num_frames = 0;
    Shortword speech_in[FRAME];
    Shortword speech_out[FRAME];
    static struct melp_param melp_par;	    /* melp parameters */
    UShortword chbuf[CHSIZE];
    unsigned int tempbuf[CHSIZE];


    /* Initialze the DSP */
    DSP_Init();


    /* Initialize MELP analysis and synthesis */
    if (melpmode != SYNTHESIS)
      melp_ana_init();
    if (melpmode != ANALYSIS)
      melp_syn_init();

    /* Run MELP coder on input signal */
    frame = 0;
    melp_par.chptr = chbuf;
    melp_par.chbit = 0;
    eof_reached = 0;
    while (eof_reached == 0) {

	/* Clear general purpose timer */
	TCount = 0;

	/* Perform MELP analysis */
	if (melpmode != SYNTHESIS) {

            /* Get the host command, process or reset */
	    getFrame(&command, 1);
	    if (command == RESET)
		c_int0();


	    /* Get data from PC */
	    length = FRAME;
	    getFrame(speech_in, FRAME);


	    if (length < FRAME) {
		v_zap(&speech_in[length],(Shortword)(FRAME-length));
		eof_reached = 1;
	    }

	    /* Run MELP analyzer */
	    if (melpmode == ANA_SYN) {
		/* reset pointers to short channel buffer */
		melp_par.chptr = chbuf;
		melp_par.chbit = 0;
	    }



	    tArray[0] = TCount;

            /* Call MELP Analysis */
	    melp_ana(speech_in,&melp_par);

	    tArray[0] = TCount - tArray[0];


	    /* IF analysis was run, send bit stream to the PC */
	    sendFrame(chbuf, CHSIZE);


	    /* Write channel output if needed */
	    if (melpmode == ANALYSIS && melp_par.chbit == 0) {
		for (i = 0; i < CHSIZE; i++)
		    tempbuf[i] = (int)chbuf[i];

		/* reset pointer to short channel buffer */
		melp_par.chptr = chbuf;
	    }


	}

	/* Perform MELP synthesis (skip first frame) */
	if (melpmode != ANALYSIS) {

	    if (melpmode == ANA_SYN) {
		/* reset pointers to short channel buffer */
		melp_par.chptr = chbuf;
		melp_par.chbit = 0;
	    }

	    /* Read channel input if needed */
	    if (melpmode == SYNTHESIS && melp_par.chbit == 0) {

		for (i = 0; i <CHSIZE; i++)
		  chbuf[i] = (Shortword)tempbuf[i];

		/* reset pointer to short channel buffer */
		melp_par.chptr = chbuf;
	    }

	    tArray[1] = TCount;
	    melp_syn(&melp_par,speech_out);
	    tArray[1] = TCount - tArray[1];


	    /* Send Data from PC */
	    sendFrame(speech_out, FRAME);

	}

	/* Now send run times to PC */
	sendFrame(&tArray, 3);

        /* Increment Frame up counter */
	frame++;
    }

}


/* The following two routines (getFrame and sendFrame) pass data from and
   to the PC host from the Tiger5x card.
*/


/* Get a variable amount of data from the PC host */
int getFrame(Shortword *buf, int size) {

    int i;
    volatile int temp;

    for (i=0;i<size;i++) {
	while (1) {
	     temp =  *(volatile int *)0x52;

	     if ( (temp & 1) == 0) break;
	}

	temp = *(volatile int *)0x50;
	*buf++ = (Shortword)temp;

    }
}


/* Send a variable amount of data to the PC host */
int sendFrame(Shortword *buf, int size) {

    int i;
    volatile int temp;

    for (i=0;i<size;i++) {

	while (1) {
	   temp =  *(volatile int *)0x52;

	   if ( (temp & 2) == 0) break;
	}

	*(volatile int *)0x50 = (volatile int)*buf++;

    }
}

⌨️ 快捷键说明

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