1 / 22

Audio input and output

Audio input and output. Speaker: Ching Chen Chang Date:2006.10.30. Outline. Multi-Media API (Input) Multi-Media API (Output) Sample program record1.cpp. Include. #include <windows.h> #include <mmsystem.h>. Multi-Media API (input). waveInOpen() waveInPrepareHeader() waveInAddBuffer()

annona
Download Presentation

Audio input and output

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Audio input and output Speaker: Ching Chen Chang Date:2006.10.30

  2. Outline • Multi-Media API (Input) • Multi-Media API (Output) • Sample program • record1.cpp

  3. Include • #include <windows.h> • #include <mmsystem.h>

  4. Multi-Media API (input) • waveInOpen() • waveInPrepareHeader() • waveInAddBuffer() • waveInStart() • waveInReset() • waveInUnprepareHeader() • waveInClose()

  5. WAVEFORMATEX • typedef struct { WORD wFormatTag; WORD nChannels; DWORD nSamplesPerSec; DWORD nAvgBytesPerSec; WORD nBlockAlign; WORD wBitsPerSample; WORD cbSize; } WAVEFORMATEX; • This structure defines the format of waveform-audio data.

  6. WAVEHDR • typedef struct { LPSTR lpData; DWORD dwBufferLength; DWORD dwBytesRecorded; DWORD dwUser; DWORD dwFlags; DWORD dwLoops; struct wavehdr_tag* lpNext; DWORD reserved; }WAVEHDR; • This structure defines the header used to identify a waveform-audio buffer.

  7. waveInOpen() • MMRESULT waveInOpen(LPHWAVEINphwi,UINTuDeviceID,LPCWAVEFORMATEXpwfx,DWORDdwCallback,DWORDdwInstance,DWORDfdwOpen ); • Open a specified waveform input device for recording. • uDeviceID : WAVE_MAPPER • fdwOpen :CALLBACK_WINDOW ,CALLBACK_THREAD • Return MMSYSERR_NOERROR means success

  8. waveInPrepareHeader() • MMRESULT waveInPrepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Prepares a buffer for waveform input. • Returns MMSYSERR_NOERROR if successful.

  9. waveInAddBuffer() • MMRESULT waveInAddBuffer(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Sends an input buffer to the specified waveform-audio input device. • Returns MMSYSERR_NOERROR if successful.

  10. waveInStart() • MMRESULT waveInStart(HWAVEINhwi ); • Starts input on the specified waveform input device. • Returns MMSYSERR_NOERROR if successful.

  11. waveInReset() • MMRESULT waveInReset(HWAVEINhwi ); • Stops input on a specified waveform input device and resets the current position to 0. • Returns MMSYSERR_NOERROR if successful.

  12. waveInUnprepareHeader() • MMRESULT waveInUnprepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Cleans up the preparation performed by waveInPrepareHeader. • Returns MMSYSERR_NOERROR if successful.

  13. waveInClose() • MMRESULT waveInClose(HWAVEINhwi ); • Closes the specified waveform-audio input device. • Returns MMSYSERR_NOERROR if successful.

  14. Multi-Media API (output) • waveOutOpen() • waveOutPrepareHeader() • waveOutWrite() • waveOutReset() • waveOutUnprepareHeader() • waveOutClose( )

  15. waveOutOpen() • MMRESULT waveOutOpen(LPHWAVEOUTphwo,UINTuDeviceID,LPWAVEFORMATEXpwfx,DWORDdwCallback,DWORDdwInstance,DWORDfdwOpen ); • Opens a specified waveform output device for playback. • Returns MMSYSERR_NOERROR if successful.

  16. waveOutPrepareHeader() • MMRESULT waveOutPrepareHeader(HWAVEOUThwo,LPWAVEHDRpwh,UINTcbwh ); • Prepares a waveform data block for playback. • Returns MMSYSERR_NOERROR if successful.

  17. waveOutWrite() • MMRESULT waveOutWrite(HWAVEOUT hwo,LPWAVEHDRpwh,UINTcbwh ); • Sends a data block to the specified waveform output device. • Returns MMSYSERR_NOERROR if successful.

  18. waveOutReset() • MMRESULT waveOutReset(HWAVEOUThwo ); • Stops playback on a specified waveform output device and resets the current position to 0. • Returns MMSYSERR_NOERROR if successful.

  19. waveOutUnprepareHeader() • MMRESULT waveOutUnprepareHeader(HWAVEOUThwo,LPWAVEHDRpwh,UINTcbwh ); • Cleans up the preparation performed by waveOutPrepareHeader. • Returns MMSYSERR_NOERROR if successful.

  20. waveOutClose( ) • MMRESULT waveOutClose(HWAVEOUThwo ); • Closes the specified waveform output device. • Returns MMSYSERR_NOERROR if successful.

  21. Sample Program • Record • Produce the Wave file • Play the record voice • nChannels=1 • nSamplesPerSec=8000 • wBitsPerSample=8 • Demo • http://ms11.voip.edu.tw/~beautidays/recordcode.txt

  22. Reference • Wavefomat http://ccrma.stanford.edu/CCRMA/Courses/422 /projects/WaveFormat/ http://www.sonicspot.com/guide/wavefiles.html • Multimedia FILE I/O http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_multimedia_file_i_o.asp

More Related