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