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

📄 audioapp.cpp

📁 windows embedded ce (wince6.0)上录音事例程序源码。可编成.exe在系统上运行。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                    // at this point we need to wait for all playback buffers to be returned from the driver
                    // waveOutReset should speed this along.
                    // once all the buffers are returned, the WM_PLAYBACK_FINISHED
                    // message will be sent and we'll take care of closing the file and streams
                    bStopPlaying = true; // this tells the MM_WOM_DONE handler to not pass any finished buffers back to the driver

              }

              return 0;
              break;
       case WM_RECORD_PAUSE: // Un-used right now, may be used in the future
              if(hwi)
              {
                 if(bIsRecordingPaused)
                 {
                    // Recording is paused, need to restart it
                    mmRtn = waveInStart(hwi);
                    if(mmRtn != MMSYSERR_NOERROR)
                    {
                        RETAILMSG(1, (TEXT("ERROR: waveInStart failed with return code %d"), mmRtn));
                        return mmRtn;
                    }
                    bIsRecordingPaused = false;
                 }
                 else
                 {
                    // Pause Recording
                    mmRtn = waveInStop(hwi);
                    if(mmRtn != MMSYSERR_NOERROR)
                    {
                        RETAILMSG(1, (TEXT("ERROR: waveInStop failed with return code %d"), mmRtn));
                        return mmRtn;
                    }
                    bIsRecordingPaused = true;
                 }
              }

              return 0;
              break;
       case WM_PLAY_PAUSE:
              // Pause/Unpause the currently playing WaveFile
              if(hwo) // make sure hwo is valid
              {
                  if(bIsPlaybackPaused)
                  {
                        // Playback is paused, need to restart it
                        mmRtn = waveOutRestart(hwo);
                        if(mmRtn != MMSYSERR_NOERROR)
                        {
                            RETAILMSG(1, (TEXT("ERROR: waveOutRestart failed with return code %d"), mmRtn));
                            return mmRtn;
                        }
                        bIsPlaybackPaused = false;
                  }
                  else
                  {
                        // Pause playback
                        mmRtn = waveOutPause(hwo);
                        if(mmRtn != MMSYSERR_NOERROR)
                        {
                            RETAILMSG(1, (TEXT("ERROR: waveOutPause failed with return code %d"), mmRtn));
                            return mmRtn;
                        }
                        bIsPlaybackPaused = true;
                  }
              }

              return 0;
              break;
       case MM_WOM_OPEN:
              return 0;
              break;
       case MM_WOM_DONE:
              RETAILMSG(1, (TEXT("WAVEOUT HEADER WAS MARKED DONE.")));
              lpwhdr = (LPWAVEHDR)lParam;
              if(!lpwhdr)
              {
                    RETAILMSG(1, (TEXT("ERROR: Unable to read header passed back in this MM_WOM_DONE message.")));
                    return -1;
              }

              if(!bStopPlaying)
              {

                  // Read more data into this buffer
                  WaveFile.ReadData(lpwhdr->lpData,lpwhdr->dwBufferLength,&nBytes);
                  if(nBytes != lpwhdr->dwBufferLength) {
                         RETAILMSG(1, (TEXT("NOTE: Could not read a full buffer's worth of data from the file.")));
                         bStopPlaying = true; // assume we reached end of file
                  }

                  // pass this buffer back to the driver to be used again
                  mmRtn=waveOutWrite(hwo,lpwhdr,sizeof(WAVEHDR));
                  if(MMSYSERR_NOERROR != mmRtn) {
                 	    RETAILMSG(1, (TEXT("ERROR: waveOutWrite failed with return code %d"), mmRtn));
                         return mmRtn;
                  }

              }
              else
              {
                  // We are done playing, unprepare buffer and don't pass it back into the driver
                  mmRtn = waveOutUnprepareHeader(hwo, lpwhdr, sizeof(WAVEHDR));
                  if(mmRtn != MMSYSERR_NOERROR)
                  {
                      RETAILMSG(1, (TEXT("ERROR: waveOutUnprepareHeader failed with return code %d"), mmRtn));
                      return mmRtn;
                  }

                  // Free the Buffer's Data Memory
                 ZeroMemory( lpwhdr, sizeof(WAVEHDR) );
                 delete [] playData1;
                 delete [] playData2;

                  // decrement count on number of outstanding buffers
                  dwNumPlaybackBuffers--;
              }

              if(dwNumPlaybackBuffers == 0)
              {
                 // All capture buffers have been returned, signal app to close capture file
                 SendMessage(hwnd, WM_PLAYBACK_FINISHED, NULL, NULL);
              }


              return 0;
              break;
       case MM_WOM_CLOSE:
              return 0;
              break;
       case MM_WIM_OPEN:
              return 0;
              break;
       case MM_WIM_DATA:
              RETAILMSG(1, (TEXT("INPUT HEADER WAS MARKED DONE.")));

              // Write this header's info to the file
              lpwhdr = (LPWAVEHDR)lParam;
              if(!lpwhdr)
              {
                    RETAILMSG(1, (TEXT("ERROR: Unable to read header passed back in this MM_WIM_DATA message.")));
                    return -1;
              }

              dwBytesRecorded = lpwhdr->dwBytesRecorded;

              if(!RecordFile.WriteData(lpwhdr->lpData, dwBytesRecorded, &dwBytesWritten))
                  RETAILMSG(1, (TEXT("ERROR: Failed to Write Data Out to file.")));

              if( dwBytesRecorded != dwBytesWritten)
              {
                   RETAILMSG(1, (TEXT("ERROR: Number of bytes written to file is less than we asked for")));
              }


              if(!bStopRecording)
              {

                  // pass this buffer back to the driver to be used again
                  mmRtn = waveInAddBuffer(hwi, lpwhdr, sizeof(WAVEHDR));
                  if(mmRtn != MMSYSERR_NOERROR)
                  {
                      RETAILMSG(1, (TEXT("ERROR: waveInAddBuffer failed with return code %d"), mmRtn));
                      return mmRtn;
                  }

              }
              else
              {
                  // We are done recording, unprepare header and don't pass it back into the driver
                 mmRtn = waveInUnprepareHeader(hwi, lpwhdr, sizeof(WAVEHDR));
                 if(mmRtn != MMSYSERR_NOERROR)
                 {
                     RETAILMSG(1, (TEXT("ERROR: waveInUnprepareHeader failed with return code %d"), mmRtn));
                     return mmRtn;
                 }

                  // Free the Buffer's Data Memory
                 ZeroMemory( lpwhdr, sizeof(WAVEHDR) );
                 delete [] data1;
                 delete [] data2;

                  // decrement count on number of outstanding buffers
                  dwNumCaptureBuffers--;
              }


              if(dwNumCaptureBuffers == 0)
              {
                 // All capture buffers have been returned, signal app to close capture file
                 SendMessage(hwnd, WM_RECORD_FINISHED, NULL, NULL);
              }

              return 0;
              break;
       case WIM_CLOSE:
              return 0;
              break;
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);

		GetClientRect(hwnd, &rect);

		DrawText(hdc, TEXT("Application uses ~20msec buffers"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

		EndPaint(hwnd, &ps);
             return 0;
             break;

	case WM_DESTROY:

               // WAVEIN Cleanup
              if(hwi)
              {
                  mmRtn = waveInUnprepareHeader(hwi, &whr1,sizeof(whr1));
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveInUnprepareHeader failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  mmRtn = waveInUnprepareHeader(hwi, &whr2,sizeof(whr2));
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveInUnprepareHeader failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  // close the waveform input stream
                  mmRtn=waveInClose(hwi);
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveInClose failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  hwi = NULL;

              }

              // do some clean up
              RecordFile.Close();

              //WAVEOUT Cleanup
              if(hwo)
              {
 
              //unprepare the headers
                  mmRtn = waveOutUnprepareHeader(hwo, &wh1,sizeof(wh1));
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveOutUnprepareHeader failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  mmRtn = waveOutUnprepareHeader(hwo, &wh2,sizeof(wh2));
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveOutUnprepareHeader failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  // close the waveform output stream
                  mmRtn=waveOutClose(hwo);
                  if(MMSYSERR_NOERROR != mmRtn) {
                  	RETAILMSG(1, (TEXT("ERROR: waveOutClose failed with return code %d"), mmRtn));
                  	bRet = false;
                  }

                  hwo = NULL;
              }

              // do some clean up
              WaveFile.Close();

		PostQuitMessage(0);
		return 0;
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
			

// Program Entry Point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
	if (lpCmdLine == NULL || *lpCmdLine == 0) {
		lpCmdLine = TEXT("windows\\exclam.wav");
	}

	static TCHAR szAppName[] = TEXT("Bucket-Brigade Buffered Audio Sample Application");
	HWND hwnd;
	MSG msg;
	WNDCLASS wndclass;

	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = hInstance;
	wndclass.hIcon = 0;
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = szAppName;

	if(!RegisterClass(&wndclass))
	{
		MessageBox(NULL, TEXT("This program requires WindowsNT!"), szAppName, MB_ICONERROR);
		return 0;
	}


	hwnd = CreateWindow(  szAppName, // window class name
						 TEXT("The Bucket-Brigade Buffered Audio Sample Application"), // window caption
						 WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, // window style
						 CW_USEDEFAULT, // initial x position
						 CW_USEDEFAULT, // initial y position
						 CW_USEDEFAULT, // initial x size
						 CW_USEDEFAULT, // initial y size
						 NULL, // parent window handle
						 NULL, //window menu handle
						 hInstance, // program instance handle
						 NULL);
	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
		
		

⌨️ 快捷键说明

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