www.pudn.com > AVS_M_ver10.rar > pre_open_pitch.c
/* *********************************************************************** * COPYRIGHT AND WARRANTY INFORMATION * * Copyright 2007 Audio Video Coding Standard, Part ¢ú * * This software module was developed by AVS Audio sub-group * * DISCLAIMER OF WARRANTY * * These software programs are available to the users without any * license fee or royalty on an "as is" basis. The AVS disclaims * any and all warranties, whether express, implied, or statutory, * including any implied warranties of merchantability or of fitness * for a particular purpose. In no event shall the contributors or * the AVS be liable for any incidental, punitive, or consequential * damages of any kind whatsoever arising from the use of this program. * * This disclaimer of warranty extends to the user of this program * and user's customers, employees, agents, transferees, successors, * and assigns. * * The AVS does not represent or warrant that the program furnished * hereunder are free of infringement of any third-party patents. * Commercial implementations of AVS, including shareware, may be * subject to royalty fees to patent holders. Information regarding * the AVS patent policy is available from the AVS Web site at * http://www.avs.org.cn * * THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY. ************************************************************************ */ #include#include #include "../include/amr_plus.h" //open the wavefile to write FILE* write_wavehead(char* filename) { FILE* fp; short data_16; int data_32; int sizenull = 0; //the real size will be filled in the write_wavetail //open the file fp = fopen(filename,"wb"); //write the head fwrite("RIFF",1,4,fp); //write RIFF sign fwrite(&sizenull,1,4,fp); //write the size of the wav file fwrite("WAVE",1,4,fp); //write the WAVE sign fwrite("fmt ",1,4,fp); //write the fmt sign data_32 = 0x10; fwrite(&data_32,4,1,fp); data_16 = 1; fwrite(&data_16,2,1,fp); //write the PCM sign data_16 = 1; fwrite(&data_16,2,1,fp); //write the mono sign data_32 = 6400; fwrite(&data_32,4,1,fp); //write the sampling rate data_32 = 1 * 6400 * 16 / 8; //cal byte per second fwrite(&data_32,4,1,fp); data_16 = 1 * 16 / 8; //cal byte per sample fwrite(&data_16,2,1,fp); data_16 = 16; fwrite(&data_16,2,1,fp); //write bits per sample fwrite("data",1,4,fp); //write "data" sign fwrite(&sizenull,4,1,fp); return(fp); } //write the data to the wav file void write_pcm(FILE* fp,float* data,int length) { int index; float tmpdata; short data_short; for(index = 0 ; index < length ; index ++ ) { tmpdata = data[index]; if(tmpdata>0) { tmpdata += 0.5; } else { tmpdata -= 0.5; } if(tmpdata > 32767) tmpdata = 32767; if(tmpdata < -32768) tmpdata = -32768; data_short = (short)tmpdata; fwrite(&data_short,sizeof(short),1,fp); } } //close the wavefile to write void write_wavetail(FILE* fp) { long beginpos; long endpos; int datalen; int filelen; //cal the length of the file endpos = ftell(fp); fseek(fp,0,SEEK_SET); beginpos = ftell(fp); filelen = endpos - beginpos - 8 ; datalen = filelen + 8 - 44; //modify the file length fseek(fp,4,SEEK_SET); fwrite(&filelen,4,1,fp); //modify the data length fseek(fp,40,SEEK_SET); fwrite(&datalen,4,1,fp); fclose(fp); } /************************************************************************/ /* function: to calculate the square sum of the signal argument list: float* sig_in (i): input signal int length (i): the length of the input signal return value: double the square sum value */ /************************************************************************/ double v_magsq(float* sig_in , int length ) { int index; //the index to look over the input signal double total; //the sum of the square value total = 0.0; //initiate to be zero for(index = 0 ; index < length ; index ++ ) { total += sig_in[index] * sig_in[index] ; } return (total) ; } /************************************************************************/ /* function: calculate the inner of the signal argument list: float* sig_1 (i): the first input signal float* sig_2 (i): the second input signal int length (i): the length of the input signals return value: double the inner value of the signal */ /************************************************************************/ double v_inner(float* sig_1,float* sig_2,int length ) { int index; //tmp index double total; //tmp sum total = 0.0 ; //initiate for(index = 0 ; index < length ; index ++ ) { total += sig_1[index] * sig_2[index] ; } return total; }