VC call ACM audio compression programming interface

zhaozj2021-02-08  218

Audio and video data are the main way of providing information to users, which typically have a higher sampling rate. If it is not compressed, save them need to consume a lot of storage space, transmitted on the network. The efficiency is also very low, so audio video digital compression encoding is an important position in multimedia technology. For audio data, there are many commonly used compression methods, and different methods have different compression ratios and reduction sound quality, and the formats and algorithms of encoding are different, and some compression algorithms are quite complicated, and ordinary procedures are impossible to go Implement its codec algorithm. Fortunately, Windows 95 / NT 4.0 provides stronger support for multimedia applications compared to Windows 3.x, introducing ACM (Audio Compression Manager, Audio Manager) and VCM (Video Compression Manager, Video Compression Manager), they are responsible for managing all audio and video codecs in the system (CODER-DECODER, referred to as CODEC, is a driver for audio video data codec), the application can call these systems via the programming interface provided by ACM or VCM Among the ready-made codecs to achieve compression and decompression of audio or video data. 95 / NT 4.0 Series from the belt audio CODECS supports a number of audio data compression standards, such as ADPCM, etc., Internet Explorer 4.0, etc. The audio CODECs containing a new compression compatible, such as MPEG Layer 3, etc. Select "high" in the multimedia component of the control panel, open the "audio compression codec", and list all audio CODECs installed in the system. What is going to be described herein is the programming method of the ACM audio compression interface, the programmed tool used to be VC 5.0.

Take CODECS information

---- ACM's API function definitions in header file MSACM.H, in addition to this, the ACM programming must also contain header files MMSystem.h, mmreg.h, which defines the most basic programming in multimedia programming. Constants and data structures. For the avoidance of the function and function of some high version of the ACM, the ACMGETVERSION function checks the version of the ACM in the apartment in the program.

---- Previously, you can view the information of CODECs in the system in the control panel, and often need to know if some kind of audio CODECS exists and obtain its codec parameter, which can be called. The following two functions are implemented. ---- MMRESULT MMR = ACMMETRICS (NULL, ACM_METRIC_COUNT_CODECS, & DWCODECS);

---- MMR = AcmdriveRenum (CodecsenumProc, 0, 0);

---- ACMMETRICS () function can get a useful information of a multi-ACM object, such as the total number of audio CODECs installed in the query system in the query system. Function acmdriveRenum () The function of enumeration is the audio codecs, which specifies the reply function codecsenumProc () in the parameter of acmdriverenum (). The Windows programming is often used to use the backup function, and the next is an example of a backup function of the audio CODECS.

Bool Callback CodeCsenumProc (HacmdriverId

Hadid, DWORD DWINSTANCE, DWORD FDWSUPPORT) {

DWORD DWSIZE = 0;

IF (fdwsupport & acmdriverdetails_supportf_codec)

Printf ("multi-format conversion / N");

Acmdriverdetails add;

Acmdd.cbstruct = sizeof (acmdd);

MmResult MMR = AcmdriverDetails (Hadid, & ACMDD, 0);

IF (MMR) Error_MSG (MMR);

Else {

Printf ("full name:% s / n", acmdd.szlongname);

Printf ("Description:% S / N", acmdd.szfeatures;

}

Hacmdriver Had = NULL;

MMR = acmdriveropen (& had, hadid, 0); // Open the driver

IF (MMR) Error_MSG (MMR);

Else {

MMR = ACMMETRICS (Had, ACM_METRIC_

MAX_SIZE_FORMAT, & DWSIZE);

Waveformatex * pwf = (Waveformatex *) Malloc (dwsize);

MEMSET (PWF, 0, DWSIZE);

PWF-> cbsize = loword (dwsize) - Sizeof (Waveformatex);

PWF-> wformattag = Wave_Format_unknown;

ACMFORMATDETAILS FD;

MEMSET (& fd, 0, sizeof (fd));

Fd.cbstruct = sizeof (fd); fd.pwfx = pwf; fd.cbwfx = dwsize;

fd.dwformattag = Wave_FORMAT_UNKNOWN;

MMR = ACMFORMATENUM (HAD, & FD, FORMATENUMPROC, 0, 0);

IF (mmr) error_msg (mmr); Free (PWF);

Acmdriverclose (HAD, 0);

}

Return True;

}

---- CODECSENUMPROC () has three parameters. The first parameter is the ID value of the driver; the second parameter is an instance data, and is not used in this example; the third parameter describes the functions supported by the driver, which is made by a set of identities or calculations, for example, If the identifier acmdriverdetails_supportf_codec is set, the driver will explain that the audio signal in the encoding format is converted into another encoding format. A information on the driving process can be obtained by the acmdriverdetails () function, such as the name of CODEC, simply described. The upper information is actually collected by the ACM, and the inside of the ACM is saved, so it is not really added to the memory when the query is notified. To get the audio format information supported by each driver, you must load the driver to memory, which is completed by acmdriveropen (), before exiting CODECSENUMPROC (), it also uses acmdriverclose () to close the opened driver. Before using the audio format enumeration function, you must first assign a buffer storage format information, and the large minus-free call acmmetrics () check ACM_METRIC_MAX_SIZE_FORMAT is obtained, the audio format identification in the format is set to Wave_Format_unkNown. The callback function is used in the audio format enumeration, which is just listed in the name and identity of the audio format.

Bool Callback FormatenumProc

(Hacmdriverid Hadid, LPACMMMATDETAILS

PAFD, DWORD DWINSUPPORT) {

Printf ("% 4.4LXH,% S / N", PAFD-> DWFORMATTAG, PAFD-> SZFORMAT);

Return True;

}

---- The above introduces all audio CODECs in the browsing system and the audio format supported by each CODEC. Some typical applications may need to list all the CODECs that can be selected in the system, and is used by the user Which A CODEC is compressed, and the above programming method is required to obtain information of CODECS.

Audio data compression

---- Next, use a CODEC real audio compression, reader friends can write the correction process. The source signal is 8K sample, a 16bits PCM code, a single channel, a length of 1 second. The drive program uses Windows 95's own TrueSpeech audio CODEC, which can be compressed by about 10: 1. In this example, TrueSpeech Codec supports conversion from source audio formats to target format, and in practical applications, some CODEC may not support directing source audio format into target format, then take two-step conversion method, ie First convert the source format into an intermediate format, then convert this intermediate format into a target format, because linear PCM encoding is the most simple, and is supported by most CODECs, so in general intermediate formats are selected as a linear PCM format. ---- First, you need to determine the ID value of the TrueSpeech driver program before the compression is compressed. For this purpose, the AcmdriveRenum () function is required, and each driver that enumerates, the callback function specified by the acmdriverenum () will check all the audio formats supported. The driver is to find Truespeech Codec, which is supported in the first WAVE_FORMAT_DSPGROUP_TRUESPEECH audio format is the target audio compression format. Check the CODEC and its supported audio format of the audio format. See the previous section.

---- According to the results of the query, Hadid is the ID value of Truespeech Codec, and the PWFDRV is a pointer to the target Waveformatex structure, which is subjected to the obtained drive program.

Hacmdriver Had = NULL;

MMR = ACMDRIVEROPEN (& Had, Hadid, 0);

IF (MMR) {Printf ("Open Driver Failure / N"); Exit (1);}

---- Compression and decompression, it is to convert the audio signal from one audio format into another form, to finish this process, first to open the conversion stream. When you open the converted flow with AcStreamopen, we specify the ACM_STREAMOPENF_NONREALTIME flag, which indicates that the conversion does not need to be in real time. Because the calculation of the calculation algorithm is a larger, it is very uncomfortable. For example, in this example, if the results are not specified, Truespeech Codec will return "unmanaged" error.

Hacmstream HSTR = NULL;

DWORD DWSRCBYTES = DWSRCSAMPLES * WFSRC.WBITSPERSAMPLE / 8; MMR = ACMSTREAMOPEN (& HSTR, HAD, // Driver Handle

PWFSRC, / / ​​Pointers to the source audio format

PWFDRV, // Pointer to target audio format

NULL, // no filter

NULL, // Non-return function

0, acm_streamopenf_nonRealTime);

---- Before the truth-to-active conversion, you must have to prepare the message head of the conversion stream. In the next code, the large-sized data of the source data and the average data rate of the target format estimate the cache area of ​​the target data, and then the ACMSTREAMPREPAREHEADER is the transformation of the message header.

---- DWORD DWDSTBYTES = PWFDRV-> NavgBytesPersec * dwsrcsamples / wfsrc.nsamplespess;

---- DWDSTBYTES = DWDSTBYTES * 3/2; // The audio data is small after calculating the compression, and the size of the output buffer area is added.

BYTE * pdstdata = new byte [dwdstbytes];

ACMSTreamheader Shdr;

MEMSET (& strHDR, 0, SIZEOF (SHDR));

SHDR.cBStruct = SizeOf (SHDR);

SHDR.PBSRC = psrcdata; // Source audio data area

SHDR.CBSRCLENGTH = DWSRCBYTES;

SHDR.PBDST = PDSTDATA; / / Compressed audio data buffer

SHDR.CBDSTLENGTH = DWDSTBYTES;

MMR = ACMSTREAMPREPAREHEADER (HSTR, & SHDR, 0);

---- Voice data is the true compression process is made of functional ACMSTREAMCONVERT (). When you call acmstreamConvert (), you can specify the reply function to display the progress information in the conversion process. In this example, the return function is not specified, but only the end of the compression is simply contracted.

---- MMR = ACMSTREAMCONVERT (HSTR, & SHDR, 0);

---- After the data is compressed, the application can be written to the data in the buffer zone.

---- Ultimate, you must turn off the conversion flow and drive.

MMR = acmstreamclose (HSTR, 0);

MMR = acmdriverclose (HAD, 0);

----

this

Text

Die

Sumptuous

In

Profit

use

ACM

Get

take

sound

frequency

CODEC

of

letter

interest

In

and

real

Now

sound

frequency

Press

Shrink

of

One

Be

square

law

with

Pass

Process,

Correct

ACM

Compose

Approach

sense

Be

interest

of

read

By

can

In

Enter

One

step

Participate

test

VC 5

of

Jointly

machine

help

help

in

turn off

in

ACM

of

letter

interest.

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

New Post(0)