Delphi multimedia design-tmediaplayer component (4)

Source: Internet
Author: User
Recording wave audio)

Recording waveform audio is not as straightforward as you might think. Perhaps all you think is to call the startrecording method. However, because of the tmediaplayer problem, it is not that simple.

To record a waveform file, you must first open an existing waveform file, which has the same recording parameters as the new file you want, and then start recording the new waveform file, changing the filename attribute is a new file name and saving the file. This is a bit clumsy, but it works.

For example, assume that a file named test.wav is recorded in a single-channel waveform format with a sampling rate of 16 bits at 8000Hz. You can click the recording waveform audio button as shown in the following code:

Procedure tform1.btn6click (Sender: tobject); begin with mpplayer do begin {set the filename attribute to the test.wav file and obtain the recording parameter information} filename: = 'test.wav '; {open device} open; {start recording} Wait: = false; startrecording; end;

At this time, the recording has started and the control has returned to the application. Now you need to stop recording, which can be done by the second stop button, as shown below:

Procedure tform1.btn7click (Sender: tobject); begin with mpplayer do begin {stop recording} Stop; {change the filename attribute to a new file name for saving to the hard disk} filename: = 'new.wav '; {save and close file} Save; close; end;

The sample program interface is as follows:

Note

In the above compilation process, due to the fault in the tmediaplayer, these steps are necessary for recording waveform audio. The tmediaplayer recording is based on an existing WAV file. The tmediaplayer function is based on MCI and should be eliminated, but we still need to understand it.

Factors that control waveform audio recording include the number of sampling digits (usually 8 or 16), the sampling frequency, and the number of audio channels. Generally, the sampling frequency is 8000 kHz, 11025 kHz, 44100 kHz, and kHz, the higher the sampling frequency, the better the recording quality. In most cases, the user may not use stereo unless the game program is designed. Even if the game program is designed, use stereo sound as needed. The number of sampling digits is also the image recording quality.

Note

The better the sound quality, the more disk space occupied by recording waveform audio files. The size of a stereo recording file is twice that of a single-channel recording file. Similarly, the size of a 16-bit file with the number of sampling digits doubles the size of the 8-bit file with the number of sampling digits. An 8-bit recording file with 22050 kHz and single-channel sampling digits may be 200 kb, the size of the same file recorded at 22050 kHz, stereo, and 16-bit sampling will be 800 KB. In most cases, stereo and 16-bit sampling are not necessarily cost-effective as compared to the extra disk space required by it. Weigh the sound quality and file size. It is a good choice for Waveform files with 22050 kHz, single channel, and 8-bit sampling.

The above code passes the test in Delphi 7. Download the sample code: tmediaplayer.rar

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.