gme 0.0.9-x86-linux → 0.0.10-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
data/ext/gme/Makefile ADDED
@@ -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/gme.c CHANGED
@@ -19,7 +19,7 @@ void Init_gme_ext()
19
19
  rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("info")));
20
20
  rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("track_count")));
21
21
  /* rb_define_alloc_func(cEmulator, gme_alloc); */
22
- rb_define_singleton_method(cEmulator, "open", gme_ruby_open, 2);
22
+ rb_define_singleton_method(cEmulator, "open", gme_ruby_open, -1);
23
23
  rb_define_method(cEmulator, "close", gme_ruby_close, 0);
24
24
  rb_define_method(cEmulator, "start_track", gme_ruby_start_track, -1);
25
25
  rb_define_method(cEmulator, "get_samples", gme_ruby_get_samples, 1);
data/ext/gme/gme_funcs.c CHANGED
@@ -9,25 +9,40 @@ extern VALUE eInvalidFile;
9
9
 
10
10
  void gme_ruby_emu_free(void* pointer);
11
11
 
12
- VALUE gme_ruby_open(VALUE self, VALUE path, VALUE sample_rate)
12
+ /*
13
+ * Opens a new input file
14
+ * Returns a new instance of GME::Emulator
15
+ */
16
+ VALUE gme_ruby_open(int argc, VALUE* argv, VALUE self)
13
17
  {
14
- Music_Emu* emulator;
15
- int c_sample_rate;
16
- char* c_path;
17
- int track = 0;
18
+ Music_Emu* emulator;
19
+ int c_sample_rate;
20
+ char* c_path;
21
+ int track = 0; // uses track 0 for getting info (FIXME)
18
22
  gme_info_t* info;
19
23
 
20
- VALUE string = StringValue(path);
24
+ // use the first (mandatory) argument, as path to file
25
+ VALUE string = StringValue(argv[0]);
21
26
  c_path = RSTRING_PTR(string);
22
- c_sample_rate = FIX2INT(sample_rate);
23
27
 
28
+ // use the second argument, if present, as sample rate
29
+ if(argc >= 2) {
30
+ c_sample_rate = FIX2INT(argv[1]);
31
+ }
32
+ else {
33
+ c_sample_rate = 44100;
34
+ }
35
+
36
+ // opens the specified file
24
37
  handle_error(gme_open_file(c_path, &emulator, c_sample_rate), eInvalidFile);
38
+ // and gets the info on the track
25
39
  handle_error(gme_track_info(emulator, &info, track), eGenericException);
26
40
 
41
+ // creates a new instance of GME::Emulator, as a wrapper around Music_Emu
27
42
  VALUE new_instance = Data_Wrap_Struct(cEmulator, 0, gme_ruby_emu_free, emulator);
28
43
 
44
+ // Fills the info hash
29
45
  VALUE info_hash = rb_hash_new();
30
-
31
46
  rb_hash_aset(info_hash, ID2SYM(rb_intern("play_length")), INT2FIX(info->play_length));
32
47
  rb_hash_aset(info_hash, ID2SYM(rb_intern("length")), INT2FIX(info->length));
33
48
  rb_hash_aset(info_hash, ID2SYM(rb_intern("intro_length")), INT2FIX(info->intro_length));
@@ -39,40 +54,37 @@ VALUE gme_ruby_open(VALUE self, VALUE path, VALUE sample_rate)
39
54
  rb_hash_aset(info_hash, ID2SYM(rb_intern("copyright")), rb_str_new2(info->copyright));
40
55
  rb_hash_aset(info_hash, ID2SYM(rb_intern("comment")), rb_str_new2(info->comment));
41
56
  rb_hash_aset(info_hash, ID2SYM(rb_intern("dumper")), rb_str_new2(info->dumper));
42
-
43
57
  rb_iv_set(new_instance, "@info", info_hash);
58
+ gme_free_info(info);
44
59
 
60
+ // sets the track count
45
61
  int track_count = gme_track_count(emulator);
46
62
  rb_iv_set(new_instance, "@track_count", INT2FIX(track_count));
47
63
 
48
- gme_free_info(info);
49
-
64
+ // returns the new instance of GME::Emulator
50
65
  return new_instance;
51
66
  }
52
67
 
68
+ /*
69
+ * is this function really needed?
70
+ */
53
71
  VALUE gme_ruby_close(VALUE self)
54
72
  {
55
- // TODO: Es necesario esto?
56
-
57
- /* Music_Emu* emulator; */
58
- /* gme_info_t* info; */
59
-
60
- /* Data_Get_Struct(self, Music_Emu, emulator); */
61
- /* Data_Get_Struct(self, gme_info_t, info); */
62
-
63
- /* gme_ruby_emu_free(emulator); */
64
- /* gme_ruby_info_free(info); */
65
-
66
73
  return Qnil;
67
74
  }
68
75
 
76
+ /*
77
+ * starts a track
78
+ * if not specified, uses track number 0
79
+ */
69
80
  VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self)
70
81
  {
71
82
  Music_Emu* emulator;
72
- int c_track;
83
+ int c_track;
73
84
 
74
85
  Data_Get_Struct(self, Music_Emu, emulator);
75
86
 
87
+ // uses the first argument, if present, as track number
76
88
  if(argc >= 1) {
77
89
  c_track = FIX2INT(argv[0]);
78
90
  }
@@ -81,39 +93,56 @@ VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self)
81
93
  c_track = 0;
82
94
  }
83
95
 
96
+ // starts the track
84
97
  handle_error(gme_start_track(emulator, c_track), eGenericException);
85
98
 
86
- return Qnil;
99
+ // returns the track number started
100
+ return INT2FIX(c_track);
87
101
  }
88
102
 
103
+ /*
104
+ * Plays the specified number of samples
105
+ * FIXME: This function allocates a buffer each time it is called.
106
+ * Maybe we should use a one-time allocated buffer.
107
+ */
89
108
  VALUE gme_ruby_get_samples(VALUE self, VALUE samples)
90
109
  {
91
- int buffer_size = FIX2INT(samples);
110
+ int buffer_size = FIX2INT(samples); // buffer size equal to number of samples
92
111
  Music_Emu* emulator;
93
- int c_samples;
94
- short* c_buffer;
112
+ int c_samples;
113
+ short* c_buffer;
95
114
 
96
115
  Data_Get_Struct(self, Music_Emu, emulator);
97
116
 
117
+ // allocates memory for a buffer
98
118
  c_buffer = (short*) malloc(buffer_size * sizeof(short));
99
119
 
120
+ // plays the file, returning the specified number of samples
100
121
  handle_error(gme_play(emulator, buffer_size, c_buffer), eGenericException);
101
122
 
123
+ // creates a ruby string, containing the buffer content (generated samples)
102
124
  VALUE ruby_string = rb_str_new((const char*)c_buffer, buffer_size * sizeof(short));
103
125
 
126
+ // releases the allocated memory
104
127
  free(c_buffer);
105
128
 
129
+ // returns the played samples
106
130
  return ruby_string;
107
131
  }
108
132
 
133
+ /*
134
+ * Plays the track 0 of the input file
135
+ * and writes in the specified (ruby) output file
136
+ */
109
137
  VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
110
138
  {
111
- int buffer_size = 1024;
112
- short* buffer;
113
- FILE* stdio_file;
139
+ int buffer_size = 1024; // hardcoded buffer size (TODO?)
140
+ short* buffer;
141
+ FILE* stdio_file;
114
142
  Music_Emu* emulator;
115
- int track = 0;
143
+ int track = 0; // plays track 0 (TODO?)
116
144
 
145
+ // allocates memory for the buffer
117
146
  buffer = (short*) malloc(buffer_size * sizeof(short));
118
147
 
119
148
  Data_Get_Struct(self, Music_Emu, emulator);
@@ -121,28 +150,34 @@ VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
121
150
  // TODO: fix for ruby-1.9 (fptr->stdio_file)
122
151
  stdio_file = RFILE(file)->fptr->f;
123
152
 
153
+ // if the stdio pointer couldn't be accesed, exit the program
124
154
  if(stdio_file == NULL) {
125
155
  rb_fatal("Couldn't access stdio FILE pointer");
126
156
  }
127
157
 
128
- gme_ignore_silence(emulator, 1);
129
-
158
+ // starts track 0
130
159
  handle_error(gme_start_track(emulator, track), eGenericException);
131
160
 
161
+ // gets the play length of the track from the info hash
132
162
  VALUE info_hash = rb_iv_get(self, "@info");
133
163
  int play_length = FIX2INT(rb_hash_aref(info_hash, ID2SYM(rb_intern("play_length"))));
134
164
 
165
+ // plays the track completely
135
166
  while(gme_tell(emulator) < play_length) {
136
167
  handle_error(gme_play(emulator, buffer_size, buffer), eGenericException);
137
168
  write_samples(stdio_file, buffer_size, buffer);
138
169
  fflush(stdio_file);
139
170
  }
140
171
 
172
+ // releases the memory of the buffer
141
173
  free(buffer);
142
174
 
143
175
  return Qnil;
144
176
  }
145
177
 
178
+ /*
179
+ * free function to the GME::Emulator wrapper for Music_Emu
180
+ */
146
181
  void gme_ruby_emu_free(void* pointer)
147
182
  {
148
183
  if(pointer != NULL) gme_delete(pointer);
data/ext/gme/gme_funcs.h CHANGED
@@ -4,7 +4,7 @@
4
4
  #include <ruby.h>
5
5
  #include <gme/gme.h>
6
6
 
7
- VALUE gme_ruby_open(VALUE self, VALUE path, VALUE sample_rate);
7
+ VALUE gme_ruby_open(int argc, VALUE* argv, VALUE self);
8
8
  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, VALUE samples);
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 9
9
- version: 0.0.9
8
+ - 10
9
+ version: 0.0.10
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 00:00:00 -04:00
17
+ date: 2010-04-21 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -31,6 +31,7 @@ files:
31
31
  - README.rdoc
32
32
  - Rakefile
33
33
  - VERSION
34
+ - ext/gme/Makefile
34
35
  - ext/gme/extconf.rb
35
36
  - ext/gme/gme.c
36
37
  - ext/gme/gme_funcs.c