Bug fixed for stdin and stdout in a different platform.
[Faustine.git] / interpreter / lib / src / libsndfile-ocaml / sndfile.ml
1 (*
2 ** File: sndfile.ml
3 **
4 ** Copyright (c) 2006, 2007 Erik de Castro Lopo <erikd at mega-nerd dot com>
5 ** WWW: http://www.mega-nerd.com/libsndfile/Ocaml/
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *)
21
22 type open_mode_t =
23 | READ
24 | WRITE
25 | RDWR
26
27 type seek_mode_t =
28 | SEEK_SET
29 | SEEK_CUR
30 | SEEL_END
31
32 type major_format_t =
33 | MAJOR_NONE
34 | MAJOR_WAV
35 | MAJOR_AIFF
36 | MAJOR_AU
37 | MAJOR_RAW
38 | MAJOR_PAF
39 | MAJOR_SVX
40 | MAJOR_NIST
41 | MAJOR_VOC
42 | MAJOR_IRCAM
43 | MAJOR_W64
44 | MAJOR_MAT4
45 | MAJOR_MAT5
46 | MAJOR_PVF
47 | MAJOR_XI
48 | MAJOR_HTK
49 | MAJOR_SDS
50 | MAJOR_AVR
51 | MAJOR_WAVEX
52 | MAJOR_SD2
53 | MAJOR_FLAC
54 | MAJOR_CAF
55
56 type minor_format_t =
57 | MINOR_NONE
58 | MINOR_PCM_S8
59 | MINOR_PCM_16
60 | MINOR_PCM_24
61 | MINOR_PCM_32
62 | MINOR_PCM_U8
63 | MINOR_FLOAT
64 | MINOR_DOUBLE
65 | MINOR_ULAW
66 | MINOR_ALAW
67 | MINOR_IMA_ADPCM
68 | MINOR_MS_ADPCM
69 | MINOR_GSM610
70 | MINOR_VOX_ADPCM
71 | MINOR_G721_32
72 | MINOR_G723_24
73 | MINOR_G723_40
74 | MINOR_DWVW_12
75 | MINOR_DWVW_16
76 | MINOR_DWVW_24
77 | MINOR_DWVW_N
78 | MINOR_DPCM_8
79 | MINOR_DPCM_16
80
81 type endianness_t =
82 | ENDIAN_FILE
83 | ENDIAN_LITTLE
84 | ENDIAN_BIG
85 | ENDIAN_CPU
86
87
88 type file_format_t
89
90 type error =
91 | No_error
92 | Unrecognised_format
93 | System
94 | Malformed_file
95 | Unsupported_encoding
96 | Internal
97
98 exception Error of (error * string)
99
100 type t
101
102 external format_e : major_format_t -> minor_format_t -> endianness_t -> file_format_t = "caml_sf_format_e"
103
104 let format major minor =
105 format_e major minor ENDIAN_FILE
106
107 external open_private :
108 string -> (* filename *)
109 open_mode_t ->
110 file_format_t ->
111 int -> (* channels *)
112 int -> (* samplerate *)
113 t = "caml_sf_open_private"
114
115 let bad_format = format MAJOR_NONE MINOR_NONE
116
117 let openfile ?(info = (READ, bad_format, 0, 0)) filename =
118 let (mode, fmt, channels, samplerate) = info in
119 open_private filename mode fmt channels samplerate
120
121 external close : t -> unit = "caml_sf_close"
122
123 external read : t -> float array -> int = "caml_sf_read"
124 external write : t -> float array -> int = "caml_sf_write"
125
126
127 external frames : t -> Int64.t = "caml_sf_frames"
128
129 external samplerate : t -> int = "caml_sf_samplerate"
130
131 external channels : t -> int = "caml_sf_channels"
132
133 external seek : t -> Int64.t -> seek_mode_t -> Int64.t = "caml_sf_seek"
134
135 external compare : t -> t -> int = "caml_sf_compare"
136
137 let _ =
138 Callback.register_exception "sndfile_open_exn" (Error (No_error, "No error."))