plant-sirens 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brandon Mechtley
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,51 @@
1
+ # sirens-ruby
2
+ sirens-ruby is a ruby extension for [Sirens](http://github.com/plant/sirens), a library for segmentation, indexing, and retrieval of environmental and natural sounds. Sirens is currently under development and only supports basic feature extraction. Please check back for updates.
3
+
4
+ ## Requirements
5
+ To install sirens-ruby, it is necessary to have these two libraries:
6
+
7
+ 1. [FFTW](http://www.fftw.org/download.html)
8
+ 2. [Sirens](http://github.com/plant/sirens)
9
+
10
+ Additionally, sirens-ruby has the following gem dependencies, which RubyGems should take care of:
11
+
12
+ 1. [rake-compiler](http://rubyforge.org/projects/rake-compiler/)
13
+ 2. [jeweler](http://github.com/technicalpickles/jeweler/)
14
+ 2. [rice](http://github.com/cout/rice/)
15
+
16
+ *Rice Note:* I've had some problems with installing the Rice 1.1.0 gem. Try 1.0.2 if it doesn't work. On OSX, neither seems to work, so you may want to look at [this workaround](http://rubyforge.org/tracker/index.php?func=detail&aid=19828&group_id=4163&atid=16066). Note that you will have to remove `-arch ppc` (or `-arch i386`) from all makefiles, i.e. Makefile, rice/Makefile, ruby/Makefile, and test/Makefile.
17
+
18
+ ## Installation
19
+ To install Soundwalk, type:
20
+
21
+ gem sources -a http://gems.github.com
22
+ sudo gem install plant-sirens-ruby
23
+
24
+ *OSX Note:* Under OSX, you might get a warning about an unsupported architecture when compiling sirens-ruby, since Ruby will try to create a universal binary for the bundle, and FFTW and Sirens don't build universal binaries by default. You can ignore this warning, as it won't affect you unless you're trying to copy sirens.so directly between machines of different architectures.
25
+
26
+ ## Usage
27
+ Sirens is pretty minimal at the moment and only supports the extraction of six basic features. In the future, Sirens will include feature-based segmentation and comparison.
28
+
29
+ Here is a basic example to extract loudness (dB) from a sound file:
30
+
31
+ require 'sirens'
32
+ include Sirens
33
+
34
+ s = Sound.new
35
+ s.frameLength = 0.04
36
+ s.hopLength = 0.02
37
+
38
+ s.open('sound.wav')
39
+
40
+ loudness = Loudness.new
41
+ loudness.historySize = s.frames
42
+
43
+ s.sampleFeatures = [loudness]
44
+ s.extractFeatures
45
+
46
+ puts loudness.history
47
+
48
+ More examples can be found in the /examples folder. Detailed documentation is on the [Wiki](http://wiki.github.com/plant/sirens-ruby).
49
+
50
+ # Copyright
51
+ Copyright (c) 2009 Brandon Mechtley. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ spec = Jeweler::Tasks.new do |gem|
7
+ gem.files.include %w(ext/sirens/extconf.rb ext/sirens/sirens.cpp)
8
+ gem.name = "sirens"
9
+ gem.add_dependency('rice', '>= 1.0.2')
10
+ gem.summary = "Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds."
11
+ gem.description = "Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds."
12
+ gem.email = "bmechtley+github@gmail.com"
13
+ gem.homepage = "http://github.com/plant/sirens-ruby"
14
+ gem.authors = ["Brandon Mechtley"]
15
+ gem.extensions = FileList["ext/**/extconf.rb"]
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/extensiontask'
23
+ Rake::ExtensionTask.new('sirens', spec.gemspec)
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/*_test.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ if File.exist?('VERSION.yml')
50
+ config = YAML.load(File.read('VERSION.yml'))
51
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
52
+ else
53
+ version = ""
54
+ end
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "sirens #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
61
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'sirens'
3
+ include Sirens
4
+
5
+ s = Sound.new
6
+ s.frameLength = 0.04
7
+ s.hopLength = 0.02
8
+ s.open('sound.wav')
9
+ l = Loudness.new
10
+ ss = SpectralSparsity.new
11
+ ts = TemporalSparsity.new
12
+ ts.windowSize = 50
13
+
14
+ [l, ss, ts].each do |f|
15
+ f.historySize = s.frames
16
+ end
17
+
18
+ s.sampleFeatures = [l, ts]
19
+ s.spectralFeatures = [ss]
20
+
21
+ s.extractFeatures
22
+
23
+ [l, ss, ts].each do |f|
24
+ f.history.each {|value| print value, ','}
25
+ print "\n"
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'mkmf'
3
+
4
+ # Upon requiring mkmf-rice, Rice makes sure -lrice can be found
5
+ # but it won't be found if it's not in the default library search
6
+ # path. require 'mkmf' above just initializes the environment
7
+ # variables for us.
8
+
9
+ $LDFLAGS << " #{ENV['LDFLAGS']}"
10
+
11
+ require 'mkmf-rice'
12
+
13
+ $CPPFLAGS << " #{ENV['CPPFLAGS']}"
14
+ $LDFLAGS << " #{ENV['LDFLAGS']}"
15
+ $CFLAGS << " #{ENV['CFLAGS']} -D__OS_MACOSX__"
16
+
17
+ have_library('sirens')
18
+ have_library('fftw3')
19
+
20
+ create_makefile('sirens')
@@ -0,0 +1,160 @@
1
+ #include "rice/Class.hpp"
2
+ #include "rice/Array.hpp"
3
+ #include "rice/String.hpp"
4
+ #include "rice/Data_Type.hpp"
5
+ #include "rice/Constructor.hpp"
6
+ using namespace Rice;
7
+
8
+ #include "sirens/Sound.h"
9
+ #include "sirens/CircularArray.h"
10
+ #include "sirens/features/Loudness.h"
11
+ #include "sirens/features/Harmonicity.h"
12
+ #include "sirens/features/TransientIndex.h"
13
+ #include "sirens/features/SpectralCentroid.h"
14
+ #include "sirens/features/SpectralSparsity.h"
15
+ #include "sirens/features/TemporalSparsity.h"
16
+ using namespace Sirens;
17
+
18
+ template <>
19
+ Object to_ruby<CircularArray*>(CircularArray* const & x) {
20
+ Array y;
21
+
22
+ for (int i = 0; i < x->getSize(); i++)
23
+ y.push(x->getValueAt(i));
24
+
25
+ return y;
26
+ }
27
+
28
+ template <>
29
+ Object to_ruby<vector<Feature*> >(vector<Feature*> const & x) {
30
+ return Array(x.begin(), x.end());
31
+ }
32
+
33
+ template <>
34
+ vector<Feature*> from_ruby<vector<Feature*> >(Object x) {
35
+ vector<Feature*> y;
36
+
37
+ Array new_features(x);
38
+
39
+ for (unsigned int i = 0; i < new_features.size(); i++)
40
+ y.push_back((Feature*)DATA_PTR(new_features[i].value()));
41
+
42
+ return y;
43
+ }
44
+
45
+ float rb_mFeatureValue () {
46
+ return 0;
47
+ }
48
+
49
+ void rb_mFeatureCalculate() {
50
+
51
+ }
52
+
53
+ Array rb_mFeatureHistory() {
54
+ return Array();
55
+ }
56
+
57
+ string rb_mFeatureToString() {
58
+ return "Feature";
59
+ }
60
+
61
+ Array rb_cSoundFeatures() {
62
+ return Array();
63
+ }
64
+
65
+ extern "C" void Init_sirens() {
66
+ Module rb_mSirens = define_module("Sirens");
67
+
68
+ Data_Type<Sound> rb_cSound =
69
+ define_class_under<Sound>(rb_mSirens, "Sound")
70
+ .define_constructor(Constructor<Sound>())
71
+ .define_method("open", &Sound::open)
72
+ .define_method("samples", &Sound::getSampleCount)
73
+ .define_method("frames", &Sound::getFrameCount)
74
+ .define_method("frameLength", &Sound::getFrameLength)
75
+ .define_method("frameLength=", &Sound::setFrameLength)
76
+ .define_method("hopLength", &Sound::getHopLength)
77
+ .define_method("hopLength=", &Sound::setHopLength)
78
+ .define_method("samplesPerFrame", &Sound::getSamplesPerFrame)
79
+ .define_method("samplesPerHop", &Sound::getSamplesPerHop)
80
+ .define_method("sampleRate", &Sound::getSampleRate)
81
+ .define_method("fftSize", &Sound::getFFTSize)
82
+ .define_method("spectrumSize", &Sound::getSpectrumSize)
83
+ .define_method("path", &Sound::getPath)
84
+ .define_method("extractFeatures", &Sound::extractFeatures)
85
+ .define_method("saveFeaturesCSV", &Sound::saveFeaturesCSV)
86
+ .define_method("spectralFeatures", &Sound::getSpectralFeatures)
87
+ .define_method("spectralFeatures=", &Sound::setSpectralFeatures)
88
+ .define_method("spectralFeatures[]", &Sound::getSpectralFeatureAt)
89
+ .define_method("sampleFeatures", &Sound::getSampleFeatures)
90
+ .define_method("sampleFeatures=", &Sound::setSampleFeatures)
91
+ .define_method("sampleFeatures[]", &Sound::getSampleFeatureAt);
92
+
93
+ Data_Type<Feature> rb_cFeature =
94
+ define_class_under<Feature>(rb_mSirens, "Feature")
95
+ .define_constructor(Constructor<Feature>())
96
+ .define_method("to_s", &Feature::toString)
97
+ .define_method("history", &Feature::getHistory)
98
+ .define_method("history[]", &Feature::getHistoryFrame)
99
+ .define_method("historySize", &Feature::getHistorySize)
100
+ .define_method("historySize=", &Feature::setHistorySize)
101
+ .define_method("value", &Feature::getValue);
102
+
103
+ // rb_mFeature = define_module("Feature");
104
+ //rb_mFeature.define_module_function("history", &rb_mFeatureHistory);
105
+ //rb_mFeature.define_module_function("value", &rb_mFeatureValue);
106
+ //rb_mFeature.define_module_function("calculate", &rb_mFeatureCalculate);
107
+ //rb_mFeature.define_module_function("to_s", rb_mFeatureToString);
108
+
109
+ Data_Type<Loudness> rb_cLoudness =
110
+ define_class_under<Loudness, Feature>(rb_mSirens, "Loudness")
111
+ .define_constructor(Constructor<Loudness>());
112
+
113
+ Data_Type<Harmonicity> rb_cHarmonicity =
114
+ define_class_under<Harmonicity, Feature>(rb_mSirens, "Harmonicity")
115
+ .define_constructor(Constructor<Harmonicity>())
116
+ .define_method("sampleRate", &Harmonicity::getSampleRate)
117
+ .define_method("sampleRate=", &Harmonicity::setSampleRate)
118
+ .define_method("spectrumSize", &Harmonicity::getSpectrumSize)
119
+ .define_method("spectrumSize=", &Harmonicity::setSpectrumSize)
120
+ .define_method("searchRegionLength", &Harmonicity::getSearchRegionLength)
121
+ .define_method("searchRegionLength=", &Harmonicity::setSearchRegionLength)
122
+ .define_method("absThreshold", &Harmonicity::getAbsThreshold)
123
+ .define_method("absThreshold=", &Harmonicity::setAbsThreshold)
124
+ .define_method("threshold", &Harmonicity::getThreshold)
125
+ .define_method("threshold=", &Harmonicity::setThreshold)
126
+ .define_method("lpfCoefficient", &Harmonicity::getLPFCoefficient)
127
+ .define_method("lpfCoefficient=", &Harmonicity::setLPFCoefficient)
128
+ .define_method("maxPeaks", &Harmonicity::getMaxPeaks)
129
+ .define_method("maxPeaks=", &Harmonicity::setMaxPeaks);
130
+
131
+ Data_Type<TransientIndex> rb_cTransientIndex =
132
+ define_class_under<TransientIndex, Feature>(rb_mSirens, "TransientIndex")
133
+ .define_constructor(Constructor<TransientIndex>())
134
+ .define_method("sampleRate", &TransientIndex::getSampleRate)
135
+ .define_method("sampleRate=", &TransientIndex::setSampleRate)
136
+ .define_method("spectrumSize", &TransientIndex::getSpectrumSize)
137
+ .define_method("spectrumSize=", &TransientIndex::setSpectrumSize)
138
+ .define_method("filters", &TransientIndex::getFilters)
139
+ .define_method("filters=", &TransientIndex::setFilters)
140
+ .define_method("mels", &TransientIndex::getMels)
141
+ .define_method("mels=", &TransientIndex::setMels);
142
+
143
+ Data_Type<SpectralCentroid> rb_cSpectralCentroid =
144
+ define_class_under<SpectralCentroid, Feature>(rb_mSirens, "SpectralCentroid")
145
+ .define_constructor(Constructor<SpectralCentroid>())
146
+ .define_method("sampleRate", &SpectralCentroid::getSampleRate)
147
+ .define_method("sampleRate=", &SpectralCentroid::setSampleRate)
148
+ .define_method("spectrumSize", &SpectralCentroid::getSpectrumSize)
149
+ .define_method("spectrumSize=", &SpectralCentroid::setSpectrumSize);
150
+
151
+ Data_Type<SpectralSparsity> rb_cSpectralSparsity =
152
+ define_class_under<SpectralSparsity, Feature>(rb_mSirens, "SpectralSparsity")
153
+ .define_constructor(Constructor<SpectralSparsity>());
154
+
155
+ Data_Type<TemporalSparsity> rb_cTemporalSparsity =
156
+ define_class_under<TemporalSparsity, Feature>(rb_mSirens, "TemporalSparsity")
157
+ .define_constructor(Constructor<TemporalSparsity>())
158
+ .define_method("windowSize", &TemporalSparsity::getWindowSize)
159
+ .define_method("windowSize=", &TemporalSparsity::setWindowSize);
160
+ }
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'sirens'
3
+
4
+ s = Sirens::Sound.new
5
+ s.frameLength = 0.04
6
+ s.hopLength = 0.02
7
+ s.open 'test/sirens/test.wav'
8
+
9
+ print "\n", s
10
+ print "\n\tPath: ", s.path
11
+ print "\n\tSamples: ", s.samples
12
+ print "\n\tSample rate: ", s.sampleRate
13
+ print "\n\tFrame length: ", s.frameLength, "s (", s.samplesPerFrame, " samples)"
14
+ print "\n\tHop length: ", s.hopLength, "s (", s.samplesPerHop, " samples)"
15
+ print "\n\tFFT Size: ", s.fftSize
16
+ print "\n\tSpectrum size: ", s.spectrumSize
17
+ print "\n\n"
18
+
19
+ loudness = Sirens::LoudnessFeature.new
20
+ temporal_sparsity = Sirens::TemporalSparsityFeature.new
21
+ spectral_sparsity = Sirens::SpectralSparsityFeature.new
22
+ spectral_centroid = Sirens::SpectralCentroidFeature.new
23
+
24
+ harmonicity = Sirens::HarmonicityFeature.new
25
+ harmonicity.absThreshold = 1
26
+ harmonicity.threshold = 0.1
27
+ harmonicity.searchRegionLength = 5
28
+ harmonicity.maxPeaks = 3
29
+ harmonicity.lpfCoefficient = 0.7
30
+
31
+ transient_index = Sirens::TransientIndexFeature.new
32
+ transient_index.mels = 15
33
+ transient_index.filters = 30
34
+
35
+ Array[loudness, temporal_sparsity, spectral_sparsity, spectral_centroid, harmonicity, transient_index].each do |feature|
36
+ feature.historySize = s.frames
37
+ end
38
+
39
+ Array[spectral_centroid, harmonicity, transient_index].each do |feature|
40
+ feature.sampleRate = s.sampleRate
41
+ feature.spectrumSize = s.spectrumSize
42
+ end
43
+
44
+ s.sampleFeatures = Array[loudness, temporal_sparsity]
45
+ s.spectralFeatures = Array[spectral_sparsity, spectral_centroid, transient_index, harmonicity]
46
+
47
+ t1 = Time.new
48
+
49
+ s.extractFeatures
50
+
51
+ t2 = Time.new
52
+
53
+ print 'Elapsed time: ', (t2 - t1), "\n\n"
54
+
55
+ histories = Array[loudness.history, temporal_sparsity.history, spectral_sparsity.history,
56
+ spectral_centroid.history, transient_index.history, harmonicity.history]
57
+
58
+ file = File.new("test/sirens/features.csv", File::CREAT|File::RDWR, 0644)
59
+ for i in 0..s.frames - 1
60
+ for j in 0..histories.size - 1
61
+ file.write(histories[j][i])
62
+ file.write(',') if i < histories.size - 1
63
+ end
64
+
65
+ file.write("\n")
66
+ end
67
+
Binary file
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'soundwalk-api'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plant-sirens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mechtley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rice
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.2
24
+ version:
25
+ description: Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.
26
+ email: bmechtley+github@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/sirens/extconf.rb
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ files:
35
+ - LICENSE
36
+ - README.markdown
37
+ - Rakefile
38
+ - VERSION
39
+ - ext/sirens/extconf.rb
40
+ - ext/sirens/sirens.cpp
41
+ - test/sirens/sirens_test.rb
42
+ - test/sirens/test.wav
43
+ - test/sirens/test_helper.rb
44
+ has_rdoc: false
45
+ homepage: http://github.com/plant/sirens-ruby
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.
70
+ test_files:
71
+ - test/sirens/sirens_test.rb
72
+ - test/sirens/test_helper.rb
73
+ - examples/three_features.rb