⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wav_adpdlg.cpp

📁 adcmp 数据编码解码原代码,处理语音数据的朋友可能需要这个,希望有帮助!
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WAV_ADPDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WAV_ADP.h"
#include "WAV_ADPDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

	DWORD	m_33;
	DWORD	m_44;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
static int indexTable[16] = {
    -1, -1, -1, -1, 2, 4, 6, 8,
    -1, -1, -1, -1, 2, 4, 6, 8,
};

static int stepsizeTable[89] = {
    7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
    19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
    50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
    130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
    337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
    876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
    2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
    5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
    15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};





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()

/////////////////////////////////////////////////////////////////////////////
// CWAV_ADPDlg dialog

CWAV_ADPDlg::CWAV_ADPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWAV_ADPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWAV_ADPDlg)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_33 = 0;
	m_44 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWAV_ADPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWAV_ADPDlg)
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDX_Text(pDX, IDC_EDIT3, m_33);
	DDX_Text(pDX, IDC_EDIT4, m_44);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWAV_ADPDlg, CDialog)
	//{{AFX_MSG_MAP(CWAV_ADPDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWAV_ADPDlg message handlers

BOOL CWAV_ADPDlg::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 CWAV_ADPDlg::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 CWAV_ADPDlg::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 CWAV_ADPDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CWAV_ADPDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
	 CFileDialog openfile(true)      ; 
     openfile.DoModal()              ;
	 m_edit1=openfile.GetPathName()  ;
	 m_edit2=m_edit1+".wav"          ;  
	 UpdateData(false)               ;  


}

void CWAV_ADPDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
  byte filehead[44]         ;
  byte readtemp[4]          ;//读入数据
  byte outtemp[1]           ;//输出数据

    signed short int val;			//* Current input sample value 当前输入值*/
    int sign;			//* Current adpcm sign bit ADP符号标志*/
    int delta;			//* Current adpcm output value ADP输出数值*/
    int diff;			//* Difference between val and valprev 当前数值和现在数值的差*/
    int step;			//* Stepsize 步长大小*/
    int valpred(0);		//* 前面一个样本数值*/
    int vpdiff;			//* 当前和以前的差距*/
    int index(0);			//* Current step change index 当前步长索引号*/


  CFile file1                                                 ;//原来的文件
  CFile file2(m_edit2,CFile::modeCreate|CFile::modeWrite)     ;//目标文件文件
  if(file1.Open(m_edit1,CFile::modeRead))
  {
  
  file1.Read(filehead,sizeof(char)*44)   ;
  file2.Write(filehead,sizeof(char)*44)  ;//写头文件
  while(file1.GetPosition()<file1.GetLength())
  {

    file1.Read(readtemp,sizeof(char)*4)   ;//读入当前2个样本
    val = (readtemp[1]<<8)+readtemp[0]    ;//输入当前样本
    step = stepsizeTable[index];           //变化数值 
	/* Step 1 - compute difference with previous value */
	diff = val - valpred;  //变化数值等于当前数值 减去前一个数值  
	sign = (diff < 0) ? 8 : 0;//如果变小了就取负- 号
	if ( sign ) diff = (-diff); //变化值为负 
	delta = 0;
	vpdiff = (step >> 3);//step = stepsizeTable[index]; 就是 除以8
	
	if ( diff >= step ) {
	    delta = 4;
	    diff -= step;
	    vpdiff += step;
	}
	step >>= 1;
	if ( diff >= step  ) {
	    delta |= 2;
	    diff -= step;
	    vpdiff += step;
	}
	step >>= 1;
	if ( diff >= step ) {
	    delta |= 1;
	    vpdiff += step;
	}
	/* Step 3 - Update previous value */
	if ( sign )
	  valpred -= vpdiff;
	else
	  valpred += vpdiff;
	/* Step 4 - Clamp previous value to 16 bits */
	if ( valpred > 32767 )
	  valpred = 32767;
	else if ( valpred < -32768 )
	  valpred = -32768;             //此数用于和下一个产生差距
	/* Step 5 - Assemble value, update index and step values */
	delta |= sign;	
	index += indexTable[delta];  //索引号
	if ( index < 0 ) index = 0;  //
	if ( index > 88 ) index = 88;

    outtemp[0] = (delta << 4) & 0xf0;
/////////////////////////////////

    val = (readtemp[3]<<8)+readtemp[2]    ;//输入当前样本
    step = stepsizeTable[index];           //变化数值 
	/* Step 1 - compute difference with previous value */
	diff = val - valpred;  //变化数值等于当前数值 减去前一个数值  
	sign = (diff < 0) ? 8 : 0;//如果变小了就取负- 号
	if ( sign ) diff = (-diff); //变化值为负 
	delta = 0;
	vpdiff = (step >> 3);//step = stepsizeTable[index]; 就是 除以8
	
	if ( diff >= step ) {
	    delta = 4;
	    diff -= step;
	    vpdiff += step;
	}
	step >>= 1;
	if ( diff >= step  ) {
	    delta |= 2;
	    diff -= step;
	    vpdiff += step;
	}
	step >>= 1;
	if ( diff >= step ) {
	    delta |= 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -