void *melp_rec(void)
{
    int length, frame,count, melp_file_count;
    int eof_reached = 0;
    //int num_frames = 0;

    //short speech_in[11];
    short speech_out[FRM];

    unsigned char enc_speech[11];

    FILE *fp_in, *fp_out;
    melpe_i();
    melp_file_count = 0;

    printf("\n1.2 kb/s Proposed Federal Standard MELP speech coder by Jawad\n");
    printf("  C simulation, version 1.0\n\n");
    while (1)
    {
        sem_wait(&melp_start);

        melp_file_count = melp_file_count + 1;
        if(melp_file_count % 2 == 1)
        {
            fp_in = fopen("out1.bit" ,"rb");
            fp_out = fopen("record0.raw","wb");
        }
        else
        {
            fp_in = fopen("out2.bit" ,"rb");
            fp_out = fopen("record1.raw","wb");
        }

        eof_reached = 0;

        while (eof_reached == 0)
        {
            length = fread(&enc_speech,sizeof(char),11,fp_in);

            melpe_s(speech_out, enc_speech);

            fwrite(speech_out,sizeof(short),FRM,fp_out);

            ///if (length < FRAME)
            if (length < 11)
            {
                eof_reached = 1;
                printf("eof reached \n");
            }
        }

        fclose(fp_in);
        fclose(fp_out);
        eof_reached = 0;

        sem_post(&play_start);
    }
    pthread_exit(NULL);
}
Exemplo n.º 2
0
Arquivo: rx.c Projeto: gegel/pairphone
//----------------------Setup----------------------------------
//*****************************************************************************
//initialize audio devices
int audio_init(void)
{ 
 if(!_soundinit()) //init audio8 play/rec Headset and audio48 play/rec Line
 {
  printf("Error of 'Line' audio device initialization, application terminated\r\n");
  return 1;  //init Headset side 8KHz audio device
 }

 if(!soundinit()) 
 {
  return 2; //init Line side 48KHz audio device
  printf("Error of 'Headset' audio device initialization, application terminated\r\n");
 }
 printf("\r\n");
 
 _soundrec(1); //start records from Line
 soundrec(1); //start recrds from Mike

 melpe_i(); //init MELPE1200 codec engine
 return 0; //success  
}
void test_melpe(void)

{
	int length, frame,count;
	int eof_reached = 0;
    int num_frames = 0;
    short speech_in[FRAME];
    short speech_out[FRAME];
	unsigned char enc_speech[11];
    //static struct melp_param melp_par;      /* melp parameters */
  //  unsigned int chbuf[CHSIZE];
    FILE *fp_in, *fp_out, *fp_out_raw;

	melpe_i();
    /* Print user message */
    printf("\n2.4 kb/s Proposed Federal Standard MELP speech coder\n");
    printf("  C simulation, version 1.2\n\n");


    /* Open input, output, and parameter files */
   /* if (( fp_in = fopen(in_name,"rb")) == NULL ) {
	printf("  ERROR: cannot read file %s.\n",in_name);
	exit(1);
    }

	if (( fp_out = fopen(out_bit,"wb")) == NULL ) {
	printf("  ERROR: cannot write file %s.\n",out_name);
	exit(1);
    }

    if (( fp_out_raw = fopen(out_name,"wb")) == NULL ) {
	printf("  ERROR: cannot write file %s.\n",out_name);
	exit(1);
    }
	count = 0;
	while (eof_reached == 0) 
	{
	    count = count + 1;
		//read input speech 

		length = fread(&speech_in,sizeof(short),FRAME,fp_in);
		printf("length number %d is : %d\n",count, length);
		
		melpe_a(enc_speech, speech_in);
		melpe_s(speech_out, enc_speech);

		fwrite(enc_speech,sizeof(char),11,fp_out);

		fwrite(speech_out,sizeof(short),FRAME,fp_out_raw);
		
		if (length < FRAME) 
		{
			eof_reached = 1;
			printf("eof reached \n");
	    }
	}
	count  = 0;
	fclose(fp_in);
	fclose(fp_out);
	fclose(fp_out_raw);
	printf("files are closed\n");*/
}