ruby-audio 0.2.1 → 1.0.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.
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RubyAudio::Buffer do
4
+ it "should initialize properly" do
5
+ buf = RubyAudio::Buffer.new('float', 100, 2)
6
+ buf.channels.should == 2
7
+ buf.size.should == 100
8
+ buf.real_size.should == 0
9
+ buf.type.should == :float
10
+ end
11
+
12
+ it "should support pretty typed constructors" do
13
+ lambda {
14
+ [:short, :int, :float, :double].each do |type|
15
+ buf = RubyAudio::Buffer.send(type, 100)
16
+ end
17
+ }.should_not raise_error
18
+ end
19
+
20
+ it "should allow [] access on single channel buffers" do
21
+ buf = RubyAudio::Buffer.int(100, 1)
22
+ buf[0] = 1.3
23
+ buf[0].should == 1
24
+ end
25
+
26
+ it "should allow [] access on multi-channel buffers" do
27
+ buf = RubyAudio::Buffer.double(100, 2)
28
+ buf[0] = [0.5, 0.3]
29
+ buf[0].should == [0.5, 0.3]
30
+ end
31
+
32
+ it "should raise exception if channel count of set frame does not match buffer's" do
33
+ lambda {
34
+ buf = RubyAudio::Buffer.double(100, 2)
35
+ buf[0] = [0.4, 0.8, 0.8]
36
+ }.should raise_error(RubyAudio::Error, "array length must match channel count")
37
+ end
38
+
39
+ it "should return nil on out-of-bounds [] access" do
40
+ buf = RubyAudio::Buffer.float(100)
41
+ buf[101].should == nil
42
+ buf[-1].should == nil
43
+ end
44
+
45
+ it "should truncate invalid real size" do
46
+ buf = RubyAudio::Buffer.float(100)
47
+ buf.real_size = 101
48
+ buf.real_size.should == 100
49
+ end
50
+ end
Binary file
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RubyAudio::SoundInfo do
4
+ it "should initialize with default properties" do
5
+ info = RubyAudio::SoundInfo.new
6
+ info.channels.should == 0
7
+ info.samplerate.should == 0
8
+ info.format.should == 0
9
+ end
10
+
11
+ it "should allow setting properties on initialize" do
12
+ info = RubyAudio::SoundInfo.new(:channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16)
13
+ info.channels.should == 1
14
+ info.samplerate.should == 48000
15
+ info.format.should == RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
16
+ end
17
+
18
+ it "should allow setting properties after initialize" do
19
+ info = RubyAudio::SoundInfo.new
20
+ info.channels = 3
21
+ info.channels.should == 3
22
+ end
23
+
24
+ it "should not be valid if properties invalid" do
25
+ info = RubyAudio::SoundInfo.new(:channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV)
26
+ info.valid?.should == false
27
+ info.format = RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
28
+ info.valid?.should == true
29
+ end
30
+
31
+ it "should allow cloning" do
32
+ info = RubyAudio::SoundInfo.new(:channels => 1, :samplerate => 48000, :format => RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16)
33
+ info2 = info.clone
34
+ info.object_id.should_not == info2.object_id
35
+ info.channels.should == info2.channels
36
+ info.samplerate.should == info2.samplerate
37
+ info.format.should == info2.format
38
+ end
39
+ end
@@ -0,0 +1,147 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RubyAudio::Sound do
4
+ MONO_TEST_WAV = File.dirname(__FILE__)+'/data/what.wav'
5
+ STEREO_TEST_WAV = File.dirname(__FILE__)+'/data/what2.wav'
6
+ TEST_MP3 = File.dirname(__FILE__)+'/data/what.mp3'
7
+ OUT_WAV = File.dirname(__FILE__)+'/data/temp.wav'
8
+
9
+ after :each do
10
+ File.delete(OUT_WAV) if File.exists?(OUT_WAV)
11
+ end
12
+
13
+ it "should open a standard wav without issues" do
14
+ lambda {
15
+ RubyAudio::Sound.open(MONO_TEST_WAV)
16
+ }.should_not raise_error
17
+ end
18
+
19
+ it "should raise an exception if the mode is invalid" do
20
+ lambda {
21
+ RubyAudio::Sound.open(MONO_TEST_WAV, 'q')
22
+ }.should raise_error(ArgumentError, 'invalid access mode q')
23
+ end
24
+
25
+ it "should close the sound on block exit" do
26
+ s = nil
27
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
28
+ snd.closed?.should be_false
29
+ s = snd
30
+ end
31
+ s.closed?.should be_true
32
+ end
33
+
34
+ it "should raise an exception for an unsupported file" do
35
+ lambda {
36
+ RubyAudio::Sound.open(TEST_MP3)
37
+ }.should raise_error(RubyAudio::Error, "File contains data in an unknown format.")
38
+ end
39
+
40
+ it "should raise an exception if file does not exist" do
41
+ lambda {
42
+ RubyAudio::Sound.open(TEST_MP3+'.not')
43
+ }.should raise_error(RubyAudio::Error, "System error : No such file or directory.")
44
+ end
45
+
46
+ it "should have the proper sound info" do
47
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
48
+ snd.info.channels.should == 1
49
+ snd.info.samplerate.should == 16000
50
+ snd.info.format.should == RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
51
+ end
52
+ end
53
+
54
+ it "should allow seeking" do
55
+ lambda {
56
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
57
+ snd.seek(100)
58
+ buf = snd.read(:float, 100)
59
+ buf[0].should > 0
60
+ end
61
+ }.should_not raise_error
62
+ end
63
+
64
+ it "should raise exceptions for invalid seeks" do
65
+ lambda {
66
+ RubyAudio::Sound.open(MONO_TEST_WAV) {|snd| snd.seek(-1)}
67
+ }.should raise_error(RubyAudio::Error, "invalid seek")
68
+ lambda {
69
+ RubyAudio::Sound.open(MONO_TEST_WAV) {|snd| snd.seek(1000000)}
70
+ }.should raise_error(RubyAudio::Error, "invalid seek")
71
+ end
72
+
73
+ it "should allow reading samples from the sound" do
74
+ RubyAudio::Sound.open(STEREO_TEST_WAV) do |snd|
75
+ buf = snd.read(:float, 1000)
76
+ buf.size.should == 1000
77
+ buf.real_size.should == 1000
78
+ buf[999].length.should == 2
79
+ end
80
+ end
81
+
82
+ it "should allow reading into an existing buffer" do
83
+ buf = RubyAudio::Buffer.float(1000)
84
+ buf.real_size.should == 0
85
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
86
+ snd.read(buf)
87
+ end
88
+ buf.real_size.should == 1000
89
+ buf[99].should > 0
90
+ end
91
+
92
+ it "should allow reading into an existing buffer partially" do
93
+ buf = RubyAudio::Buffer.float(1000)
94
+ buf.real_size.should == 0
95
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
96
+ snd.read(buf, 100)
97
+ end
98
+ buf.real_size.should == 100
99
+ buf[99].should > 0
100
+ buf[100].should == nil
101
+ end
102
+
103
+ it "should raise exception for channel count mismatch on read" do
104
+ buf = RubyAudio::Buffer.float(1000, 1)
105
+ lambda {
106
+ RubyAudio::Sound.open(STEREO_TEST_WAV) do |snd|
107
+ snd.read(buf)
108
+ end
109
+ }.should raise_error(RubyAudio::Error, "channel count mismatch: 1 vs 2")
110
+ end
111
+
112
+ it "should allow writing to a new sound" do
113
+ in_buf = RubyAudio::Buffer.float(100)
114
+ out_buf = RubyAudio::Buffer.float(100)
115
+ out_info = nil
116
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
117
+ snd.read(in_buf)
118
+ out_info = snd.info.clone
119
+ end
120
+
121
+ RubyAudio::Sound.open(OUT_WAV, 'rw', out_info) do |snd|
122
+ snd.write(in_buf)
123
+ snd.seek(0)
124
+ snd.read(out_buf)
125
+ end
126
+
127
+ out_buf[50].should == in_buf[50]
128
+ end
129
+
130
+ it "should allow writing to a new sound using <<" do
131
+ in_buf = RubyAudio::Buffer.float(100)
132
+ out_buf = RubyAudio::Buffer.float(100)
133
+ out_info = nil
134
+ RubyAudio::Sound.open(MONO_TEST_WAV) do |snd|
135
+ snd.read(in_buf)
136
+ out_info = snd.info.clone
137
+ end
138
+
139
+ RubyAudio::Sound.open(OUT_WAV, 'rw', out_info) do |snd|
140
+ snd << in_buf
141
+ snd.seek(0)
142
+ snd.read(out_buf)
143
+ end
144
+
145
+ out_buf[50].should == in_buf[50]
146
+ end
147
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ -f nested
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+ require 'spec/autorun'
9
+
10
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'ext'))
11
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+ require 'ruby-audio'
metadata CHANGED
@@ -1,58 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-audio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Hans Fugal <hans@fugal.net>
8
7
  - Stephen Augenstein
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2010-02-15 00:00:00 -05:00
12
+ date: 2010-03-16 00:00:00 -04:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: narray
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- version:
14
+ dependencies: []
15
+
26
16
  description:
27
17
  email: perl.programmer@gmail.com
28
18
  executables: []
29
19
 
30
20
  extensions:
31
- - ext/sndfile/extconf.rb
21
+ - ext/extconf.rb
32
22
  extra_rdoc_files: []
33
23
 
34
24
  files:
35
25
  - README.rdoc
36
26
  - Rakefile
37
27
  - LICENSE
38
- - TODO
39
- - examples/load_samples.rb
40
- - examples/t.rb
41
- - lib/audio/sndfile.rb
42
- - lib/audio.rb
43
- - test/test_audio.rb
44
- - test/test_sndfile.rb
45
- - test/what.wav
46
- - test/what2.wav
47
- - ext/sndfile/extconf.rb
48
- - ext/sndfile/sndfile.i
28
+ - lib/ruby-audio/buffer.rb
29
+ - lib/ruby-audio/sound.rb
30
+ - lib/ruby-audio/sound_info.rb
31
+ - lib/ruby-audio.rb
32
+ - spec/buffer_spec.rb
33
+ - spec/sound_info_spec.rb
34
+ - spec/sound_spec.rb
35
+ - spec/spec_helper.rb
36
+ - spec/spec.opts
37
+ - spec/data/what.wav
38
+ - spec/data/what2.wav
39
+ - spec/data/what.mp3
40
+ - ext/extconf.rb
41
+ - ext/ra_buffer.c
42
+ - ext/ra_sound.c
43
+ - ext/ra_soundinfo.c
44
+ - ext/rubyaudio_ext.c
45
+ - ext/ra_buffer.h
46
+ - ext/ra_sound.h
47
+ - ext/ra_soundinfo.h
49
48
  has_rdoc: true
50
49
  homepage: http://github.com/warhammerkid/ruby-audio
51
50
  licenses: []
52
51
 
53
52
  post_install_message:
54
- rdoc_options: []
55
-
53
+ rdoc_options:
54
+ - --line-numbers
55
+ - --main
56
+ - README.rdoc
57
+ - ext/ra_buffer.c
58
+ - ext/ra_sound.c
59
+ - ext/ra_soundinfo.c
60
+ - ext/rubyaudio_ext.c
61
+ - README.rdoc
56
62
  require_paths:
57
63
  - lib
58
64
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,12 +75,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
75
  version:
70
76
  requirements:
71
77
  - libsndfile (http://www.mega-nerd.com/libsndfile/)
72
- - SWIG (http://www.swig.org/)
73
78
  rubyforge_project:
74
79
  rubygems_version: 1.3.5
75
80
  signing_key:
76
81
  specification_version: 3
77
82
  summary: ruby-audio wraps around libsndfile to provide simplified sound reading and writing support to ruby programs
78
83
  test_files:
79
- - test/test_audio.rb
80
- - test/test_sndfile.rb
84
+ - spec/buffer_spec.rb
85
+ - spec/sound_info_spec.rb
86
+ - spec/sound_spec.rb
data/TODO DELETED
@@ -1,5 +0,0 @@
1
- automagic write bug
2
- document Sndfile::SF_*
3
- sebastian's error
4
- leopard ugliness :(
5
- carl's request for optional 2nd argument to {write,read}_*
@@ -1,27 +0,0 @@
1
- require 'ostruct'
2
- require 'pp'
3
- require 'rubygems'
4
- require 'google_chart'
5
- require 'narray'
6
-
7
- require 'lib/audio.rb'
8
- require 'lib/audio/sndfile.rb'
9
-
10
- @files = [
11
- 'audio_files/063_1.WAV',
12
- 'audio_files/063_2.WAV',
13
- 'audio_files/063_3.WAV'
14
- ]
15
-
16
- @sound_files = []
17
- @files.each do |f|
18
- @sound_files << Audio::Soundfile.open(f)
19
- end
20
-
21
- @sounds = []
22
- @sound_files.each do |sf|
23
- @sounds << sf.read_int(sf.frames)
24
- end
25
-
26
- @f = @sounds.first
27
- @l = @sounds.last
data/examples/t.rb DELETED
@@ -1,10 +0,0 @@
1
- eval(File.read('load_samples.rb'))
2
-
3
- @samples_to_graph = 500
4
- lc = GoogleChart::LineChart.new('640x400', "Line Chart", false)
5
- lc.data "First Sound", @f.to_a[0][0..@samples_to_graph], '0000ff'
6
- lc.data "Last Sound", @l.to_a[0][0..@samples_to_graph], '00ff00'
7
-
8
- lc.axis :y, :range => [[@f.min, @l.min].min, [@f.max,@l.max].max], :color => 'ff00ff', :font_size => 16, :alignment => :center
9
- lc.axis :x, :range => [0,1000], :color => '00ffff', :font_size => 16, :alignment => :center
10
- puts lc.to_url
@@ -1,31 +0,0 @@
1
- require 'rubygems'
2
- require 'mkmf'
3
-
4
- $CFLAGS = '-I/opt/local/include'
5
- $LDFLAGS = '-L/opt/local/lib -L/usr/local/lib'
6
-
7
- # Add narray header to path
8
- matches = Gem.source_index.find_name 'narray', Gem::Requirement.default
9
- if matches.empty?
10
- raise 'You need to install NArray gem'
11
- exit
12
- end
13
- spec = matches.last
14
- $CFLAGS += " -I#{spec.full_gem_path}"
15
-
16
- # libsndfile requirements
17
- unless find_library 'sndfile', 'sf_open'
18
- raise 'You need to install libsndfile (http://www.mega-nerd.com/libsndfile/)'
19
- exit
20
- end
21
-
22
- # NArray gem requirements (double check that header there)
23
- unless have_header 'narray.h'
24
- raise 'You need to install NArray gem'
25
- exit
26
- end
27
-
28
- # Swig
29
- system 'swig -ruby -I/usr/include -I/usr/local/include -I/opt/local/include sndfile.i'
30
-
31
- create_makefile 'sndfile'