Advertisement
Guest User

Untitled

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