NAME
g721_encode g721_decode g721_init_state - CCITT G.721 audio
compression and decompression.
SYNOPSIS
#include <multimedia/libaudio.h>
int g721_encode(in_buf, in_size, header, out_buf, out_size, state_ptr)
void *in_buf;
int in_size;
Audio_hdr *header;
char *out_buf;
int *out_size;
struct audio_g72x_state *state_ptr;
int g721_decode(in_buf, in_size, header, out_buf, out_size, state_ptr)
char *in_buf;
int size;
Audio_hdr *header;
void *out_buf;
int *out_size;
struct audio_g72x_state *state_ptr;
void g721_init_state(state_ptr)
struct audio_g72x_state *state_ptr;
DESCRIPTION
These routines implement the CCITT G.721 standard for encod-
ing 8-bit u-law or A-law coded or 16-bit linear PCM audio
data as 4-bit Adaptive Differential Pulse Coded Modulated
(ADPCM) data. They provide 32 Kbps coding for 8KHz audio
data with little degradation in sound quality. The encode
and decode routines use a audio_g72x_state structure to
store state information between calls. An audio_g72x_state
structure must be initialized by calling g721_init_state().
This routine should also be used whenever there is a discon-
tinuity in the compressed data stream (for instance, if one
input/output file is closed and another is opened for
decoding/encoding).
The g721_encode() function encodes size bytes of input data
from the buffer pointed by in_buf. The encoding type of the
input data is given in the header structure. The compressed
ADPCM data is returned in out_buf, whose length (in bytes)
is returned in out_size. state_ptr points to the
audio_g72x_state structure for preserving encoding state.
The first 4-bit code is returned in the least significant
nibble of the first byte in the output buffer, while the
succeeding code is packed into the high order nibble. In
the event that the total number of nibbles in out_buf is
odd, the last unpairable nibble is saved in the state struc-
ture until the next invocation of g721_encode() - at which
time it is packed with the code from the first value in the
new input buffer. The output buffer specified by out_buf
must then contain at least (in_size + 1) / 2 bytes for u-law
or A-law input data and (in_size / 2) + 1) / 2 bytes for
linear PCM input data to accomodate the encoded output.
After the entire input signal is processed, the remaining
state structure should be flushed by calling g721_encode()
one more time with the in_size argument set to zero.
out_buf should refer to a valid output buffer to which up to
one byte of data may be written. If data is returned, the
final nibble of encoded data was paired with zero, which is
harmless when decoded.
The g721_decode() function expands 4-bit ADPCM data into
16-bit linear PCM or 8-bit u-law or A-law format. in_buf
specifies the address of a buffer containing in_size bytes
of ADPCM data. The data type of the decoded data is speci-
fied in the header structure. Decoded data is stored in the
buffer whose address is given by out_buf. The number of
decoded samples (not bytes!) is returned in out_size. The
output buffer must contain enough room to store (2 * size)
samples. state_ptr points to the audio_g72x_state structure
for preserving decoding state.
RETURN VALUE
g721_encode() and g721_decode() return the audio error codes
or AUDIO_SUCCESS.
SEE ALSO
audio_g711(3), audio_g723(3).
NOTES
These routines comprise an implementation of the CCITT G.721
ADPCM encoding algorithm. This implementation has passed
the test vectors furnished by CCITT (Dec. 20, 1988) for u-
law and A-law data.
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |