spectrum-analyzer 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/spectrum-analyzer/clients/generator.rb +32 -5
- data/lib/spectrum-analyzer/config.rb +2 -2
- data/lib/spectrum-analyzer/criteria/domain.rb +2 -0
- data/lib/spectrum-analyzer/criteria/spectrum.rb +1 -1
- data/spectrum-analyzer.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTU2MDRiMjNmMjlmMWFlZWQ5ZjRlNjU5ODFiMDg0NzlhMjVhZTc2NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTE3YzkxY2FkNmNjNTJhMjI5M2M5ZjM4MmU1MTE1Y2ZhMWUyMjY4Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTU3MGY2NjczZmQwNTAyZDQwYjUwZTI0NTdiYTFiZTVjYzQ5NjA2NWIzOWNm
|
10
|
+
ZGQ2OWQ0OTFkODFjOGQxMDQ2YzAyYzQzY2NlZDJlMDhiYTI1OWIzZjAyZjE0
|
11
|
+
YzE0NzUwYzE4Y2IyMWI5YzllOWJlZGY3NTBlYjJmNzk1YzQzNGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDE5ZjU5NjBhNjJlYTdkOGY5MDc4YjdlZmQyMGUzNTBhOTMyMGI3MzE2NWYx
|
14
|
+
MzljNTY3OTg1YzhhNDcxZmNkNjIyMGQ1MjM5ZDFkZTA1OTgzNzBjYjY1Njlh
|
15
|
+
NjY3ZjUwMjBkYjM3ZjI0OGViNzgwYjczNjljZTMzOGQ0MGNkMDk=
|
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)
|
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)
|
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!!!!
|
@@ -28,7 +28,7 @@ You now have a bunch of "domains" held in the spectrum (SpectrumAnalyzer.spectru
|
|
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 represent the amplitude of
|
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.
|
32
32
|
|
33
33
|
Want them to be available as both complex and magnitudes? Let me know, or submit a pull request!
|
34
34
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -42,6 +42,13 @@ module SpectrumAnalyzer
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def sum_domains
|
46
|
+
@spectrum.entire_spectrum = Array.new(@spectrum.domains[0].values.length, 0)
|
47
|
+
@spectrum.domains.each do |domain|
|
48
|
+
@spectrum.entire_spectrum.map!.with_index{ |x,i| x + domain.values[i]}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
45
52
|
def generate_domain(buffer)
|
46
53
|
windowed_array = apply_window(buffer.to_a, windows[@config.window_function])
|
47
54
|
na = NArray.to_na(windowed_array)
|
@@ -52,11 +59,31 @@ module SpectrumAnalyzer
|
|
52
59
|
end
|
53
60
|
|
54
61
|
def analyze_spectrum
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
sum_domains
|
63
|
+
find_occurrences
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_occurrences
|
67
|
+
ranges = @config.analysis_ranges
|
68
|
+
occurrence_count = 0
|
69
|
+
@spectrum.domains.each do |domain|
|
70
|
+
ranges.each do |range|
|
71
|
+
if find_occurrence(range, domain)
|
72
|
+
occurrence_count += 1
|
73
|
+
domain.contains_frequency_range = true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
@spectrum.num_occurrences = occurrence_count
|
78
|
+
end
|
79
|
+
|
80
|
+
def find_occurrence (range, domain)
|
81
|
+
sum_total = 0
|
82
|
+
for i in range[:b_index]..range[:t_index]
|
83
|
+
sum_total += domain.values[i] if !domain.nil?
|
84
|
+
end
|
85
|
+
average = sum_total / (range[:t_index] - range[:b_index])
|
86
|
+
average > range[:min] and average < range[:max]
|
60
87
|
end
|
61
88
|
|
62
89
|
def build_file_info
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module SpectrumAnalyzer
|
2
2
|
class Config
|
3
|
-
attr_accessor :file_name, :window_function, :window_size, :
|
3
|
+
attr_accessor :file_name, :window_function, :window_size, :analysis_ranges
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@window_size = 512
|
7
7
|
@window_function = :hanning
|
8
|
-
@
|
8
|
+
@analysis_ranges = [{ :b_index => 27, :t_index => 47, :min => 1, :max => 2}, #Low area
|
9
9
|
{ :b_index => 58, :t_index => 64, :min => 2.5, :max => 6.5}, #High peak
|
10
10
|
{ :b_index => 70, :t_index => 74, :min => 2.0, :max => 4.2 }, #Mid peak
|
11
11
|
{ :b_index => 82, :t_index => 109, :min => 0.8, :max => 2}] #Low area
|
data/spectrum-analyzer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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.
|
5
|
+
# stub: spectrum-analyzer 0.1.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "spectrum-analyzer"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.4"
|
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"]
|