File: sfircam.h

package info (click to toggle)
sox 12.16-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,180 kB
  • ctags: 1,466
  • sloc: ansic: 16,658; sh: 2,071; makefile: 126
file content (218 lines) | stat: -rw-r--r-- 6,867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*				SFHEADER.H				*/

/* definitions and structures needed for manipulating soundfiles.
 */

#define SIZEOF_HEADER 1024
#define SF_BUFSIZE	(16*1024) /* used only in play */
#define SF_MAXCHAN	4
#define MAXCOMM 512
#define MINCOMM 256

#define SF_MAGIC1 0144
#define SF_MAGIC2 0243

/* Definition of SF_MACHINE and SF_MAGIC
 *
 * Note that SF_MAGIC always has SF_MAGIC1 as its first byte, SF_MAGIC2 as its
 * second, SF_MACHINE as its third, and zero as its fourth.  Separate define's
 * are needed because byte order is different on different machines.
 */
#define SF_VAX 1
#define SF_SUN 2
#define SF_MIPS 3
#define SF_NEXT 4
#ifdef vax
#define SF_MACHINE SF_VAX
#define SF_MAGIC ((LONG)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
#endif
#ifdef sun
#define SF_MACHINE SF_SUN
#define SF_MAGIC ((LONG)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
#endif
#ifdef mips
#define SF_MACHINE SF_MIPS
#define SF_MAGIC ((LONG)(SF_MAGIC1 | SF_MAGIC2 << 8 | SF_MACHINE << 16))
#endif
#ifdef NeXT
#define SF_MACHINE SF_NEXT
#define SF_MAGIC ((LONG)(SF_MAGIC1 << 24 | SF_MAGIC2 << 16 | SF_MACHINE << 8))
#endif


/* Packing modes, as stored in the SFHEADER.sf_packmode field
 *
 * For each packing mode, the lower-order short is the number of bytes per
 * sample, and for backward compatibility, SF_SHORT and SF_FLOAT have
 * high-order short = 0 so overall they're the bytes per sample, but that's not
 * true for all SF_'s.  Thus while the "sfclass" macro still returns a unique
 * ID for each packing mode, the new "sfsamplesize" macro should be used to get
 * the bytes per sample.
 *
 * Note that SF_X == SFMT_X in most, but not all, cases, because MIT changed
 * SFMT_FLOAT and we kept SF_FLOAT for compatibility with existing sound files.
 *
 * Possible values of sf_packmode:
 */
#define SF_CHAR  ((LONG) sizeof(char))
#define SF_ALAW  ((LONG) sizeof(char) | 0x10000)
#define SF_ULAW  ((LONG) sizeof(char) | 0x20000)
#define SF_SHORT ((LONG) sizeof(short))
#define SF_LONG  ((LONG) sizeof(LONG) | 0x40000)
#define SF_FLOAT ((LONG) sizeof(float))

/* For marking data after fixed section of soundfile header -- see man (3carl)
 * sfcodes and defintions of SFCODE and related structures, below.
 */
#define SF_END 0            /* Meaning no more information */
#define SF_MAXAMP 1         /* Meaning maxamp follows */
#define SF_COMMENT 2        /* code for "comment line" */
#define SF_PVDATA      3
#define SF_AUDIOENCOD  4
#define SF_CODMAX      4

/*
 * DEFINITION OF SFHEADER FORMAT
 *
 * The first four bytes are the magic information for the sound file.  They
 * can be accessed, via a union, either as a structure of four unsigned bytes
 * sf_magic1, sf_magic2, sf_machine, sf_param, or as the single long sf_magic.
 * sf_magic is for backward compatibility; it should be SF_MAGIC as defined
 * above.
 */
typedef union sfheader {
	struct sfinfo {
		union magic_union {
			struct {
				unsigned char sf_magic1;  /* byte 1 of magic */
				unsigned char sf_magic2;  /* 2 */
				unsigned char sf_machine; /* 3 */
				unsigned char sf_param;	  /* 4 */
				} _magic_bytes;
			LONG sf_magic;			  /* magic as a 4-byte long */
			} magic_union;
		float	  sf_srate;
		LONG	  sf_chans;
		LONG	  sf_packmode;
		char	  sf_codes;
	} sfinfo;
	char	filler[SIZEOF_HEADER];
} SFHEADER;

/*
 * Definition of SFCODE and related data structs
 *
 * Two routines in libbicsf/sfcodes.c, getsfcode() and putsfcode()
 * are used to insert additionnal information into a header
 * or to retreive such information. See man sfcodes.
 *
 * 10/90 pw
 *	These routines are now part of libcarl/sfcodes.c
 */

typedef struct sfcode {
	short	code;
	short	bsize;
} SFCODE;

typedef struct Sfmaxamp {
	float	value[SF_MAXCHAN];
	LONG	samploc[SF_MAXCHAN];
	LONG	timetag;
} SFMAXAMP;

typedef struct sfcomment {
        char    comment[MAXCOMM];
} SFCOMMENT;

typedef struct {                  /* this code written by pvanal */
        short   frameSize;
	short   frameIncr;
} SFPVDATA;

typedef struct {                  /*     ditto                    */
        short   encoding;
	short   grouping;
} SFAUDIOENCOD;

/*
 * DEFINITION OF MACROS TO GET HEADER INFO
 *     x is a pointer to SFHEADER
 *
 * For backward compatibility in MIT Csound code, sfmagic(x) still provides
 * access to the first long of SFHEADER x.  It can be compared to SF_MAGIC,
 * which is defined machine-dependently (above) to always be the right four
 * bytes in the right order.
 *
 * sfclass(x) returns one of SF_SHORT, SF_FLOAT etc. defined above, while
 * sfsamplesize(x) returns just the bytes per object, the lower-order short of
 * sf_packmode.
 */
#define sfmagic(x) ((x)->sfinfo.magic_union.sf_magic)
#define sfmagic1(x) ((x)->sfinfo.magic_union._magic_bytes.sf_magic1)
#define sfmagic2(x) ((x)->sfinfo.magic_union._magic_bytes.sf_magic2)
#define sfmachine(x) ((x)->sfinfo.magic_union._magic_bytes.sf_machine)
#define sfparam(x) ((x)->sfinfo.magic_union._magic_bytes.sf_param)
#define sfsrate(x) ((x)->sfinfo.sf_srate)
#define sfchans(x) ((x)->sfinfo.sf_chans)
#define sfclass(x) ((x)->sfinfo.sf_packmode)
#define sfsamplesize(x) ((size_t) ((x)->sfinfo.sf_packmode & 0xFFFF))
#define sfbsize(x) ((x)->st_size - sizeof(SFHEADER))
#define sfcodes(x) ((x)->sfinfo.sf_codes)

/*
 * Macros for testing soundfiles
 */
/* True if soundfile and good arch */
#define ismagic(x) ((sfmagic1(x) == SF_MAGIC1) && \
	(sfmagic2(x) == SF_MAGIC2) && \
	(sfmachine(x) == SF_MACHINE))

/* True if soundfile */
#define isforeignmagic(x) ((sfmagic1(x) == SF_MAGIC1) && \
	(sfmagic2(x) == SF_MAGIC2))

/* True if soundfile */
#define issoundfile(x)  ((sfmagic1(x) == SF_MAGIC1) && \
	(sfmagic2(x) == SF_MAGIC2))

/* True if soundfile and foreign arch */
#define isforeignsoundfile(x) ((sfmagic1(x) == SF_MAGIC1) && \
	(sfmagic2(x) == SF_MAGIC2) && \
	(sfmachine(x) != SF_MACHINE))

/* True if foreign arch */
#define isforeign(x) (sfmachine(x) != SF_MACHINE)


/*
 * The macros for opening soundfiles have been rewritten as C routines.
 * In order to preserve compatibility, we supply the following new macros
 */

#define readopensf(name,fd,sfh,sfst,prog,result) \
	result = (fd = openrosf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;

#define freadopensf(name,fp,sfh,sfst,prog,result) \
	result = fopenrosf(name, &fp, &sfh, &sfst, prog);

#define wropensf(name,fd,sfh,prog,result) \
	result = (fd = openwosf(name, &sfh, prog)) < 0 ? fd : 0;

#define rdwropensf(name,fd,sfh,sfst,prog,result) \
	result = (fd = openrwsf(name, &sfh, &sfst, prog)) < 0 ? fd : 0;


/*
 * Definition of macro to get MAXAMP and COMMENT info
 *
 * sfm is ptr to SFMAXAMP
 * sfst is the address of a stat struct
 */

#define sfmaxamp(mptr,chan) (mptr)->value[chan]
#define sfmaxamploc(mptr,chan) (mptr)->samploc[chan]
#define sfmaxamptime(x) (x)->timetag
#define ismaxampgood(x,s) (sfmaxamptime(x) >= (s)->st_mtime)
#define sfcomm(x,n) (x)->comment[n]