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

📄 abdlg.cpp

📁 LCD模拟程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	str.Format("%d",ymin);
	dcMem.TextOut(600,230,str);
	dc.BitBlt(xCon,yCon,wCon,hCon,&dcMem, 0, 0, SRCCOPY);
	dcMem.SelectObject(pbmOld);
	dcMem.DeleteDC(); 
// 	FILE *F1=fopen("LB1.txt","w");
// 	fwrite(pdraw,1,dwDataLength,F1);
// 	fclose(F1);
	FILE *F2=fopen("LB.txt","w");
	for(x =0 ; x < 11025; x++)
	{
	fprintf(F2,"%d\n",pdraw[x]);
	}

	
		fclose(F2);
	
// 	CString  str2;
//     for(x =0 ; x < 2048; x++) 
// 	{
// 	  y=2*pdraw[x];
// 	  str2.Format("%u",y);
//       }
// 	int   j;   
//    j=atoi(str2);
//    for (i=0;i<10000;i++)
//    {g_nData[i]=j;
//    }
}
void CABDlg::OnPlayStart() 
{
	// TODO: Add your control notification handler code here
	if (bPlaying) 
	{
		waveOutReset(hWaveOut);
	}
	
	//open waveform audio for output
	waveform.wFormatTag		=	WAVE_FORMAT_PCM;
	waveform.nChannels		=	1;
	waveform.nSamplesPerSec	=11025;
	waveform.nAvgBytesPerSec=11025;
	waveform.nBlockAlign	=1;
	waveform.wBitsPerSample	=8;
	waveform.cbSize			=0;
	
	
	if (waveOutOpen(&hWaveOut,WAVE_MAPPER,&waveform,(DWORD)this->m_hWnd,NULL,CALLBACK_WINDOW))
	{
		MessageBeep(MB_ICONEXCLAMATION);
		AfxMessageBox("Audio output erro");
	}
	
	
	return ;
	
}

void CABDlg::OnPlayPause() 
{
	// TODO: Add your control notification handler code here
	if (!bPlaying)
	{
		return;
	}
	if (!bPaused) 
	{
		waveOutPause(hWaveOut);
		bPaused = TRUE;
	}
	else
	{
		waveOutRestart(hWaveOut);
		bPaused=FALSE;
	}	
	return ;
}

void CABDlg::OnPlayStop() 
{
	// TODO: Add your control notification handler code here
	if (!bPlaying) {
		return ;
	}
	bEnding=TRUE;
	waveOutReset(hWaveOut);
	return ;

}

void CABDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	CDialog::OnClose();
	if (bRecording) 
	{
		bTerminating=TRUE;
		bEnding=TRUE;
		waveInReset(hWaveIn);
		TRACE("waveInReset\n");
		Sleep(500);
		//return CWinThread::ExitInstance();
	}
	if (bPlaying)
	{
		bTerminating=TRUE;
		bEnding=TRUE;
		waveOutReset(hWaveOut);
		Sleep(500);
		//return CWinThread::ExitInstance();
	}
	free (pWaveHdr1) ;
	free (pWaveHdr2) ;
	free (pSaveBuffer) ;
}

void CABDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    CDialog::OnTimer(nIDEvent);
	MMTIME mmTime;
	mmTime.wType=TIME_MS;
	TCHAR time[20];
	switch(nIDEvent) 
	{
	case 1:
		waveInGetPosition(hWaveIn,&mmTime,sizeof(MMTIME));
		itoa(mmTime.u.ms/10000,time,10);
	((CWnd *)GetDlgItem(IDC_STATIC))->SetWindowText(time);
	
}
}

/////////////////////////////////////////////////////////////////////
//开始采集消息响应函数
void CABDlg::OnMM_WIM_OPEN(UINT wParam, LONG lParam) 
{
	// TODO: Add your message handler code here and/or call default
	((CWnd *)(this->GetDlgItem(IDC_REC_START)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_REC_STOP)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_START)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_PAUSE)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_STOP)))->EnableWindow(FALSE);
	SetTimer(1,100,NULL);
	bRecording=TRUE;
	
	
	//	TRACE("MM_WIM_OPEN\n");
	
	
}
/////////////////////////////////////////////////////////////////////
//缓冲采满消息响应函数
////////////////////////////////////////////////////////////////////
void CABDlg::OnMM_WIM_DATA(UINT wParam, LONG lParam) 
{
	// TODO: Add your message handler code here and/or call default
	// Reallocate save buffer memory
	
	//////////////////////////////////////////////////////////////////////////
	
	
	pNewBuffer = (PBYTE)realloc (pSaveBuffer, dwDataLength +
		((PWAVEHDR) lParam)->dwBytesRecorded) ;
	
	if (pNewBuffer == NULL)  //如果申请新内存不成功,返回
	{
		waveInClose (hWaveIn) ;//waveInClose :关闭声音输入设备
		MessageBeep (MB_ICONEXCLAMATION) ;
		AfxMessageBox("erro memory");
		return ;
	}
	
	pSaveBuffer = pNewBuffer ;////如果申请新内存成功
	//////////////////////////////////////////////////////////////////////////
	
	CopyMemory (pSaveBuffer + dwDataLength, ((PWAVEHDR) lParam)->lpData,
		((PWAVEHDR) lParam)->dwBytesRecorded) ;
	
	dwDataLength += ((PWAVEHDR) lParam)->dwBytesRecorded ;
	
	if (bEnding)
	{
		waveInClose (hWaveIn) ;//waveInClose :关闭声音输入设备
		return ;
	}
	//////////////////////////////////////////////////////////////////////////
// 	       FILE *fp1;
//          if((fp1=fopen("a1.txt","r"))== NULL)
// 			{
// 				printf("can not\n");
// 		 	}
// 		 	for( i=0; i<3200 ;i++)
// 		 	{ 
// 		 		fscanf(fp1,"%d",&g_nData[i]);
// 		 	}
//       	fclose(fp1);
    

 
// 	for(x =0 ; x < 2048; x++)  // display Input
// 	{ 
//     y=2*pdraw[x];
// 	}
	
    


	//////////////////////////////////////////////////////////////////////////
// 	CFile m_file;
//     CFileException fileException;
//     CString m_csFileName= "G:\\A.LB.r.wav";
// 	m_file.Open(m_csFileName,CFile::modeCreate|CFile::modeReadWrite, &fileException);
// 	DWORD m_WaveHeaderSize = 38;
// 	DWORD m_WaveFormatSize = 18;
// 	m_file.SeekToBegin();
//     m_file.Write("RIFF",4);
//    	unsigned int Sec=(sizeof pSaveBuffer + m_WaveHeaderSize);
//    	m_file.Write(&Sec,sizeof(Sec));
//    	m_file.Write("WAVE",4);
//    	m_file.Write("fmt ",4);
//    	m_file.Write(&m_WaveFormatSize,sizeof(m_WaveFormatSize));
//    	
//    	m_file.Write(&waveform.wFormatTag,sizeof(waveform.wFormatTag));
//    	m_file.Write(&waveform.nChannels,sizeof(waveform.nChannels));
//    	m_file.Write(&waveform.nSamplesPerSec,sizeof(waveform.nSamplesPerSec));
//    	m_file.Write(&waveform.nAvgBytesPerSec,sizeof(waveform.nAvgBytesPerSec));
//    	m_file.Write(&waveform.nBlockAlign,sizeof(waveform.nBlockAlign));
//    	m_file.Write(&waveform.wBitsPerSample,sizeof(waveform.wBitsPerSample));
//    	m_file.Write(&waveform.cbSize,sizeof(waveform.cbSize));
//    	m_file.Write("data",4);
//    	m_file.Write(&dwDataLength,sizeof(dwDataLength));
//    	
//    	m_file.Write(pSaveBuffer,dwDataLength);
// //	m_file.Write(pdraw,dwDataLength);
// 	m_file.Seek(dwDataLength,CFile::begin);
// 	m_file.Close();		
	
	// Send out a new buffer
	
	waveInAddBuffer (hWaveIn, (PWAVEHDR) lParam, sizeof (WAVEHDR)) ;//waveInAddBuffer :向声音输入设备发送缓冲区
	TRACE("done input data\n");
	//
     draw();
	// double m;
	// FILE *F1=fopen("LB.txt","w");
	 // 		 	for (x=0;x<10;i++)
	 // 		 	{
// 	 m=atoi((const char*)pWaveHdr1);
// 	 fprintf(F1,"%f",m);  
	 
	 //  	}
	          
			 // m_file.Write(&dwDataLength,sizeof(dwDataLength));
	          
// 	          FILE *F1=fopen("LB1.txt","a+");
// 	 		  fwrite(pSaveBuffer,1,dwDataLength,F1);
// 	          fclose(F1);
//               FILE *F2=fopen("LB2.txt","a+");
//               fprintf(F2,"%d",F1);
// 			  fclose(F2);
			// fprintf(F1,"%d",pWaveHdr1);  
			 
	//
	return ;
	
	
}
/////////////////////////////////////////////////////////////////////
//采集结束消息响应函数
////////////////////////////////////////////////////////////////////
void CABDlg::OnMM_WIM_CLOSE(UINT wParam, LONG lParam) 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer(1);
	TRACE("MM_WIM_CLOSE\n");
	if (0==dwDataLength) 
	{
		return;
	}
	
	
	waveInUnprepareHeader (hWaveIn, pWaveHdr1, sizeof (WAVEHDR)) ;
	//当然在用GlobalFreeP tr来释放缓冲区之前,必须先要用WaveInUnprepareHeader函数来解除这种保护。
	waveInUnprepareHeader (hWaveIn, pWaveHdr2, sizeof (WAVEHDR)) ;
	
	free (pBuffer1) ;
	free (pBuffer2) ;
	
	if (dwDataLength > 0)
	{
		//enable play
		((CWnd *)(this->GetDlgItem(IDC_REC_START)))->EnableWindow(TRUE);
		((CWnd *)(this->GetDlgItem(IDC_REC_STOP)))->EnableWindow(FALSE);
		((CWnd *)(this->GetDlgItem(IDC_PLAY_START)))->EnableWindow(TRUE);
		((CWnd *)(this->GetDlgItem(IDC_PLAY_PAUSE)))->EnableWindow(FALSE);
		((CWnd *)(this->GetDlgItem(IDC_PLAY_STOP)))->EnableWindow(FALSE);
	}
	bRecording = FALSE ;
	((CWnd *)(this->GetDlgItem(IDC_REC_START)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_REC_STOP)))->EnableWindow(FALSE);
	return ;
	
}

////////////////////////////////////////////////////////////////////
//回放开始消息响应函数
////////////////////////////////////////////////////////////////////
void CABDlg::OnMM_WOM_OPEN(UINT wParam, LONG lParam)
{
	TRACE("open MM_WOM_OPEN\n");
	// Set up header
	
	pWaveHdr1->lpData          = (LPTSTR)pSaveBuffer ;  // 回放数据首址
	pWaveHdr1->dwBufferLength  = dwDataLength ;
	pWaveHdr1->dwBytesRecorded = 0 ;
	pWaveHdr1->dwUser          = 0 ;
	pWaveHdr1->dwFlags         = WHDR_BEGINLOOP | WHDR_ENDLOOP ;
	pWaveHdr1->dwLoops         = dwRepetitions ;
	pWaveHdr1->lpNext          = NULL ;
	pWaveHdr1->reserved        = 0 ;
	
	// Prepare and write
	
	waveOutPrepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
	waveOutWrite (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;   //回放
	
	bEnding = FALSE ;
	bPlaying = TRUE ;
	
	//面板按键维护
	((CWnd *)(this->GetDlgItem(IDC_REC_START)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_REC_STOP)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_START)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_PAUSE)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_STOP)))->EnableWindow(TRUE);
	
	
	
	
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//回放完成消息响应函数
////////////////////////////////////////////////////////////////////

void CABDlg::OnMM_WOM_DONE(UINT wParam, LONG lParam){
	
	TRACE("open MM_WOM_DONE\n");
	waveOutUnprepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
	waveOutClose (hWaveOut) ;                                         //关回放设备
	
	bPaused = FALSE ;
	dwRepetitions = 1 ;
	bPlaying = FALSE ;	
	
	return  ;
	
}
////////////////////////////////////////////////////////////////////
//回放关闭消息响应函数
////////////////////////////////////////////////////////////////////
void CABDlg::OnMM_WOM_CLOSE(UINT wParam, LONG lParam){
	TRACE("open MM_WOM_CLOSE\n");
	bPaused = FALSE ;
	dwRepetitions = 1 ;
	bPlaying = FALSE ;	
	
	((CWnd *)(this->GetDlgItem(IDC_REC_START)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_REC_STOP)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_START)))->EnableWindow(TRUE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_PAUSE)))->EnableWindow(FALSE);
	((CWnd *)(this->GetDlgItem(IDC_PLAY_STOP)))->EnableWindow(FALSE);
	return ;
	
}



⌨️ 快捷键说明

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