1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _MULTIMEDIA_AUDIO_HDR_H 28*7c478bd9Sstevel@tonic-gate #define _MULTIMEDIA_AUDIO_HDR_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 31*7c478bd9Sstevel@tonic-gate extern "C" { 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate /* 35*7c478bd9Sstevel@tonic-gate * Define an in-core audio data header. 36*7c478bd9Sstevel@tonic-gate * 37*7c478bd9Sstevel@tonic-gate * This is different that the on-disk file header. 38*7c478bd9Sstevel@tonic-gate * The fields defined here are preliminary at best. 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* 42*7c478bd9Sstevel@tonic-gate * The audio header contains the following fields: 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * endian Byte order of 16-bit or greater PCM, 45*7c478bd9Sstevel@tonic-gate * and possibly floating point data. 46*7c478bd9Sstevel@tonic-gate * 47*7c478bd9Sstevel@tonic-gate * sample_rate Number of samples per second (per channel). 48*7c478bd9Sstevel@tonic-gate * 49*7c478bd9Sstevel@tonic-gate * samples_per_unit This field describes the number of samples 50*7c478bd9Sstevel@tonic-gate * represented by each sample unit (which, by 51*7c478bd9Sstevel@tonic-gate * definition, are aligned on byte boundaries). 52*7c478bd9Sstevel@tonic-gate * Audio samples may be stored individually 53*7c478bd9Sstevel@tonic-gate * or, in the case of compressed formats 54*7c478bd9Sstevel@tonic-gate * (e.g., ADPCM), grouped in algorithm- 55*7c478bd9Sstevel@tonic-gate * specific ways. If the data is bit-packed, 56*7c478bd9Sstevel@tonic-gate * this field tells the number of samples 57*7c478bd9Sstevel@tonic-gate * needed to get to a byte boundary. 58*7c478bd9Sstevel@tonic-gate * 59*7c478bd9Sstevel@tonic-gate * bytes_per_unit Number of bytes stored for each sample unit 60*7c478bd9Sstevel@tonic-gate * 61*7c478bd9Sstevel@tonic-gate * channels Number of interleaved sample units. 62*7c478bd9Sstevel@tonic-gate * For any given time quantum, the set 63*7c478bd9Sstevel@tonic-gate * consisting of 'channels' sample units 64*7c478bd9Sstevel@tonic-gate * is called a sample frame. Seeks in 65*7c478bd9Sstevel@tonic-gate * the data should be aligned to the start 66*7c478bd9Sstevel@tonic-gate * of the nearest sample frame. 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * encoding Data encoding format. 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * data_size Number of bytes in the data. 71*7c478bd9Sstevel@tonic-gate * This value is advisory only, and may 72*7c478bd9Sstevel@tonic-gate * be set to the value AUDIO_UNKNOWN_SIZE 73*7c478bd9Sstevel@tonic-gate * if the data size is unknown (for 74*7c478bd9Sstevel@tonic-gate * instance, if the data is being 75*7c478bd9Sstevel@tonic-gate * recorded or generated and piped 76*7c478bd9Sstevel@tonic-gate * to another process). 77*7c478bd9Sstevel@tonic-gate * 78*7c478bd9Sstevel@tonic-gate * The first four values are used to compute the byte offset given a 79*7c478bd9Sstevel@tonic-gate * particular time, and vice versa. Specifically: 80*7c478bd9Sstevel@tonic-gate * 81*7c478bd9Sstevel@tonic-gate * seconds = offset / C 82*7c478bd9Sstevel@tonic-gate * offset = seconds * C 83*7c478bd9Sstevel@tonic-gate * where: 84*7c478bd9Sstevel@tonic-gate * C = (channels * bytes_per_unit * sample_rate) / samples_per_unit 85*7c478bd9Sstevel@tonic-gate * 86*7c478bd9Sstevel@tonic-gate * 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate typedef struct { 89*7c478bd9Sstevel@tonic-gate unsigned sample_rate; /* samples per second */ 90*7c478bd9Sstevel@tonic-gate unsigned samples_per_unit; /* samples per unit */ 91*7c478bd9Sstevel@tonic-gate unsigned bytes_per_unit; /* bytes per sample unit */ 92*7c478bd9Sstevel@tonic-gate unsigned channels; /* # of interleaved channels */ 93*7c478bd9Sstevel@tonic-gate unsigned encoding; /* data encoding format */ 94*7c478bd9Sstevel@tonic-gate unsigned endian; /* byte order */ 95*7c478bd9Sstevel@tonic-gate unsigned data_size; /* length of data (optional) */ 96*7c478bd9Sstevel@tonic-gate } Audio_hdr; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * Define the possible encoding types. 100*7c478bd9Sstevel@tonic-gate * Note that the names that overlap the encodings in <sun/audioio.h> 101*7c478bd9Sstevel@tonic-gate * must have the same values. 102*7c478bd9Sstevel@tonic-gate */ 103*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_NONE (0) /* No encoding specified ... */ 104*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */ 105*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */ 106*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */ 107*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_FLOAT (100) /* IEEE float (-1. <-> +1.) */ 108*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G721 (101) /* CCITT g.721 ADPCM */ 109*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G722 (102) /* CCITT g.722 ADPCM */ 110*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G723 (103) /* CCITT g.723 ADPCM */ 111*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */ 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate /* 114*7c478bd9Sstevel@tonic-gate * Define the possible endian types. 115*7c478bd9Sstevel@tonic-gate */ 116*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_BIG 0 /* SPARC, 68000, etc. */ 117*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_SMALL 1 /* Intel */ 118*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_UNKNOWN 2 /* Unknown endian */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* Value used for indeterminate size (e.g., data passed through a pipe) */ 121*7c478bd9Sstevel@tonic-gate #define AUDIO_UNKNOWN_SIZE ((unsigned)(~0)) 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* Define conversion macros for integer<->floating-point conversions */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* double to 8,16,32-bit linear */ 127*7c478bd9Sstevel@tonic-gate #define audio_d2c(X) ((X) >= 1. ? 127 : (X) <= -1. ? -127 : \ 128*7c478bd9Sstevel@tonic-gate (char)(rint((X) * 127.))) 129*7c478bd9Sstevel@tonic-gate #define audio_d2s(X) ((X) >= 1. ? 32767 : (X) <= -1. ? -32767 :\ 130*7c478bd9Sstevel@tonic-gate (short)(rint((X) * 32767.))) 131*7c478bd9Sstevel@tonic-gate #define audio_d2l(X) ((X) >= 1. ? 2147483647 : (X) <= -1. ? \ 132*7c478bd9Sstevel@tonic-gate -2147483647 : \ 133*7c478bd9Sstevel@tonic-gate (long)(rint((X) * 2147483647.))) 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* 8,16,32-bit linear to double */ 136*7c478bd9Sstevel@tonic-gate #define audio_c2d(X) (((unsigned char)(X)) == 0x80 ? -1. : \ 137*7c478bd9Sstevel@tonic-gate ((double)((char)(X))) / 127.) 138*7c478bd9Sstevel@tonic-gate #define audio_s2d(X) (((unsigned short)(X)) == 0x8000 ? -1. :\ 139*7c478bd9Sstevel@tonic-gate ((double)((short)(X))) / 32767.) 140*7c478bd9Sstevel@tonic-gate #define audio_l2d(X) (((unsigned long)(X)) == 0x80000000 ? -1. :\ 141*7c478bd9Sstevel@tonic-gate ((double)((long)(X))) / 2147483647.) 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate #endif 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIO_HDR_H */ 148