ruby-audio 1.3.0 → 1.4.0
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/Rakefile +1 -1
- data/ext/extconf.rb +19 -5
- data/ext/ra_buffer.c +28 -20
- data/ext/ra_buffer.h +4 -4
- data/ext/ra_sound.c +1 -1
- data/lib/ruby-audio/sound_info.rb +1 -1
- data/spec/buffer_spec.rb +1 -1
- data/spec/sound_info_spec.rb +1 -1
- data/spec/sound_spec.rb +1 -1
- metadata +9 -4
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'spec/rake/spectask'
|
|
6
6
|
|
7
7
|
spec = Gem::Specification.new do |s|
|
8
8
|
s.name = 'ruby-audio'
|
9
|
-
s.version = '1.
|
9
|
+
s.version = '1.4.0'
|
10
10
|
s.summary = 'ruby-audio wraps around libsndfile to provide simplified sound reading and writing support to ruby programs'
|
11
11
|
s.authors = ['Stephen Augenstein']
|
12
12
|
s.email = 'perl.programmer@gmail.com'
|
data/ext/extconf.rb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
$CFLAGS
|
4
|
-
$LDFLAGS
|
3
|
+
$CFLAGS.gsub!("-arch i386", "")
|
4
|
+
$LDFLAGS.gsub!("-arch i386", "")
|
5
|
+
|
6
|
+
dir_config('sndfile')
|
7
|
+
|
8
|
+
# Mega-Nerd windows installer installs as libsndfile-1.dll
|
9
|
+
if RUBY_PLATFORM =~ /(mswin|mingw|cygwin)/
|
10
|
+
sndfile_lib = 'sndfile-1'
|
11
|
+
else
|
12
|
+
sndfile_lib = 'sndfile'
|
13
|
+
end
|
5
14
|
|
6
15
|
# libsndfile requirements
|
7
|
-
|
8
|
-
|
9
|
-
|
16
|
+
find_header 'sndfile.h', '/opt/local/include', '/usr/local/include', 'C:/Program Files/Mega-Nerd/libsndfile/include'
|
17
|
+
unless find_library sndfile_lib, 'sf_open', '/opt/local/lib', '/usr/local/lib', 'C:/Program Files/Mega-Nerd/libsndfile'
|
18
|
+
fail <<-EOM
|
19
|
+
Can't find libsndfile (http://www.mega-nerd.com/libsndfile/)
|
20
|
+
|
21
|
+
Try passing --with-sndfile-dir or --with-sndfile-lib and --with-sndfile-include
|
22
|
+
options to extconf.
|
23
|
+
EOM
|
10
24
|
end
|
11
25
|
|
12
26
|
# Check for format support
|
data/ext/ra_buffer.c
CHANGED
@@ -48,13 +48,21 @@ static void ra_buffer_free(RA_BUFFER *buf) {
|
|
48
48
|
* Uses size, channels, and type to allocate a properly sized array and set data
|
49
49
|
* to the pointer for that data. Returns size.
|
50
50
|
*/
|
51
|
-
static
|
52
|
-
|
51
|
+
static long ra_buffer_alloc_data(RA_BUFFER *buf) {
|
52
|
+
long size = 0;
|
53
53
|
switch(buf->type) {
|
54
|
-
case RA_BUFFER_TYPE_SHORT:
|
55
|
-
|
56
|
-
|
57
|
-
case
|
54
|
+
case RA_BUFFER_TYPE_SHORT:
|
55
|
+
size = sizeof(short) * buf->size * buf->channels;
|
56
|
+
break;
|
57
|
+
case RA_BUFFER_TYPE_INT:
|
58
|
+
size = sizeof(int) * buf->size * buf->channels;
|
59
|
+
break;
|
60
|
+
case RA_BUFFER_TYPE_FLOAT:
|
61
|
+
size = sizeof(float) * buf->size * buf->channels;
|
62
|
+
break;
|
63
|
+
case RA_BUFFER_TYPE_DOUBLE:
|
64
|
+
size = sizeof(double) * buf->size * buf->channels;
|
65
|
+
break;
|
58
66
|
}
|
59
67
|
buf->data = (void*)xmalloc(size);
|
60
68
|
return size;
|
@@ -95,7 +103,7 @@ static VALUE ra_buffer_init(int argc, VALUE *argv, VALUE self) {
|
|
95
103
|
buf->channels = (argc == 3) ? FIX2INT(argv[2]) : 1;
|
96
104
|
|
97
105
|
// Allocate data array based on type
|
98
|
-
buf->size =
|
106
|
+
buf->size = FIX2LONG(argv[1]);
|
99
107
|
buf->real_size = 0;
|
100
108
|
if(strcmp(buf_type, "short") == 0) buf->type = RA_BUFFER_TYPE_SHORT;
|
101
109
|
else if(strcmp(buf_type, "int") == 0) buf->type = RA_BUFFER_TYPE_INT;
|
@@ -124,7 +132,7 @@ static VALUE ra_buffer_init_copy(VALUE copy, VALUE buf) {
|
|
124
132
|
|
125
133
|
// Clone data
|
126
134
|
memcpy(copy_struct, buf_struct, sizeof(RA_BUFFER));
|
127
|
-
|
135
|
+
long size = ra_buffer_alloc_data(copy_struct);
|
128
136
|
memcpy(copy_struct->data, buf_struct->data, size);
|
129
137
|
|
130
138
|
return copy;
|
@@ -151,7 +159,7 @@ static VALUE ra_buffer_channels(VALUE self) {
|
|
151
159
|
static VALUE ra_buffer_size(VALUE self) {
|
152
160
|
RA_BUFFER *buf;
|
153
161
|
Data_Get_Struct(self, RA_BUFFER, buf);
|
154
|
-
return
|
162
|
+
return LONG2FIX(buf->size);
|
155
163
|
}
|
156
164
|
|
157
165
|
/*
|
@@ -164,7 +172,7 @@ static VALUE ra_buffer_size(VALUE self) {
|
|
164
172
|
static VALUE ra_buffer_real_size(VALUE self) {
|
165
173
|
RA_BUFFER *buf;
|
166
174
|
Data_Get_Struct(self, RA_BUFFER, buf);
|
167
|
-
return
|
175
|
+
return LONG2FIX(buf->real_size);
|
168
176
|
}
|
169
177
|
|
170
178
|
/*:nodoc:*/
|
@@ -172,7 +180,7 @@ static VALUE ra_buffer_real_size_set(VALUE self, VALUE real_size) {
|
|
172
180
|
RA_BUFFER *buf;
|
173
181
|
Data_Get_Struct(self, RA_BUFFER, buf);
|
174
182
|
|
175
|
-
|
183
|
+
long new_real_size = FIX2LONG(real_size);
|
176
184
|
if(new_real_size > buf->size) {
|
177
185
|
buf->real_size = buf->size;
|
178
186
|
} else if(new_real_size < 0) {
|
@@ -181,7 +189,7 @@ static VALUE ra_buffer_real_size_set(VALUE self, VALUE real_size) {
|
|
181
189
|
buf->real_size = new_real_size;
|
182
190
|
}
|
183
191
|
|
184
|
-
return
|
192
|
+
return LONG2FIX(buf->real_size);
|
185
193
|
}
|
186
194
|
|
187
195
|
/*
|
@@ -219,15 +227,15 @@ static VALUE ra_buffer_aref(VALUE self, VALUE index) {
|
|
219
227
|
Data_Get_Struct(self, RA_BUFFER, buf);
|
220
228
|
|
221
229
|
// Bounds check
|
222
|
-
|
230
|
+
long f = FIX2LONG(index);
|
223
231
|
if(f < 0 || f >= buf->real_size) return Qnil;
|
224
|
-
|
232
|
+
long i = f * buf->channels;
|
225
233
|
|
226
234
|
if(buf->channels == 1) {
|
227
235
|
return ra_buffer_index_get(buf, i);
|
228
236
|
} else {
|
229
237
|
VALUE frame = rb_ary_new();
|
230
|
-
|
238
|
+
long j;
|
231
239
|
for(j = 0; j < buf->channels; j++) {
|
232
240
|
rb_ary_push(frame, ra_buffer_index_get(buf, i+j));
|
233
241
|
}
|
@@ -235,7 +243,7 @@ static VALUE ra_buffer_aref(VALUE self, VALUE index) {
|
|
235
243
|
}
|
236
244
|
}
|
237
245
|
|
238
|
-
static VALUE ra_buffer_index_get(RA_BUFFER *buf,
|
246
|
+
static VALUE ra_buffer_index_get(RA_BUFFER *buf, long i) {
|
239
247
|
switch(buf->type) {
|
240
248
|
case RA_BUFFER_TYPE_SHORT: return INT2FIX((int)((short*)buf->data)[i]);
|
241
249
|
case RA_BUFFER_TYPE_INT: return INT2FIX(((int*)buf->data)[i]);
|
@@ -263,9 +271,9 @@ static VALUE ra_buffer_aset(VALUE self, VALUE index, VALUE val) {
|
|
263
271
|
Data_Get_Struct(self, RA_BUFFER, buf);
|
264
272
|
|
265
273
|
// Bounds check
|
266
|
-
|
274
|
+
long f = FIX2LONG(index);
|
267
275
|
if(f < 0 || f >= buf->size) rb_raise(eRubyAudioError, "setting frame out of bounds");
|
268
|
-
|
276
|
+
long i = f * buf->channels;
|
269
277
|
|
270
278
|
// Set data
|
271
279
|
if(buf->channels == 1) {
|
@@ -275,7 +283,7 @@ static VALUE ra_buffer_aset(VALUE self, VALUE index, VALUE val) {
|
|
275
283
|
long length = RARRAY_LEN(val);
|
276
284
|
if(length != buf->channels) rb_raise(eRubyAudioError, "array length must match channel count");
|
277
285
|
|
278
|
-
|
286
|
+
long j;
|
279
287
|
for(j = 0; j < length; j++) {
|
280
288
|
ra_buffer_index_set(buf, i+j, rb_ary_entry(val, j));
|
281
289
|
}
|
@@ -289,7 +297,7 @@ static VALUE ra_buffer_aset(VALUE self, VALUE index, VALUE val) {
|
|
289
297
|
return val;
|
290
298
|
}
|
291
299
|
|
292
|
-
static void ra_buffer_index_set(RA_BUFFER *buf,
|
300
|
+
static void ra_buffer_index_set(RA_BUFFER *buf, long i, VALUE val) {
|
293
301
|
switch(buf->type) {
|
294
302
|
case RA_BUFFER_TYPE_SHORT:
|
295
303
|
((short*)buf->data)[i] = (short)FIX2INT(val);
|
data/ext/ra_buffer.h
CHANGED
@@ -13,8 +13,8 @@ typedef enum {
|
|
13
13
|
typedef struct {
|
14
14
|
BUFFER_TYPE type;
|
15
15
|
void *data;
|
16
|
-
|
17
|
-
|
16
|
+
long size;
|
17
|
+
long real_size;
|
18
18
|
int channels;
|
19
19
|
} RA_BUFFER;
|
20
20
|
|
@@ -33,8 +33,8 @@ static VALUE ra_buffer_real_size(VALUE self);
|
|
33
33
|
static VALUE ra_buffer_real_size_set(VALUE self, VALUE new_real_size);
|
34
34
|
static VALUE ra_buffer_type(VALUE self);
|
35
35
|
static VALUE ra_buffer_aref(VALUE self, VALUE index);
|
36
|
-
static VALUE ra_buffer_index_get(RA_BUFFER *buf,
|
36
|
+
static VALUE ra_buffer_index_get(RA_BUFFER *buf, long i);
|
37
37
|
static VALUE ra_buffer_aset(VALUE self, VALUE index, VALUE val);
|
38
|
-
static void ra_buffer_index_set(RA_BUFFER *buf,
|
38
|
+
static void ra_buffer_index_set(RA_BUFFER *buf, long i, VALUE val);
|
39
39
|
|
40
40
|
#endif // #ifndef RA_BUFFER_H
|
data/ext/ra_sound.c
CHANGED
data/spec/buffer_spec.rb
CHANGED
data/spec/sound_info_spec.rb
CHANGED
data/spec/sound_spec.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-audio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
+
- 4
|
8
9
|
- 0
|
9
|
-
version: 1.
|
10
|
+
version: 1.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Stephen Augenstein
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-12-23 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -67,23 +68,27 @@ rdoc_options:
|
|
67
68
|
require_paths:
|
68
69
|
- lib
|
69
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
70
72
|
requirements:
|
71
73
|
- - ">="
|
72
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
73
76
|
segments:
|
74
77
|
- 0
|
75
78
|
version: "0"
|
76
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
77
81
|
requirements:
|
78
82
|
- - ">="
|
79
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
80
85
|
segments:
|
81
86
|
- 0
|
82
87
|
version: "0"
|
83
88
|
requirements:
|
84
89
|
- libsndfile (http://www.mega-nerd.com/libsndfile/)
|
85
90
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.3.
|
91
|
+
rubygems_version: 1.3.7
|
87
92
|
signing_key:
|
88
93
|
specification_version: 3
|
89
94
|
summary: ruby-audio wraps around libsndfile to provide simplified sound reading and writing support to ruby programs
|