220 likes | 376 Views
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()
E N D
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() • waveInStart() • waveInReset() • waveInUnprepareHeader() • waveInClose()
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.
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.
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
waveInPrepareHeader() • MMRESULT waveInPrepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Prepares a buffer for waveform input. • Returns MMSYSERR_NOERROR if successful.
waveInAddBuffer() • MMRESULT waveInAddBuffer(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Sends an input buffer to the specified waveform-audio input device. • Returns MMSYSERR_NOERROR if successful.
waveInStart() • MMRESULT waveInStart(HWAVEINhwi ); • Starts input on the specified waveform input device. • Returns MMSYSERR_NOERROR if successful.
waveInReset() • MMRESULT waveInReset(HWAVEINhwi ); • Stops input on a specified waveform input device and resets the current position to 0. • Returns MMSYSERR_NOERROR if successful.
waveInUnprepareHeader() • MMRESULT waveInUnprepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh ); • Cleans up the preparation performed by waveInPrepareHeader. • Returns MMSYSERR_NOERROR if successful.
waveInClose() • MMRESULT waveInClose(HWAVEINhwi ); • Closes the specified waveform-audio input device. • Returns MMSYSERR_NOERROR if successful.
Multi-Media API (output) • waveOutOpen() • waveOutPrepareHeader() • waveOutWrite() • waveOutReset() • waveOutUnprepareHeader() • waveOutClose( )
waveOutOpen() • MMRESULT waveOutOpen(LPHWAVEOUTphwo,UINTuDeviceID,LPWAVEFORMATEXpwfx,DWORDdwCallback,DWORDdwInstance,DWORDfdwOpen ); • Opens a specified waveform output device for playback. • Returns MMSYSERR_NOERROR if successful.
waveOutPrepareHeader() • MMRESULT waveOutPrepareHeader(HWAVEOUThwo,LPWAVEHDRpwh,UINTcbwh ); • Prepares a waveform data block for playback. • Returns MMSYSERR_NOERROR if successful.
waveOutWrite() • MMRESULT waveOutWrite(HWAVEOUT hwo,LPWAVEHDRpwh,UINTcbwh ); • Sends a data block to the specified waveform output device. • Returns MMSYSERR_NOERROR if successful.
waveOutReset() • MMRESULT waveOutReset(HWAVEOUThwo ); • Stops playback on a specified waveform output device and resets the current position to 0. • Returns MMSYSERR_NOERROR if successful.
waveOutUnprepareHeader() • MMRESULT waveOutUnprepareHeader(HWAVEOUThwo,LPWAVEHDRpwh,UINTcbwh ); • Cleans up the preparation performed by waveOutPrepareHeader. • Returns MMSYSERR_NOERROR if successful.
waveOutClose( ) • MMRESULT waveOutClose(HWAVEOUThwo ); • Closes the specified waveform output device. • Returns MMSYSERR_NOERROR if successful.
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
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