spectrum-analyzer 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTU2MDRiMjNmMjlmMWFlZWQ5ZjRlNjU5ODFiMDg0NzlhMjVhZTc2NA==
4
+ OTg3YmUwNmQxOTAzNDZjOWZmMTc3NjJjMTE2ZjUyODg4MzgxNzljOQ==
5
5
  data.tar.gz: !binary |-
6
- MTE3YzkxY2FkNmNjNTJhMjI5M2M5ZjM4MmU1MTE1Y2ZhMWUyMjY4Yw==
6
+ ZTgzZjMyYWM0MzAyNTE2MWVmNmNmYzg4N2E4YjA0OTg2ZWI1NThlYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTU3MGY2NjczZmQwNTAyZDQwYjUwZTI0NTdiYTFiZTVjYzQ5NjA2NWIzOWNm
10
- ZGQ2OWQ0OTFkODFjOGQxMDQ2YzAyYzQzY2NlZDJlMDhiYTI1OWIzZjAyZjE0
11
- YzE0NzUwYzE4Y2IyMWI5YzllOWJlZGY3NTBlYjJmNzk1YzQzNGE=
9
+ ZWNhNmNiYTc3Njg0YmE2Zjk5NmRlYTQzZDJiMWJhMjZiZWExOGExOWYxZDRm
10
+ MDBjNWM0ZDkzMWUzNTg2MDQxOTIzMzRlNzA1NjI0MDZjYWFjNDk4Nzg4ZDY1
11
+ Y2RiNTRmYzYyNmVmMTU0ZWNkZDg0M2NkNmM2ZTVhM2FmYzgwYmY=
12
12
  data.tar.gz: !binary |-
13
- ZDE5ZjU5NjBhNjJlYTdkOGY5MDc4YjdlZmQyMGUzNTBhOTMyMGI3MzE2NWYx
14
- MzljNTY3OTg1YzhhNDcxZmNkNjIyMGQ1MjM5ZDFkZTA1OTgzNzBjYjY1Njlh
15
- NjY3ZjUwMjBkYjM3ZjI0OGViNzgwYjczNjljZTMzOGQ0MGNkMDk=
13
+ NmM2NGQ4NjRlNzhhMjljYzU3M2UwZmQzMjA3YzY5YWM0ZTY5M2YzYzZkZGQx
14
+ NmRiODU4Y2VkZDIxNGRkODU0NGE5MTI2Y2NjMTg1MzI4Zjg1ZTFlMjY1MTY4
15
+ NDQ0MzZiNjAzN2M0Y2U4MjIwYTFkMDgyYWRhNzk2NTAyY2Y1N2Y=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Code Climate](https://codeclimate.com/github/jusroberts/spectrum-analyzer.png)](https://codeclimate.com/github/jusroberts/spectrum-analyzer) [![Gem Version](https://badge.fury.io/rb/spectrum-analyzer.png)](http://badge.fury.io/rb/spectrum-analyzer)
1
+ [![Code Climate](https://codeclimate.com/github/jusroberts/spectrum-analyzer.png)](https://codeclimate.com/github/jusroberts/spectrum-analyzer) [![Gem Version](https://badge.fury.io/rb/spectrum-analyzer.png)](http://badge.fury.io/rb/spectrum-analyzer) [![Dependency Status](https://gemnasium.com/jusroberts/spectrum-analyzer.png)](https://gemnasium.com/jusroberts/spectrum-analyzer)
2
2
  # Ruby Sound Spectrum Analyzer
3
3
 
4
4
  Have you ever wanted to break apart a sound file and see what frequencies make it up? Well, you're in luck! This program does JUST THAT!!!!
@@ -15,7 +15,7 @@ c = SpectrumAnalyzer.configuration
15
15
  c.file_name = "whatever"
16
16
  c.window_function = :hanning #or :rectangular. Those are the only two implemented currently
17
17
  c.window_size = 512 #MUST BE A POWER OF 2!!!! 128, 256, 512, 1024, etc. If not, I cannot guarantee your results. In fact, you'll probably break FFTW3. Sorry.
18
- c.analysis_array = [] #This does nothing right now. #eventually
18
+ c.analysis_ranges = [] #This does things! Put an array with values you want to define your analysis range.
19
19
  ```
20
20
 
21
21
  generate a spectrum
@@ -23,16 +23,14 @@ generate a spectrum
23
23
  g = SpectrumAnalyzer.generate
24
24
  g.build_spectrum
25
25
  ```
26
- You now have a bunch of "domains" held in the spectrum (SpectrumAnalyzer.spectrum)
26
+ You now have a bunch of "domains" held in the spectrum (SpectrumAnalyzer.spectrum).
27
27
  ```ruby
28
28
  s = SpectrumAnalyzer.spectrum
29
29
  s.domains
30
30
  ```
31
- These domains are an array of frequencies that occur over the time slice defined by the window_size. The values are currently magnitudes of the complex numbers, and the complex numbers themselves. They represent the amplitude of the frequency ranges.
31
+ These domains are an array of frequencies that occur over the time slice defined by the window_size. The values are currently magnitudes of the complex numbers, and the complex numbers themselves. They represent the amplitude of the frequency ranges. The spectrum super class will contain the number of occurrences that match your analysis_ranges, and each domain will know if is an occurrence or not.
32
32
 
33
- Want them to be available as both complex and magnitudes? Let me know, or submit a pull request!
34
-
35
- More to come.
33
+ The last feature before this is released as 0.2.0 will be quick_analyze. This will return true on the first occurrence of the analysis_ranges. This is useful if you are just trying to see if a wav file contains your ranges or not.
36
34
 
37
35
  ##Contributing to spectrum-analyzer
38
36
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -12,16 +12,14 @@ module SpectrumAnalyzer
12
12
  @configuration ||= SpectrumAnalyzer::Config.new()
13
13
  end
14
14
 
15
- def self.generate
16
- SpectrumAnalyzer::Generator.new()
17
- end
18
-
19
15
  def self.analyze
20
- SpectrumAnalyzer::Analyze
16
+ configuration
17
+ SpectrumAnalyzer::Generator.new().build_spectrum
21
18
  end
22
19
 
23
20
  def self.quick_analyze
24
- SpectrumAnalyzer::Generator.quick_analyze
21
+ configuration
22
+ SpectrumAnalyzer::Generator.new().quick_analyze
25
23
  end
26
24
 
27
25
  def self.file
@@ -12,10 +12,19 @@ module SpectrumAnalyzer
12
12
  end
13
13
 
14
14
  def quick_analyze
15
- #For each FFT window built
16
- #check for hit
17
- #return true if found
18
- #return false
15
+ begin
16
+ buffer = RubyAudio::Buffer.float(@config.window_size)
17
+ RubyAudio::Sound.open(@config.file_name) do |snd|
18
+ while snd.read(buffer) != 0
19
+ domain = generate_domain(buffer)
20
+ return true if domain_contains_frequencies?(domain)
21
+ end
22
+ end
23
+
24
+ rescue => error
25
+ p "Error: " + error.to_s
26
+ exit
27
+ end
19
28
  end
20
29
 
21
30
  def build_spectrum
@@ -25,6 +34,22 @@ module SpectrumAnalyzer
25
34
 
26
35
  private
27
36
 
37
+ def domain_contains_frequencies?(domain)
38
+ j=0
39
+ match = Array.new()
40
+ @config.analysis_ranges.each do |range|
41
+ sum_total = 0
42
+ for i in range[:b_index]..range[:t_index]
43
+ sum_total += domain.values[i] if !domain.values[i].nil?
44
+ end
45
+ average = sum_total / (range[:t_index] - range[:b_index])
46
+ match[j] = average > range[:min] and average < range[:max]
47
+ j+=1
48
+ end
49
+ return !match.include?(false)
50
+
51
+ end
52
+
28
53
 
29
54
  def generate_spectrum
30
55
  begin
@@ -32,7 +57,7 @@ module SpectrumAnalyzer
32
57
  RubyAudio::Sound.open(@config.file_name) do |snd|
33
58
  while snd.read(buffer) != 0
34
59
  domain = generate_domain(buffer)
35
- @spectrum.domains.push (domain)
60
+ @spectrum.domains.push(domain)
36
61
  end
37
62
  end
38
63
 
@@ -93,18 +118,7 @@ module SpectrumAnalyzer
93
118
  end
94
119
 
95
120
  def windows
96
- {
97
- :hanning => @window_functions.hanning(),
98
- :rectangle => @window_functions.rectangle()
99
- }
100
- end
101
-
102
- def gen_fft
103
-
104
-
105
- #p hits
106
- return false
107
-
121
+ @window_functions.windows()
108
122
  end
109
123
 
110
124
 
@@ -118,24 +132,6 @@ module SpectrumAnalyzer
118
132
  @config.analysis_array
119
133
  end
120
134
 
121
- def analyze_for_hit(fft_array, index)
122
- #ranges = analysis_array
123
- #
124
- #j=0
125
- #hit = Array.new()
126
- ##p "INDEX: #{index}"
127
- #ranges.each do |x|
128
- # sum_total = 0
129
- # for i in x[:b_index]..x[:t_index]
130
- # sum_total += fft_array[i] if !fft_array[i].nil?
131
- # end
132
- # average = sum_total / (x[:t_index] - x[:b_index])
133
- # hit[j] = average > x[:min] and average < x[:max]
134
- # j+=1
135
- #end
136
- #ping = !hit.include?(false)
137
- #return ping
138
- end
139
135
 
140
136
  end
141
137
  end
@@ -3,7 +3,17 @@ module SpectrumAnalyzer
3
3
  def initialize(window_size)
4
4
  @window_size = window_size
5
5
  end
6
- def hanning
6
+
7
+ def windows()
8
+ {
9
+ :hanning => hanning(),
10
+ :rectangle => rectangle()
11
+ }
12
+ end
13
+
14
+ private
15
+
16
+ def hanning()
7
17
  hannified_array = Array.new
8
18
  i=0
9
19
  (0..@window_size).each { |x| hannified_array[i] = 0.5 - 0.5 * Math.cos(2 * Math::PI * i / @window_size) ; i+=1}
@@ -11,7 +21,7 @@ module SpectrumAnalyzer
11
21
  hannified_array
12
22
  end
13
23
 
14
- def rectangle
24
+ def rectangle()
15
25
  Array.new(@window_size, 1)
16
26
  end
17
27
 
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: spectrum-analyzer 0.1.4 ruby lib
5
+ # stub: spectrum-analyzer 0.1.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "spectrum-analyzer"
9
- s.version = "0.1.4"
9
+ s.version = "0.1.5"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Justin Roberts"]
13
- s.date = "2013-11-27"
13
+ s.date = "2013-12-12"
14
14
  s.description = "Analyze a wav file for specific frequency signatures"
15
15
  s.email = "justin.roberts@careerbuilder.com"
16
16
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectrum-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2013-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec