1c72fcc34Sopenharmony_ci#ifndef FORMATS_H 2c72fcc34Sopenharmony_ci#define FORMATS_H 1 3c72fcc34Sopenharmony_ci 4c72fcc34Sopenharmony_ci#include "bswap.h" 5c72fcc34Sopenharmony_ci 6c72fcc34Sopenharmony_ci/* Definitions for .VOC files */ 7c72fcc34Sopenharmony_ci 8c72fcc34Sopenharmony_ci#define VOC_MAGIC_STRING "Creative Voice File\x1A" 9c72fcc34Sopenharmony_ci#define VOC_ACTUAL_VERSION 0x010A 10c72fcc34Sopenharmony_ci#define VOC_SAMPLESIZE 8 11c72fcc34Sopenharmony_ci 12c72fcc34Sopenharmony_ci#define VOC_MODE_MONO 0 13c72fcc34Sopenharmony_ci#define VOC_MODE_STEREO 1 14c72fcc34Sopenharmony_ci 15c72fcc34Sopenharmony_ci#define VOC_DATALEN(bp) ((u_long)(bp->datalen) | \ 16c72fcc34Sopenharmony_ci ((u_long)(bp->datalen_m) << 8) | \ 17c72fcc34Sopenharmony_ci ((u_long)(bp->datalen_h) << 16) ) 18c72fcc34Sopenharmony_ci 19c72fcc34Sopenharmony_citypedef struct voc_header { 20c72fcc34Sopenharmony_ci uint8_t magic[20]; /* must be MAGIC_STRING */ 21c72fcc34Sopenharmony_ci uint16_t headerlen; /* Headerlength, should be 0x1A */ 22c72fcc34Sopenharmony_ci uint16_t version; /* VOC-file version */ 23c72fcc34Sopenharmony_ci uint16_t coded_ver; /* 0x1233-version */ 24c72fcc34Sopenharmony_ci} VocHeader; 25c72fcc34Sopenharmony_ci 26c72fcc34Sopenharmony_citypedef struct voc_blocktype { 27c72fcc34Sopenharmony_ci uint8_t type; 28c72fcc34Sopenharmony_ci uint8_t datalen; /* low-byte */ 29c72fcc34Sopenharmony_ci uint8_t datalen_m; /* medium-byte */ 30c72fcc34Sopenharmony_ci uint8_t datalen_h; /* high-byte */ 31c72fcc34Sopenharmony_ci} VocBlockType; 32c72fcc34Sopenharmony_ci 33c72fcc34Sopenharmony_citypedef struct voc_voice_data { 34c72fcc34Sopenharmony_ci uint8_t tc; 35c72fcc34Sopenharmony_ci uint8_t pack; 36c72fcc34Sopenharmony_ci} VocVoiceData; 37c72fcc34Sopenharmony_ci 38c72fcc34Sopenharmony_citypedef struct voc_ext_block { 39c72fcc34Sopenharmony_ci uint16_t tc; 40c72fcc34Sopenharmony_ci uint8_t pack; 41c72fcc34Sopenharmony_ci uint8_t mode; 42c72fcc34Sopenharmony_ci} VocExtBlock; 43c72fcc34Sopenharmony_ci 44c72fcc34Sopenharmony_ci/* Definitions for Microsoft WAVE format */ 45c72fcc34Sopenharmony_ci 46c72fcc34Sopenharmony_ci#if __BYTE_ORDER == __LITTLE_ENDIAN 47c72fcc34Sopenharmony_ci#define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24)) 48c72fcc34Sopenharmony_ci#define LE_SHORT(v) (v) 49c72fcc34Sopenharmony_ci#define LE_INT(v) (v) 50c72fcc34Sopenharmony_ci#define BE_SHORT(v) bswap_16(v) 51c72fcc34Sopenharmony_ci#define BE_INT(v) bswap_32(v) 52c72fcc34Sopenharmony_ci#elif __BYTE_ORDER == __BIG_ENDIAN 53c72fcc34Sopenharmony_ci#define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24)) 54c72fcc34Sopenharmony_ci#define LE_SHORT(v) bswap_16(v) 55c72fcc34Sopenharmony_ci#define LE_INT(v) bswap_32(v) 56c72fcc34Sopenharmony_ci#define BE_SHORT(v) (v) 57c72fcc34Sopenharmony_ci#define BE_INT(v) (v) 58c72fcc34Sopenharmony_ci#else 59c72fcc34Sopenharmony_ci#error "Wrong endian" 60c72fcc34Sopenharmony_ci#endif 61c72fcc34Sopenharmony_ci 62c72fcc34Sopenharmony_ci/* Note: the following macros evaluate the parameter v twice */ 63c72fcc34Sopenharmony_ci#define TO_CPU_SHORT(v, be) \ 64c72fcc34Sopenharmony_ci ((be) ? BE_SHORT(v) : LE_SHORT(v)) 65c72fcc34Sopenharmony_ci#define TO_CPU_INT(v, be) \ 66c72fcc34Sopenharmony_ci ((be) ? BE_INT(v) : LE_INT(v)) 67c72fcc34Sopenharmony_ci 68c72fcc34Sopenharmony_ci#define WAV_RIFF COMPOSE_ID('R','I','F','F') 69c72fcc34Sopenharmony_ci#define WAV_RIFX COMPOSE_ID('R','I','F','X') 70c72fcc34Sopenharmony_ci#define WAV_WAVE COMPOSE_ID('W','A','V','E') 71c72fcc34Sopenharmony_ci#define WAV_FMT COMPOSE_ID('f','m','t',' ') 72c72fcc34Sopenharmony_ci#define WAV_DATA COMPOSE_ID('d','a','t','a') 73c72fcc34Sopenharmony_ci 74c72fcc34Sopenharmony_ci/* WAVE fmt block constants from Microsoft mmreg.h header */ 75c72fcc34Sopenharmony_ci#define WAV_FMT_PCM 0x0001 76c72fcc34Sopenharmony_ci#define WAV_FMT_IEEE_FLOAT 0x0003 77c72fcc34Sopenharmony_ci#define WAV_FMT_DOLBY_AC3_SPDIF 0x0092 78c72fcc34Sopenharmony_ci#define WAV_FMT_EXTENSIBLE 0xfffe 79c72fcc34Sopenharmony_ci 80c72fcc34Sopenharmony_ci/* Used with WAV_FMT_EXTENSIBLE format */ 81c72fcc34Sopenharmony_ci#define WAV_GUID_TAG "\x00\x00\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71" 82c72fcc34Sopenharmony_ci 83c72fcc34Sopenharmony_ci/* it's in chunks like .voc and AMIGA iff, but my source say there 84c72fcc34Sopenharmony_ci are in only in this combination, so I combined them in one header; 85c72fcc34Sopenharmony_ci it works on all WAVE-file I have 86c72fcc34Sopenharmony_ci */ 87c72fcc34Sopenharmony_citypedef struct { 88c72fcc34Sopenharmony_ci uint32_t magic; /* 'RIFF' */ 89c72fcc34Sopenharmony_ci uint32_t length; /* filelen */ 90c72fcc34Sopenharmony_ci uint32_t type; /* 'WAVE' */ 91c72fcc34Sopenharmony_ci} WaveHeader; 92c72fcc34Sopenharmony_ci 93c72fcc34Sopenharmony_citypedef struct { 94c72fcc34Sopenharmony_ci uint16_t format; /* see WAV_FMT_* */ 95c72fcc34Sopenharmony_ci uint16_t channels; 96c72fcc34Sopenharmony_ci uint32_t sample_fq; /* frequence of sample */ 97c72fcc34Sopenharmony_ci uint32_t byte_p_sec; 98c72fcc34Sopenharmony_ci uint16_t byte_p_spl; /* samplesize; 1 or 2 bytes */ 99c72fcc34Sopenharmony_ci uint16_t bit_p_spl; /* 8, 12 or 16 bit */ 100c72fcc34Sopenharmony_ci} WaveFmtBody; 101c72fcc34Sopenharmony_ci 102c72fcc34Sopenharmony_citypedef struct { 103c72fcc34Sopenharmony_ci WaveFmtBody format; 104c72fcc34Sopenharmony_ci uint16_t ext_size; 105c72fcc34Sopenharmony_ci uint16_t bit_p_spl; 106c72fcc34Sopenharmony_ci uint32_t channel_mask; 107c72fcc34Sopenharmony_ci uint16_t guid_format; /* WAV_FMT_* */ 108c72fcc34Sopenharmony_ci uint8_t guid_tag[14]; /* WAV_GUID_TAG */ 109c72fcc34Sopenharmony_ci} WaveFmtExtensibleBody; 110c72fcc34Sopenharmony_ci 111c72fcc34Sopenharmony_citypedef struct { 112c72fcc34Sopenharmony_ci uint32_t type; /* 'data' */ 113c72fcc34Sopenharmony_ci uint32_t length; /* samplecount */ 114c72fcc34Sopenharmony_ci} WaveChunkHeader; 115c72fcc34Sopenharmony_ci 116c72fcc34Sopenharmony_ci/* Definitions for Sparc .au header */ 117c72fcc34Sopenharmony_ci 118c72fcc34Sopenharmony_ci#define AU_MAGIC COMPOSE_ID('.','s','n','d') 119c72fcc34Sopenharmony_ci 120c72fcc34Sopenharmony_ci#define AU_FMT_ULAW 1 121c72fcc34Sopenharmony_ci#define AU_FMT_LIN8 2 122c72fcc34Sopenharmony_ci#define AU_FMT_LIN16 3 123c72fcc34Sopenharmony_ci 124c72fcc34Sopenharmony_citypedef struct au_header { 125c72fcc34Sopenharmony_ci uint32_t magic; /* '.snd' */ 126c72fcc34Sopenharmony_ci uint32_t hdr_size; /* size of header (min 24) */ 127c72fcc34Sopenharmony_ci uint32_t data_size; /* size of data */ 128c72fcc34Sopenharmony_ci uint32_t encoding; /* see to AU_FMT_XXXX */ 129c72fcc34Sopenharmony_ci uint32_t sample_rate; /* sample rate */ 130c72fcc34Sopenharmony_ci uint32_t channels; /* number of channels (voices) */ 131c72fcc34Sopenharmony_ci} AuHeader; 132c72fcc34Sopenharmony_ci 133c72fcc34Sopenharmony_ci#endif /* FORMATS */ 134