summaryrefslogtreecommitdiff
path: root/audio/dap/patches/patch-ag
blob: fc85c0ecc31c1fd79d6ecfe2a45377b9f7efd5ac (plain)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
$NetBSD: patch-ag,v 1.1.1.1 1999/12/04 12:56:31 scw Exp $

--- libaudiofile/audiofile.c.orig	Fri Nov 12 17:19:12 1999
+++ libaudiofile/audiofile.c	Tue Nov 30 21:55:15 1999
@@ -528,25 +528,39 @@
   const char *mode,
   AFfilesetup setup)
 {
-  int file;
+  fhandle file;
   AFfilehandle tempHandle;
 
   if (!mode) return AF_NULL_FILEHANDLE;
 
   if (!strcmp (mode,"r"))
   {
+#ifndef USE_STDIO
     file = open (name,O_RDONLY);
     if (file == -1) return AF_NULL_FILEHANDLE;
     if ((tempHandle = AFopenfd (file,mode,setup)) == AF_NULL_FILEHANDLE)
       close (file);
+#else
+    file = fopen (name,"rb");
+    if (file == NULL) return AF_NULL_FILEHANDLE;
+    if ((tempHandle = AFopenfd (file,mode,setup)) == AF_NULL_FILEHANDLE)
+      fclose (file);
+#endif
   }
   else if (!strcmp (mode,"w"))
   {
+#ifndef USE_STDIO
     // NB decimal 438 = octal 666
     file = open (name,O_RDWR | O_CREAT | O_TRUNC,438);
     if (file == -1) return AF_NULL_FILEHANDLE;
     if ((tempHandle = AFopenfd (file,mode,setup)) == AF_NULL_FILEHANDLE)
       close (file);
+#else
+    file = fopen (name,"wb");
+    if (file == NULL) return AF_NULL_FILEHANDLE;
+    if ((tempHandle = AFopenfd (file,mode,setup)) == AF_NULL_FILEHANDLE)
+      fclose (file);
+#endif
   }
   else
   {
@@ -558,7 +572,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFopenfd
 ---------------------------------------------------------------------------*/
-AFfilehandle AFopenfd (int file,const char *mode,AFfilesetup setup)
+AFfilehandle AFopenfd (fhandle file,const char *mode,AFfilesetup setup)
 {
   if (!mode) return AF_NULL_FILEHANDLE;
   if (!strcmp (mode,"r"))
@@ -628,7 +642,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFreadAIFF
 ---------------------------------------------------------------------------*/
-AFfilehandle AFreadAIFF (int file)
+AFfilehandle AFreadAIFF (fhandle file)
 {
   int i;
   int j;
@@ -692,7 +706,11 @@
   else
     fail ("AIFF header does not contain a valid form type\n")
 
+#ifndef USE_STDIO
   while (!done && !error) // && !feof (file))
+#else
+  while (!done && !error && !feof (file))
+#endif
   {
     if (!idRead (file,id))
     {
@@ -753,14 +771,22 @@
       uiread (blocksize)
 
       // Skip past data for now
+#ifndef USE_STDIO
       handle->ssndStart = lseek (file,0L,SEEK_CUR);
+#else
+      handle->ssndStart = ftell (file);
+#endif
       if (handle->ssndStart == -1) aiffError
       handle->ssndStart += offset;
       if (chunksize >= 8)
       {
         seeksize = chunksize - 8;
         if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
         if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+        if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
       }
       else
       {
@@ -817,7 +843,11 @@
           {
             comment [i].text =
               (char *) calloc (comment [i].count + 1,sizeof (char));
+#ifndef USE_STDIO
             if (read (file,comment [i].text,comment [i].count)
+#else
+            if (fread (comment [i].text,1,comment [i].count,file)
+#endif
               != comment [i].count)
             {
               if (comment)
@@ -902,7 +932,11 @@
       if (chunksize != 24) aiffError
 
       handle->aiff.aesdatapresent = TRUE;
+#ifndef USE_STDIO
       if (read (file,handle->aiff.aesdata,24) != 24) aiffError
+#else
+      if (fread (handle->aiff.aesdata,1,24,file) != 24) aiffError
+#endif
       aesd = TRUE;
     }
     else if (!strncmp (id,"NAME",4))
@@ -919,7 +953,11 @@
         handle->aiff.misc [0].current = 0;
         handle->aiff.misc [0].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [0].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [0].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -945,7 +983,11 @@
         handle->aiff.misc [1].current = 0;
         handle->aiff.misc [1].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [1].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [1].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -971,7 +1013,11 @@
         handle->aiff.misc [2].current = 0;
         handle->aiff.misc [2].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [2].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [2].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -1007,7 +1053,11 @@
         handle->aiff.misc [3].current = 0;
         handle->aiff.misc [3].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [3].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [3].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -1043,7 +1093,11 @@
         handle->aiff.misc [4].current = 0;
         handle->aiff.misc [4].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [4].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [4].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -1079,7 +1133,11 @@
         handle->aiff.misc [5].current = 0;
         handle->aiff.misc [5].data    =
           (char *) calloc (chunksize,sizeof (char));
+#ifndef USE_STDIO
         if (read (file,handle->aiff.misc [5].data,chunksize)
+#else
+        if (fread (handle->aiff.misc [5].data,1,chunksize,file)
+#endif
           != chunksize)
           aiffError
         if (chunksize % 2) ucread (uctemp)
@@ -1100,7 +1158,11 @@
       // Skip past data
       seeksize = chunksize;
       if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
       if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+      if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
     }
   }
 
@@ -1121,7 +1183,11 @@
   }
 
   // Read to start of sound data
+#ifndef USE_STDIO
   if (lseek (file,handle->ssndStart,SEEK_SET) == -1)
+#else
+  if (fseek (file,handle->ssndStart,SEEK_SET) == -1)
+#endif
     fail ("error seeking to start of sound data\n")
 
   handle = (AFfilehandle) calloc (1,sizeof (aiffHandle));
@@ -1132,7 +1198,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFwriteAIFF
 ---------------------------------------------------------------------------*/
-AFfilehandle AFwriteAIFF (int file,AFfilesetup setup)
+AFfilehandle AFwriteAIFF (fhandle file,AFfilesetup setup)
 {
   int i;
   int j;
@@ -1309,7 +1375,11 @@
     idwrite ("AESD")
     chunksize = 24;
     iwrite (chunksize)
+#ifndef USE_STDIO
     if (write (file,handle->aiff.aesdata,24) != 24)
+#else
+    if (fwrite (handle->aiff.aesdata,1,24,file) != 24)
+#endif
       return AF_NULL_FILEHANDLE;
     handle->actualBytes += 24;
   }
@@ -1339,7 +1409,11 @@
         iwrite (chunksize)
         if (chunksize)
         {
+#ifndef USE_STDIO
           if (write (file,handle->aiff.misc [i].data,chunksize)
+#else
+          if (fwrite (handle->aiff.misc [i].data,1,chunksize,file)
+#endif
             != chunksize)
             return AF_NULL_FILEHANDLE;
           handle->actualBytes += chunksize;
@@ -1364,7 +1438,10 @@
   // Offset and blocksize zero
   uiwrite (0)
   uiwrite (0)
-  // fflush (file); no flushing needed
+
+#ifdef USE_STDIO
+  fflush (file);
+#endif
 
   handle = (AFfilehandle) calloc (1,sizeof (aiffHandle));
   *handle = handleAct;
@@ -1374,7 +1451,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFgetfd
 ---------------------------------------------------------------------------*/
-int AFgetfd (AFfilehandle handle)
+fhandle AFgetfd (AFfilehandle handle)
 {
   if (!handle) return 0;
   return handle->file;
@@ -1427,7 +1504,7 @@
   double dtemp;
   char *tempString;
   char idtemp [4];
-  int file;
+  fhandle file;
   int byteWidth;
   int bytes;
 
@@ -1439,7 +1516,11 @@
   
   if (handle->mode == READONLY)
   {
+#ifndef USE_STDIO
     if (close (handle->file) == -1) return -1;
+#else
+    if (fclose (handle->file) == -1) return -1;
+#endif
     free (handle);
     return 0;
   }
@@ -1454,7 +1535,11 @@
       ucwrite (0)
     
     // Reset file descriptor
+#ifndef USE_STDIO
     if (lseek (file,0L,SEEK_SET) == -1)
+#else
+    if (fseek (file,0L,SEEK_SET) == -1)
+#endif
     {
       fprintf (stderr,"unable to seek on file\n");
       return -1;
@@ -1605,7 +1690,11 @@
       idupdate ("AESD")
       chunksize = 24;
       iupdate (chunksize)
+#ifndef USE_STDIO
       if (write (file,handle->aiff.aesdata,24) != 24)
+#else
+      if (fwrite (handle->aiff.aesdata,1,24,file) != 24)
+#endif
         return AF_NULL_FILEHANDLE;
     }
     
@@ -1634,7 +1723,11 @@
           iupdate (chunksize)
           if (chunksize)
           {
+#ifndef USE_STDIO
             if (write (file,handle->aiff.misc [i].data,chunksize)
+#else
+            if (fwrite (handle->aiff.misc [i].data,1,chunksize,file)
+#endif
               != chunksize)
               return AF_NULL_FILEHANDLE;
             
@@ -1664,7 +1757,11 @@
     uiupdate (0)
     uiupdate (0)
 
+#ifndef USE_STDIO
     if (close (handle->file) == -1) return -1;
+#else
+    if (fclose (handle->file) == -1) return -1;
+#endif
     free (handle);
     return 0;
   }
@@ -1693,7 +1790,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFidentifyfd
 ---------------------------------------------------------------------------*/
-int AFidentifyfd (int file)
+int AFidentifyfd (fhandle file)
 {
   char id [4];
   int bytes;
@@ -1702,13 +1799,21 @@
   if (!file) return AF_FILE_UNKNOWN;
     
   // Check FORM chunk
+#ifndef USE_STDIO
   if (read (file,id,4) != 4 || strncmp (id,"FORM",4))
+#else
+  if (fread (id,1,4,file) != 4 || strncmp (id,"FORM",4))
+#endif
     return AF_FILE_UNKNOWN;
 
   if (!iRead (file,&bytes))
     return AF_FILE_UNKNOWN;
 
+#ifndef USE_STDIO
   if (read (file,id,4) != 4)
+#else
+  if (fread (id,1,4,file) != 4)
+#endif
     return AF_FILE_UNKNOWN;
 
   if (!strncmp (id,"AIFF",4))
@@ -2379,7 +2484,7 @@
   int i;
   int j;
   int frameCount;
-  int file;
+  fhandle file;
   signed char ctemp;
   short stemp;
   int itemp;
@@ -2393,7 +2498,11 @@
   i = 0;
   frameCount = 0;
   while (handle->actualFrames < handle->aiff.framecount &&
+#ifndef USE_STDIO
     frameCount < count) // && !(feof (file)))
+#else
+    frameCount < count && !(feof (file)))
+#endif
   {
     for (j=0; j<handle->aiff.channels; j++)
     {
@@ -2468,7 +2577,7 @@
   int i;
   int j;
   int frameCount;
-  int file;
+  fhandle file;
   signed char ctemp;
   short stemp;
   int itemp;
@@ -2481,7 +2590,11 @@
 
   i = 0;
   frameCount = 0;
+#ifndef USE_STDIO
   while (frameCount < count) // && !(feof (file)))
+#else
+  while (frameCount < count && !(feof (file)))
+#endif
   {
     for (j=0; j<handle->aiff.channels; j++)
     {
@@ -2520,7 +2633,7 @@
 int AFseekframe (AFfilehandle handle,int trackid,int offset)
 {
   int seeksize;
-  int file;
+  fhandle file;
 
   if (!handle || trackid != AF_DEFAULT_TRACK) return 0;
   if (handle->mode != READONLY) return 0;
@@ -2554,7 +2667,11 @@
   
   seeksize *= handle->aiff.channels;
   handle->actualFrames = offset;
+#ifndef USE_STDIO
   if (lseek (file,seeksize,SEEK_CUR) == -1)
+#else
+  if (fseek (file,seeksize,SEEK_CUR) == -1)
+#endif
     return -1;
   else
     return offset;