Windows audio processing

zhaozj2021-02-17  51

Process of audio under Windows

Windows

The processing of the audio is roughly divided into two parts, namely, the audio input, output, and

ACM

Compression processing.

In general

Windows

Can be called such as

SndplaySound

Wait

API (MCI)

To play one

WAV

File, but that is obviously not what we need to do. The audio stream must be processed directly. in

Windows

Next, it also provides a series of

API

To

Wavein

with

Waveout

Starting group

API

That is to do this.

Let's talk about it first. Commonly related

API

for

Waveinopen

(Open an audio input device),

Waveinprepareheader

(For a soon

Waveinaddbuffer

Input buffer prepare the head),

Waveinaddbuffer

(Add an input to the data buffer),

WaveInstart

(start recording),

WaveInClose

(Turning off audio input device), etc., and needs

Waveinopen

A callback function or thread specified in it is called to be called after a data buffer is recorded to process these data, and others related operations.

First you have to determine what callback mode you need, that is, after the audio data of a certain time film is completed,

Windows

The processing of these data will be activated through this callback, which is generally used.

FUNCTION

,

Thread

with

Event

These categories, and more convenient and simple

FUNCTION

with

Thread

.

FUNCTION

The way

Windows

Will call your function, and

Thread

Be

Windows

To activate the thread you specify. These are all

Waveinopen

Present specified. Its function prototype is:

MmResult Waveininken (lphwavein phwi, uint udeviceid, lpwaveformatex pwfx, dWord dwcallback, dword dwcallbackinstance, dword fdwopen);

among them:

PHWI

Is the end of the handle storage address,

UdeviceID

Is an audio device to open

Id

No., generally designated

WAVE_MAPPER

.

DWCallback

The address of the designated callback function or thread, etc.

FDWOPEN

Specify the callback mode,

DWCallbackInstance

To call back

User parameters sent by functions or threads. As for that one

PWFX

Then, the key is the key, it specifies what audio format opens the audio input device,

It is a structure

Waveformatex

:

Typedef struct {word wordettag; word nchannels; dword nsampletes; word nblockAlign; Word wbitsPersample; Word Cbsize;} Word CBSIZE;

Machine

Win9x

The audio compression is selected at the time of installation.

WFormattag

Specify some compressed audio formats, such as

G723.1

,

Ture DSP

, Etc. However, it is generally selected.

Waveformat_pcm

Format, an uncompressed audio format, as for compression, can call the following will be mentioned after recording

ACM

Elite.

NChannels is the number of channels,

1

or

2

.

Nsamplespersec

Sampling per second,

8000

,

11025

,

22050

,

44100

For a few standard values, other non-standard values ​​I have not tried it.

Navgbytespersec

For the average number of bytes per second,

PCM

Mode is equal to

NChannels * nsamplesperspec * wbitsPersample / 8

However, for other compressed audio formats, because many compression methods are carried out according to the time tablets, such as

G723.1

It is

30ms

For a compressed unit, so

Navgbytespersec

Just a probably figure, not accurate, the calculation in the program should not be subject to this amount. This is below the compressed audio output and

ACM

It is very important in audio compression.

NblockAlign

Is a relatively special value, indicating the minimum processing unit when the audio processing is

PCM

Non-compressed, it is

WBITSPERSMPLE * NCHANNELS / 8

And for the non-compression format, it is compressed

/

Unzip the minimum unit, such as

G723.1

It is

30ms

Data size (

20bytes

or

24bytes

).

WBITSPERSMPLE

The number of digits per sample value,

8

or

16

.

CBSIZE

It is said that

Waveformatex

How many bytes of bytes after the standard head, for many non-

PCM

Audio format, have some own definition format parameters, these are closely in standard

Waveformatex

Behind, its size is

CBSIZE

Specify. for

PCM

Format, for

0

Or ignore it.

In this way, after these parameters are specified, you should open the audio input device. The thing you have to do is preparing a few buffers that use the recording. Multiple buffers are often prepared and cycled in the callback. In addition, you have to consider the audio data that recorded, such as a temporary file, you have to prepare the handle of the file. For buffer, use

WaveinPerPareHeader

Prepare the head, this

API

It's relatively simple, if you are cycled using buffers, you only need to call each buffer.

Waveinprepareheader

.

After everything is ready, you can call

Waveinaddbuffer

with

WaveInstart

Start recording, as long as you call this

WaveInstart

The recording begins. Even after this buffer is recorded, you didn't join the new buffer in, the recording will not stop, but the speech data in this is lost. Pass

Waveinaddbuffer

After the buffer sent is recorded,

Windows

Will pass you

Waveinopen

The callback is made in the way, and the recorded voice data is taken out in the callback, and if you want to continue recording, you have to add the next buffer into it. Considering this processing is time delay, and the audio is very sensitive to time, usually must first prepare several buffers, for example, a total of a total definition

8

A buffer, and for insurance, it is best to ensure that at least

3

The buffer can be recorded, then add it when starting recording.

4

A buffer, then in the callback, if the current buffer is

n

Others

(N 4)% 8

transfer

Waveinaddbuffer

At this time, there is also the first

(N 1)% 8, (N 2)% 8, (N 3)% 8

These three buffers can be used, ie, can guarantee that there is no disconnected interval in the recorded audio.

Want to end recording, it is best

WaveInClose

Call before

WaveinReset

This can clear the buffer still waiting for the recording, and must pay attention to the type of message in the parameter in the callback.

The audio output is relatively simple. corresponding

API

Have

Waveoutopen

,

WaveoutPrepareHeader

,

Waveoutwrite

as well as

WaveoutClose

. If you want to directly output an audio of the compressed format, you must pay attention

Waveoutopen

The audio format parameters specified in the middle. You must be aware of the specific parameters of this type of format and its meaning. However, you can pass the following

ACM

(

Audio Compress Manager

) Get the specific parameters of the audio format you need, this format parameter can be used directly

Waveoutopen

. Like the input of audio,

WaveoutPrepareHeader

It is also necessary.

Waveoutwrite

It is to fill in the output buffer. In order to avoid interruption, it should also ensure that the number of buffer queues in a certain moment is sufficient.

If installed

Win98

When the audio compression is selected in the attachment, then on the machine

ACM

It can be used.

ACM

for

Audio Compress Manager

.

Win98

Provides some common audio compression algorithm package for user calls. able to pass

ACM

Get all audio compression drives on this unit and its supported audio format. However, it doesn't seem to be every

ACM

Format can be called to compress

,

but

ACM

Most of the compression drives are directed to the voice band. If the audio used to compress the frequency band, such as music, the effect is very poor.

.

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

New Post(0)