Advertisement
Guest User

MICcpp

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