Communicate sound in Internet

zhaozj2021-02-08  369

- Using Audio Compression Manager (ACM)

Author / Peter Morris Translation / Chen

In the past few years, IP phones were fried boiling, but they used people feel that this technology is very immature, the voice quality is very poor, and the time is time, and there is often a delay. As a result, the application of this technology is not popular. However, with the increasing wider range of Internet applications, the sound quality of the related technologies is constantly increasing. It is no longer a dream through the internet. It has become a part of our life. Today I use IP phone to lead, only 3 cents per minute, use OICQ's voice chat, netizens seem to be by your side. If our bandwidth is enough, we can even watch the QuickTime video broadcast on the Internet, listen to the radio broadcast with Reaudio, or to inform the MP3 song. However, for programmers, better news is what we have more and more easily programmed for these media streams. Why do you say this, let's take a look at CODEC.

CODECS

What is CODECS? In fact, it is an audio compression decoder, which is actually a bit similar to ActiveX control. The ActiveX control allows the programmer to call some other people to achieve good features without doing from the head. Codecs provide a similar feature, but it focuses on how to convert the media format. For example, if you want to write an application that turn your CD to MP3, we just need to do the following:

l Reads data from the CD track.

l Generate an effective MP3 file header.

l Call the corresponding CODEC to encode the track data to MP3.

Windows itself has brought a lot of CODEC. Here are a few of the descriptions:

name

Description

GSM

It seems to be used for some mobile phone networks.

DSP TRUESPEECH

A one-piece sound format can be generated for voice calls - the sound is very clear.

Fraunhoffer IIS MP3

This can be used to generate an MP3 format.

PCM

Used to generate a Windows standard sound format. Most CODEC supported sound formats can be transformed with it.

A complete list of currently installed CODECs can be obtained by viewing the part of the multimedia in the control panel.

ACM API

ACM is an abbreviation of "Audio Compression Manager", translated is the sound compression manager. It is Microsoft's interface functions for calling the CODEC function. It should have declared in the MMSystem.Pas unit, but because some causes of Borland will omit it. So the first thing we have to make is to find its API declaration unit MSACM.PAS. You must thank Francois Piette, he shared the unit files he converted, we can download it from www.delphi-jedi.org.

Using the ACM conversion media format includes the following steps:

l First, you must specify the input and output format, we need to set a TWAVEFormatex record, but this structure record is too small to accommodate the information required by most CODEC. In order to solve this problem, we use a custom Tacmformat record, which adds 128 bytes on the basis of TWAVEFormatex.

l Open an ACM stream. First call the ACMSTreamopen function, pass the input and output format as a parameter to the past. The ACM then returns an effective handle or returns an error code (such as an acmer_notpossible) to indicate that the conversion request cannot be completed.

l Next To determine the size of the output buffer. Calling the acmstreamsize function notifies the ACM Each time we will generate how many bytes of data, then the function returns a buffer request size (we should always overestimate the size to ensure a sufficiently large buffer). L then, we have to generate a converted head. You need to call the ACMSTREAMPREPAREHEADER function, and the flow script that is previously called the ACMSTREAMOPEN function is called as a parameter. The generated conversion head tells the ACM source buffer and the address of the destination buffer. ACM does not automatically assign memory, we must apply for memory yourself.

l All preparations are basically completed, only how to convert data. This is very simple, just call the ACMSTREAMCONVERT function. The parameters of the ACMSTREAMCONVERT function include flowers and conversion headers. This function indicates the number of bytes truly used during the conversion process by setting the CBDSTLEngthUses in the conversion header.

l Once the ACM session is completed, we must release all resources used. The conversion head is released by the ACMStreamUnpreprePreheader function, and the flow of acmstreamClose is turned off.

Select format

As mentioned earlier, you must set the input and output format before starting the conversion. TWAVEFormatex record (declared in the MMSystem.Pas unit), which specifies the bit rate, frequency, and the like. Unless we only intend to convert between different PCM formats, TWAVEFORMATEX is not enough. Here is its alternative format:

Tacmwaveformat = Packed Record

Case Integer of

0: (Format: TWAVEFORMATEX);

1: (Rawdata: array [0..128] of byte);

END;

This variant record allows us to still read TWAVEFORMATEX structure data, while Rawdata provides adequate space to accommodate additional information required for other CODEC.

Although we don't know the size of additional information, we can use the ACMFORMAMATCHOOSE function to get.

The acmformatchoose function requires only a TACMMMatchA type of parameters. This parameter is a simple structure that can include the following information:

member

Description

转载请注明原文地址:https://www.9cbs.com/read-787.html

New Post(0)