AudioHdr.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1992-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#ifndef _MULTIMEDIA_AUDIOHDR_H
#define _MULTIMEDIA_AUDIOHDR_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef NO_EXTERN_C
#ifdef __cplusplus
extern "C" {
#endif
#endif /* NO_EXTERN_C */
#include <AudioTypes.h>
#include <AudioError.h>
#include <audio_hdr.h>
// Required for the use of MAXSHORT
#include <values.h>
// Required by htons() and other network services.
// Define an in-core audio data header.
//
// This is different than the on-disk file header.
//
//
// The audio header contains the following fields:
//
// sample_rate Number of samples per second (per channel).
//
// samples_per_unit This field describes the number of samples
// represented by each sample unit (which, by
// definition, are aligned on byte boundaries).
// Audio samples may be stored individually
// or, in the case of compressed formats
// (e.g., ADPCM), grouped in algorithm-
// specific ways. If the data is bit-packed,
// this field tells the number of samples
// needed to get to a byte boundary.
//
// bytes_per_unit Number of bytes stored for each sample unit
//
// channels Number of interleaved sample units.
// For any given time quantum, the set
// consisting of 'channels' sample units
// is called a sample frame. Seeks in
// the data should be aligned to the start
// of the nearest sample frame.
//
// encoding Data encoding format.
//
//
// The first four values are used to compute the byte offset given a
// particular time, and vice versa. Specifically:
//
// seconds = offset / C
// offset = seconds * C
// where:
// C = (channels * bytes_per_unit * sample_rate) / samples_per_unit
// Define the possible encoding types.
// XXX - As long as audio_hdr.h exists, these values should match the
// corresponding fields in audio_hdr.h since the cast operator
// copies them blindly. This implies that the values should
// XXX - How can encoding types be added dynamically?
enum AudioEncoding {
NONE = 0, // no encoding type set
};
// The byte order of the data. This is only applicable if the data
// is 16-bit. All variables of this type will have the prefix "endian".
enum AudioEndian {
BIG_ENDIAN = 0, // Sun and network byte order
// by coerceEndian().
UNDEFINED_ENDIAN = -1
};
// Define a public data header structure.
// Clients must be able to modify multiple fields inbetween validity checking.
unsigned int sample_rate; // samples per second
unsigned int samples_per_unit; // samples per unit
unsigned int bytes_per_unit; // bytes per sample unit
unsigned int channels; // # of interleaved channels
AudioHdr(): // Constructor
{
// The default for files is BIG, but this is
// set in the AudioUnixfile class.
endian = localByteOrder();
}
{
// The default for files is BIG, but this is
// set in the AudioUnixfile class.
endian = localByteOrder();
}
// Determines the local byte order, otherwise know as the endian
// nature of the current machine.
AudioEndian localByteOrder() const;
// Conversion between time (in seconds) and byte offsets
// Round down a byte count to a sample frame boundary
// Conversion between time (in seconds) and sample frames
// Return the number of bytes in a sample frame for the audio encoding.
virtual unsigned int FrameLength() const;
// Return some meaningful strings. The returned char pointers
// must be deleted when the caller is through with them.
// Parse strings and set corresponding header fields.
// for casting to C Audio_hdr struct
return (hdr);
};
// compare two AudioHdr objects
{
// Audioconvert uses this method to see if a conversion should take
// place, but doesn't know how to convert between endian formats.
// This makes it ignore endian differences.
// (endian = tst.endian) &&
}
{
}
};
#ifdef NO_EXTERN_C
#ifdef __cplusplus
}
#endif
#endif /* NO_EXTERN_C */
#endif /* !_MULTIMEDIA_AUDIOHDR_H */