1 // SuperCollider real time audio synthesis system
2 // Copyright (c) 2002 James McCartney. All rights reserved.
3 // http://www.audiosynth.com
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "PyrFileUtils.h"
22 # include "PyrSymbol.h"
23 # include "SFHeaders.h"
28 bool filelen(FILE *file
, size_t *length
);
29 bool filelen(FILE *file
, size_t *length
)
30 { // does not preserve file pointer
32 if (fseek(file
, 0, SEEK_END
)) return true;
33 if (fgetpos(file
, &pos
)) return true;
45 extern short gHomeVol
;
49 long setTypeCreator(unsigned char *filename
, long type
, long creator
)
54 long err
, bytespersamp
;
55 int sampleSize
, numchannels
;
59 HGetVol(NULL
, &saveVol
, &saveDir
);
60 HSetVol(NULL
, gHomeVol
, gHomeDir
);
61 err
= FSMakeFSSpec(gHomeVol
, 0L, filename
, &fsspec
);
63 postfl("IOError: %d\n", err
);
64 HSetVol(NULL
, saveVol
, saveDir
);
67 FSpGetFInfo(&fsspec
, &finfo
);
69 finfo
.fdCreator
= creator
;
70 FSpSetFInfo(&fsspec
, &finfo
);
71 HSetVol(NULL
, saveVol
, saveDir
);
78 int sampleFormatFromSymbol(PyrSymbol
*inSymbol
, int inHeaderFormat
)
80 bool isRIFF
= inHeaderFormat
== RIFF_sound_file
;
82 char *name
= inSymbol
->name
;
84 if (name
[3] == '8') return isRIFF
? snd_8_unsigned
: snd_8_linear
;
85 if (name
[3] == '1') return isRIFF
? snd_16_linear_little_endian
: snd_16_linear
;
86 if (name
[3] == '2') return isRIFF
? snd_24_linear_little_endian
: snd_24_linear
;
87 if (name
[3] == '3') return isRIFF
? snd_32_linear_little_endian
: snd_32_linear
;
89 if (name
[0] == 'f') return isRIFF
? snd_32_float_little_endian
: snd_32_float
;
90 if (name
[0] == 'd') return isRIFF
? snd_64_double_little_endian
: snd_64_double
;
91 if (name
[0] == 'm') return snd_8_mulaw
;
92 if (name
[0] == 'a') return snd_8_alaw
;
93 return snd_unsupported
;
96 int headerFormatFromSymbol(PyrSymbol
*inSymbol
)
98 char *name
= inSymbol
->name
;
99 if (strcmp(name
, "AIFF")==0) return AIFF_sound_file
;
100 if (strcmp(name
, "AIFC")==0) return AIFC_sound_file
;
101 if (strcmp(name
, "RIFF")==0) return RIFF_sound_file
;
102 if (strcmp(name
, "WAVE")==0) return RIFF_sound_file
;
103 if (strcmp(name
, "WAV" )==0) return RIFF_sound_file
;
104 if (strcmp(name
, "Sun" )==0) return NeXT_sound_file
;
105 if (strcmp(name
, "SD2" )==0) return SD2_sound_file
;
106 if (strcmp(name
, "IRCAM")==0) return IRCAM_sound_file
;
107 if (strcmp(name
, "NeXT")==0) return NeXT_sound_file
;
108 if (strcmp(name
, "Next")==0) return NeXT_sound_file
;
109 if (strcmp(name
, "NEXT")==0) return NeXT_sound_file
;
110 if (strcmp(name
, "Raw")==0) return raw_sound_file
;
111 if (strcmp(name
, "raw")==0) return raw_sound_file
;
112 if (strcmp(name
, "RAW")==0) return raw_sound_file
;
113 if (strcmp(name
, "vorbis")==0) return vorbis_sound_file
;
114 if (strcmp(name
, "FLAC")==0) return flac_sound_file
;
115 //if (strcmp(name, "BICSF")==0) return BICSF_sound_file;
116 return unsupported_sound_file
;