📄 dlgvalue.cpp
字号:
// DlgValue.cpp : implementation file
//
#include "stdafx.h"
#include "pgm.h"
#include "DlgValue.h"
#include "engine.h"
#include "matrix.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgValue dialog
DlgValue::DlgValue(CWnd* pParent /*=NULL*/)
: CDialog(DlgValue::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgValue)
m_nButton1 = -1;
m_nButton6 = -1;
m_nButton11 = -1;
m_nButton16 = -1;
m_nButton21 = -1;
m_nButton26 = -1;
m_nButton31 = -1;
m_nButton36 = -1;
m_nButton41 = -1;
m_nButton46 = -1;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void DlgValue::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgValue)
DDX_Control(pDX, IDC_BUTTON10_SNR, m_SNR);
DDX_Control(pDX, IDC_BUTTON10_AVERAGE, m_Average);
DDX_Radio(pDX, IDC_RADIO1, m_nButton1);
DDX_Radio(pDX, IDC_RADIO6, m_nButton6);
DDX_Radio(pDX, IDC_RADIO11, m_nButton11);
DDX_Radio(pDX, IDC_RADIO16, m_nButton16);
DDX_Radio(pDX, IDC_RADIO21, m_nButton21);
DDX_Radio(pDX, IDC_RADIO26, m_nButton26);
DDX_Radio(pDX, IDC_RADIO31, m_nButton31);
DDX_Radio(pDX, IDC_RADIO36, m_nButton36);
DDX_Radio(pDX, IDC_RADIO41, m_nButton41);
DDX_Radio(pDX, IDC_RADIO46, m_nButton46);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgValue, CDialog)
//{{AFX_MSG_MAP(DlgValue)
ON_BN_CLICKED(IDC_BUTTON10_AVERAGE, OnButton10Average)
ON_BN_CLICKED(IDC_BUTTON10_SNR, OnButton10Snr)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgValue message handlers
BOOL DlgValue::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
CheckRadioButton(IDC_RADIO1, //第一个参数为该组的第一个单选按钮的ID
IDC_RADIO2, //第二个参数为该组的最后一个单选按钮的ID
IDC_RADIO3); //第三个参数为该组中被选中的单选按钮的ID
return TRUE; // return TRUE unless you set the focus to a control
}
void DlgValue::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
DlgValue 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 DlgValue::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 DlgValue::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void DlgValue::OnButton10Average()
{
// TODO: Add your control notification handler code here
int average;
average=(m_nButton1+m_nButton6+m_nButton11+m_nButton16+m_nButton21+m_nButton26+m_nButton31+m_nButton36+m_nButton41+m_nButton46+10)/10;
UpdateData(TRUE);
if(average<=1)
MessageBox("质量:优;损害:不可察觉");
else if(average<=2)
MessageBox("质量:良;损害:可察觉,但不刺耳");
else if(average<=3)
MessageBox("质量:中;损害:轻微刺耳");
else if(average<=4)
MessageBox("质量:差;损害:刺耳");
else if(average<=5)
MessageBox("质量:极差;损害:非常刺耳");
UpdateData(false);
}
void DlgValue::OnButton10Snr()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
Engine *ep;
if(!(ep=engOpen(NULL)))
{
AfxMessageBox("Can not open the matlab engine!");
exit(-1);
}
CString fname1,pname1,fname2,pname2,fname3,pname3;
mxArray* x=NULL;
mxArray* y=NULL;
mxArray* RNS=NULL;
mxArray* SNR=NULL;
x=mxCreateDoubleMatrix(1,5000000,mxREAL);
y=mxCreateDoubleMatrix(1,5000000,mxREAL);
RNS=mxCreateDoubleMatrix(1,1,mxREAL);
SNR=mxCreateDoubleMatrix(1,1,mxREAL);
int fs=44100,nbits=16;
double *temp=new double[sizeof(double)];
engEvalString(ep,"[fname1,pname1]=uigetfile('*.wav','open the audio file')");
engEvalString(ep,"[fname2,pname2]=uigetfile('*.wav','open the watermarkaudio file')");
engEvalString(ep,"[fname3,pname3]=uigetfile('*.png;*.jpg;*.gif','open the watermark')");
//RNS=mxCreateDoubleMatrix(1,1,mxREAL);
//fname2=mxCreateDoubleMatrix(1,1,mxREAL);
//mxSetName(x,"x");
//mxSetName(y,"y");
//engPutArray(ep,"fname1");
//engPutArray(ep,"fname2");
//engPutArray(ep,fname3);
engEvalString(ep,"[x,fs,nbits]=wavread(fname1)");
engEvalString(ep,"[y,fs,nbits]=wavread(fname2)");
engEvalString(ep,"RNS=sum((x-y).^2)./sum(x.^2)");
//AfxMessageBox(y1);
engEvalString(ep,"SNR=-10*log10(RNS)");
SNR=engGetVariable(ep,"SNR");
memcpy((double *)temp,(double *)mxGetPr(SNR),sizeof(double));
CString str;
str.Format("%lf",*temp);
AfxMessageBox(str);
mxDestroyArray(x);
mxDestroyArray(y);
mxDestroyArray(RNS);
mxDestroyArray(SNR);
engClose(ep);
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -