WaveDlg.cpp
上传用户:amei960
上传日期:2007-02-05
资源大小:143k
文件大小:6k
源码类别:

Audio

开发平台:

Visual C++

  1. // WaveDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Wave.h"
  5. #include "WaveDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CWaveDlg dialog
  50. CWaveDlg::CWaveDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CWaveDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CWaveDlg)
  54. //}}AFX_DATA_INIT
  55. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  56. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  57. bRecord = FALSE;
  58. }
  59. void CWaveDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CWaveDlg)
  63. DDX_Control(pDX, IDC_SOUND, m_Show);
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CWaveDlg, CDialog)
  67. //{{AFX_MSG_MAP(CWaveDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_BN_CLICKED(IDC_START, OnStart)
  72. ON_BN_CLICKED(IDC_STOP, OnStop)
  73. //}}AFX_MSG_MAP
  74. ON_MESSAGE(MM_WIM_OPEN,OnOpenMessage)
  75. ON_MESSAGE(MM_WIM_CLOSE,OnCloseMessage)
  76. ON_MESSAGE(MM_WIM_DATA,OnDataMessage)
  77. END_MESSAGE_MAP()
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CWaveDlg message handlers
  80. BOOL CWaveDlg::OnInitDialog()
  81. {
  82. CDialog::OnInitDialog();
  83. // Add "About..." menu item to system menu.
  84. // IDM_ABOUTBOX must be in the system command range.
  85. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  86. ASSERT(IDM_ABOUTBOX < 0xF000);
  87. CMenu* pSysMenu = GetSystemMenu(FALSE);
  88. if (pSysMenu != NULL)
  89. {
  90. CString strAboutMenu;
  91. strAboutMenu.LoadString(IDS_ABOUTBOX);
  92. if (!strAboutMenu.IsEmpty())
  93. {
  94. pSysMenu->AppendMenu(MF_SEPARATOR);
  95. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  96. }
  97. }
  98. // Set the icon for this dialog.  The framework does this automatically
  99. //  when the application's main window is not a dialog
  100. SetIcon(m_hIcon, TRUE); // Set big icon
  101. SetIcon(m_hIcon, FALSE); // Set small icon
  102. // TODO: Add extra initialization here
  103. filter.Init(m_Show.GetSafeHwnd(),16);
  104. m_Compress = &m_G729aCompress;
  105. //m_Compress = &m_Gsm;
  106. return TRUE;  // return TRUE  unless you set the focus to a control
  107. }
  108. void CWaveDlg::OnSysCommand(UINT nID, LPARAM lParam)
  109. {
  110. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  111. {
  112. CAboutDlg dlgAbout;
  113. dlgAbout.DoModal();
  114. }
  115. else
  116. {
  117. CDialog::OnSysCommand(nID, lParam);
  118. }
  119. }
  120. // If you add a minimize button to your dialog, you will need the code below
  121. //  to draw the icon.  For MFC applications using the document/view model,
  122. //  this is automatically done for you by the framework.
  123. void CWaveDlg::OnPaint() 
  124. {
  125. if (IsIconic())
  126. {
  127. CPaintDC dc(this); // device context for painting
  128. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  129. // Center icon in client rectangle
  130. int cxIcon = GetSystemMetrics(SM_CXICON);
  131. int cyIcon = GetSystemMetrics(SM_CYICON);
  132. CRect rect;
  133. GetClientRect(&rect);
  134. int x = (rect.Width() - cxIcon + 1) / 2;
  135. int y = (rect.Height() - cyIcon + 1) / 2;
  136. // Draw the icon
  137. dc.DrawIcon(x, y, m_hIcon);
  138. }
  139. else
  140. {
  141. CDialog::OnPaint();
  142. }
  143. }
  144. // The system calls this to obtain the cursor to display while the user drags
  145. //  the minimized window.
  146. HCURSOR CWaveDlg::OnQueryDragIcon()
  147. {
  148. return (HCURSOR) m_hIcon;
  149. }
  150. void CWaveDlg::OnOpenMessage(WPARAM wParam,LPARAM lParam)
  151. {
  152. TRACE("CWaveIn::Open()n");
  153. }
  154. void CWaveDlg::OnCloseMessage(WPARAM wParam,LPARAM lParam)
  155. {
  156. TRACE("CWaveIn::Close()n");
  157. }
  158. void CWaveDlg::OnDataMessage(WPARAM wParam,LPARAM lParam)
  159. {
  160. WAVEHDR* pWH=(WAVEHDR*)lParam;
  161. waveInUnprepareHeader((HWAVEIN)wParam,pWH,sizeof(WAVEHDR));
  162. if(pWH->dwBytesRecorded != SIZE_AUDIO_FRAME)
  163. return;
  164. if( !m_WaveIn.IsOpen() )
  165. return;
  166. if(filter.Filter((char*)pWH->lpData))
  167. {
  168. char buf2[1024];
  169. memset(buf,0,sizeof(buf));
  170. memset(buf1,0,sizeof(buf1));
  171. memcpy(buf,pWH->lpData,pWH->dwBytesRecorded);
  172. m_Compress->Compress(buf,pWH->dwBytesRecorded,
  173. buf2,&len);
  174. sprintf(buf1,"%s/","DATA");
  175. memcpy(buf1+5,buf2,len);
  176. memset(buf,0,sizeof(buf));
  177. m_Compress->UnCompress(&buf1[5],len,buf,&len1);
  178. m_WaveOut.Play(buf,len1);
  179. }
  180. waveInPrepareHeader((HWAVEIN)wParam,pWH,sizeof(WAVEHDR));
  181. waveInAddBuffer((HWAVEIN)wParam,pWH,sizeof(WAVEHDR));
  182. }
  183. void CWaveDlg::OnStart() 
  184. {
  185. m_WaveIn.SetHwnd(GetSafeHwnd());
  186. m_WaveIn.Start();
  187. m_WaveOut.Start();
  188. bRecord = TRUE;
  189. }
  190. void CWaveDlg::OnStop() 
  191. {
  192. m_WaveIn.Stop();
  193. m_WaveOut.Stop();
  194. bRecord = FALSE;
  195. }
  196. void CWaveDlg::OnCancel() 
  197. {
  198. if( bRecord )
  199. {
  200. AfxMessageBox("Please stop recording!");
  201. return;
  202. }
  203. CDialog::OnCancel();
  204. }