gme 0.0.12-x86-linux → 0.0.13-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +37 -0
- data/VERSION +1 -1
- data/ext/gme/build/Makefile +157 -0
- data/ext/gme/build/gme.o +0 -0
- data/ext/gme/build/gme_ext.so +0 -0
- data/ext/gme/build/gme_funcs.o +0 -0
- data/ext/gme/build/mkmf.log +12 -0
- data/ext/gme/build/util.o +0 -0
- data/ext/gme/gme.c +8 -0
- data/ext/gme/gme_funcs.c +90 -4
- data/ext/gme/gme_funcs.h +4 -0
- data/lib/gme/exceptions.rb +7 -1
- data/lib/gme_ext.so +0 -0
- data/spec/emulator_spec.rb +126 -0
- data/spec/spec_helper.rb +4 -0
- metadata +13 -5
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'jeweler'
|
3
5
|
|
@@ -22,3 +24,38 @@ begin
|
|
22
24
|
rescue LoadError
|
23
25
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
24
26
|
end
|
27
|
+
|
28
|
+
require 'rake'
|
29
|
+
require 'spec'
|
30
|
+
require 'spec/rake/spectask'
|
31
|
+
|
32
|
+
spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
33
|
+
|
34
|
+
desc "Run specs"
|
35
|
+
Spec::Rake::SpecTask.new do |t|
|
36
|
+
t.spec_files = spec_files
|
37
|
+
t.spec_opts = ["-c"]
|
38
|
+
end
|
39
|
+
|
40
|
+
namespace :gme do
|
41
|
+
desc "Builds gme_ext and deploys locally on lib/gme_ext.so"
|
42
|
+
task :extbuild do
|
43
|
+
# cd to ext/gme/build
|
44
|
+
# run extconf.rb
|
45
|
+
# run make
|
46
|
+
# cp gme_ext.so to lib/
|
47
|
+
puts ">> Compiling gme_ext.so ..."
|
48
|
+
path = File.expand_path(File.dirname(__FILE__) + '/ext/gme/build')
|
49
|
+
`cd #{path}; ruby ../extconf.rb; make; cp gme_ext.so ../../../lib/gme_ext.so`
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Runs clean task in build directory and deletes lib/gme_ext.so"
|
53
|
+
task :extclean do
|
54
|
+
path = File.expand_path(File.dirname(__FILE__) + '/ext/gme/build')
|
55
|
+
`cd #{path}; make clean; rm ../../../lib/gme_ext.so`
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
task :spec => "gme:extbuild"
|
60
|
+
|
61
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = ..
|
7
|
+
topdir = /usr/lib/ruby/1.8/i486-linux
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
exec_prefix = $(prefix)
|
11
|
+
prefix = $(DESTDIR)/usr
|
12
|
+
sharedstatedir = $(prefix)/com
|
13
|
+
mandir = $(prefix)/share/man
|
14
|
+
psdir = $(docdir)
|
15
|
+
oldincludedir = $(DESTDIR)/usr/include
|
16
|
+
localedir = $(datarootdir)/locale
|
17
|
+
bindir = $(exec_prefix)/bin
|
18
|
+
libexecdir = $(prefix)/lib/ruby1.8
|
19
|
+
sitedir = $(DESTDIR)/usr/local/lib/site_ruby
|
20
|
+
htmldir = $(docdir)
|
21
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
+
includedir = $(prefix)/include
|
23
|
+
infodir = $(prefix)/share/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
+
sysconfdir = $(DESTDIR)/etc
|
26
|
+
libdir = $(exec_prefix)/lib
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
+
dvidir = $(docdir)
|
31
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
+
datarootdir = $(prefix)/share
|
33
|
+
pdfdir = $(docdir)
|
34
|
+
archdir = $(rubylibdir)/$(arch)
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(DESTDIR)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
+
|
40
|
+
CC = gcc
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags)
|
48
|
+
INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I..
|
49
|
+
DEFS = -D_FILE_OFFSET_BITS=64
|
50
|
+
CPPFLAGS = -D_FILE_OFFSET_BITS=64
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = $(CC) -shared
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby1.8
|
61
|
+
RUBY_SO_NAME = ruby1.8
|
62
|
+
arch = i486-linux
|
63
|
+
sitearch = i486-linux
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /usr/bin/ruby1.8
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lgme -lpthread -lrt -ldl -lcrypt -lm -lc
|
90
|
+
SRCS = gme_funcs.c gme.c util.c
|
91
|
+
OBJS = gme_funcs.o gme.o util.o
|
92
|
+
TARGET = gme_ext
|
93
|
+
DLLIB = $(TARGET).so
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS) Makefile
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/ext/gme/build/gme.o
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
have_library: checking for main() in -lgme... -------------------- yes
|
2
|
+
|
3
|
+
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/i486-linux -I.. -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgme -lpthread -lrt -ldl -lcrypt -lm -lc"
|
4
|
+
checked program was:
|
5
|
+
/* begin */
|
6
|
+
1: /*top*/
|
7
|
+
2: int main() { return 0; }
|
8
|
+
3: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
9
|
+
/* end */
|
10
|
+
|
11
|
+
--------------------
|
12
|
+
|
Binary file
|
data/ext/gme/gme.c
CHANGED
@@ -8,13 +8,17 @@ VALUE cEmulator;
|
|
8
8
|
|
9
9
|
VALUE eGenericException;
|
10
10
|
VALUE eInvalidFile;
|
11
|
+
VALUE eTrackNotStarted;
|
11
12
|
|
12
13
|
void Init_gme_ext()
|
13
14
|
{
|
14
15
|
mGME = rb_define_module("GME");
|
16
|
+
|
15
17
|
rb_require("gme/exceptions");
|
16
18
|
eGenericException = rb_define_class_under(mGME, "GenericException", rb_eException);
|
17
19
|
eInvalidFile = rb_define_class_under(mGME, "InvalidFile", eGenericException);
|
20
|
+
eTrackNotStarted = rb_define_class_under(mGME, "TrackNotStarted", eGenericException);
|
21
|
+
|
18
22
|
cEmulator = rb_define_class_under(mGME, "Emulator", rb_cObject);
|
19
23
|
rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("info")));
|
20
24
|
rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("track_count")));
|
@@ -30,4 +34,8 @@ void Init_gme_ext()
|
|
30
34
|
rb_define_method(cEmulator, "start_track", gme_ruby_start_track, -1);
|
31
35
|
rb_define_method(cEmulator, "get_samples", gme_ruby_get_samples, 0);
|
32
36
|
rb_define_method(cEmulator, "play_to_file", gme_ruby_play_to_file, 1);
|
37
|
+
rb_define_method(cEmulator, "track_started?", gme_ruby_track_started, 0);
|
38
|
+
rb_define_method(cEmulator, "tell", gme_ruby_tell, 0);
|
39
|
+
rb_define_method(cEmulator, "track_ended?", gme_ruby_track_ended, 0);
|
40
|
+
rb_define_method(cEmulator, "ignore_silence", gme_ruby_ignore_silence, 1);
|
33
41
|
}
|
data/ext/gme/gme_funcs.c
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
extern VALUE cEmulator;
|
7
7
|
extern VALUE eGenericException;
|
8
8
|
extern VALUE eInvalidFile;
|
9
|
+
extern VALUE eTrackNotStarted;
|
9
10
|
|
10
11
|
void gme_ruby_emu_free(void* pointer);
|
11
12
|
|
@@ -97,6 +98,9 @@ VALUE gme_ruby_open(int argc, VALUE* argv, VALUE self)
|
|
97
98
|
int track_count = gme_track_count(emulator);
|
98
99
|
rb_iv_set(new_instance, "@track_count", INT2FIX(track_count));
|
99
100
|
|
101
|
+
// no track has been started
|
102
|
+
rb_iv_set(new_instance, "@track_started", Qfalse);
|
103
|
+
|
100
104
|
// returns the new instance of GME::Emulator
|
101
105
|
return new_instance;
|
102
106
|
}
|
@@ -131,15 +135,16 @@ VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self)
|
|
131
135
|
|
132
136
|
// starts the track
|
133
137
|
handle_error(gme_start_track(emulator, c_track), eGenericException);
|
138
|
+
|
139
|
+
// a track has been started...
|
140
|
+
rb_iv_set(self, "@track_started", Qtrue);
|
134
141
|
|
135
142
|
// returns the track number started
|
136
143
|
return INT2FIX(c_track);
|
137
144
|
}
|
138
145
|
|
139
146
|
/*
|
140
|
-
* Plays
|
141
|
-
* FIXME: This function allocates a buffer each time it is called.
|
142
|
-
* Maybe we should use a one-time allocated buffer.
|
147
|
+
* Plays some samples, and returns them as an array
|
143
148
|
*/
|
144
149
|
VALUE gme_ruby_get_samples(VALUE self)
|
145
150
|
{
|
@@ -148,6 +153,9 @@ VALUE gme_ruby_get_samples(VALUE self)
|
|
148
153
|
short* c_buffer;
|
149
154
|
int c_buffer_len;
|
150
155
|
|
156
|
+
VALUE track_started = rb_iv_get(self, "@track_started");
|
157
|
+
if(!RTEST(track_started)) rb_raise(eTrackNotStarted, "you must start a track first");
|
158
|
+
|
151
159
|
Data_Get_Struct(self, Music_Emu, emulator);
|
152
160
|
|
153
161
|
// recovers a pointer to the internal buffer
|
@@ -176,11 +184,17 @@ VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
|
|
176
184
|
Music_Emu* emulator;
|
177
185
|
int track = 0; // plays track 0 (TODO?)
|
178
186
|
|
187
|
+
// throws an exception if the file passed is not valid
|
188
|
+
// FIXME: currently it *requires* an object of class File
|
189
|
+
if(NIL_P(file) || TYPE(file) != T_FILE) {
|
190
|
+
rb_raise(eGenericException, "the file is not valid.");
|
191
|
+
}
|
192
|
+
|
179
193
|
// allocates memory for the buffer
|
180
194
|
buffer = (short*) malloc(buffer_size * sizeof(short));
|
181
195
|
|
182
196
|
Data_Get_Struct(self, Music_Emu, emulator);
|
183
|
-
|
197
|
+
|
184
198
|
// TODO: fix for ruby-1.9 (fptr->stdio_file)
|
185
199
|
stdio_file = RFILE(file)->fptr->f;
|
186
200
|
|
@@ -192,6 +206,9 @@ VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
|
|
192
206
|
// starts track 0
|
193
207
|
handle_error(gme_start_track(emulator, track), eGenericException);
|
194
208
|
|
209
|
+
// track 0 has been started
|
210
|
+
rb_iv_set(self, "@track_started", Qtrue);
|
211
|
+
|
195
212
|
// gets the play length of the track from the info hash
|
196
213
|
VALUE info_hash = rb_iv_get(self, "@info");
|
197
214
|
int play_length = FIX2INT(rb_hash_aref(info_hash, ID2SYM(rb_intern("play_length"))));
|
@@ -209,6 +226,75 @@ VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
|
|
209
226
|
return Qnil;
|
210
227
|
}
|
211
228
|
|
229
|
+
/*
|
230
|
+
* Returns true if a track has been started
|
231
|
+
* and false in other cases.
|
232
|
+
*/
|
233
|
+
VALUE gme_ruby_track_started(VALUE self)
|
234
|
+
{
|
235
|
+
VALUE track_started = rb_iv_get(self, "@track_started");
|
236
|
+
|
237
|
+
if(RTEST(track_started)) return Qtrue;
|
238
|
+
|
239
|
+
return Qfalse;
|
240
|
+
}
|
241
|
+
|
242
|
+
/*
|
243
|
+
* Returns the number of milliseconds played since the start of the track
|
244
|
+
*/
|
245
|
+
VALUE gme_ruby_tell(VALUE self)
|
246
|
+
{
|
247
|
+
Music_Emu* emulator;
|
248
|
+
int milliseconds;
|
249
|
+
|
250
|
+
Data_Get_Struct(self, Music_Emu, emulator);
|
251
|
+
|
252
|
+
// gets number of millisecons played
|
253
|
+
milliseconds = gme_tell(emulator);
|
254
|
+
|
255
|
+
return INT2FIX(milliseconds);
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
/*
|
260
|
+
* Returns true if the track has ended
|
261
|
+
* and false in other cases
|
262
|
+
*/
|
263
|
+
VALUE gme_ruby_track_ended(VALUE self)
|
264
|
+
{
|
265
|
+
Music_Emu* emulator;
|
266
|
+
|
267
|
+
// throws an exception if a track hasn't been started
|
268
|
+
VALUE track_started = gme_ruby_track_started(self);
|
269
|
+
if(!RTEST(track_started)) rb_raise(eTrackNotStarted, "you have to start a track first");
|
270
|
+
|
271
|
+
Data_Get_Struct(self, Music_Emu, emulator);
|
272
|
+
|
273
|
+
// checks if the track has ended
|
274
|
+
int track_ended = gme_track_ended(emulator);
|
275
|
+
if(track_ended) return Qtrue;
|
276
|
+
|
277
|
+
return Qfalse;
|
278
|
+
}
|
279
|
+
|
280
|
+
/*
|
281
|
+
* sets whether or not to disable automatic end of track detection
|
282
|
+
* and skipping at the beginning
|
283
|
+
*/
|
284
|
+
VALUE gme_ruby_ignore_silence(VALUE self, VALUE ignore)
|
285
|
+
{
|
286
|
+
Music_Emu* emulator;
|
287
|
+
|
288
|
+
Data_Get_Struct(self, Music_Emu, emulator);
|
289
|
+
|
290
|
+
// if the parameter 'ignore' is true, then ignore the automatic
|
291
|
+
// handling of silences
|
292
|
+
if(RTEST(ignore)) gme_ignore_silence(emulator, 1);
|
293
|
+
else gme_ignore_silence(emulator, 0);
|
294
|
+
|
295
|
+
return Qnil;
|
296
|
+
}
|
297
|
+
|
212
298
|
/*
|
213
299
|
* free function to the GME::Emulator wrapper for Music_Emu
|
214
300
|
*/
|
data/ext/gme/gme_funcs.h
CHANGED
@@ -9,5 +9,9 @@ VALUE gme_ruby_close(VALUE self);
|
|
9
9
|
VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self);
|
10
10
|
VALUE gme_ruby_get_samples(VALUE self);
|
11
11
|
VALUE gme_ruby_play_to_file(VALUE self, VALUE file);
|
12
|
+
VALUE gme_ruby_track_started(VALUE self);
|
13
|
+
VALUE gme_ruby_tell(VALUE self);
|
14
|
+
VALUE gme_ruby_track_ended(VALUE self);
|
15
|
+
VALUE gme_ruby_ignore_silence(VALUE self, VALUE ignore);
|
12
16
|
|
13
17
|
#endif
|
data/lib/gme/exceptions.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module GME
|
2
|
+
# describes a generic exception, related to this gem
|
2
3
|
class GenericException < Exception
|
3
4
|
end
|
4
|
-
|
5
|
+
|
6
|
+
# thrown when a path supplied doesn't point to a valid file for the library
|
5
7
|
class InvalidFile < GenericException
|
6
8
|
end
|
9
|
+
|
10
|
+
# thrown when one tries to play a file without starting a track first
|
11
|
+
class TrackNotStarted < GenericException
|
12
|
+
end
|
7
13
|
end
|
data/lib/gme_ext.so
ADDED
Binary file
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
include GME
|
5
|
+
|
6
|
+
describe Emulator, "when first created" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
path = File.expand_path(File.dirname(__FILE__) + '/fixtures/sample.spc')
|
10
|
+
@song = Emulator.open(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not be nil" do
|
14
|
+
@song.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should acknowledge 1 track" do
|
18
|
+
@song.track_count.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should respond to the message 'info' and return a non-empty container" do
|
22
|
+
@song.info.should_not be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should correctly return the metadata of track 0 in a hash" do
|
26
|
+
@song.info[:game].should == "Super Castlevania 4"
|
27
|
+
@song.info[:song].should == "Stage Clear"
|
28
|
+
@song.info[:length].should == 4000
|
29
|
+
@song.info[:copyright].should == "1991 Konami"
|
30
|
+
@song.info[:author].should == "Masanori Adachi, Taro Kudou"
|
31
|
+
@song.info[:play_length].should == 4000
|
32
|
+
@song.info[:comment].should == ""
|
33
|
+
@song.info[:dumper].should == "Datschge"
|
34
|
+
@song.info[:system].should == "Super Nintendo"
|
35
|
+
@song.info[:loop_length].should == -1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should indicate that no track has been started" do
|
39
|
+
@song.track_started?.should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise an exception when asked if the current track has ended" do
|
43
|
+
lambda { @song.track_ended? }.should raise_exception(TrackNotStarted)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return 0 when asked for the time played since start" do
|
47
|
+
@song.tell.should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should raise and exception if get_samples is called" do
|
51
|
+
lambda { @song.get_samples }.should raise_exception(TrackNotStarted)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when play_to_file is called" do
|
55
|
+
|
56
|
+
context "when given an invalid file" do
|
57
|
+
|
58
|
+
it "should raise an exception if the file argument is nil" do
|
59
|
+
@file = nil
|
60
|
+
lambda { @song.play_to_file(@file) }.should raise_exception(GenericException)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise an exception if the file argument is not of File class" do
|
64
|
+
@file = StringIO.new
|
65
|
+
lambda { @song.play_to_file(@file) }.should raise_exception(GenericException)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when given a valid file" do
|
71
|
+
|
72
|
+
before(:each) do
|
73
|
+
@file = File.new("temp.out", "w+")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should play track 0 and write the samples to the specified file" do
|
77
|
+
lambda { @song.play_to_file(@file) }.should_not raise_exception
|
78
|
+
@song.close
|
79
|
+
File.size("temp.out").should == 706560
|
80
|
+
Digest::SHA1.hexdigest(File.read("temp.out")).should == "5a557efdb64cb71baa953b7129663b1503f4a7d9"
|
81
|
+
end
|
82
|
+
|
83
|
+
after(:each) do
|
84
|
+
@file.close unless @file.closed?
|
85
|
+
File.delete("temp.out") if File.exists?("temp.out")
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when starting a track" do
|
92
|
+
|
93
|
+
it "should start the specified track and return that number when successful" do
|
94
|
+
@song.start_track(0).should == 0
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should start track 0 when no track number is specified" do
|
98
|
+
@song.start_track.should == 0
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should raise an exception when the specified track number is invalid" do
|
102
|
+
lambda { @song.start_track(1) }.should raise_exception(GenericException)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when a track has been started" do
|
107
|
+
before(:each) do
|
108
|
+
@song.start_track(0)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should indicate that a track has been started when asked" do
|
112
|
+
@song.track_started?.should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should indicate that the track has not ended" do
|
116
|
+
@song.track_ended?.should be_false
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return 0 as the time played since the start of the track" do
|
120
|
+
@song.tell.should == 0
|
121
|
+
end
|
122
|
+
|
123
|
+
# TODO: get_samples, open with options, etc.
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 13
|
9
|
+
version: 0.0.13
|
10
10
|
platform: x86-linux
|
11
11
|
authors:
|
12
12
|
- "Carlos Beltr\xC3\xA1n-Recabarren"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-30 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -32,6 +32,12 @@ files:
|
|
32
32
|
- Rakefile
|
33
33
|
- VERSION
|
34
34
|
- ext/gme/Makefile
|
35
|
+
- ext/gme/build/Makefile
|
36
|
+
- ext/gme/build/gme.o
|
37
|
+
- ext/gme/build/gme_ext.so
|
38
|
+
- ext/gme/build/gme_funcs.o
|
39
|
+
- ext/gme/build/mkmf.log
|
40
|
+
- ext/gme/build/util.o
|
35
41
|
- ext/gme/extconf.rb
|
36
42
|
- ext/gme/gme.c
|
37
43
|
- ext/gme/gme_funcs.c
|
@@ -41,6 +47,7 @@ files:
|
|
41
47
|
- lib/gme.rb
|
42
48
|
- lib/gme/exceptions.rb
|
43
49
|
- lib/gme/gme.rb
|
50
|
+
- lib/gme_ext.so
|
44
51
|
has_rdoc: true
|
45
52
|
homepage: http://www.beltran-recabarren.com
|
46
53
|
licenses: []
|
@@ -71,5 +78,6 @@ rubygems_version: 1.3.6
|
|
71
78
|
signing_key:
|
72
79
|
specification_version: 3
|
73
80
|
summary: gme for Ruby
|
74
|
-
test_files:
|
75
|
-
|
81
|
+
test_files:
|
82
|
+
- spec/emulator_spec.rb
|
83
|
+
- spec/spec_helper.rb
|