?? pickwavdlg.cpp
字號:
// PickWavDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PickWav.h"
#include "PickWavDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char *INdex = "Nlist.txt";
typedef struct
{
long Version; // 版本號,本次為 20001120 000-003
char Name[15]; // 姓名 004-018
char Sex[4]; // 性別 019-022
char Age[15]; // 年齡 022-037
char HomeTown[30]; // 方言類型,例如“上海普通話” 038-067
char Date[24]; // 日期 068-091
char Group[10]; // 00 組別 092-101
short nSentenceNum; // 句子數 102-103
long SampleRate; // 采樣率 104-107
char ParameterType[10]; / 參數類型(WAVE) 108-117
short SampleType; // 數據類型(1=char;2=short;3=long; 118-119
//4=float;5=double)
char Reservation[78]; // 保留位 120-197
short nSentenceNum1; / 句子數 198-199
} dataHEAD;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPickWavDlg dialog
CPickWavDlg::CPickWavDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPickWavDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPickWavDlg)
m_SCRname = _T("");
m_TAGname = _T("3");
m_parameter = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPickWavDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPickWavDlg)
DDX_Text(pDX, IDC_EDIT_Total, m_SCRname);
DDX_Text(pDX, IDC_EDIT_Repeat, m_TAGname);
DDX_Text(pDX, IDC_EDIT_Index, m_parameter);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPickWavDlg, CDialog)
//{{AFX_MSG_MAP(CPickWavDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_EDIT_Total, OnChangeEDITTotal)
ON_EN_CHANGE(IDC_EDIT_Repeat, OnChangeEDITRepeat)
ON_EN_CHANGE(IDC_EDIT_Index, OnChangeEDITIndex)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPickWavDlg message handlers
BOOL CPickWavDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPickWavDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPickWavDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPickWavDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPickWavDlg::OnOK()
{
// TODO: Add extra validation here
CFile fileS,fileT;
CString strout,str;
UpdateData(TRUE);
strout="";
int i=0;
int j,n;
int strlen;
int total_sen_num, repeat_times;
str = m_SCRname.Mid(0,4);
total_sen_num = atoi(str);
str = m_TAGname.Mid(0,2);
repeat_times = atoi(str);
strlen=m_parameter.GetLength();
n=0;
while(1)
{
j=m_parameter.Find(",",i);
if(j==-1)
{
str=m_parameter.Mid(i,strlen-i);
index[n]=atoi(str);
n++;
break;
}
else
{
str=m_parameter.Mid(i,j-i);
index[n]=atoi(str);
n++;
i=j+1;
}
}
//--------------------
//皮皮
paranum=repeat_times*n;
for(i=0;i<n;i++)
for(j=1;j<repeat_times;j++)
index[j*n+i]=index[i]+total_sen_num*j;
char tempName[_MAX_FNAME];
char inName[_MAX_FNAME];
char outName[_MAX_FNAME];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
short FileAmount;
CString strtemp;
FILE *findex;
findex= fopen(INdex,"r");
fscanf(findex, "%d\n", &FileAmount);
for(i=0;i<FileAmount;i++)
{
fscanf(findex,"%s",&tempName);
strcpy( inName, tempName);
_splitpath(tempName,drive,dir,fname,ext);
strcpy( outName, drive);
strcat( outName, dir);
strtemp.Format("%s%s",outName,"pickout");
CreateDirectory(strtemp,NULL);
strcat( outName, "pickout\\");
strcat( outName, fname);
strcat( outName, ".dat" );
printf("文件 %d begin.\n", i);
PickOneFile(inName,outName);
printf("文件 %d over.\n", i);
}
AfxMessageBox("轉換文件完畢!");
}
int CPickWavDlg::PickOneFile(char *File_In, char *File_Out)
{
dataHEAD head;
int i,j;
//打開輸入輸出文件
//------------------------------------------------
FILE *infile,*outfile;
if ((infile = fopen(File_In,"rb")) == NULL)
{
printf("Cannot open input file %s\n",File_In);
exit(-1);
}
if ((outfile = fopen(File_Out,"wb")) == NULL)
{
if ((outfile = fopen(File_Out,"w+")) == NULL)
{
printf("Cannot open output file %s\n",File_Out);
exit(-1);
}
}
//寫輸出文件頭
//fseek(infile,198,SEEK_SET);
//fread(&Sentence,sizeof(short),1,infile);
//fseek(infile,0,SEEK_SET);
//------------------------------------------
//short stemp;
//short temp2 = (200+Sentence*8)/2;
/*
for( i=0 ; i<temp2 ; i++ )
{
fread(&stemp,sizeof(short),1,infile);
fwrite(&stemp,sizeof(short),1,outfile);
}
*/
rewind( infile );
rewind( outfile );
fread(&head,sizeof(dataHEAD),1,infile);
head.nSentenceNum=paranum;
head.nSentenceNum1=paranum;
//head.SampleRate= 8000;
fwrite(&head,sizeof(dataHEAD),1,outfile);
//讀取語音起始地址和長度
//-----------------------------------------
//fseek(outfile,198,SEEK_SET);
//fwrite(&Sentence,sizeof(short),1,infile);
long *Begin;
if((Begin = new long[paranum]) == NULL)
{
printf("Not enough memory!Begin \n");
exit(-1);
}
long *Length;
if((Length = new long[paranum]) == NULL)
{
printf("Not enough memory!Length \n");
exit(-1);
}
long *PBegin;
if((PBegin = new long[paranum]) == NULL)
{
printf("Not enough memory!Begin \n");
exit(-1);
}
long *PLength;
if((PLength = new long[paranum]) == NULL)
{
printf("Not enough memory!Length \n");
exit(-1);
}
long ltemp;
//讀出需要的索引
fseek(infile,200,SEEK_SET);
fseek(outfile, 200 ,SEEK_SET);
PBegin[0] = 200+8*paranum;
for( i=0 ; i<paranum ; i++ )
{
fseek(infile,200+index[i]*8,SEEK_SET);
fread(<emp,sizeof(long),1,infile);
Begin[i] = ltemp;
fread(<emp,sizeof(long),1,infile);
Length[i] = ltemp;
PLength[i] = Length[i];
if(i<paranum-1)
PBegin[i+1] = PBegin[i] + Length[i];
fwrite(&PBegin[i],sizeof(long),1,outfile);
fwrite(&PLength[i],sizeof(long),1,outfile);
}
//fseek(outfile, Sentence*8+200 ,SEEK_SET);
//--------------------------------------
long DataBegin,DataLength;
short InSample,OutSample;
for( i=0 ; i<paranum ; i++ )
{
DataBegin = Begin[i];
DataLength = Length[i];
fseek(infile,DataBegin,SEEK_SET);
fseek(outfile, PBegin[i],SEEK_SET);
for( j=0 ; j<DataLength/2 ; j++ )
{
fread(&InSample,sizeof(short),1,infile);
OutSample = InSample;
fwrite(&OutSample,sizeof(short),1,outfile);
}
// printf("%d\n",i);
}
fclose(infile);
fclose(outfile);
delete Begin;
delete Length;
delete PBegin;
delete PLength;
return 1;
}
void CPickWavDlg::OnChangeEDITTotal()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CPickWavDlg::OnChangeEDITRepeat()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CPickWavDlg::OnChangeEDITIndex()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CPickWavDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -