gme 0.0.9-x86-linux

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/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = GME: Game Music Emulator for Ruby
2
+
3
+ This gem allows the use of the gme library (http://code.google.com/p/game-music-emu/)
4
+ by Blargg (http://www.fly.net/~ant/libs/audio.html) in Ruby programs.
5
+
6
+ At the moment, it implements just the basic functionality, and it's not suitable for production.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |gemspec|
5
+ gemspec.name = "gme"
6
+ gemspec.summary = "gme for Ruby"
7
+ gemspec.description = "libgme interface for Ruby"
8
+
9
+ gemspec.authors << "Carlos Beltrán-Recabarren"
10
+ gemspec.email = "cbrecabarren@gmail.com"
11
+ gemspec.homepage = "http://www.beltran-recabarren.com"
12
+
13
+ gemspec.extensions << "ext/gme/extconf.rb"
14
+ gemspec.platform = Gem::Platform::CURRENT
15
+
16
+ gemspec.requirements = "libgme v0.5.5 (http://code.google.com/p/game-music-emu/) by Blargg"
17
+ gemspec.files = FileList['lib/**/*', 'ext/**/*', '[A-Z]*'].to_a
18
+ end
19
+
20
+ Jeweler::GemcutterTasks.new
21
+
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: gem install jeweler"
24
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.9
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+ have_library 'gme'
3
+ create_makefile 'gme_ext'
data/ext/gme/gme.c ADDED
@@ -0,0 +1,27 @@
1
+ #include <ruby.h>
2
+ #include "gme_funcs.h"
3
+ #include "util.h"
4
+
5
+ // classes and modules representations
6
+ VALUE mGME;
7
+ VALUE cEmulator;
8
+
9
+ VALUE eGenericException;
10
+ VALUE eInvalidFile;
11
+
12
+ void Init_gme_ext()
13
+ {
14
+ mGME = rb_define_module("GME");
15
+ rb_require("gme/exceptions");
16
+ eGenericException = rb_define_class_under(mGME, "GenericException", rb_eException);
17
+ eInvalidFile = rb_define_class_under(mGME, "InvalidFile", eGenericException);
18
+ cEmulator = rb_define_class_under(mGME, "Emulator", rb_cObject);
19
+ rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("info")));
20
+ rb_funcall(cEmulator, rb_intern("attr_reader"), 1, ID2SYM(rb_intern("track_count")));
21
+ /* rb_define_alloc_func(cEmulator, gme_alloc); */
22
+ rb_define_singleton_method(cEmulator, "open", gme_ruby_open, 2);
23
+ rb_define_method(cEmulator, "close", gme_ruby_close, 0);
24
+ rb_define_method(cEmulator, "start_track", gme_ruby_start_track, -1);
25
+ rb_define_method(cEmulator, "get_samples", gme_ruby_get_samples, 1);
26
+ rb_define_method(cEmulator, "play_to_file", gme_ruby_play_to_file, 1);
27
+ }
@@ -0,0 +1,149 @@
1
+ #include "gme_funcs.h"
2
+ #include "util.h"
3
+
4
+ #include <rubyio.h>
5
+
6
+ extern VALUE cEmulator;
7
+ extern VALUE eGenericException;
8
+ extern VALUE eInvalidFile;
9
+
10
+ void gme_ruby_emu_free(void* pointer);
11
+
12
+ VALUE gme_ruby_open(VALUE self, VALUE path, VALUE sample_rate)
13
+ {
14
+ Music_Emu* emulator;
15
+ int c_sample_rate;
16
+ char* c_path;
17
+ int track = 0;
18
+ gme_info_t* info;
19
+
20
+ VALUE string = StringValue(path);
21
+ c_path = RSTRING_PTR(string);
22
+ c_sample_rate = FIX2INT(sample_rate);
23
+
24
+ handle_error(gme_open_file(c_path, &emulator, c_sample_rate), eInvalidFile);
25
+ handle_error(gme_track_info(emulator, &info, track), eGenericException);
26
+
27
+ VALUE new_instance = Data_Wrap_Struct(cEmulator, 0, gme_ruby_emu_free, emulator);
28
+
29
+ VALUE info_hash = rb_hash_new();
30
+
31
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("play_length")), INT2FIX(info->play_length));
32
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("length")), INT2FIX(info->length));
33
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("intro_length")), INT2FIX(info->intro_length));
34
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("loop_length")), INT2FIX(info->loop_length));
35
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("system")), rb_str_new2(info->system));
36
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("game")), rb_str_new2(info->game));
37
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("song")), rb_str_new2(info->song));
38
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("author")), rb_str_new2(info->author));
39
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("copyright")), rb_str_new2(info->copyright));
40
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("comment")), rb_str_new2(info->comment));
41
+ rb_hash_aset(info_hash, ID2SYM(rb_intern("dumper")), rb_str_new2(info->dumper));
42
+
43
+ rb_iv_set(new_instance, "@info", info_hash);
44
+
45
+ int track_count = gme_track_count(emulator);
46
+ rb_iv_set(new_instance, "@track_count", INT2FIX(track_count));
47
+
48
+ gme_free_info(info);
49
+
50
+ return new_instance;
51
+ }
52
+
53
+ VALUE gme_ruby_close(VALUE self)
54
+ {
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
+ return Qnil;
67
+ }
68
+
69
+ VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self)
70
+ {
71
+ Music_Emu* emulator;
72
+ int c_track;
73
+
74
+ Data_Get_Struct(self, Music_Emu, emulator);
75
+
76
+ if(argc >= 1) {
77
+ c_track = FIX2INT(argv[0]);
78
+ }
79
+ else {
80
+ // default value
81
+ c_track = 0;
82
+ }
83
+
84
+ handle_error(gme_start_track(emulator, c_track), eGenericException);
85
+
86
+ return Qnil;
87
+ }
88
+
89
+ VALUE gme_ruby_get_samples(VALUE self, VALUE samples)
90
+ {
91
+ int buffer_size = FIX2INT(samples);
92
+ Music_Emu* emulator;
93
+ int c_samples;
94
+ short* c_buffer;
95
+
96
+ Data_Get_Struct(self, Music_Emu, emulator);
97
+
98
+ c_buffer = (short*) malloc(buffer_size * sizeof(short));
99
+
100
+ handle_error(gme_play(emulator, buffer_size, c_buffer), eGenericException);
101
+
102
+ VALUE ruby_string = rb_str_new((const char*)c_buffer, buffer_size * sizeof(short));
103
+
104
+ free(c_buffer);
105
+
106
+ return ruby_string;
107
+ }
108
+
109
+ VALUE gme_ruby_play_to_file(VALUE self, VALUE file)
110
+ {
111
+ int buffer_size = 1024;
112
+ short* buffer;
113
+ FILE* stdio_file;
114
+ Music_Emu* emulator;
115
+ int track = 0;
116
+
117
+ buffer = (short*) malloc(buffer_size * sizeof(short));
118
+
119
+ Data_Get_Struct(self, Music_Emu, emulator);
120
+
121
+ // TODO: fix for ruby-1.9 (fptr->stdio_file)
122
+ stdio_file = RFILE(file)->fptr->f;
123
+
124
+ if(stdio_file == NULL) {
125
+ rb_fatal("Couldn't access stdio FILE pointer");
126
+ }
127
+
128
+ gme_ignore_silence(emulator, 1);
129
+
130
+ handle_error(gme_start_track(emulator, track), eGenericException);
131
+
132
+ VALUE info_hash = rb_iv_get(self, "@info");
133
+ int play_length = FIX2INT(rb_hash_aref(info_hash, ID2SYM(rb_intern("play_length"))));
134
+
135
+ while(gme_tell(emulator) < play_length) {
136
+ handle_error(gme_play(emulator, buffer_size, buffer), eGenericException);
137
+ write_samples(stdio_file, buffer_size, buffer);
138
+ fflush(stdio_file);
139
+ }
140
+
141
+ free(buffer);
142
+
143
+ return Qnil;
144
+ }
145
+
146
+ void gme_ruby_emu_free(void* pointer)
147
+ {
148
+ if(pointer != NULL) gme_delete(pointer);
149
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef GME_FUNCS_H
2
+ #define GME_FUNCS_H
3
+
4
+ #include <ruby.h>
5
+ #include <gme/gme.h>
6
+
7
+ VALUE gme_ruby_open(VALUE self, VALUE path, VALUE sample_rate);
8
+ VALUE gme_ruby_close(VALUE self);
9
+ VALUE gme_ruby_start_track(int argc, VALUE* argv, VALUE self);
10
+ VALUE gme_ruby_get_samples(VALUE self, VALUE samples);
11
+ VALUE gme_ruby_play_to_file(VALUE self, VALUE file);
12
+
13
+ #endif
data/ext/gme/util.c ADDED
@@ -0,0 +1,13 @@
1
+ #include "util.h"
2
+
3
+ void handle_error(const char* string, VALUE exception)
4
+ {
5
+ if(string) {
6
+ rb_raise(exception, string);
7
+ }
8
+ }
9
+
10
+ void write_samples(FILE* file, int buffer_size, short* buffer)
11
+ {
12
+ fwrite(buffer, sizeof(short), buffer_size, file);
13
+ }
data/ext/gme/util.h ADDED
@@ -0,0 +1,9 @@
1
+ #ifndef _UTIL_H
2
+ #define _UTIL_H
3
+
4
+ #include <ruby.h>
5
+
6
+ void handle_error(const char* string, VALUE exception);
7
+ void write_samples(FILE* file, int buffer_size, short* buffer);
8
+
9
+ #endif
@@ -0,0 +1,7 @@
1
+ module GME
2
+ class GenericException < Exception
3
+ end
4
+
5
+ class InvalidFile < GenericException
6
+ end
7
+ end
data/lib/gme/gme.rb ADDED
@@ -0,0 +1 @@
1
+ require 'gme/exceptions'
data/lib/gme.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'gme/gme.rb'
2
+ require 'gme_ext.so'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gme
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 9
9
+ version: 0.0.9
10
+ platform: x86-linux
11
+ authors:
12
+ - "Carlos Beltr\xC3\xA1n-Recabarren"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-17 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: libgme interface for Ruby
22
+ email: cbrecabarren@gmail.com
23
+ executables: []
24
+
25
+ extensions:
26
+ - ext/gme/extconf.rb
27
+ - ext/gme/extconf.rb
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - README.rdoc
32
+ - Rakefile
33
+ - VERSION
34
+ - ext/gme/extconf.rb
35
+ - ext/gme/gme.c
36
+ - ext/gme/gme_funcs.c
37
+ - ext/gme/gme_funcs.h
38
+ - ext/gme/util.c
39
+ - ext/gme/util.h
40
+ - lib/gme.rb
41
+ - lib/gme/exceptions.rb
42
+ - lib/gme/gme.rb
43
+ has_rdoc: true
44
+ homepage: http://www.beltran-recabarren.com
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements:
67
+ - libgme v0.5.5 (http://code.google.com/p/game-music-emu/) by Blargg
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: gme for Ruby
73
+ test_files: []
74
+