?? creatfeature.cpp
字號:
/*******************************************************************
**** 文件: CreatFeature.cpp ****
**** 功能: 生成特征矩陣 ****
**** ****
**** 修改記錄: 2001.7.23 摘自G.732.1 ****
*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "Head.h"
#include "Read_Dat.h"
#include "mfcc_xhg.h"
int ExtractFeature(char *filename_in, char *filename_VadOut);
//特征提取程序
void main(int argc,char **argv)
{
/* argc = 3;
char sourcefilename[] = "E:\\Program_Data\\temp_data\\zx.dat";
char Vadfilename[] = "E:\\Program_Data\\temp_data\\zxvad.dat";
//*/
//*
if(argc!= 3) {
printf("Usage: endpointD <sourcefilename.dat> <endpoint.txt>\n");
exit(0);
}
char sourcefilename[100], endpointfilename[100];
strcpy(sourcefilename,argv[1]);
strcpy(endpointfilename, argv[2]);
//*/
int returnflag;
returnflag=ExtractFeature(sourcefilename, endpointfilename);
printf("Finished !\n");
}
//函數名:ExtractFeature
//傳入參數:輸入語音文件名 filename_in,輸出文件名filename_Cepout
// 添加到文件頭中的額外信息
//返回是否成功的標志,0為失敗,1為成功
//說明:提取LPCC特征數據函數
int ExtractFeature(char *filename_in, char *filename_Vadout)
{
FILE *fp_in, *fp_Vadout;
//與語音數據相關的變量
short testflag; //為了跟蹤使用,在現有程序中已經不使用了
int TotalNumSentence; //總句子數
int SentenceCount; //句子循環計數器
long SentenceLength_Byte;
long datahead;
long lStartPnt, lEndPnt;
long lSampleRate=16;
//與特征提取相關的變量
short *VoiceData_Short = NULL;//16bit
dataHEAD filehead;
//--------------------------------------
//取系統日期
char datebuff[128];
_tzset();
_strdate(datebuff);
//--------------------------------------
fp_in = fopen(filename_in,"rb");
fp_Vadout = fopen(filename_Vadout, "w+");
if((fp_in==NULL)||(fp_Vadout == NULL))
return 0;
fread(&filehead,sizeof(dataHEAD),1,fp_in);
printf("Now the voice data come from file: %s\n",filename_in);
printf("Sample Rate: %d Quantity byte: %d \n", filehead.SampleRate, filehead.SampleType );
printf("output: %s\n",filename_Vadout);
TotalNumSentence=Read_Sentence_Amount(filename_in);
fprintf(fp_Vadout, "TotalNumSentence= %d\n", TotalNumSentence);
for(SentenceCount=0; SentenceCount<TotalNumSentence; SentenceCount++)
{
//-------------------------------------------------------------------------------------
//得到每個句子的長度,填充到相應的SentenceLength_Byte,SentenceLength_Short
//中去。為VoiceData_Short或VoiceData_Byte數據區分配內存
//同時將數據讀入到對應的VoiceData_Short或VoiceData_Byte數據區
fseek(fp_in,200+SentenceCount*2*sizeof(long),SEEK_SET);
fread(&datahead,sizeof(long),1,fp_in);
fread(&SentenceLength_Byte,sizeof(long),1,fp_in);
fseek(fp_in,datahead,SEEK_SET);
VoiceData_Short=(short *)malloc(SentenceLength_Byte);
testflag=fread(VoiceData_Short,SentenceLength_Byte,1,fp_in);
StartEnd(VoiceData_Short, SentenceLength_Byte/2,
&lStartPnt, &lEndPnt,
lSampleRate);
//輸出端點結果
fprintf(fp_Vadout, "%ld\t%ld\n", lStartPnt / LPCCFIX_FRAME, lEndPnt / LPCCFIX_FRAME);
//刪除內存的分配
if(VoiceData_Short!=NULL)
{
free(VoiceData_Short);
VoiceData_Short=NULL;
}
//fprintf(stdout, "Done: %3d\r", SentenceCount);
}
//關閉文件
printf("\n");
fclose(fp_in);
fclose(fp_Vadout);
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -