10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*10400SJimmy.Vetayases@Sun.COM * Common Development and Distribution License (the "License"). 6*10400SJimmy.Vetayases@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*10400SJimmy.Vetayases@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * This header file defines the .wav audio file format. 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _WAV_H 310Sstevel@tonic-gate #define _WAV_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * Define the on-disk audio file header for the .wav file format. 410Sstevel@tonic-gate * By definition .wav files are little endian. Macros are provided 420Sstevel@tonic-gate * to make the conversion easier. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * The .wav format is one of the variations of the RIFF format. To 450Sstevel@tonic-gate * that end it contains a RIFF header chunk, a type chunk, a format 460Sstevel@tonic-gate * chunk, and then one or more data chunks. The following illustrates 470Sstevel@tonic-gate * the format: 480Sstevel@tonic-gate * 490Sstevel@tonic-gate * RIFF <Length of data> RIFF header chunk 500Sstevel@tonic-gate * WAVE type chunk 510Sstevel@tonic-gate * fmt<sp> format chunk 520Sstevel@tonic-gate * DATA <Length of data> <data> data chunk (one or more) 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * Since the RIFF headers never change for a .wav file there's no real reason 550Sstevel@tonic-gate * to separate the header into the different chunks. Thus a single header 560Sstevel@tonic-gate * structure is defined for the header. 570Sstevel@tonic-gate * 580Sstevel@tonic-gate * When building a .wav header the size of the data isn't always known. 590Sstevel@tonic-gate * The following define is used for that situation. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate #define AUDIO_WAV_UNKNOWN_SIZE (~0) 620Sstevel@tonic-gate 630Sstevel@tonic-gate struct wav_filehdr { 640Sstevel@tonic-gate uint32_t wav_riff_ID; /* RIFF file ID */ 650Sstevel@tonic-gate int32_t wav_riff_size; /* size of file - wav_riff* */ 660Sstevel@tonic-gate uint32_t wav_type_ID; /* file type ID */ 670Sstevel@tonic-gate uint32_t wav_fmt_ID; /* format ID */ 680Sstevel@tonic-gate uint32_t wav_fmt_size; /* size of wav_fmt_*'s */ 690Sstevel@tonic-gate uint16_t wav_fmt_encoding; /* audio data encoding method */ 700Sstevel@tonic-gate uint16_t wav_fmt_channels; /* number of channels */ 710Sstevel@tonic-gate uint32_t wav_fmt_sample_rate; /* sample rate */ 720Sstevel@tonic-gate uint32_t wav_fmt_bytes_per_second; /* bytes per sec. of audio */ 730Sstevel@tonic-gate uint16_t wav_fmt_bytes_per_sample; /* bytes per audio sample */ 740Sstevel@tonic-gate uint16_t wav_fmt_bits_per_sample; /* bits per audio sample */ 750Sstevel@tonic-gate uint32_t wav_data_ID; /* data ID */ 760Sstevel@tonic-gate int32_t wav_data_size; /* size of the data */ 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate typedef struct wav_filehdr wav_filehdr_t; 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* define for wav_filehdr.wav_riff_ID */ 810Sstevel@tonic-gate #define AUDIO_WAV_RIFF_ID ((uint32_t)0x46464952) /* 'RIFF' */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* define for wav_filehdr.wav_wave_ID */ 840Sstevel@tonic-gate #define AUDIO_WAV_TYPE_ID ((uint32_t)0x45564157) /* 'WAVE' */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* define for wav_filehdr.wav_fmt_ID */ 870Sstevel@tonic-gate #define AUDIO_WAV_FORMAT_ID ((uint32_t)0x20746d66) /* 'fmt ' */ 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* define for wav_filehdr.wav_fmt_size */ 900Sstevel@tonic-gate #define AUDIO_WAV_FORMAT_SIZE 0x10 /* constant value */ 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* defines for wav_filehdr.wav_fmt_encoding */ 930Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_UNKNOWN 0x0000 940Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_PCM 0x0001 950Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_MS_ADPCM 0x0002 960Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_ALAW 0x0006 970Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_MULAW 0x0007 980Sstevel@tonic-gate #define AUDIO_WAV_FMT_ENCODING_DVI_ADPCM 0x0011 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* defines for wav_filehdr.wav_fmt_channels */ 1010Sstevel@tonic-gate #define AUDIO_WAV_FMT_CHANNELS_MONO 0 1020Sstevel@tonic-gate #define AUDIO_WAV_FMT_CHANNELS_STEREO 1 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* defines for wav_filehdr.wav_fmt_bytes_per_sample */ 1050Sstevel@tonic-gate #define AUDIO_WAV_FMT_BYTES_PER_SAMPLE_8_BIT_MONO 1 1060Sstevel@tonic-gate #define AUDIO_WAV_FMT_BYTES_PER_SAMPLE_8_BIT_STEREO 2 1070Sstevel@tonic-gate #define AUDIO_WAV_FMT_BYTES_PER_SAMPLE_16_BIT_MONO 2 1080Sstevel@tonic-gate #define AUDIO_WAV_FMT_BYTES_PER_SAMPLE_16_BIT_STEREO 4 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* defines for wav_filehdr.wav_fmt_bits_per_sample */ 1110Sstevel@tonic-gate #define AUDIO_WAV_FMT_BITS_PER_SAMPLE_8_BITS 8 1120Sstevel@tonic-gate #define AUDIO_WAV_FMT_BITS_PER_SAMPLE_16_BITS 16 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /* defines for wav_filehdr.wav_data_ID */ 115*10400SJimmy.Vetayases@Sun.COM #define AUDIO_WAV_DATA_ID_UC ((uint32_t)0x41544144) /* DATA */ 116*10400SJimmy.Vetayases@Sun.COM #define AUDIO_WAV_DATA_ID_LC ((uint32_t)0x61746164) /* data */ 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* byte swapping macros */ 1200Sstevel@tonic-gate #if defined(__sparc) /* big endian */ 1210Sstevel@tonic-gate #define AUDIO_WAV_FILE2HOST_INT(from, to) \ 1220Sstevel@tonic-gate (*to) = ((((*from) >> 24) & 0xff) | (((*from) & 0xff) << 24) | \ 1230Sstevel@tonic-gate (((*from) >> 8) & 0xff00) | (((*from) & 0xff00) << 8)) 1240Sstevel@tonic-gate #define AUDIO_WAV_FILE2HOST_SHORT(from, to) \ 1250Sstevel@tonic-gate (*to) = ((((*from) >> 8) & 0xff) | (((*from) & 0xff) << 8)) 1260Sstevel@tonic-gate #define AUDIO_WAV_HOST2FILE_INT(from, to) \ 1270Sstevel@tonic-gate AUDIO_WAV_FILE2HOST_INT((from), (to)) 1280Sstevel@tonic-gate #define AUDIO_WAV_HOST2FILE_SHORT(from, to) \ 1290Sstevel@tonic-gate AUDIO_WAV_FILE2HOST_SHORT((from), (to)) 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) /* little endian */ 1320Sstevel@tonic-gate #define AUDIO_WAV_FILE2HOST_INT(from, to) \ 1330Sstevel@tonic-gate *((int *)(to)) = *((int *)(from)) 1340Sstevel@tonic-gate #define AUDIO_WAV_FILE2HOST_SHORT(from, to) \ 1350Sstevel@tonic-gate *((short *)(to)) = *((short *)(from)) 1360Sstevel@tonic-gate #define AUDIO_WAV_HOST2FILE_INT(from, to) \ 1370Sstevel@tonic-gate *((int *)(to)) = *((int *)(from)) 1380Sstevel@tonic-gate #define AUDIO_WAV_HOST2FILE_SHORT(from, to) \ 1390Sstevel@tonic-gate *((short *)(to)) = *((short *)(from)) 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate #else 1420Sstevel@tonic-gate #error unknown machine type; 1430Sstevel@tonic-gate #endif /* byte swapping */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate #ifdef __cplusplus 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate #endif 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #endif /* _WAV_H */ 151