220 likes | 369 Views
Multimedia File I/O. Speaker: Ching Chen Chang Date:2006.11.13. Outline. Multimedia File I/O Sample program recordingmakingwave.cpp Waveout.cpp. Multi-Media API (Input). waveInOpen() waveInPrepareHeader() waveInAddBuffer() waveInStart() waveInUnprepareHeader() waveInClose().
E N D
Multimedia File I/O Speaker: Ching Chen Chang Date:2006.11.13
Outline • Multimedia File I/O • Sample program • recordingmakingwave.cpp • Waveout.cpp
Multi-Media API (Input) • waveInOpen() • waveInPrepareHeader() • waveInAddBuffer() • waveInStart() • waveInUnprepareHeader() • waveInClose()
Wave File Format(1/3) RIFF (Resource Interchange File Format) • A binary Multimedia file format. • RIFF provides an excellent way to store all these varied types of data. • WAV、AVI 、ANI …etc.
Wave File Format(2/3) • A binary Multimedia file format containing multiple nested data structures. • Storing data in tagged chunks. • Structure of Chunk 1.Chunk ID(4 characters) 2.Chunk size 3.Chunk data
MMCKINFO • typedef struct { FOURCC ckid; DWORD cksize; FOURCC fccType; DWORD dwDataOffset; DWORD dwFlags; } MMCKINFO; • The structure contains information about a chunk in a RIFF file.
mmioFOURCC() • FOURCC mmioFOURCC( CHAR ch0, CHAR ch1, CHAR ch2, CHAR ch3 ); • The mmioFOURCC macro converts four characters into a four-character code. • FOURCC(Four-Character Code) • Returns the four-character code created from the given characters.
mmioOpen() • HMMIO mmioOpen( LPSTR Filename, MMIOINFO mmioinfo, DWORD dwOpenFlags ); • Open a file. • Returns a handle of the opened file. • If the file cannot be opened, the return value is NULL. • dwOpenFlags:MMIO_CREATE、MMIO_WRITE、MMIO_READ …etc.
mmioCreateChunk() • MMRESULT mmioCreateChunk( HMMIO hmmio, MMCKINFO &ck, UINT wFlags ); • Creates a chunk in a RIFF file that was opened ,and the current file position =>is the beginning of the data portion of the new chunk. • wFlags :MMIO_CREATERIFF 、MMIO_CREATELIST • Returns MMSYSERR_NOERROR if successful
mmioWrite() • LONG mmioWrite( HMMIO hmmio, char * pch, LONG cch ); • Writes a specified number of bytes to a file opened. • Returns the number of bytes actually written. • If there is an error, return -1.
mmioAscend() • MMRESULT mmioAscend( HMMIO hmmio, MMCKINFO &ck, UINT wFlags ); • Ascends out of a chunk in a RIFF file , and the current file position is the location following the end of the chunk • wFlags : must be zero. • Returns MMSYSERR_NOERROR if successful
mmioClose() • MMRESULT mmioClose( HMMIO hmmio, UINT wFlags ); • Returns zero if successful.
Sample program • Record • Produce the Wave file • Recordingmakingwave.cpp • http://ms11.voip.edu.tw/~beautidays/recordingmakingwave.txt
Multimedia File I/O • Save Wave File mmioOpen() mmioCreateChunk() mmioWrite() mmioAscend() mmioClose() • Read Wave File mmioOpen() mmioDescend() mmioRead() mmioAscend() mmioClose()
mmioDescend() • MMRESULT mmioDescend( HMMIO hmmio, MMCKINFO lpck, MMCKINFO lpckParent, UINT wFlags ); • Descends into a chunk of a RIFF file that was opened. It can also search for a given chunk. • wFlags:MMIO_FINDCHUNK、MMIO_FINDRIFF • Returns MMSYSERR_NOERROR if successful • If the chunk is not founded, return MMIOERR_CHUNKNOTFOUND.
mmioRead() • LONG mmioRead( HMMIO hmmio, HPSTR pch, LONG cch ); • Returns the number of bytes actually read. • If there is an error, then return value -1.
Multi-Media API (Input) • waveOutOpen() • waveOutPrepareHeader() • waveOutWrite() • waveOutPause() • waveOutUnprepareHeader() • waveOutClose()
Sample Program • Play a wav file. • Waveout.txt • http://ms11.voip.edu.tw/~beautidays/waveout.txt
Reference(1/2) • 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
Reference(2/2) • Waveform Audio http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_about_waveform_audio.asp • RIFF http://www.oreilly.com/www/centers/gff/formats/micriff/ http://www.geocities.com/siliconvalley/bay/9932/zxs.html