ruby-audio 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -67,6 +67,7 @@ static long ra_buffer_alloc_data(RA_BUFFER *buf) {
67
67
  break;
68
68
  }
69
69
  buf->data = (void*)xmalloc(size);
70
+ memset(buf->data, 0, size);
70
71
  return size;
71
72
  }
72
73
 
@@ -321,18 +322,21 @@ static VALUE ra_buffer_aset(VALUE self, VALUE index, VALUE val) {
321
322
  }
322
323
 
323
324
  static void ra_buffer_index_set(RA_BUFFER *buf, long i, VALUE val) {
324
- switch(buf->type) {
325
- case RA_BUFFER_TYPE_SHORT:
326
- ((short*)buf->data)[i] = (short)FIX2INT(val);
327
- break;
328
- case RA_BUFFER_TYPE_INT:
329
- ((int*)buf->data)[i] = FIX2INT(val);
330
- break;
331
- case RA_BUFFER_TYPE_FLOAT:
332
- ((float*)buf->data)[i] = (float)RFLOAT_VALUE(val);
333
- break;
334
- case RA_BUFFER_TYPE_DOUBLE:
335
- ((double*)buf->data)[i] = RFLOAT_VALUE(val);
336
- break;
325
+ if(buf->type == RA_BUFFER_TYPE_SHORT || buf->type == RA_BUFFER_TYPE_INT) {
326
+ // Convert val to an integer
327
+ VALUE int_obj = rb_Integer(val);
328
+ if(TYPE(int_obj) != T_FIXNUM) rb_raise(eRubyAudioError, "could not convert frame value to an integer");
329
+ long int_val = FIX2LONG(int_obj);
330
+
331
+ // Set it
332
+ if(buf->type == RA_BUFFER_TYPE_SHORT) ((short*)buf->data)[i] = (short)int_val;
333
+ else ((int*)buf->data)[i] = (int)int_val;
334
+ } else {
335
+ // Convert val to a float
336
+ double float_val = RFLOAT_VALUE(rb_Float(val));
337
+
338
+ // Set it
339
+ if(buf->type == RA_BUFFER_TYPE_FLOAT) ((float*)buf->data)[i] = (float)float_val;
340
+ else ((double*)buf->data)[i] = float_val;
337
341
  }
338
342
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ruby-audio'
5
- s.version = '1.6.0'
5
+ s.version = '1.6.1'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Stephen Augenstein']
8
8
  s.email = ['perl.programmer@gmail.com']
@@ -17,10 +17,24 @@ describe RubyAudio::Buffer do
17
17
  }.should_not raise_error
18
18
  end
19
19
 
20
- it "should allow [] access on single channel buffers" do
20
+ it "should allow [] access on integer single channel buffers" do
21
21
  buf = RubyAudio::Buffer.int(100, 1)
22
22
  buf[0] = 1.3
23
23
  buf[0].should == 1
24
+
25
+ buf = RubyAudio::Buffer.short(100, 1)
26
+ buf[20] = 614
27
+ buf[20].should == 614
28
+ end
29
+
30
+ it "should allow [] access on floating point single channel buffers" do
31
+ buf = RubyAudio::Buffer.double(100, 1)
32
+ buf[30] = 1.375
33
+ buf[30].should == 1.375
34
+
35
+ buf = RubyAudio::Buffer.float(100, 1)
36
+ buf[12] = 5
37
+ buf[12].should == 5.0
24
38
  end
25
39
 
26
40
  it "should allow [] access on multi-channel buffers" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 6
8
- - 0
9
- version: 1.6.0
8
+ - 1
9
+ version: 1.6.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Stephen Augenstein
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-11-19 00:00:00 -05:00
17
+ date: 2012-02-28 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20