spectrum-analyzer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTlmMzUwYjdkNDU3NzYzZDc3MThmYzZkMmZmNDY0ZWE4YzIxY2ZlZg==
5
+ data.tar.gz: !binary |-
6
+ NzgzZjUxNWE2MTBkM2ZkNjA3NDljZTQ3OTM2MWJlMzIxYWFlNDEwNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDI1YzkyMjE5OWMwOTNjZTBmMDg1MmE4ZjE1OGVhYzkyNTVlMTRiOTA2NGU4
10
+ MzJkYzIzNjU5OThjOWY5ODQ2NDE0N2U1MTQzZWNjNmJkNjRjMjYwZmNlYmI0
11
+ MzExMTgyNzY2MmUyNmRjNDdkYTVhMWRjNjFkOTRmMGVlOTRhYTY=
12
+ data.tar.gz: !binary |-
13
+ MjZhNDY4MWQ3NjhmMjM1ZThmOTg1YTI2ZGRiYWU0ZjA4YmE4OWI3OTRkOTJj
14
+ NDc1ZDNkOTBmNmYzMGY4OTljNjE4MmVkMmUzMDIwNzgzNDU5Mjk3MGYwYTNl
15
+ OGFhZTIyZWZiYmMzYWMxOWRhZTRhNDNlZTA3NTE1YTQyNDBmMDM=
data/Gemfile CHANGED
@@ -11,4 +11,6 @@ group :development do
11
11
  gem "bundler", "~> 1.0"
12
12
  gem "jeweler", "~> 1.8.7"
13
13
  gem "simplecov", ">= 0"
14
+ gem "ruby-audio"
15
+ gem "fftw3"
14
16
  end
data/Gemfile.lock CHANGED
@@ -7,6 +7,8 @@ GEM
7
7
  docile (1.1.0)
8
8
  faraday (0.8.8)
9
9
  multipart-post (~> 1.2.0)
10
+ fftw3 (0.3)
11
+ narray
10
12
  git (1.2.6)
11
13
  github_api (0.10.1)
12
14
  addressable
@@ -34,6 +36,7 @@ GEM
34
36
  multi_json (1.8.2)
35
37
  multi_xml (0.5.5)
36
38
  multipart-post (1.2.0)
39
+ narray (0.6.0.8)
37
40
  nokogiri (1.5.10)
38
41
  oauth2 (0.9.2)
39
42
  faraday (~> 0.8)
@@ -54,6 +57,7 @@ GEM
54
57
  rspec-expectations (2.8.0)
55
58
  diff-lcs (~> 1.1.2)
56
59
  rspec-mocks (2.8.0)
60
+ ruby-audio (1.6.1)
57
61
  simplecov (0.8.1)
58
62
  docile (~> 1.1.0)
59
63
  lockfile (>= 2.1.0)
@@ -66,7 +70,9 @@ PLATFORMS
66
70
 
67
71
  DEPENDENCIES
68
72
  bundler (~> 1.0)
73
+ fftw3
69
74
  jeweler (~> 1.8.7)
70
75
  rdoc (~> 3.12)
71
76
  rspec (~> 2.8.0)
77
+ ruby-audio
72
78
  simplecov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,35 @@
1
+ require 'ruby-audio'
2
+ require 'fftw3'
3
+
4
+ require_relative '../lib/spectrum-analyzer/config'
5
+
6
+ Dir[File.dirname(__FILE__) + '/spectrum-analyzer/clients/*.rb'].each {| file| load file }
7
+ Dir[File.dirname(__FILE__) + '/spectrum-analyzer/criteria/*.rb'].each {| file| load file }
8
+
9
+ module SpectrumAnalyzer
10
+
11
+ def self.configuration
12
+ @configuration ||= SpectrumAnalyzer::Config.new()
13
+ end
14
+
15
+ def self.generate
16
+ SpectrumAnalyzer::Generator.new()
17
+ end
18
+
19
+ def self.analyze
20
+ SpectrumAnalyzer::Analyze
21
+ end
22
+
23
+ def self.quick_analyze
24
+ SpectrumAnalyzer::Generator.quick_analyze
25
+ end
26
+
27
+ def self.file
28
+ @file ||= SpectrumAnalyzer::File.new()
29
+ end
30
+
31
+ def self.spectrum
32
+ @spectrum ||= SpectrumAnalyzer::Spectrum.new()
33
+ end
34
+
35
+ end
@@ -0,0 +1,5 @@
1
+ module SpectrumAnalyzer
2
+ class Analyze
3
+
4
+ end
5
+ end
@@ -0,0 +1,139 @@
1
+ module SpectrumAnalyzer
2
+ class Generator
3
+ def initialize
4
+ @config = SpectrumAnalyzer.configuration
5
+ @file = build_file_info
6
+ @spectrum = SpectrumAnalyzer.spectrum
7
+ end
8
+
9
+ def set_file(file)
10
+ @file = file
11
+ end
12
+
13
+ def quick_analyze
14
+ #For each FFT window built
15
+ #check for hit
16
+ #return true if found
17
+ #return false
18
+ end
19
+
20
+ def build_spectrum
21
+ generate_spectrum()
22
+ analyze_spectrum()
23
+ end
24
+
25
+ private
26
+
27
+
28
+ def generate_spectrum
29
+ #For each FFT window built
30
+ #add FFT window to spectrum class
31
+ begin
32
+ buffer = RubyAudio::Buffer.float(@config.window_size)
33
+ RubyAudio::Sound.open(@config.file_name) do |snd|
34
+ while snd.read(buffer) != 0
35
+ fft_slice = generate_domain(buffer)
36
+ @spectrum.domains.push (SpectrumAnalyzer::Domain.new(fft_slice))
37
+ #i=0
38
+ #fft_slice.each { |x| spectrum[i] += x.magnitude; i+=1}
39
+ #
40
+ #spectrum_array[iterations] = fft_slice
41
+ #i = 0
42
+ #spectrum_array[iterations].each { |x| spectrum_array[iterations][i] = x.magnitude; i+=1}
43
+ #iterations += 1
44
+ #
45
+ #ping = analyze_for_hit(fft_slice, iterations - 1)
46
+ #return ping if ping
47
+ #hits += 1 if ping
48
+ end
49
+ end
50
+
51
+ rescue => err
52
+ p "error reading audio file: " + err.to_s
53
+ exit
54
+ end
55
+ end
56
+
57
+ def generate_domain(buffer)
58
+ wave = Array.new()
59
+ windowed_array = apply_window(buffer.to_a, windows[@config.window_function])
60
+ wave.concat(windowed_array)
61
+ na = NArray.to_na(windowed_array)
62
+ FFTW3.fft(na).to_a[0, @config.window_size/2]
63
+ end
64
+
65
+ def analyze_spectrum
66
+ #for each FFT window in spectrum class
67
+ #determine if window contains hit
68
+ #apply hit bool to that fft object
69
+ #sum all FFT windows in spectrum to create overall freq spectrum
70
+ #return spectrum class
71
+ end
72
+
73
+ def build_file_info
74
+ file = SpectrumAnalyzer::File.new(@config.file_name)
75
+ file.sample_rate = RubyAudio::Sound.open(file.name).info.samplerate
76
+ file
77
+ end
78
+
79
+ def windows
80
+ {
81
+ :hanning => hanning(@config.window_size),
82
+ :rectangle => rectangle(@config.window_size)
83
+ }
84
+ end
85
+
86
+ def gen_fft
87
+
88
+
89
+ #p hits
90
+ return false
91
+
92
+ end
93
+
94
+
95
+ def apply_window(buffer, window_type)
96
+ windowed_array = Array.new()
97
+ i=0
98
+ buffer.each { |x| windowed_array[i] = x * window_type[i]; i+=1}
99
+ end
100
+
101
+ def hanning (window_size)
102
+ hannified_array = Array.new
103
+ i=0
104
+ (0..window_size).each { |x| hannified_array[i] = 0.5 - 0.5 * Math.cos(2 * Math::PI * i / window_size) ; i+=1}
105
+
106
+ hannified_array
107
+ end
108
+
109
+ def rectangle (window_size)
110
+ Array.new(window_size, 1)
111
+ end
112
+
113
+ def analysis_array
114
+ @config.analysis_array
115
+ end
116
+
117
+ def analyze_for_hit(fft_array, index)
118
+ ranges = analysis_array
119
+
120
+ j=0
121
+ hit = Array.new()
122
+ #p "INDEX: #{index}"
123
+ ranges.each do |x|
124
+ sum_total = 0
125
+ for i in x[:b_index]..x[:t_index]
126
+ sum_total += fft_array[i] if !fft_array[i].nil?
127
+ end
128
+ average = sum_total / (x[:t_index] - x[:b_index])
129
+ hit[j] = average > x[:min] and average < x[:max]
130
+ j+=1
131
+ end
132
+ ping = !hit.include?(false)
133
+ return ping
134
+ end
135
+
136
+ end
137
+ end
138
+
139
+
@@ -0,0 +1,19 @@
1
+ module SpectrumAnalyzer
2
+ class Config
3
+ attr_accessor :file_name, :window_function, :window_size, :analysis_range
4
+
5
+ def initialize
6
+ @window_size = 512
7
+ @window_function = :hanning
8
+ @analysis_array = [{ :b_index => 27, :t_index => 47, :min => 1, :max => 2}, #Low area
9
+ { :b_index => 58, :t_index => 64, :min => 2.5, :max => 6.5}, #High peak
10
+ { :b_index => 70, :t_index => 74, :min => 2.0, :max => 4.2 }, #Mid peak
11
+ { :b_index => 82, :t_index => 109, :min => 0.8, :max => 2}] #Low area
12
+ @file_name = "spec/analyze.wav"
13
+ end
14
+
15
+ end
16
+
17
+
18
+
19
+ end
@@ -0,0 +1,9 @@
1
+ module SpectrumAnalyzer
2
+ class Domain
3
+ attr_accessor :values, :contains_frequency_range
4
+
5
+ def initialize(values)
6
+ @values = values
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module SpectrumAnalyzer
2
+ class File
3
+ attr_accessor :name, :sample_rate
4
+
5
+ def initialize(name)
6
+ @name = name || ''
7
+ end
8
+
9
+ def read
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module SpectrumAnalyzer
2
+ class Spectrum
3
+ attr_accessor :domains, :entire_spectrum
4
+
5
+ def initialize(spectrum = [])
6
+ @domains = spectrum
7
+ end
8
+ end
9
+ end
data/spec/analyze.wav ADDED
Binary file
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: spectrum-analyzer 0.1.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "spectrum-analyzer"
9
+ s.version = "0.1.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Justin Roberts"]
13
+ s.date = "2013-11-27"
14
+ s.description = "Analyze a wav file for specific frequency signatures"
15
+ s.email = "justin.roberts@careerbuilder.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/spectrum-analyzer.rb",
30
+ "lib/spectrum-analyzer/clients/analyze.rb",
31
+ "lib/spectrum-analyzer/clients/generator.rb",
32
+ "lib/spectrum-analyzer/config.rb",
33
+ "lib/spectrum-analyzer/criteria/domain.rb",
34
+ "lib/spectrum-analyzer/criteria/file.rb",
35
+ "lib/spectrum-analyzer/criteria/spectrum.rb",
36
+ "spec/analyze.wav",
37
+ "spec/spec_helper.rb",
38
+ "spec/spectrum-analyzer_spec.rb",
39
+ "spectrum-analyzer.gemspec"
40
+ ]
41
+ s.homepage = "http://github.com/jusroberts/spectrum-analyzer"
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = "2.1.11"
45
+ s.summary = "Analyze a wav file for specific frequency signatures"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
52
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
55
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
56
+ s.add_development_dependency(%q<ruby-audio>, [">= 0"])
57
+ s.add_development_dependency(%q<fftw3>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
63
+ s.add_dependency(%q<simplecov>, [">= 0"])
64
+ s.add_dependency(%q<ruby-audio>, [">= 0"])
65
+ s.add_dependency(%q<fftw3>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
69
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
72
+ s.add_dependency(%q<simplecov>, [">= 0"])
73
+ s.add_dependency(%q<ruby-audio>, [">= 0"])
74
+ s.add_dependency(%q<fftw3>, [">= 0"])
75
+ end
76
+ end
77
+
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectrum-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Justin Roberts
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rdoc
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: jeweler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: simplecov
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,34 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-audio
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fftw3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
90
107
  requirements:
91
108
  - - ! '>='
92
109
  - !ruby/object:Gem::Version
@@ -108,34 +125,38 @@ files:
108
125
  - Rakefile
109
126
  - VERSION
110
127
  - lib/spectrum-analyzer.rb
128
+ - lib/spectrum-analyzer/clients/analyze.rb
129
+ - lib/spectrum-analyzer/clients/generator.rb
130
+ - lib/spectrum-analyzer/config.rb
131
+ - lib/spectrum-analyzer/criteria/domain.rb
132
+ - lib/spectrum-analyzer/criteria/file.rb
133
+ - lib/spectrum-analyzer/criteria/spectrum.rb
134
+ - spec/analyze.wav
111
135
  - spec/spec_helper.rb
112
136
  - spec/spectrum-analyzer_spec.rb
137
+ - spectrum-analyzer.gemspec
113
138
  homepage: http://github.com/jusroberts/spectrum-analyzer
114
139
  licenses:
115
140
  - MIT
141
+ metadata: {}
116
142
  post_install_message:
117
143
  rdoc_options: []
118
144
  require_paths:
119
145
  - lib
120
146
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
147
  requirements:
123
148
  - - ! '>='
124
149
  - !ruby/object:Gem::Version
125
150
  version: '0'
126
- segments:
127
- - 0
128
- hash: 3408237005152452297
129
151
  required_rubygems_version: !ruby/object:Gem::Requirement
130
- none: false
131
152
  requirements:
132
153
  - - ! '>='
133
154
  - !ruby/object:Gem::Version
134
155
  version: '0'
135
156
  requirements: []
136
157
  rubyforge_project:
137
- rubygems_version: 1.8.25
158
+ rubygems_version: 2.1.11
138
159
  signing_key:
139
- specification_version: 3
160
+ specification_version: 4
140
161
  summary: Analyze a wav file for specific frequency signatures
141
162
  test_files: []