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 #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * Define an in-core audio data header. 38*7c478bd9Sstevel@tonic-gate * 39*7c478bd9Sstevel@tonic-gate * This is different that the on-disk file header. 40*7c478bd9Sstevel@tonic-gate * The fields defined here are preliminary at best. 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate /* 44*7c478bd9Sstevel@tonic-gate * The audio header contains the following fields: 45*7c478bd9Sstevel@tonic-gate * 46*7c478bd9Sstevel@tonic-gate * endian Byte order of 16-bit or greater PCM, 47*7c478bd9Sstevel@tonic-gate * and possibly floating point data. 48*7c478bd9Sstevel@tonic-gate * 49*7c478bd9Sstevel@tonic-gate * sample_rate Number of samples per second (per channel). 50*7c478bd9Sstevel@tonic-gate * 51*7c478bd9Sstevel@tonic-gate * samples_per_unit This field describes the number of samples 52*7c478bd9Sstevel@tonic-gate * represented by each sample unit (which, by 53*7c478bd9Sstevel@tonic-gate * definition, are aligned on byte boundaries). 54*7c478bd9Sstevel@tonic-gate * Audio samples may be stored individually 55*7c478bd9Sstevel@tonic-gate * or, in the case of compressed formats 56*7c478bd9Sstevel@tonic-gate * (e.g., ADPCM), grouped in algorithm- 57*7c478bd9Sstevel@tonic-gate * specific ways. If the data is bit-packed, 58*7c478bd9Sstevel@tonic-gate * this field tells the number of samples 59*7c478bd9Sstevel@tonic-gate * needed to get to a byte boundary. 60*7c478bd9Sstevel@tonic-gate * 61*7c478bd9Sstevel@tonic-gate * bytes_per_unit Number of bytes stored for each sample unit 62*7c478bd9Sstevel@tonic-gate * 63*7c478bd9Sstevel@tonic-gate * channels Number of interleaved sample units. 64*7c478bd9Sstevel@tonic-gate * For any given time quantum, the set 65*7c478bd9Sstevel@tonic-gate * consisting of 'channels' sample units 66*7c478bd9Sstevel@tonic-gate * is called a sample frame. Seeks in 67*7c478bd9Sstevel@tonic-gate * the data should be aligned to the start 68*7c478bd9Sstevel@tonic-gate * of the nearest sample frame. 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * encoding Data encoding format. 71*7c478bd9Sstevel@tonic-gate * 72*7c478bd9Sstevel@tonic-gate * data_size Number of bytes in the data. 73*7c478bd9Sstevel@tonic-gate * This value is advisory only, and may 74*7c478bd9Sstevel@tonic-gate * be set to the value AUDIO_UNKNOWN_SIZE 75*7c478bd9Sstevel@tonic-gate * if the data size is unknown (for 76*7c478bd9Sstevel@tonic-gate * instance, if the data is being 77*7c478bd9Sstevel@tonic-gate * recorded or generated and piped 78*7c478bd9Sstevel@tonic-gate * to another process). 79*7c478bd9Sstevel@tonic-gate * 80*7c478bd9Sstevel@tonic-gate * The first four values are used to compute the byte offset given a 81*7c478bd9Sstevel@tonic-gate * particular time, and vice versa. Specifically: 82*7c478bd9Sstevel@tonic-gate * 83*7c478bd9Sstevel@tonic-gate * seconds = offset / C 84*7c478bd9Sstevel@tonic-gate * offset = seconds * C 85*7c478bd9Sstevel@tonic-gate * where: 86*7c478bd9Sstevel@tonic-gate * C = (channels * bytes_per_unit * sample_rate) / samples_per_unit 87*7c478bd9Sstevel@tonic-gate * 88*7c478bd9Sstevel@tonic-gate * 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate typedef struct { 91*7c478bd9Sstevel@tonic-gate unsigned sample_rate; /* samples per second */ 92*7c478bd9Sstevel@tonic-gate unsigned samples_per_unit; /* samples per unit */ 93*7c478bd9Sstevel@tonic-gate unsigned bytes_per_unit; /* bytes per sample unit */ 94*7c478bd9Sstevel@tonic-gate unsigned channels; /* # of interleaved channels */ 95*7c478bd9Sstevel@tonic-gate unsigned encoding; /* data encoding format */ 96*7c478bd9Sstevel@tonic-gate unsigned endian; /* byte order */ 97*7c478bd9Sstevel@tonic-gate unsigned data_size; /* length of data (optional) */ 98*7c478bd9Sstevel@tonic-gate } Audio_hdr; 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate /* 101*7c478bd9Sstevel@tonic-gate * Define the possible encoding types. 102*7c478bd9Sstevel@tonic-gate * Note that the names that overlap the encodings in <sun/audioio.h> 103*7c478bd9Sstevel@tonic-gate * must have the same values. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_NONE (0) /* No encoding specified ... */ 106*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */ 107*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */ 108*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */ 109*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_FLOAT (100) /* IEEE float (-1. <-> +1.) */ 110*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G721 (101) /* CCITT g.721 ADPCM */ 111*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G722 (102) /* CCITT g.722 ADPCM */ 112*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_G723 (103) /* CCITT g.723 ADPCM */ 113*7c478bd9Sstevel@tonic-gate #define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */ 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate /* 116*7c478bd9Sstevel@tonic-gate * Define the possible endian types. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_BIG 0 /* SPARC, 68000, etc. */ 119*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_SMALL 1 /* Intel */ 120*7c478bd9Sstevel@tonic-gate #define AUDIO_ENDIAN_UNKNOWN 2 /* Unknown endian */ 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* Value used for indeterminate size (e.g., data passed through a pipe) */ 123*7c478bd9Sstevel@tonic-gate #define AUDIO_UNKNOWN_SIZE ((unsigned)(~0)) 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* Define conversion macros for integer<->floating-point conversions */ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* double to 8,16,32-bit linear */ 129*7c478bd9Sstevel@tonic-gate #define audio_d2c(X) ((X) >= 1. ? 127 : (X) <= -1. ? -127 : \ 130*7c478bd9Sstevel@tonic-gate (char)(rint((X) * 127.))) 131*7c478bd9Sstevel@tonic-gate #define audio_d2s(X) ((X) >= 1. ? 32767 : (X) <= -1. ? -32767 :\ 132*7c478bd9Sstevel@tonic-gate (short)(rint((X) * 32767.))) 133*7c478bd9Sstevel@tonic-gate #define audio_d2l(X) ((X) >= 1. ? 2147483647 : (X) <= -1. ? \ 134*7c478bd9Sstevel@tonic-gate -2147483647 : \ 135*7c478bd9Sstevel@tonic-gate (long)(rint((X) * 2147483647.))) 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 8,16,32-bit linear to double */ 138*7c478bd9Sstevel@tonic-gate #define audio_c2d(X) (((unsigned char)(X)) == 0x80 ? -1. : \ 139*7c478bd9Sstevel@tonic-gate ((double)((char)(X))) / 127.) 140*7c478bd9Sstevel@tonic-gate #define audio_s2d(X) (((unsigned short)(X)) == 0x8000 ? -1. :\ 141*7c478bd9Sstevel@tonic-gate ((double)((short)(X))) / 32767.) 142*7c478bd9Sstevel@tonic-gate #define audio_l2d(X) (((unsigned long)(X)) == 0x80000000 ? -1. :\ 143*7c478bd9Sstevel@tonic-gate ((double)((long)(X))) / 2147483647.) 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate #endif 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIO_HDR_H */ 150