plant-soundwalk 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ # Soundwalk
2
+
3
+ Soundwalk is a library for feature extraction, segmentation, and comparison of environmental (non-musical) sounds.
4
+
5
+ ## requirements
6
+
7
+ To install Soundwalk, it is necessary to have two libraries:
8
+ 1. FFTW (http://www.fftw.org/download.html) *Note:* 'fftw3f' is needed for float precision. Double precision (fftw3) is the default installation.
9
+ 2. libsndfile (http://www.mega-nerd.com/libsndfile/)
10
+
11
+ *OSX Note:* Under OSX, you might get a warning about an unsupported architecture when compiling Soundwalk, since Ruby will try to create a universal binary for the bundle. This shouldn't matter, unless you want to copy the binary to another Mac with a different architecture. Alternatively, you can compile FFTW and libsndfile for the different architectures and use the `lipo` tool to combine them before compiling Soundwalk.
12
+
13
+ # Copyright
14
+
15
+ Copyright (c) 2009 Brandon Mechtley. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.files.include %w(lib/c/*.cpp lib/c/*.h lib/ruby/extconf.rb lib/ruby/*.cpp lib/ruby/*.h)
8
+ gem.files.exclude 'lib/ruby/soundwalk-api.rb'
9
+ gem.name = "soundwalk"
10
+ gem.summary = %Q{TODO}
11
+ gem.email = "bmechtley+github@gmail.com"
12
+ gem.homepage = "http://github.com/plant/soundwalk"
13
+ gem.authors = ["Brandon Mechtley"]
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
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
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION.yml')
47
+ config = YAML.load(File.read('VERSION.yml'))
48
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "soundwalk-api #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
58
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,11 @@
1
+ #include "FeatureTemplate.h"
2
+
3
+ namespace SoundwalkLib {
4
+ FeatureTemplate::FeatureTemplate() {
5
+
6
+ }
7
+
8
+ FeatureTemplate::~FeatureTemplate() {
9
+
10
+ }
11
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ FeatureTemplate:
3
+ Class defining a "template" for a feature's trajectory in a sound.
4
+ This template (an HMM) is used to compare one sound with another sound.
5
+
6
+ One sound's feature trajectory is run through the template of another sound
7
+ to compute the emission probability, that is the likelihood that the observed
8
+ feature trajectory can be explained by this template.
9
+ */
10
+
11
+ #ifndef FEATURETEMPLATE_H
12
+ #define FEATURETEMPLATE_H
13
+
14
+ namespace SoundwalkLib {
15
+ class FeatureTemplate {
16
+ private:
17
+
18
+ public:
19
+ FeatureTemplate();
20
+ ~FeatureTemplate();
21
+ };
22
+ }
23
+
24
+ #endif
data/lib/c/Sound.cpp ADDED
@@ -0,0 +1,149 @@
1
+ #include "Sound.h"
2
+
3
+ #include "SoundFileExceptions.h"
4
+
5
+ namespace SoundwalkLib {
6
+ Sound::Sound() {
7
+ soundFile = 0;
8
+ }
9
+
10
+ Sound::~Sound() {
11
+ if (soundFile) {
12
+ sf_close(soundFile);
13
+ soundFile = 0;
14
+ }
15
+ }
16
+
17
+ /*
18
+ * Sound processing.
19
+ */
20
+
21
+ void Sound::openSound(string new_path) {
22
+ soundFile = sf_open(new_path.c_str(), SFM_READ, &soundFileInformation);
23
+
24
+ if (soundFile) {
25
+ if (soundFileInformation.frames > 0) {
26
+ path = new_path;
27
+ } else {
28
+ sf_close(soundFile);
29
+ throw ExceptionEmptySoundFile();
30
+ }
31
+ } else
32
+ throw ExceptionSoundFileLoadError(sf_error(soundFile));
33
+ }
34
+
35
+ void Sound::extractFeatures() {
36
+
37
+ }
38
+
39
+ /*
40
+ * Sound information.
41
+ */
42
+
43
+ void Sound::checkSoundFileOpen() {
44
+ if (!isOpen())
45
+ throw ExceptionSoundFileNotOpen();
46
+ }
47
+
48
+ bool Sound::isOpen() {
49
+ if (soundFile)
50
+ return true;
51
+ else
52
+ return false;
53
+ }
54
+
55
+ string Sound::getPath() {
56
+ checkSoundFileOpen();
57
+ return path;
58
+ }
59
+
60
+ int Sound::getLength() {
61
+ checkSoundFileOpen();
62
+ return soundFileInformation.frames;
63
+ }
64
+
65
+ int Sound::getSampleRate() {
66
+ checkSoundFileOpen();
67
+ return soundFileInformation.samplerate;
68
+ }
69
+
70
+ int Sound::getChannels() {
71
+ checkSoundFileOpen();
72
+ return soundFileInformation.channels;
73
+ }
74
+
75
+ int Sound::getFormat() {
76
+ checkSoundFileOpen();
77
+ return soundFileInformation.format;
78
+ }
79
+
80
+ /*
81
+ * Feature list manipulations.
82
+ */
83
+
84
+ void Sound::addCepstralFeature(Feature* feature) {
85
+ cepstralFeatures.push_back(feature);
86
+ }
87
+
88
+ void Sound::addSpectralFeature(Feature* feature) {
89
+ spectralFeatures.push_back(feature);
90
+ }
91
+
92
+ void Sound::addSampleFeature(Feature* feature) {
93
+ sampleFeatures.push_back(feature);
94
+ }
95
+
96
+ void Sound::emptyCepstralFeatures() {
97
+ cepstralFeatures.empty();
98
+ }
99
+
100
+ void Sound::emptySpectralFeatures() {
101
+ spectralFeatures.empty();
102
+ }
103
+
104
+ void Sound::emptySampleFeatures() {
105
+ sampleFeatures.empty();
106
+ }
107
+
108
+ void Sound::emptyAllFeatures() {
109
+ emptyCepstralFeatures();
110
+ emptySpectralFeatures();
111
+ emptySampleFeatures();
112
+ }
113
+
114
+ vector<Feature*> Sound::getCepstralFeatures() {
115
+ return cepstralFeatures;
116
+ }
117
+
118
+ vector<Feature*> Sound::getSpectralFeatures() {
119
+ return spectralFeatures;
120
+ }
121
+
122
+ vector<Feature*> Sound::getSampleFeatures() {
123
+ return sampleFeatures;
124
+ }
125
+
126
+ /*
127
+ * Spectrum properties.
128
+ */
129
+
130
+ void Sound::setSpectrumWindow(WindowFunction* window) {
131
+ spectrumWindow = window;
132
+ }
133
+
134
+ void Sound::setFFTSize(int fft_size) {
135
+ fftSize = fft_size;
136
+ }
137
+
138
+ int Sound::getFFTSize() {
139
+ return fftSize;
140
+ }
141
+
142
+ void Sound::setMFCCSize(int mfcc_size) {
143
+ mfccSize = mfcc_size;
144
+ }
145
+
146
+ int Sound::getMFCCSize() {
147
+ return mfccSize;
148
+ }
149
+ }
data/lib/c/Sound.h ADDED
@@ -0,0 +1,75 @@
1
+ #ifndef SOUND_H
2
+ #define SOUND_H
3
+
4
+ #include <vector>
5
+ #include <string>
6
+ using namespace std;
7
+
8
+ #include "sndfile.h"
9
+
10
+ namespace SoundwalkLib {
11
+ class Feature;
12
+ class WindowFunction;
13
+
14
+ class Sound {
15
+ protected:
16
+ // File information.
17
+ string path;
18
+ SNDFILE* soundFile;
19
+ SF_INFO soundFileInformation;
20
+
21
+ // Features.
22
+ vector<float*> featureHistories;
23
+
24
+ vector<Feature*> cepstralFeatures;
25
+ vector<Feature*> spectralFeatures;
26
+ vector<Feature*> sampleFeatures;
27
+
28
+ // Frames
29
+ int hopSize;
30
+ int frameSize;
31
+ int fftSize;
32
+ int mfccSize;
33
+
34
+ WindowFunction* spectrumWindow;
35
+
36
+ void checkSoundFileOpen();
37
+
38
+ public:
39
+ Sound();
40
+ ~Sound();
41
+
42
+ // Sound processing.
43
+ void openSound(string path);
44
+ void extractFeatures();
45
+
46
+ // Sound information.
47
+ bool isOpen();
48
+ string getPath();
49
+ int getLength();
50
+ int getSampleRate();
51
+ int getChannels();
52
+ int getFormat();
53
+
54
+ // Feature list manipulations.
55
+ void addCepstralFeature(Feature* feature);
56
+ void addSpectralFeature(Feature* feature);
57
+ void addSampleFeature(Feature* feature);
58
+ void emptyCepstralFeatures();
59
+ void emptySpectralFeatures();
60
+ void emptySampleFeatures();
61
+ void emptyAllFeatures();
62
+ vector<Feature*> getCepstralFeatures();
63
+ vector<Feature*> getSpectralFeatures();
64
+ vector<Feature*> getSampleFeatures();
65
+
66
+ // Spectrum information.
67
+ void setSpectrumWindow(WindowFunction* window);
68
+ void setFFTSize(int fft_size);
69
+ void setMFCCSize(int mfcc_size);
70
+ int getFFTSize();
71
+ int getMFCCSize();
72
+ };
73
+ }
74
+
75
+ #endif
@@ -0,0 +1,47 @@
1
+ #ifndef SOUNDFILEEXCEPTIONS_H
2
+ #define SOUNDFILEEXCEPTIONS_H
3
+
4
+ #include <exception>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ class ExceptionSoundFileNotOpen : public exception {
9
+ public:
10
+ virtual const char* what() const throw() {
11
+ return "Tried to perform an operation on a sound file that is not open.";
12
+ }
13
+ };
14
+
15
+ class ExceptionSoundFileLoadError : public exception {
16
+ private:
17
+ int error;
18
+
19
+ public:
20
+ ExceptionSoundFileLoadError(int new_error) {
21
+ error = new_error;
22
+ }
23
+
24
+ virtual const char* what() const throw() {
25
+ if (error == SF_ERR_UNRECOGNISED_FORMAT)
26
+ return "Tried to open a file with unrecognized format.";
27
+ else if (error == SF_ERR_SYSTEM)
28
+ return "Tried to open a file that does not exist.";
29
+ else if (error == SF_ERR_MALFORMED_FILE)
30
+ return "Tried to open a malformed sound file.";
31
+ else if (error == SF_ERR_UNSUPPORTED_ENCODING)
32
+ return "Tried to open a sound file with unsupported encoding scheme.";
33
+ else
34
+ return "There was an unknown error opening the sound file.";
35
+ }
36
+ };
37
+
38
+ class ExceptionEmptySoundFile : public exception {
39
+ public:
40
+ virtual const char* what() const throw() {
41
+ return "Tried to open an empty sound file.";
42
+ }
43
+ };
44
+ }
45
+
46
+
47
+ #endif
@@ -0,0 +1,15 @@
1
+ #include "WindowFunctions.h"
2
+
3
+ namespace SoundwalkLib {
4
+ float HannWindowFunction::apply(float input, int frame_size) {
5
+ return 0.5 * (1.0 - cos((2 * PI * input) / (float)(frame_size - 1)));
6
+ }
7
+
8
+ float HammingWindowFunction::apply(float input, int frame_size) {
9
+ return 0.54 - 0.46 * cos((2 * PI * input) / (float)(frame_size - 1));
10
+ }
11
+
12
+ float RectangularWindowFunction::apply(float input, int frame_size) {
13
+ return input;
14
+ }
15
+ }
@@ -0,0 +1,31 @@
1
+ #ifndef WINDOWS_H
2
+ #define WINDOWS_H
3
+
4
+ #include <cmath>
5
+ using namespace std;
6
+
7
+ #define PI 3.14159265
8
+
9
+ namespace SoundwalkLib {
10
+ class WindowFunction {
11
+ public:
12
+ virtual float apply(float input, int frame_size) = 0;
13
+ };
14
+
15
+ class HannWindowFunction : public WindowFunction {
16
+ public:
17
+ virtual float apply(float input, int frame_size);
18
+ };
19
+
20
+ class HammingWindowFunction : public WindowFunction {
21
+ public:
22
+ virtual float apply(float input, int frame_size);
23
+ };
24
+
25
+ class RectangularWindowFunction : public WindowFunction {
26
+ public:
27
+ virtual float apply(float input, int frame_size);
28
+ };
29
+ }
30
+
31
+ #endif
@@ -0,0 +1,15 @@
1
+ #include "Feature.h"
2
+
3
+ namespace SoundwalkLib {
4
+ void Feature::calculate(vector<float> values) {
5
+ value = 0;
6
+ }
7
+
8
+ string Feature::toString() {
9
+ return "Feature";
10
+ }
11
+
12
+ float Feature::getValue() {
13
+ return value;
14
+ }
15
+ }
@@ -0,0 +1,20 @@
1
+ #ifndef FEATURE_H
2
+ #define FEATURE_H
3
+
4
+ #include <vector>
5
+ #include <string>
6
+ using namespace std;
7
+
8
+ namespace SoundwalkLib {
9
+ class Feature {
10
+ protected:
11
+ float value;
12
+
13
+ public:
14
+ void calculate(vector<float> values);
15
+ string toString();
16
+ float getValue();
17
+ };
18
+ }
19
+
20
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "HarmonicityFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void HarmonicityFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string HarmonicityFeature::toString() {
19
+ return string("Harmonicity");
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef HARMONICITYFEATURE_H
2
+ #define HARMONICITYFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class HarmonicityFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();
15
+ };
16
+ }
17
+
18
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "LoudnessFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void LoudnessFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string LoudnessFeature::toString() {
19
+ return string("Loudness");
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef LOUDNESSFEATURE_H
2
+ #define LOUDNESSFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class LoudnessFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();
15
+ };
16
+ }
17
+
18
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "SpectralCentroidFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void SpectralCentroidFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string SpectralCentroidFeature::toString() {
19
+ return string("Spectral Centroid");
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef SPECTRALCENTROIDFEATURE_H
2
+ #define SPECTRALCENTROIDFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class SpectralCentroidFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();
15
+ };
16
+ }
17
+
18
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "SpectralSparsityFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void SpectralSparsityFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string SpectralSparsityFeature::toString() {
19
+ return string("Spectral Sparsity");
20
+ }
21
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef SPECTRALSPARSITYFEATURE_H
2
+ #define SPECTRALSPARSITYFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class SpectralSparsityFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();};
15
+ }
16
+
17
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "TemporalSparsityFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void TemporalSparsityFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string TemporalSparsityFeature::toString() {
19
+ return string("Temporal Sparsity");
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef TEMPORALSPARSITYFEATURE_H
2
+ #define TEMPORALSPARSITYFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class TemporalSparsityFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();
15
+ };
16
+ }
17
+
18
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "TransientIndexFeature.h"
2
+
3
+ #include <cmath>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ namespace SoundwalkLib {
8
+ void TransientIndexFeature::calculate(vector<float> values) {
9
+ float rms = 0;
10
+
11
+ for (int i = 0; i < values.size(); i++) {
12
+ rms += values[i] * values[i];
13
+ }
14
+
15
+ value = 20 * log10(rms / (float) values.size());
16
+ }
17
+
18
+ string TransientIndexFeature::toString() {
19
+ return string("Transient Index");
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef TRANSIENTINDEXFEATURE_H
2
+ #define TRANSIENTINDEXFEATURE_H
3
+
4
+ #include "Feature.h"
5
+
6
+ #include <string>
7
+ #include <vector>
8
+ using namespace std;
9
+
10
+ namespace SoundwalkLib {
11
+ class TransientIndexFeature : public Feature {
12
+ public:
13
+ void calculate(vector<float> values);
14
+ string toString();
15
+ };
16
+ }
17
+
18
+ #endif
@@ -0,0 +1,26 @@
1
+ require 'mkmf-rice'
2
+ require 'FileUtils'
3
+
4
+ $CFLAGS << " -I../c -I../c/features #{ENV['CFLAGS']}"
5
+
6
+ extension_name = 'Soundwalk'
7
+
8
+ %w[ ../c/features/HarmonicityFeature.cpp
9
+ ../c/features/TemporalSparsityFeature.cpp
10
+ ../c/features/SpectralSparsityFeature.cpp
11
+ ../c/features/SpectralCentroidFeature.cpp
12
+ ../c/features/LoudnessFeature.cpp
13
+ ../c/features/TransientIndexFeature.cpp
14
+ ../c/features/Feature.cpp
15
+ ../c/Sound.cpp
16
+ ../c/WindowFunctions.cpp
17
+ ].each do |filename|
18
+ abort "Error: #{filename} not found. Type 'make ruby' in the top directory.\n" unless File.exists? filename
19
+ FileUtils.cp(filename, ".")
20
+ end
21
+
22
+ have_library("sndfile")
23
+ have_library("fftw3f")
24
+ have_library("stdc++")
25
+
26
+ create_makefile("soundwalk")
@@ -0,0 +1,174 @@
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 "Sound.h"
9
+ #include "Feature.h"
10
+ #include "HarmonicityFeature.h"
11
+ #include "LoudnessFeature.h"
12
+ #include "SpectralCentroidFeature.h"
13
+ #include "SpectralSparsityFeature.h"
14
+ #include "TemporalSparsityFeature.h"
15
+ #include "TransientIndexFeature.h"
16
+ #include "WindowFunctions.h"
17
+ #include "SoundFileExceptions.h"
18
+ using namespace SoundwalkLib;
19
+
20
+ vector<float> FloatVectorFromArray(Array array) {
21
+ vector<float> values;
22
+
23
+ for (int i = 0; i < array.size(); i++)
24
+ values.push_back(NUM2DBL(array[i].value()));
25
+
26
+ return values;
27
+ }
28
+
29
+ class RubyLoudnessFeature : public LoudnessFeature {
30
+ public:
31
+ void calculate(Array array) {
32
+ LoudnessFeature::calculate(FloatVectorFromArray(array));
33
+ }
34
+ };
35
+
36
+ class RubyHarmonicityFeature : public HarmonicityFeature {
37
+ public:
38
+ void calculate(Array array) {
39
+ HarmonicityFeature::calculate(FloatVectorFromArray(array));
40
+ }
41
+ };
42
+
43
+ class RubyTransientIndexFeature : public TransientIndexFeature {
44
+ public:
45
+ void calculate(Array array) {
46
+ TransientIndexFeature::calculate(FloatVectorFromArray(array));
47
+ }
48
+ };
49
+
50
+ class RubySpectralCentroidFeature : public SpectralCentroidFeature {
51
+ public:
52
+ void calculate(Array array) {
53
+ SpectralCentroidFeature::calculate(FloatVectorFromArray(array));
54
+ }
55
+ };
56
+
57
+ class RubySpectralSparsityFeature : public SpectralSparsityFeature {
58
+ public:
59
+ void calculate(Array array) {
60
+ SpectralSparsityFeature::calculate(FloatVectorFromArray(array));
61
+ }
62
+ };
63
+
64
+ class RubyTemporalSparsityFeature : public TemporalSparsityFeature {
65
+ public:
66
+ void calculate(Array array) {
67
+ TemporalSparsityFeature::calculate(FloatVectorFromArray(array));
68
+ }
69
+ };
70
+
71
+ class RubySound : public Sound {
72
+ public:
73
+ Array cepstralFeaturesToArray() {
74
+ return Array(cepstralFeatures.begin(), cepstralFeatures.end());
75
+ }
76
+
77
+ Array spectralFeaturesToArray() {
78
+ return Array(spectralFeatures.begin(), spectralFeatures.end());
79
+ }
80
+
81
+ Array sampleFeaturesToArray() {
82
+ return Array(sampleFeatures.begin(), sampleFeatures.end());
83
+ }
84
+
85
+ void cepstralFeaturesFromArray(Array new_features) {
86
+ emptyCepstralFeatures();
87
+
88
+ for (int i = 0; i < new_features.size(); i++)
89
+ cepstralFeatures.push_back((Feature*)DATA_PTR(new_features[i].value()));
90
+ }
91
+
92
+ void spectralFeaturesFromArray(Array new_features) {
93
+ emptySpectralFeatures();
94
+
95
+ for (int i = 0; i < new_features.size(); i++)
96
+ spectralFeatures.push_back((Feature*)DATA_PTR(new_features[i].value()));
97
+ }
98
+
99
+ void sampleFeaturesFromArray(Array new_features) {
100
+ emptySampleFeatures();
101
+
102
+ for (int i = 0; i < new_features.size(); i++)
103
+ sampleFeatures.push_back((Feature*)DATA_PTR(new_features[i].value()));
104
+ }
105
+ };
106
+
107
+ Array rb_cSoundFeatures() {
108
+ return Array();
109
+ }
110
+
111
+ extern "C" void Init_soundwalk() {
112
+ Data_Type<Sound> rb_cSound =
113
+ define_class<RubySound>("Sound")
114
+ .define_constructor(Constructor<RubySound>())
115
+ .define_method("length", &RubySound::getLength)
116
+ .define_method("sampleRate", &RubySound::getSampleRate)
117
+ .define_method("channels", &RubySound::getChannels)
118
+ .define_method("format", &RubySound::getFormat)
119
+ .define_method("path", &RubySound::getPath)
120
+ .define_method("fftSize=", &RubySound::setFFTSize)
121
+ .define_method("fftSize", &RubySound::getFFTSize)
122
+ .define_method("mfccSize=", &RubySound::setMFCCSize)
123
+ .define_method("mfccSize", &RubySound::getMFCCSize)
124
+ .define_method("openSound", &RubySound::openSound)
125
+ .define_method("cepstralFeatures", &RubySound::cepstralFeaturesToArray)
126
+ .define_method("cepstralFeatures=", &RubySound::cepstralFeaturesFromArray)
127
+ .define_method("spectralFeatures", &RubySound::spectralFeaturesToArray)
128
+ .define_method("spectralFeatures=", &RubySound::spectralFeaturesFromArray)
129
+ .define_method("sampleFeatures", &RubySound::sampleFeaturesToArray)
130
+ .define_method("sampleFeatures=", &RubySound::sampleFeaturesFromArray);
131
+
132
+ Data_Type<Feature> rb_cFeature =
133
+ define_class<Feature>("Feature")
134
+ .define_constructor(Constructor<Feature>())
135
+ .define_method("value", &Feature::getValue)
136
+ .define_method("calculate", &Feature::calculate)
137
+ .define_method("toString", &Feature::toString);
138
+
139
+ Data_Type<RubyLoudnessFeature> rb_cLoudnessFeature =
140
+ define_class<RubyLoudnessFeature, Feature>("LoudnessFeature")
141
+ .define_constructor(Constructor<RubyLoudnessFeature>())
142
+ .define_method("calculate", &RubyLoudnessFeature::calculate)
143
+ .define_method("toString", &RubyLoudnessFeature::toString);
144
+
145
+ Data_Type<RubyHarmonicityFeature> rb_cHarmonicityFeature =
146
+ define_class<RubyHarmonicityFeature, Feature>("HarmonicityFeature")
147
+ .define_constructor(Constructor<RubyHarmonicityFeature>())
148
+ .define_method("calculate", &RubyHarmonicityFeature::calculate)
149
+ .define_method("toString", &RubyHarmonicityFeature::toString);
150
+
151
+ Data_Type<RubyTransientIndexFeature> rb_cTransientIndexFeature =
152
+ define_class<RubyTransientIndexFeature, Feature>("TransientIndexFeature")
153
+ .define_constructor(Constructor<RubyTransientIndexFeature>())
154
+ .define_method("calculate", &RubyTransientIndexFeature::calculate)
155
+ .define_method("toString", &RubyTransientIndexFeature::toString);
156
+
157
+ Data_Type<RubySpectralCentroidFeature> rb_cSpectralCentroidFeature =
158
+ define_class<RubySpectralCentroidFeature, Feature>("SpectralCentroidFeature")
159
+ .define_constructor(Constructor<RubySpectralCentroidFeature>())
160
+ .define_method("calculate", &RubySpectralCentroidFeature::calculate)
161
+ .define_method("toString", &RubySpectralCentroidFeature::toString);
162
+
163
+ Data_Type<RubySpectralSparsityFeature> rb_cSpectralSparsityFeature =
164
+ define_class<RubySpectralSparsityFeature, Feature>("SpectralSparsityFeature")
165
+ .define_constructor(Constructor<RubySpectralSparsityFeature>())
166
+ .define_method("calculate", &RubySpectralSparsityFeature::calculate)
167
+ .define_method("toString", &RubySpectralSparsityFeature::toString);
168
+
169
+ Data_Type<RubyTemporalSparsityFeature> rb_cTemporalSparsityFeature =
170
+ define_class<RubyTemporalSparsityFeature, Feature>("TemporalSparsityFeature")
171
+ .define_constructor(Constructor<RubyTemporalSparsityFeature>())
172
+ .define_method("calculate", &RubyTemporalSparsityFeature::calculate)
173
+ .define_method("toString", &RubyTemporalSparsityFeature::toString);
174
+ }
@@ -0,0 +1,27 @@
1
+ require 'soundwalk'
2
+
3
+ filename = '/Users/brandon/Desktop/segment_10.wav'
4
+ s = Sound.new
5
+ s.openSound filename
6
+
7
+ print "\n", s
8
+ print "\n\tPath: ", s.path
9
+ print "\n\tChannels: ", s.channels
10
+ print "\n\tFormat: ", s.format
11
+ print "\n\tLength: ", s.length
12
+ print "\n\tSample rate: ", s.sampleRate
13
+ print "\n\n\n"
14
+
15
+ sampleFeatures = Array[LoudnessFeature.new, TemporalSparsityFeature.new]
16
+ cepstralFeatures = Array[SpectralCentroidFeature.new, TransientIndexFeature.new]
17
+ spectralFeatures = Array[HarmonicityFeature.new, SpectralSparsityFeature.new]
18
+
19
+ s.sampleFeatures = sampleFeatures
20
+ s.cepstralFeatures = cepstralFeatures
21
+ s.spectralFeatures = spectralFeatures
22
+
23
+ print "\n", s.sampleFeatures
24
+ print "\n", s.cepstralFeatures
25
+ print "\n", s.spectralFeatures
26
+
27
+ print "\n\n\n"
data/soundwalk.gemspec ADDED
@@ -0,0 +1,78 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{soundwalk}
5
+ s.version = "0.0.0"
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-05-22}
10
+ s.email = %q{bmechtley+github@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/c/FeatureTemplate.cpp",
23
+ "lib/c/FeatureTemplate.cpp",
24
+ "lib/c/FeatureTemplate.h",
25
+ "lib/c/FeatureTemplate.h",
26
+ "lib/c/Sound.cpp",
27
+ "lib/c/Sound.cpp",
28
+ "lib/c/Sound.h",
29
+ "lib/c/Sound.h",
30
+ "lib/c/SoundFileExceptions.h",
31
+ "lib/c/SoundFileExceptions.h",
32
+ "lib/c/WindowFunctions.cpp",
33
+ "lib/c/WindowFunctions.cpp",
34
+ "lib/c/WindowFunctions.h",
35
+ "lib/c/WindowFunctions.h",
36
+ "lib/c/features/Feature.cpp",
37
+ "lib/c/features/Feature.h",
38
+ "lib/c/features/HarmonicityFeature.cpp",
39
+ "lib/c/features/HarmonicityFeature.h",
40
+ "lib/c/features/LoudnessFeature.cpp",
41
+ "lib/c/features/LoudnessFeature.h",
42
+ "lib/c/features/SpectralCentroidFeature.cpp",
43
+ "lib/c/features/SpectralCentroidFeature.h",
44
+ "lib/c/features/SpectralSparsityFeature.cpp",
45
+ "lib/c/features/SpectralSparsityFeature.h",
46
+ "lib/c/features/TemporalSparsityFeature.cpp",
47
+ "lib/c/features/TemporalSparsityFeature.h",
48
+ "lib/c/features/TransientIndexFeature.cpp",
49
+ "lib/c/features/TransientIndexFeature.h",
50
+ "lib/ruby/extconf.rb",
51
+ "lib/ruby/extconf.rb",
52
+ "lib/ruby/soundwalk.cpp",
53
+ "lib/ruby/soundwalk.cpp",
54
+ "lib/ruby/soundwalk.rb",
55
+ "soundwalk.gemspec",
56
+ "test/soundwalk-api_test.rb",
57
+ "test/test_helper.rb"
58
+ ]
59
+ s.homepage = %q{http://github.com/plant/soundwalk}
60
+ s.rdoc_options = ["--charset=UTF-8"]
61
+ s.require_paths = ["lib"]
62
+ s.rubygems_version = %q{1.3.3}
63
+ s.summary = %q{Gem for feature extraction, segmentation, and comparison of environmental (non-musical) sounds.}
64
+ s.test_files = [
65
+ "test/soundwalk-api_test.rb",
66
+ "test/test_helper.rb"
67
+ ]
68
+
69
+ if s.respond_to? :specification_version then
70
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
74
+ else
75
+ end
76
+ else
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SoundwalkApiTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -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,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plant-soundwalk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mechtley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: bmechtley+github@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/c/FeatureTemplate.cpp
33
+ - lib/c/FeatureTemplate.h
34
+ - lib/c/Sound.cpp
35
+ - lib/c/Sound.h
36
+ - lib/c/SoundFileExceptions.h
37
+ - lib/c/WindowFunctions.cpp
38
+ - lib/c/WindowFunctions.h
39
+ - lib/c/features/Feature.cpp
40
+ - lib/c/features/Feature.h
41
+ - lib/c/features/HarmonicityFeature.cpp
42
+ - lib/c/features/HarmonicityFeature.h
43
+ - lib/c/features/LoudnessFeature.cpp
44
+ - lib/c/features/LoudnessFeature.h
45
+ - lib/c/features/SpectralCentroidFeature.cpp
46
+ - lib/c/features/SpectralCentroidFeature.h
47
+ - lib/c/features/SpectralSparsityFeature.cpp
48
+ - lib/c/features/SpectralSparsityFeature.h
49
+ - lib/c/features/TemporalSparsityFeature.cpp
50
+ - lib/c/features/TemporalSparsityFeature.h
51
+ - lib/c/features/TransientIndexFeature.cpp
52
+ - lib/c/features/TransientIndexFeature.h
53
+ - lib/ruby/extconf.rb
54
+ - lib/ruby/soundwalk.cpp
55
+ - lib/ruby/soundwalk.rb
56
+ - soundwalk.gemspec
57
+ - test/soundwalk-api_test.rb
58
+ - test/test_helper.rb
59
+ has_rdoc: false
60
+ homepage: http://github.com/plant/soundwalk
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.2.0
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Gem for feature extraction, segmentation, and comparison of environmental (non-musical) sounds.
85
+ test_files:
86
+ - test/soundwalk-api_test.rb
87
+ - test/test_helper.rb