plant-sirens-ruby 0.0.1

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/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,45 @@
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 the three libraries:
6
+
7
+ 1. [FFTW](http://www.fftw.org/download.html)
8
+ 2. [STK](http://ccrma.stanford.edu/software/stk/)
9
+ 3. [Sirens](http://github.com/plant/sirens)
10
+
11
+ ## Installation
12
+ To install Soundwalk, perform the following steps.
13
+
14
+ 1. `git clone git://github.com/plant/sirens-ruby.git`
15
+ 2. `cd sirens-ruby`
16
+ 3. `rake compile`
17
+ 4. `rake build`
18
+
19
+ *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 STK don't build universal binaries by default. For STK, in the future I may just include the necessary source in [Sirens](http://github.com/plant/sirens) rather than linking against a library, as is conventional.
20
+
21
+ ## Usage
22
+ 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.
23
+
24
+ Here is a basic example to extract loudness (dB) values from a sound file:
25
+ require 'sirens'
26
+
27
+ s = Sirens::Sound.new
28
+ s.frameLength = 0.04
29
+ s.hopLength = 0.02
30
+
31
+ loudness = Sirens::LoudnessFeature.new
32
+ loudness.historySize = s.frames
33
+
34
+ s.sampleFeatures = Array[loudness]
35
+
36
+ s.extractFeatures
37
+
38
+ for value in loudness.history
39
+ puts value
40
+ end
41
+
42
+ More detailed documentation is on the Wiki (http://wiki.github.com/plant/sirens-ruby). You can also check out `test/soundwalk_test.rb` for an example of extracting all six features with some default parameters.
43
+
44
+ # Copyright
45
+ Copyright (c) 2009 Brandon Mechtley. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,63 @@
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/ruby/extconf.rb ext/ruby/sirens-ruby.cpp)
8
+ gem.name = "sirens-ruby"
9
+ gem.summary = "Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds."
10
+ gem.description = "Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds."
11
+ gem.email = "bmechtley+github@gmail.com"
12
+ gem.homepage = "http://github.com/plant/sirens-ruby"
13
+ gem.authors = ["Brandon Mechtley"]
14
+ gem.extensions = FileList["ext/**/extconf.rb"]
15
+ end
16
+
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ Rake::GemPackageTask.new(spec.gemspec) do |pkg|
22
+ end
23
+
24
+ require 'rake/extensiontask'
25
+ Rake::ExtensionTask.new('sirens', spec.gemspec)
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ if File.exist?('VERSION.yml')
52
+ config = YAML.load(File.read('VERSION.yml'))
53
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
54
+ else
55
+ version = ""
56
+ end
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "sirens #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
63
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,10 @@
1
+ require 'mkmf-rice'
2
+ require 'FileUtils'
3
+
4
+ $CFLAGS << "#{ENV['CFLAGS']} -D__OS_MACOSX__"
5
+
6
+ have_library('sirens')
7
+ have_library('stk')
8
+ have_library('fftw3')
9
+
10
+ create_makefile('sirens')
@@ -0,0 +1,158 @@
1
+ #include "rice/Class.hpp"
2
+ #include "rice/String.hpp"
3
+ #include "rice/Data_Type.hpp"
4
+ #include "rice/Constructor.hpp"
5
+ #include "rice/Array.hpp"
6
+ using namespace Rice;
7
+
8
+ #include "sirens/Sound.h"
9
+ #include "sirens/CircularArray.h"
10
+ #include "sirens/LoudnessFeature.h"
11
+ #include "sirens/HarmonicityFeature.h"
12
+ #include "sirens/TransientIndexFeature.h"
13
+ #include "sirens/SpectralCentroidFeature.h"
14
+ #include "sirens/SpectralSparsityFeature.h"
15
+ #include "sirens/TemporalSparsityFeature.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<LoudnessFeature> rb_cLoudnessFeature =
110
+ define_class_under<LoudnessFeature, Feature>(rb_mSirens, "LoudnessFeature")
111
+ .define_constructor(Constructor<LoudnessFeature>());
112
+
113
+ Data_Type<HarmonicityFeature> rb_cHarmonicityFeature =
114
+ define_class_under<HarmonicityFeature, Feature>(rb_mSirens, "HarmonicityFeature")
115
+ .define_constructor(Constructor<HarmonicityFeature>())
116
+ .define_method("sampleRate", &HarmonicityFeature::getSampleRate)
117
+ .define_method("sampleRate=", &HarmonicityFeature::setSampleRate)
118
+ .define_method("spectrumSize", &HarmonicityFeature::getSpectrumSize)
119
+ .define_method("spectrumSize=", &HarmonicityFeature::setSpectrumSize)
120
+ .define_method("searchRegionLength", &HarmonicityFeature::getSearchRegionLength)
121
+ .define_method("searchRegionLength=", &HarmonicityFeature::setSearchRegionLength)
122
+ .define_method("absThreshold", &HarmonicityFeature::getAbsThreshold)
123
+ .define_method("absThreshold=", &HarmonicityFeature::setAbsThreshold)
124
+ .define_method("threshold", &HarmonicityFeature::getThreshold)
125
+ .define_method("threshold=", &HarmonicityFeature::setThreshold)
126
+ .define_method("lpfCoefficient", &HarmonicityFeature::getLPFCoefficient)
127
+ .define_method("lpfCoefficient=", &HarmonicityFeature::setLPFCoefficient)
128
+ .define_method("maxPeaks", &HarmonicityFeature::getMaxPeaks)
129
+ .define_method("maxPeaks=", &HarmonicityFeature::setMaxPeaks);
130
+
131
+ Data_Type<TransientIndexFeature> rb_cTransientIndexFeature =
132
+ define_class_under<TransientIndexFeature, Feature>(rb_mSirens, "TransientIndexFeature")
133
+ .define_constructor(Constructor<TransientIndexFeature>())
134
+ .define_method("sampleRate", &TransientIndexFeature::getSampleRate)
135
+ .define_method("sampleRate=", &TransientIndexFeature::setSampleRate)
136
+ .define_method("spectrumSize", &TransientIndexFeature::getSpectrumSize)
137
+ .define_method("spectrumSize=", &TransientIndexFeature::setSpectrumSize)
138
+ .define_method("filters", &TransientIndexFeature::getFilters)
139
+ .define_method("filters=", &TransientIndexFeature::setFilters)
140
+ .define_method("mels", &TransientIndexFeature::getMels)
141
+ .define_method("mels=", &TransientIndexFeature::setMels);
142
+
143
+ Data_Type<SpectralCentroidFeature> rb_cSpectralCentroidFeature =
144
+ define_class_under<SpectralCentroidFeature, Feature>(rb_mSirens, "SpectralCentroidFeature")
145
+ .define_constructor(Constructor<SpectralCentroidFeature>())
146
+ .define_method("sampleRate", &SpectralCentroidFeature::getSampleRate)
147
+ .define_method("sampleRate=", &SpectralCentroidFeature::setSampleRate)
148
+ .define_method("spectrumSize", &SpectralCentroidFeature::getSpectrumSize)
149
+ .define_method("spectrumSize=", &SpectralCentroidFeature::setSpectrumSize);
150
+
151
+ Data_Type<SpectralSparsityFeature> rb_cSpectralSparsityFeature =
152
+ define_class_under<SpectralSparsityFeature, Feature>(rb_mSirens, "SpectralSparsityFeature")
153
+ .define_constructor(Constructor<SpectralSparsityFeature>());
154
+
155
+ Data_Type<TemporalSparsityFeature> rb_cTemporalSparsityFeature =
156
+ define_class_under<TemporalSparsityFeature, Feature>(rb_mSirens, "TemporalSparsityFeature")
157
+ .define_constructor(Constructor<TemporalSparsityFeature>());
158
+ }
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sirens-ruby}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brandon Mechtley"]
9
+ s.date = %q{2009-06-26}
10
+ s.description = %q{Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.}
11
+ s.email = %q{bmechtley+github@gmail.com}
12
+ s.extensions = ["ext/sirens/extconf.rb"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.markdown"
16
+ ]
17
+ s.files = [
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "ext/sirens/extconf.rb",
23
+ "ext/sirens/sirens.cpp",
24
+ "sirens-ruby.gemspec",
25
+ "test/sirens/sirens_test.rb",
26
+ "test/sirens/test.wav",
27
+ "test/sirens/test_helper.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/plant/sirens-ruby}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.3}
33
+ s.summary = %q{Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.}
34
+ s.test_files = [
35
+ "test/sirens/sirens_test.rb",
36
+ "test/sirens/test_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ else
45
+ end
46
+ else
47
+ end
48
+ end
@@ -0,0 +1,66 @@
1
+ require 'sirens'
2
+
3
+ s = Sirens::Sound.new
4
+ s.frameLength = 0.04
5
+ s.hopLength = 0.02
6
+ s.open 'test/sirens/test.wav'
7
+
8
+ print "\n", s
9
+ print "\n\tPath: ", s.path
10
+ print "\n\tSamples: ", s.samples
11
+ print "\n\tSample rate: ", s.sampleRate
12
+ print "\n\tFrame length: ", s.frameLength, "s (", s.samplesPerFrame, " samples)"
13
+ print "\n\tHop length: ", s.hopLength, "s (", s.samplesPerHop, " samples)"
14
+ print "\n\tFFT Size: ", s.fftSize
15
+ print "\n\tSpectrum size: ", s.spectrumSize
16
+ print "\n\n"
17
+
18
+ loudness = Sirens::LoudnessFeature.new
19
+ temporal_sparsity = Sirens::TemporalSparsityFeature.new
20
+ spectral_sparsity = Sirens::SpectralSparsityFeature.new
21
+ spectral_centroid = Sirens::SpectralCentroidFeature.new
22
+
23
+ harmonicity = Sirens::HarmonicityFeature.new
24
+ harmonicity.absThreshold = 1
25
+ harmonicity.threshold = 0.1
26
+ harmonicity.searchRegionLength = 5
27
+ harmonicity.maxPeaks = 3
28
+ harmonicity.lpfCoefficient = 0.7
29
+
30
+ transient_index = Sirens::TransientIndexFeature.new
31
+ transient_index.mels = 15
32
+ transient_index.filters = 30
33
+
34
+ Array[loudness, temporal_sparsity, spectral_sparsity, spectral_centroid, harmonicity, transient_index].each do |feature|
35
+ feature.historySize = s.frames
36
+ end
37
+
38
+ Array[spectral_centroid, harmonicity, transient_index].each do |feature|
39
+ feature.sampleRate = s.sampleRate
40
+ feature.spectrumSize = s.spectrumSize
41
+ end
42
+
43
+ s.sampleFeatures = Array[loudness, temporal_sparsity]
44
+ s.spectralFeatures = Array[spectral_sparsity, spectral_centroid, transient_index, harmonicity]
45
+
46
+ t1 = Time.new
47
+
48
+ s.extractFeatures
49
+
50
+ t2 = Time.new
51
+
52
+ print 'Elapsed time: ', (t2 - t1), "\n\n"
53
+
54
+ histories = Array[loudness.history, temporal_sparsity.history, spectral_sparsity.history,
55
+ spectral_centroid.history, transient_index.history, harmonicity.history]
56
+
57
+ file = File.new("test/sirens/features.csv", File::CREAT|File::RDWR, 0644)
58
+ for i in 0..s.frames - 1
59
+ for j in 0..histories.size - 1
60
+ file.write(histories[j][i])
61
+ file.write(',') if i < histories.size - 1
62
+ end
63
+
64
+ file.write("\n")
65
+ end
66
+
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,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plant-sirens-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mechtley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.
17
+ email: bmechtley+github@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/sirens/extconf.rb
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.markdown
25
+ files:
26
+ - LICENSE
27
+ - README.markdown
28
+ - Rakefile
29
+ - VERSION
30
+ - ext/sirens/extconf.rb
31
+ - ext/sirens/sirens.cpp
32
+ - sirens-ruby.gemspec
33
+ - test/sirens/sirens_test.rb
34
+ - test/sirens/test.wav
35
+ - test/sirens/test_helper.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/plant/sirens-ruby
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Ruby gem that implements Sirens, a library for segmentation, indexing, and retrieval of environmental and natural sounds.
62
+ test_files:
63
+ - test/sirens/sirens_test.rb
64
+ - test/sirens/test_helper.rb