catori 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -0
- data/bin/catori +9 -0
- data/changelog.txt +3 -0
- data/construir +3 -0
- data/crear_vista.sql +8 -0
- data/ext/audiofile/MANIFEST +8 -0
- data/ext/audiofile/README +11 -0
- data/ext/audiofile/audiofile.c +833 -0
- data/ext/audiofile/audiofile.rd +265 -0
- data/ext/audiofile/depend +0 -0
- data/ext/audiofile/extconf.rb +8 -0
- data/ext/audiofile/fail.rb +22 -0
- data/ext/audiofile/mkmf.log +34 -0
- data/ext/audiofile/test.rb +229 -0
- data/ext/flac/extconf.rb +5 -0
- data/ext/flac/flac.c +75 -0
- data/ext/flac/mkmf.log +12 -0
- data/ext/flac/test.rb +3 -0
- data/ext/mahoro-0.1/INSTALL +9 -0
- data/ext/mahoro-0.1/extconf.rb +7 -0
- data/ext/mahoro-0.1/mahoro.c +187 -0
- data/ext/mahoro-0.1/mkmf.log +24 -0
- data/ext/mahoro-0.1/test.rb +41 -0
- data/ext/mpc/extconf.rb +5 -0
- data/ext/mpc/id3tag.c +245 -0
- data/ext/mpc/id3tag.h +5 -0
- data/ext/mpc/mkmf.log +12 -0
- data/ext/mpc/mpc.c +56 -0
- data/ext/mpc/mpp.h +194 -0
- data/ext/mpc/mppdec.h +1171 -0
- data/ext/mpc/test.rb +3 -0
- data/ext/rmac/extconf.rb +7 -0
- data/ext/rmac/mkmf.log +22 -0
- data/ext/rmac/rmac.cpp +162 -0
- data/ext/vorbisfile/ChangeLog +11 -0
- data/ext/vorbisfile/README +33 -0
- data/ext/vorbisfile/configure +2 -0
- data/ext/vorbisfile/extconf.rb +9 -0
- data/ext/vorbisfile/mkmf.log +68 -0
- data/ext/vorbisfile/test.rb +78 -0
- data/ext/vorbisfile/vorbisfile.c +482 -0
- data/instalar.txt +19 -0
- data/install.rb +11 -0
- data/lib/audioinfo.rb +321 -0
- data/lib/catori.rb +131 -0
- data/lib/catori/Catalogador.rb +71 -0
- data/lib/catori/Db.rb +81 -0
- data/lib/catori/Gui.rb +52 -0
- data/lib/catori/Installer.rb +16 -0
- data/lib/catori/Query.rb +82 -0
- data/lib/catori/XML.rb +42 -0
- data/lib/catori/catori_gui.glade +340 -0
- data/lib/catori/catori_gui.glade.bak +340 -0
- data/lib/catori/catori_gui.gladep +8 -0
- data/lib/catori/catori_gui.gladep.bak +8 -0
- data/lib/catori/taglib.rb +227 -0
- data/lib/pixmaps/album.png +0 -0
- data/lib/pixmaps/artist.png +0 -0
- data/lib/pixmaps/cdr.png +0 -0
- data/lib/pixmaps/song.png +0 -0
- data/lib/taglib.rb +230 -0
- data/sql/catori_mysql.sql +68 -0
- data/sql/catori_pg.sql +65 -0
- data/tests/saw.ape +0 -0
- data/tests/saw.flac +0 -0
- data/tests/saw.mp3 +0 -0
- data/tests/saw.mpc +0 -0
- data/tests/saw.ogg +0 -0
- data/tests/saw.wav +0 -0
- data/tests/test_audioinfo.rb +43 -0
- metadata +217 -0
@@ -0,0 +1,265 @@
|
|
1
|
+
=begin RD
|
2
|
+
|
3
|
+
= ruby-audiofile
|
4
|
+
== a ruby binding to the audiofile library
|
5
|
+
== The underlying library
|
6
|
+
|
7
|
+
The ((<"http://dreamscape.68k.org/~michael/audiofile"|audiofile library>))
|
8
|
+
was originally proprietary to SGI, and was used in Irix to read and
|
9
|
+
write audio files of various types: wav, aiff, au, etc. After a bit of coding
|
10
|
+
by Michael Pruett, and a few more things, it's no longer proprietary, though
|
11
|
+
some parts are not yet in existence. We'll talk about that later. But here's
|
12
|
+
|
13
|
+
=== What audiofile does:
|
14
|
+
|
15
|
+
* Reads audio files of various types
|
16
|
+
* Supports mu-law and A-law compression and uncompressed files
|
17
|
+
* Provides information on them, such as sampling rate, sample type, etc.
|
18
|
+
* Can switch byte order on the fly while reading, for user convenience
|
19
|
+
* Writes audio files
|
20
|
+
* Supports weird extensions (e.g. instruments in AIFF files, loops in WAV files)
|
21
|
+
|
22
|
+
=== But audiofile doesn't:
|
23
|
+
|
24
|
+
* Read MP3's
|
25
|
+
* Read Vorbis files (see ((<"http://www.xiph.org/ogg/vorbis/">)) for that)
|
26
|
+
* Write either of these
|
27
|
+
* Resample files on the fly while writing or reading (yet)
|
28
|
+
* Change sample formats or compression on the fly (yet)
|
29
|
+
* Support multitrack files (yet). It does support multiple ((*channels*)),
|
30
|
+
i.e. stereo and whatnot, but doesn't support any formats yet that can store
|
31
|
+
multiple ((*tracks*)).
|
32
|
+
|
33
|
+
== This binding
|
34
|
+
|
35
|
+
This extension is a binding of the audiofile library to the Ruby language. With
|
36
|
+
the aid of this super-wonderful extension, you can do everything you could do
|
37
|
+
with audiofile in Ruby, except:
|
38
|
+
|
39
|
+
=== Things supported by audiofile, but not ruby-audiofile
|
40
|
+
|
41
|
+
* reading non-raw files in a raw way
|
42
|
+
* handling errors elegantly (error handling works fairly well, but may
|
43
|
+
need changes)
|
44
|
+
* querying the capabilities of the library itself (afQuery)
|
45
|
+
* messing with loops, instruments, text data, or anything but the audio itself
|
46
|
+
* doing anything that audiofile has API for, but doesn't actually support
|
47
|
+
|
48
|
+
The last item may need a small bit of explanation: there are a number of
|
49
|
+
functions declared in audiofile.h (or commented out) which show that the
|
50
|
+
author has a clear idea of what it will look like to the user of the library
|
51
|
+
to use these not-yet-supported features, but there's not actually any code
|
52
|
+
behind these declarations.
|
53
|
+
|
54
|
+
== ruby-audiofile version 0.2.1
|
55
|
+
|
56
|
+
Version 0.2 adds file writing support, and fixes a bug with #read where
|
57
|
+
it returned half the data it was supposed to. Also the API has changed
|
58
|
+
some; the real_ prefixes no longer exist and there is a new virtual_
|
59
|
+
prefix. This makes code using ruby-audiofile shorter and more succinct.
|
60
|
+
|
61
|
+
Version 0.2.1 takes out a couple of debugging printf's i accidentally left in,
|
62
|
+
and changes the width/width= methods to bits/bits= to fit better with
|
63
|
+
Linux::SoundDSP. Minor documentation changes as well.
|
64
|
+
|
65
|
+
Version 0.2.2 has more documentation changes, and an update to my email
|
66
|
+
address.
|
67
|
+
|
68
|
+
== How to install
|
69
|
+
ruby extconf.rb
|
70
|
+
make
|
71
|
+
sudo make install
|
72
|
+
|
73
|
+
== How to use
|
74
|
+
|
75
|
+
In your scripts,
|
76
|
+
require 'audiofile'
|
77
|
+
This defines the AudioFile class, which has the following methods:
|
78
|
+
|
79
|
+
=== AudioFile class
|
80
|
+
|
81
|
+
--- AudioFile.new( filename, [mode] )
|
82
|
+
--- AudioFile.open( filename, [mode] )
|
83
|
+
Open a new AudioFile and return it. The mode is either "r" or "w" - for read or
|
84
|
+
write.
|
85
|
+
|
86
|
+
If you open a file for writing, you must set the following properties before
|
87
|
+
writing to the file:
|
88
|
+
|
89
|
+
* rate
|
90
|
+
* bits
|
91
|
+
* channels
|
92
|
+
* byte_order
|
93
|
+
* compression
|
94
|
+
* file_format
|
95
|
+
* sample_format
|
96
|
+
|
97
|
+
If you do not set these properties before calling the #write method, the
|
98
|
+
results are unspecified.
|
99
|
+
|
100
|
+
--- AudioFile#close
|
101
|
+
Close the file.
|
102
|
+
|
103
|
+
--- AudioFile#read( [frames] )
|
104
|
+
Read frames frames from the file. A ((:frame:)) is one sample for each channel.
|
105
|
+
So in a 44100Hz, 16-bit, stereo file, a frame would take four bytes: two for
|
106
|
+
the left channel, and two for the right. (Two bytes is 16 bits of course.)
|
107
|
+
This returns a new string every time, so if you're reading many times from an
|
108
|
+
audio file, read_into is suggested. That way your script will not grow huge in
|
109
|
+
memory.
|
110
|
+
|
111
|
+
--- AudioFile#read_into( string )
|
112
|
+
Read into string from the file. This replaces the contents of the string by
|
113
|
+
reading the largest number of frames that will fit into the current length of
|
114
|
+
the string. It returns the number of bytes actually read. Example:
|
115
|
+
string = " " * 32
|
116
|
+
file.read_into(string)
|
117
|
+
|
118
|
+
--- AudioFile#write( string )
|
119
|
+
Write the string to the file. See the note under #open: in short, you must set
|
120
|
+
the properties of the file before writing to it.
|
121
|
+
|
122
|
+
Also note that both #read_into and #write round to the frame. That is,
|
123
|
+
read_into will only read as many whole frames as fit into the string you give
|
124
|
+
it, and write will only write as many whole frames as are contained in the
|
125
|
+
string you pass to it.
|
126
|
+
|
127
|
+
--- AudioFile#flush
|
128
|
+
Flush the write buffers for the file.
|
129
|
+
|
130
|
+
--- AudioFile#pos
|
131
|
+
Returns the current position inside the file, in frames. (See #read about
|
132
|
+
what frames are.)
|
133
|
+
|
134
|
+
--- AudioFile#pos=( [new_pos] )
|
135
|
+
Move to a new position inside the file. The position is specified in frames.
|
136
|
+
You cannot move backwards inside the file; #pos= will throw an exception if you
|
137
|
+
do.
|
138
|
+
|
139
|
+
--- AudioFile#frame_count
|
140
|
+
Returns how many frames are in this file.
|
141
|
+
|
142
|
+
--- AudioFile#virtual_byte_order=( [new_byte_order] )
|
143
|
+
Sets the virtual byte order. new_byte_order should be either
|
144
|
+
AudioFile::BIG_ENDIAN or AudioFile::LITTLE_ENDIAN.
|
145
|
+
|
146
|
+
When you read from the file, this byte order is the one the results will come
|
147
|
+
back in. So if you are reading a little-endian file and you use
|
148
|
+
#virtual_byte_order= AudioFile::BIG_ENDIAN, then #read, the data you get will
|
149
|
+
be in big-endian byte order, because the library will switch the bytes on the
|
150
|
+
fly.
|
151
|
+
|
152
|
+
Conversely, if you are writing a file, and you set the virtual byte order,
|
153
|
+
audiofile will take the bytes you give it in the virtual byte order, and swap
|
154
|
+
them if needed in order to get them into the file in the real byte order.
|
155
|
+
|
156
|
+
--- AudioFile#virtual_byte_order
|
157
|
+
Returns the virtual byte order. This will be one of:
|
158
|
+
* AudioFile::BIG_ENDIAN
|
159
|
+
* AudioFile::LITTLE_ENDIAN
|
160
|
+
|
161
|
+
--- AudioFile#byte_order
|
162
|
+
Returns the real byte order. See the constants above. This is the byte
|
163
|
+
order in which the file is stored and does not change when you use
|
164
|
+
#virtual_byte_order=.
|
165
|
+
|
166
|
+
--- AudioFile#byte_order=
|
167
|
+
Sets the byte order in which the file will be written. For use when writing
|
168
|
+
files only. Use before actually writing to the file.
|
169
|
+
|
170
|
+
--- AudioFile#compression
|
171
|
+
Returns the compression type, which will be one of:
|
172
|
+
* AudioFile::UNKNOWN
|
173
|
+
* AudioFile::NONE
|
174
|
+
* AudioFile::G722
|
175
|
+
* AudioFile::G711_ULAW
|
176
|
+
* AudioFile::G711_ALAW
|
177
|
+
|
178
|
+
Or one of these, which are detected but unsupported by the audiofile library:
|
179
|
+
* AudioFile::APPLE_ACE2
|
180
|
+
* AudioFile::APPLE_ACE8
|
181
|
+
* AudioFile::APPLE_MAC3
|
182
|
+
* AudioFile::APPLE_MAC6
|
183
|
+
* AudioFile::G726
|
184
|
+
* AudioFile::G728
|
185
|
+
* AudioFile::DVI_AUDIO
|
186
|
+
* AudioFile::GSM
|
187
|
+
* AudioFile::FS1016
|
188
|
+
|
189
|
+
--- AudioFile#compression=
|
190
|
+
Sets the compression type. See the constants above. For use when
|
191
|
+
writing files only. Use before actually writing to the file.
|
192
|
+
|
193
|
+
--- AudioFile#sample_format
|
194
|
+
Returns the sample format, which will be one of:
|
195
|
+
* AudioFile::TWOS_COMPLEMENT
|
196
|
+
* AudioFile::UNSIGNED
|
197
|
+
* AudioFile::FLOAT
|
198
|
+
* AudioFile::DOUBLE
|
199
|
+
|
200
|
+
--- AudioFile#sample_format=
|
201
|
+
Sets the sample format. See the constants above. For use when
|
202
|
+
writing files only. Use before actually writing to the file.
|
203
|
+
|
204
|
+
--- AudioFile#bits
|
205
|
+
Returns the number of bits in a sample. Commonly, this is 8 or 16. Some of the
|
206
|
+
file formats supported support sample widths greater than 16, which are usually
|
207
|
+
24 or 32. The default behavior is to pad 24-bit samples to 32 bits for speed of
|
208
|
+
handling (and to expect padded samples when writing, thus throwing away every
|
209
|
+
fourth byte). To change this, look for the EXPAND_3TO4 define in the source
|
210
|
+
(audiofile.c, around line 90), change and recompile.
|
211
|
+
|
212
|
+
--- AudioFile#bits=
|
213
|
+
Sets the number of bits in a sample. For use when writing files only. Use
|
214
|
+
before actually writing to the file.
|
215
|
+
|
216
|
+
--- AudioFile#rate
|
217
|
+
Returns the number of samples per second. (commonly 44100, 22050, etc.)
|
218
|
+
|
219
|
+
--- AudioFile#rate=
|
220
|
+
Sets the number of samples per second. For use when writing files
|
221
|
+
only. Use before actually writing to the file.
|
222
|
+
|
223
|
+
--- AudioFile#channels
|
224
|
+
Returns the number of channels. (commonly 1 or 2)
|
225
|
+
|
226
|
+
--- AudioFile#channels=
|
227
|
+
Sets the number of channels. For use when writing files only. Use before
|
228
|
+
actually writing to the file.
|
229
|
+
|
230
|
+
--- AudioFile#pcm_mapping
|
231
|
+
Returns an array containing four floats. See below.
|
232
|
+
|
233
|
+
--- AudioFile#pcm_mapping=( param )
|
234
|
+
param is an array containing four floats, corresponding to the slope,
|
235
|
+
intercept, minimum clip and maximum clip values. This alters how the library
|
236
|
+
sees the samples. Example:
|
237
|
+
file.real_pcm_mapping = [0.0, 1.0, -1.0, 1.0]
|
238
|
+
The numbers define a piecewise linear function through which sample values are
|
239
|
+
mapped. By changing this, you can do things like make audiofile double all the
|
240
|
+
sample values it reads on the fly before you see them.
|
241
|
+
|
242
|
+
== About the virtual_ prefix on method names
|
243
|
+
The audiofile library (ideally) supports complete virtualization of all
|
244
|
+
parameters of a sound file (sampling frequency, sample type, compresson...)
|
245
|
+
such that the library would translate on the fly from the format in the file to
|
246
|
+
the format the user of the library wishes to see. All of this support isn't in
|
247
|
+
place yet: in fact, the only thing that is virtualized right now is the byte
|
248
|
+
order. So when complete virtualization is supported, this binding will have
|
249
|
+
#virtual_sample_rate=, #virtual_sample_format=, etc. methods. Right now there's
|
250
|
+
only #virtual_byte_order and #virtual_byte_order=.
|
251
|
+
|
252
|
+
== Have fun with it!
|
253
|
+
If you have any more questions about ruby-audiofile, you can look at the source
|
254
|
+
(by the way, many thanks to matz for writing extensions before I did; I copied
|
255
|
+
the structure of my extension from gdbm, which he wrote). Or you can ask me
|
256
|
+
questions at ((<"mailto:jjenning@fastmail.fm"|jjenning@fastmail.fm>)).
|
257
|
+
|
258
|
+
If you use this extension, I'd love to know! Email me and tell me.
|
259
|
+
|
260
|
+
== Possible future features
|
261
|
+
* querying the library for its capabilities.
|
262
|
+
* reading and writing non-strictly-audio data parts like instruments and loops.
|
263
|
+
|
264
|
+
The methods that return constants will hopefully end up more elegant in
|
265
|
+
some way.
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'audiofile'
|
2
|
+
|
3
|
+
# Version 0.2: This script now works OK and does not fail.
|
4
|
+
# In an older version it caused Ruby to segfault (inside audiofile).
|
5
|
+
|
6
|
+
# change for your setup.
|
7
|
+
WORKING_AUDIO_FILE = "/home/jaredj/plasmoid.wav"
|
8
|
+
|
9
|
+
begin
|
10
|
+
bytes_read = 10000
|
11
|
+
while bytes_read > 0
|
12
|
+
print bytes_read, " "
|
13
|
+
bytes_read = bytes_read - 1
|
14
|
+
end
|
15
|
+
rescue
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
20
|
+
f.close
|
21
|
+
rescue
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
have_library: checking for afOpenFile() in -laudiofile... -------------------- yes
|
2
|
+
|
3
|
+
"i686-pc-linux-gnu-gcc -o conftest -I. -I/usr/lib/ruby/1.8/i686-linux -I. -O2 -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -pipe -fno-strict-aliasing -fPIC conftest.c -L'.' -L'/usr/lib' -Wl,-R'/usr/lib' -L. -rdynamic -Wl,-export-dynamic -lruby18-static -laudiofile -ldl -lcrypt -lm -lc"
|
4
|
+
conftest.c: En la función ‘t’:
|
5
|
+
conftest.c:3: error: ‘afOpenFile’ no se declaró aquí (primer uso en esta función)
|
6
|
+
conftest.c:3: error: (Cada identificador no declarado solamente se reporta una vez
|
7
|
+
conftest.c:3: error: ara cada funcion en la que aparece.)
|
8
|
+
checked program was:
|
9
|
+
/* begin */
|
10
|
+
1: /*top*/
|
11
|
+
2: int main() { return 0; }
|
12
|
+
3: int t() { void ((*volatile p)()); p = (void ((*)()))afOpenFile; return 0; }
|
13
|
+
/* end */
|
14
|
+
|
15
|
+
"i686-pc-linux-gnu-gcc -o conftest -I. -I/usr/lib/ruby/1.8/i686-linux -I. -O2 -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -pipe -fno-strict-aliasing -fPIC conftest.c -L'.' -L'/usr/lib' -Wl,-R'/usr/lib' -L. -rdynamic -Wl,-export-dynamic -lruby18-static -laudiofile -ldl -lcrypt -lm -lc"
|
16
|
+
checked program was:
|
17
|
+
/* begin */
|
18
|
+
1: /*top*/
|
19
|
+
2: int main() { return 0; }
|
20
|
+
3: int t() { afOpenFile(); return 0; }
|
21
|
+
/* end */
|
22
|
+
|
23
|
+
--------------------
|
24
|
+
|
25
|
+
have_header: checking for audiofile.h... -------------------- yes
|
26
|
+
|
27
|
+
"i686-pc-linux-gnu-gcc -E -I. -I/usr/lib/ruby/1.8/i686-linux -I. -O2 -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -pipe -fno-strict-aliasing -fPIC conftest.c -o conftest.i"
|
28
|
+
checked program was:
|
29
|
+
/* begin */
|
30
|
+
1: #include <audiofile.h>
|
31
|
+
/* end */
|
32
|
+
|
33
|
+
--------------------
|
34
|
+
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require './audiofile'
|
2
|
+
|
3
|
+
# change for your setup.
|
4
|
+
WORKING_AUDIO_FILE = "/home/jaredj/plasmoid.wav"
|
5
|
+
WRITING_AUDIO_FILE = "/home/jaredj/plasmoid-new.wav"
|
6
|
+
|
7
|
+
# this should be nonexistent, or try files with the wrong format, etc
|
8
|
+
BOGUS_AUDIO_FILE = "/home/jaredj/wuhwiuthw4otwoti"
|
9
|
+
|
10
|
+
begin
|
11
|
+
one = AudioFile.new
|
12
|
+
rescue
|
13
|
+
print "OK ! illegal # parameters to AudioFile.new fails\n"
|
14
|
+
print " ", $!, "\n\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
two = AudioFile.new WORKING_AUDIO_FILE
|
19
|
+
two.close
|
20
|
+
three = AudioFile.new WORKING_AUDIO_FILE,"r"
|
21
|
+
three.close
|
22
|
+
rescue
|
23
|
+
print "FAILED! Opening #{WORKING_AUDIO_FILE} for reading\n"
|
24
|
+
print " ", $!, "\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
three_half = AudioFile.open WORKING_AUDIO_FILE
|
29
|
+
three_half.close
|
30
|
+
rescue
|
31
|
+
print "FAILED! AudioFile.open doesn't work\n"
|
32
|
+
print " ", $!, "\n\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
AudioFile.open(WORKING_AUDIO_FILE) do |file|
|
37
|
+
a = 4
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
print "FAILED! AudioFile.open with block doesn't work\n"
|
41
|
+
print " ", $!, "\n\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
begin
|
48
|
+
four = AudioFile.new WORKING_AUDIO_FILE,"w"
|
49
|
+
four.close
|
50
|
+
rescue
|
51
|
+
print "OK ! Writing doesn't work without a FileSetup\n"
|
52
|
+
print " (In this version, writing doesn't work at all)\n"
|
53
|
+
print " ", $!, "\n\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
begin
|
57
|
+
five = AudioFile.new WORKING_AUDIO_FILE,"foo"
|
58
|
+
five.close
|
59
|
+
rescue
|
60
|
+
print "OK ! AudioFile.new with nonsense mode fails\n"
|
61
|
+
print " ", $!, "\n\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
six = AudioFile.new BOGUS_AUDIO_FILE
|
66
|
+
rescue
|
67
|
+
print "OK ! Opening nonexistent or unsupported files doesn't work\n"
|
68
|
+
print " ", $!, "\n\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
begin
|
72
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
73
|
+
[
|
74
|
+
"pos",
|
75
|
+
"rate",
|
76
|
+
"bits",
|
77
|
+
"channels",
|
78
|
+
"byte_order",
|
79
|
+
"compression",
|
80
|
+
"file_format",
|
81
|
+
"sample_format",
|
82
|
+
"virtual_byte_order",
|
83
|
+
"file_format_version",
|
84
|
+
"frame_count",
|
85
|
+
"frame_size",
|
86
|
+
].each { |method|
|
87
|
+
print " ", method, " = ", f.instance_eval(method), "\n"
|
88
|
+
}
|
89
|
+
rescue
|
90
|
+
print "FAILED! Getting info about #{WORKING_AUDIO_FILE} doesn't work\n"
|
91
|
+
print " ", $!, "\n\n"
|
92
|
+
ensure
|
93
|
+
f.close
|
94
|
+
end
|
95
|
+
|
96
|
+
# take these $stdout.flush'es out and Ruby crashes when you run this script
|
97
|
+
# for minimum case that causes the error, see fail.rb
|
98
|
+
|
99
|
+
begin
|
100
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
101
|
+
string = " " * 10000;
|
102
|
+
bytes_read = 1
|
103
|
+
print "Reading from #{WORKING_AUDIO_FILE}... "
|
104
|
+
$stdout.flush
|
105
|
+
while bytes_read > 0
|
106
|
+
bytes_read = f.read_into(string)
|
107
|
+
print bytes_read, " "
|
108
|
+
$stdout.flush
|
109
|
+
end
|
110
|
+
print "\n"
|
111
|
+
rescue
|
112
|
+
print "FAILED! Couldn't read #{WORKING_AUDIO_FILE} properly.\n"
|
113
|
+
print " ", $!, "\n\n"
|
114
|
+
ensure
|
115
|
+
f.close
|
116
|
+
end
|
117
|
+
|
118
|
+
begin
|
119
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
120
|
+
f.pos
|
121
|
+
f.pos=100
|
122
|
+
rescue
|
123
|
+
print "FAILED! Couldn't seek/tell within #{WORKING_AUDIO_FILE}.\n"
|
124
|
+
print " ", $!, "\n\n"
|
125
|
+
ensure
|
126
|
+
f.close
|
127
|
+
end
|
128
|
+
|
129
|
+
begin
|
130
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
131
|
+
f.pos=100
|
132
|
+
f.pos=0
|
133
|
+
rescue
|
134
|
+
print "OK ! Couldn't seek backwards within #{WORKING_AUDIO_FILE}.\n"
|
135
|
+
print " ", $!, "\n\n"
|
136
|
+
ensure
|
137
|
+
f.close
|
138
|
+
end
|
139
|
+
|
140
|
+
begin
|
141
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
142
|
+
f.pcm_mapping= [0.1,0.9,0.1,0.9]
|
143
|
+
rescue
|
144
|
+
print "FAILED! Changing PCM mapping doesn't work\n"
|
145
|
+
print " ", $!, "\n\n"
|
146
|
+
ensure
|
147
|
+
f.close
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# writing tests
|
154
|
+
|
155
|
+
begin
|
156
|
+
g = AudioFile.new WRITING_AUDIO_FILE, "w"
|
157
|
+
rescue
|
158
|
+
print "FAILED! Couldn't open #{WRITING_AUDIO_FILE} for writing.\n"
|
159
|
+
print " ", $!, "\n\n"
|
160
|
+
ensure
|
161
|
+
g.close
|
162
|
+
end
|
163
|
+
|
164
|
+
begin
|
165
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
166
|
+
g = AudioFile.new WRITING_AUDIO_FILE, "w"
|
167
|
+
|
168
|
+
g.rate= f.rate
|
169
|
+
g.bits= f.bits
|
170
|
+
g.channels= f.channels
|
171
|
+
g.byte_order= f.byte_order
|
172
|
+
g.compression= f.compression
|
173
|
+
g.file_format= f.file_format
|
174
|
+
g.sample_format= f.sample_format
|
175
|
+
|
176
|
+
rescue
|
177
|
+
print "FAILED! Couldn't change things about #{WRITING_AUDIO_FILE} while writing.\n"
|
178
|
+
print " ", $!, "\n\n"
|
179
|
+
ensure
|
180
|
+
f.close
|
181
|
+
g.close
|
182
|
+
end
|
183
|
+
|
184
|
+
begin
|
185
|
+
g = AudioFile.new WRITING_AUDIO_FILE, "w"
|
186
|
+
|
187
|
+
g.rate= 44100
|
188
|
+
g.write "poit"
|
189
|
+
g.bits= 16
|
190
|
+
rescue
|
191
|
+
print "OK ! Couldn't set things about a file after opening it for writing\n"
|
192
|
+
print " ", $!, "\n\n"
|
193
|
+
ensure
|
194
|
+
g.close
|
195
|
+
end
|
196
|
+
|
197
|
+
begin
|
198
|
+
f = AudioFile.new WORKING_AUDIO_FILE
|
199
|
+
g = AudioFile.new WRITING_AUDIO_FILE, "w"
|
200
|
+
|
201
|
+
g.rate= f.rate
|
202
|
+
g.bits= f.bits
|
203
|
+
g.channels= f.channels
|
204
|
+
g.byte_order= f.byte_order
|
205
|
+
g.compression= f.compression
|
206
|
+
g.file_format= f.file_format
|
207
|
+
g.sample_format= f.sample_format
|
208
|
+
|
209
|
+
print "Copying: "
|
210
|
+
bytes_read = 1
|
211
|
+
while(bytes_read != 0)
|
212
|
+
str = f.read 10000
|
213
|
+
bytes_read = str.length
|
214
|
+
print "read #{bytes_read} - "
|
215
|
+
$stdout.flush
|
216
|
+
bytes_written = g.write str
|
217
|
+
print "wrote #{bytes_written} - "
|
218
|
+
end
|
219
|
+
print "done!\n"
|
220
|
+
rescue
|
221
|
+
print "FAILED! Couldn't write #{WRITING_AUDIO_FILE}\n"
|
222
|
+
print " ", $!, "\n\n"
|
223
|
+
ensure
|
224
|
+
f.close
|
225
|
+
g.close
|
226
|
+
end
|
227
|
+
|
228
|
+
puts "Now play #{WORKING_AUDIO_FILE} and #{WRITING_AUDIO_FILE}."
|
229
|
+
puts "They should sound the same"
|