Advertisement
Guest User

MICccp

a guest
Apr 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. // MICDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MIC.h"
  6. #include "MICDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11.  
  12. #include <math.h>
  13.  
  14.  
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20. CAboutDlg();
  21.  
  22. // Dialog Data
  23. enum { IDD = IDD_ABOUTBOX };
  24.  
  25. protected:
  26. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  27.  
  28. // Implementation
  29. protected:
  30. DECLARE_MESSAGE_MAP()
  31. };
  32.  
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. }
  36.  
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. }
  41.  
  42. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  43. END_MESSAGE_MAP()
  44.  
  45.  
  46. #pragma once
  47.  
  48. #include "Mmsystem.h"
  49.  
  50. // CMICDlg dialog
  51. class CMICDlg : public CDialog
  52. {
  53. public:
  54. CMICDlg(CWnd* pParent = NULL);
  55. public:
  56. HWAVEOUT outHandle;
  57.  
  58. WAVEHDR outBuffer;
  59. unsigned char outBufAudio[88000*2];
  60.  
  61. enum { IDD = IDD_MIC_DIALOG };
  62.  
  63. protected:
  64. virtual void DoDataExchange(CDataExchange* pDX);
  65.  
  66. protected:
  67. HICON m_hIcon;
  68.  
  69. virtual BOOL OnInitDialog();
  70. afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  71. afx_msg void OnPaint();
  72. afx_msg HCURSOR OnQueryDragIcon();
  73. DECLARE_MESSAGE_MAP()
  74. public:
  75. afx_msg void OnBnClickedButmicOutopen();
  76. public:
  77. afx_msg void OnBnClickedButmicOutclose();
  78. public:
  79. afx_msg void OnBnClickedButmicOutplay();
  80. afx_msg LRESULT OnOutDone(WPARAM wParam, LPARAM lParam);
  81. };
  82.  
  83.  
  84.  
  85. CMICDlg::CMICDlg(CWnd* pParent /*=NULL*/)
  86. : CDialog(CMICDlg::IDD, pParent)
  87. {
  88. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  89. }
  90.  
  91. void CMICDlg::DoDataExchange(CDataExchange* pDX)
  92. {
  93. CDialog::DoDataExchange(pDX);
  94. }
  95.  
  96. BEGIN_MESSAGE_MAP(CMICDlg, CDialog)
  97. ON_WM_SYSCOMMAND()
  98. ON_WM_PAINT()
  99. ON_WM_QUERYDRAGICON()
  100. //}}AFX_MSG_MAP
  101. ON_BN_CLICKED(IDC_BUTMIC_OUTOPEN, &CMICDlg::OnBnClickedButmicOutopen)
  102. ON_BN_CLICKED(IDC_BUTMIC_OUTCLOSE, &CMICDlg::OnBnClickedButmicOutclose)
  103. ON_BN_CLICKED(IDC_BUTMIC_OUTPLAY, &CMICDlg::OnBnClickedButmicOutplay)
  104. ON_MESSAGE(WOM_DONE, &CMICDlg::OnOutDone )
  105. END_MESSAGE_MAP()
  106.  
  107. LRESULT CMICDlg::OnOutDone(WPARAM wParam, LPARAM lParam){
  108. MessageBox( L"Bufor zagrany do konca, mozna wstawic nowy" );
  109. return 0;
  110.  
  111. };
  112.  
  113.  
  114. // CMICDlg message handlers
  115.  
  116. BOOL CMICDlg::OnInitDialog()
  117. {
  118. CDialog::OnInitDialog();
  119.  
  120. // Add "About..." menu item to system menu.
  121.  
  122. // IDM_ABOUTBOX must be in the system command range.
  123. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  124. ASSERT(IDM_ABOUTBOX < 0xF000);
  125.  
  126. CMenu* pSysMenu = GetSystemMenu(FALSE);
  127. if (pSysMenu != NULL)
  128. {
  129. CString strAboutMenu;
  130. strAboutMenu.LoadString(IDS_ABOUTBOX);
  131. if (!strAboutMenu.IsEmpty())
  132. {
  133. pSysMenu->AppendMenu(MF_SEPARATOR);
  134. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  135. }
  136. }
  137.  
  138. // Set the icon for this dialog. The framework does this automatically
  139. // when the application's main window is not a dialog
  140. SetIcon(m_hIcon, TRUE); // Set big icon
  141. SetIcon(m_hIcon, FALSE); // Set small icon
  142.  
  143. // TODO: Add extra initialization here
  144.  
  145. return TRUE; // return TRUE unless you set the focus to a control
  146. }
  147.  
  148. void CMICDlg::OnSysCommand(UINT nID, LPARAM lParam)
  149. {
  150. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  151. {
  152. CAboutDlg dlgAbout;
  153. dlgAbout.DoModal();
  154. }
  155. else
  156. {
  157. CDialog::OnSysCommand(nID, lParam);
  158. }
  159. }
  160.  
  161. // If you add a minimize button to your dialog, you will need the code below
  162. // to draw the icon. For MFC applications using the document/view model,
  163. // this is automatically done for you by the framework.
  164.  
  165. void CMICDlg::OnPaint()
  166. {
  167. if (IsIconic())
  168. {
  169. CPaintDC dc(this); // device context for painting
  170.  
  171. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  172.  
  173. // Center icon in client rectangle
  174. int cxIcon = GetSystemMetrics(SM_CXICON);
  175. int cyIcon = GetSystemMetrics(SM_CYICON);
  176. CRect rect;
  177. GetClientRect(&rect);
  178. int x = (rect.Width() - cxIcon + 1) / 2;
  179. int y = (rect.Height() - cyIcon + 1) / 2;
  180.  
  181. // Draw the icon
  182. dc.DrawIcon(x, y, m_hIcon);
  183. }
  184. else
  185. {
  186. CDialog::OnPaint();
  187. }
  188. }
  189.  
  190. // The system calls this function to obtain the cursor to display while the user drags
  191. // the minimized window.
  192. HCURSOR CMICDlg::OnQueryDragIcon()
  193. {
  194. return static_cast<HCURSOR>(m_hIcon);
  195. }
  196.  
  197.  
  198. void CMICDlg::OnBnClickedButmicOutopen()
  199. {
  200. unsigned long result;
  201. WAVEFORMATEX waveFormat;
  202.  
  203. waveFormat.wFormatTag = WAVE_FORMAT_PCM;
  204. waveFormat.nChannels = 1;
  205. waveFormat.nSamplesPerSec = 44100;
  206. waveFormat.wBitsPerSample = 8;
  207. waveFormat.nBlockAlign = waveFormat.nChannels * (waveFormat.wBitsPerSample/8);
  208. waveFormat.nAvqBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
  209. waveFormat.cbSize = 0;
  210.  
  211. result = waveOutOpen(&outHandle,WAVE_MAPPER, &waveFormat,(DWORD)(this->m_hWnd),0,CALLBACK_WINDOW);
  212. if( result ){
  213. MessageBox( L"Blad otwierania wyjsciowego urzadzenia audio!!!" );
  214. }
  215. // TODO: Add your control notification handler code here
  216. }
  217.  
  218. void CMICDlg::OnBnClickedButmicOutclose()
  219. {
  220. waveOutClose( outHandle );
  221. // TODO: Add your control notification handler code here
  222. }
  223.  
  224. void CMICDlg::OnBnClickedButmicOutplay()
  225. {
  226. float c = 523,3
  227. float cis = 554,4
  228. float d = 587,3
  229. float dis = 622,3
  230. float e = 659,3
  231. float f = 698,5
  232. float fis = 740
  233. float g = 784
  234. float gis = 830,6
  235. float a = 880
  236. float b = 932,3
  237. float h = 987,8
  238. float C = 1046,5
  239.  
  240. const double pi = 3.1415926535;
  241.  
  242. double wsp1Hz = 2.0 / 44100.0;
  243. double wsp = 50 * wsp1Hz;
  244.  
  245. double wspI = 170.0 / (88000.0*2);
  246.  
  247. for( int i=0; i<(88000*2); i++ ){
  248. wsp= f* wsp1Hz;
  249. wsp= g* wsp1Hz;
  250. wsp= c* wsp1Hz;
  251. wsp= C* wsp1Hz;
  252. wsp= b* wsp1Hz;
  253. wsp= a* wsp1Hz;
  254. wsp= g* wsp1Hz;
  255. wsp= a* wsp1Hz;
  256. wsp= b* wsp1Hz;
  257. wsp= a* wsp1Hz;
  258. wsp= g* wsp1Hz;
  259. wsp= f* wsp1Hz;
  260. wsp= e* wsp1Hz;
  261. wsp= f* wsp1Hz;
  262. wsp= e* wsp1Hz;
  263. wsp= d* wsp1Hz;
  264. outBufAudio[i] = (unsigned char)( 170.0* (1.0 + sin( i*pi*wsp ) / 2.0) );
  265. wsp += wsp1Hz / 175.0;
  266. };
  267.  
  268. outBuffer.lpData = (LPSTR)( this->outBufAudio );
  269. outBuffer.dwBufferLength = (88000*2);
  270. outBuffer.dwFlags = 0;
  271.  
  272. int err;
  273. if( (err = waveOutPrepareHeader( outHandle, &outBuffer, sizeof(WAVEHDR))) )
  274. { MessageBox( L"BLAD przygotowywania struktury WAVEHDR" );
  275. }
  276.  
  277. waveOutWrite( outHandle, &outBuffer, sizeof(WAVEHDR) );
  278. // TODO: Add your control notification handler code here
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement