bumping version to 3.5-rc1
[supercollider.git] / lang / LangSource / PyrFileUtils.cpp
blob6be911aa63463e50111ad1a60bec5bc40540af22
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
19 #include "SCBase.h"
20 #include "PyrFileUtils.h"
22 # include "PyrSymbol.h"
23 # include "SFHeaders.h"
25 #include <string.h>
26 #include <fcntl.h>
28 bool filelen(FILE *file, size_t *length);
29 bool filelen(FILE *file, size_t *length)
30 { // does not preserve file pointer
31 fpos_t pos;
32 if (fseek(file, 0, SEEK_END)) return true;
33 if (fgetpos(file, &pos)) return true;
35 #ifdef SC_LINUX
36 // sk: hack alert!
37 *length = pos.__pos;
38 #else
39 *length = pos;
40 #endif
42 return false;
45 extern short gHomeVol;
46 extern long gHomeDir;
48 #ifdef NOCLASSIC
49 long setTypeCreator(unsigned char *filename, long type, long creator)
51 FSSpec fsspec;
52 short saveVol;
53 long saveDir;
54 long err, bytespersamp;
55 int sampleSize, numchannels;
56 FInfo finfo;
59 HGetVol(NULL, &saveVol, &saveDir);
60 HSetVol(NULL, gHomeVol, gHomeDir);
61 err = FSMakeFSSpec(gHomeVol, 0L, filename, &fsspec);
62 if (err) {
63 postfl("IOError: %d\n", err);
64 HSetVol(NULL, saveVol, saveDir);
65 return errFailed;
67 FSpGetFInfo(&fsspec, &finfo);
68 finfo.fdType = type;
69 finfo.fdCreator = creator;
70 FSpSetFInfo(&fsspec, &finfo);
71 HSetVol(NULL, saveVol, saveDir);
72 return errNone;
74 #endif
78 int sampleFormatFromSymbol(PyrSymbol *inSymbol, int inHeaderFormat)
80 bool isRIFF = inHeaderFormat == RIFF_sound_file;
82 char *name = inSymbol->name;
83 if (name[0] == 'i') {
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;