Table of Contents

NAME

QccChannel - generic data structure for channel of indices

SYNOPSIS

#include "libQccPack.h"

int QccChannelInitialize(QccChannel *channel);
int QccChannelAlloc(QccChannel *channel);
void QccChannelFree(QccChannel *channel);
int QccChannelGetBlockSize(const QccChannel *channel);
int QccChannelPrint(const QccChannel *channel);

DESCRIPTION

QccPack provides data structure QccChannel for representing a generic channel of channel symbols. These channel symbols, which are inherently nonnegative integers, are typically the output of a quantizer (see QccPackSQ(3) , QccPackVQ(3) ). The QccChannel channel structure can be read from and written to CHN-format files, or a QccChannel structure can be used without file input or output.

The main component of a QccChannel structure is a list of channel symbols. For file input and output, this symbol list is the current block of symbols being written to or read from the file. That is, access to CHN-format files is block-based, with a block of symbols being written or read at once. Optionally, the block size can be set to be the same as the file size, so that all symbols in the channel are accessed simultaneously. QccChannel channels that do not involve file access typically hold all symbols of the channel in the symbol list.

Channel symbols are nonnegative integers drawn from a channel-symbol alphabet. The QccChannel structure possesses a field (see below) that gives the size of this alphabet; the channel-symbol alphabet is then the integers 0 through alphabet_size - 1, although not all of these symbols necessary appear in any given channel. Additionally to this alphabet of symbols, there exists a special null symbol, QCCCHANNEL_NULLSYMBOL, defined as -1, that indicates the absence of a symbol in the channel.

DATA STRUCTURE

The QccChannel data structure is defined as:

typedef struct
{
QccString filename;
FILE *fileptr;
QccString magic_num;
int major_version;
int minor_version;
int channel_length;
int access_block_size;
int num_blocks_accessed;
int alphabet_size;
int *channel_symbols;
} QccChannel;

The fields of QccChannel are as follows:

filename
For channels associated with a file, this is the name of the file.
fileptr
For channels associated with an open file, this is the FILE pointer.
magic_num, major_version, minor_version
For channels associated with a file, these are the magic number and version of the file.
channel_length
The total number of symbols contained in the channel.
access_block_size
For channels associated with a file, this is the number of symbols that will be read or written at a time; i.e., the block size for block-based reading and writing.
num_blocks_accessed
For channels associated with a file, this is the number of blocks of symbols that have already been read or written.
alphabet_size
the number of possible channel symbols (not including the special null symbol). It is assumed that the alphabet of possible channel symbols is the integers 0 through alphabet_size - 1.
channel_symbols
The current block of symbols from the channel; this array contains access_block_size symbols.

FILE FORMAT

For reading and writing structures of type QccChannel, QccPack provides the CHN file format. This file format starts with an ASCII header followed by ASCII data. The ASCII header consists of magic-number/revision information followed by any amount of white space (space, `\t' (tab), `\n' (newline), `\r' (return)) and/or comments lines (lines starting with `#'). Following this white space, additional ASCII header information is given, separated by blanks and newlines. ASCII data follows the header information.

The CHN file format consists of the following information:

CHNX.X
<white space>
N
A
C1
C2
.
.
.

where CHN is the magic number, X.X is the version number, <white space> is white space and/or comment lines, N is the length of the channel, A is size of the channel alphabet, and Ci is the ith channel symbol. N, A, and Ci are integers and are stored as ASCII.

ROUTINES

QccChannelInitialize() should be called before any use of a QccChannel structure. QccChannelInitialize() initializes the fields of channel to the following values:

filename: NULL string
magic_num: QCCCHANNEL_MAGICNUM
major_version, minor_version: initialized to output of QccGetQccPackVersion(3)
channel_length: 0
access_block_size: QCCCHANNEL_ACCESSWHOLEFILE
num_blocks_accessed: 0
alphabet_size: 0
channel_symbols: NULL

QccChannelAlloc() allocates storage space for the channel_symbols array of channel. If channel_symbols is not NULL, QccChannelAlloc() returns immediately without changing the state of any memory allocation. Otherwise, the channel_symbols array is allocated. The fields access_block_size and channel_length must be defined prior to calling QccChannelAlloc(). If access_block_size equals QCCCHANNEL_ACCESSWHOLEFILE, then space for channel_length symbols is allocated; otherwise, space for access_block_size symbols is allocated.

QccChannelFree() frees the channel_symbols array previously allocated by QccChannelAlloc() .

QccChannelGetBlockSize() returns the block size of the channel_symbols array of channel. If access_block_size is QCCCHANNEL_ACCESSWHOLEFILE, channel_length is returned; otherwise, access_block_size is returned.

QccChannelPrint() prints the contents of channel to stdout.

RETURN VALUE

Except for QccChannelGetBlockSize(), each of these routines return 0 upon successful completion, 1 on error.

SEE ALSO

QccGetQccPackVersion(3) , QccChannelRead(3) , QccChannelWrite(3) , QccPack(3)

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads