Delphi Multimedia Wave operations (1)

Source: Internet
Author: User

Wave File Format

Microsoft's multimedia files (WAV, Avi, Tif, and so on) all have a riff header. The wave file basically looks like this:

Riff Header
  FMT sub-block
Data sub-block

There are many encoding methods for wave files. The most common and simple method is PCM encoding.
Other codes contain more "blocks", but at least the above blocks. PCM codes only contain the above blocks.

 

 

2. Determine whether a file is a wave file.

The first 12 bytes of the wave file can be described as follows:

Triff =Record
Ckid: DWORD; {'riff '}
Cksize: DWORD; {file size, excluding the first 8 bytes}
Fcctype: DWORD; {'wave '}
End;

 

3. mmio functions are used for I/O operations on multimedia files such as wave.

Mmio functions are more suitable for operating riff-format multimedia files than general I/O functions. They are mainly used to operate riff file blocks more conveniently. The official website also said they are more optimized.

Like other I/O functions, they also need to open to get the handle, read and write, and finally close; but they are not compatible with the handles of other I/O functions, however, some functions (the first seven functions) can also be used for operations on common files.

UsesMmsystem;

ProcedureTform1.formcreate (Sender: tobject );

Const

Filepath = 'C: \ temp \ mm.txt ';

VaR

Hfile: hmmio; STR: rawbytestring;

Begin

 Hfile: = mmioopen (pchar (filepath), {file to be opened}Nil, {Pointer that accepts the structure information of tmmioinfo, not used yet}

Mmio_createOrMmio_readwrite {open option; this is created and opened with read/write permissions });

Mmiowrite (hfile, 'delphi ', 6); {write 6 Characters}

Mmioseek (hfile, 0, seek_set); {move the read/write pointer to the file header}

Setlength (STR, 6); mmioread (hfile, pansichar (STR), 6); {read 6 Characters}

Showmessage (STR); {Delphi}

Mmioclose (hfile, 0); {close the file; the second parameter can also be mmio_fhopen, and it can be used} {delete the file at last. Since the file has been deleted, no close is required}

Mmioopen (pchar (filepath ),Nil, Mmio_delete );

End;

 

4. There are two structures: tmmioinfo and tmmckinfo.

Tmmioinfo is the status information after the multimedia file is opened. The second parameter of the mmioopen function is the pointer to this structure. tmmckinfo is used first. This is the information of the "Block" inside the file, which is composed of the following:

Tmmckinfo =Record
Ckid: fourcc; {block ID}
Cksize: DWORD; {block size}
Fcctype: fourcc; {format type identifier}
Dwdataoffset: DWORD; {offset address}
Dwflags: DWORD; {Additional information}
End;

To search for "blocks", you must use mmiodescend and mmioascend functions.

Mmioascend jumps out of the sub-block;

Mmiodescend is used to enter the child block. Entering the child block refers to the ckid and parent block information of the Child block;
Mmiodescend is also used to find the primary block (riff). You can find the primary block with little information.

 

5. Obtain the waveform data of the wave file.

Uses mmsystem;

Function getwavedata (filepath: string; var stream: tmemorystream): Boolean;
VaR
Hfile: hmmio;
Ckiriff, ckidata: tmmckinfo;
Begin
Result: = false;
Hfile: = mmioopen (pchar (filepath), nil, mmio_read );
If hfile = 0 Then exit;

Zeromemory (@ ckiriff, sizeof (tmmckinfo ));
Zeromemory (@ ckidata, sizeof (tmmckinfo ));
Ckidata. ckid: = mmiostringtofourcc ('data', 0 );

// Obtain the information of the primary block first
Mmiodescend (hfile, @ ckiriff, nil, mmio_findriff );

// After obtaining the data block information, the pointer automatically points to the starting point of the data, and then reads the data.
If (ckiriff. ckid = fourcc_riff) and
(Ckiriff. fcctype = mmiostringtofourcc ('wave ', 0) and
(Mmiodescend (hfile, @ ckidata, @ ckiriff, mmio_findchunk) = mmsyserr_noerror) then
Begin
Stream. Size: = ckidata. cksize;
Result: = (mmioread (hfile, stream. Memory, ckidata. cksize) = ckidata. cksize );
End;
Mmioclose (hfile, 0 );
End;

// Call the test
Procedure tform1.button1click (Sender: tobject );
Const
Filepath = 'C: \ windows \ media \ Windows XP start .wav ';
VaR
Stream: tmemorystream;
Begin
Stream: = tmemorystream. Create;

If getwavedata (filepath, stream) then
Showmessagefmt ('read data size: % d', [stream. Size]); {424600}

Stream. Free;
End;

6. Use tmediaplayer to record WAV Files

Tmediaplayer recording is based on an existing WAV file. The last blank WAV function created can be used. the tmediaplayer function is based on MCI and should be eliminated.
Next we will also learn how to use the wavein... Series Function recording and directsound recording.

 

7. multimedia function library bass. dll

Http://www.cnblogs.com/del/category/150851.html

Recently I want to write a small program that uses MP3 for playing. Because of the complicated control and functions, I think of Bass. dll.

Previously I thought that bass. dll is the Windows system comes with the library, and later I know that the original is a third-party: http://www.un4seen.com /.

Bass. dll has been updated, and the latest version is 2.411,: http://us2.un4seen.com/files/bass24.zip

There are three steps to do before using in Delphi:
1. Copy bass. DLL to a folder that can be recognized by the system, such as Windows \ system32, windows, WINDOWS \ SYSTEM, or any directory specified by the system or user's environment variable path, you can also put it in the current directory during Program Creation, put a folder and specify a path in the program.
2. Place the header file bass. PAS for Delphi in a directory (for example, c: \ Program Files \ codegear \ rad studio \ 6.0 \ imports \ bass24 ).
3, and then from the Delphi menu-> Tools-> options-> Library-Win32-> library path-> and then add this directory (example ).

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.