pulse-analysis 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/pulse-analysis.rb +1 -1
- data/lib/pulse-analysis/analysis.rb +18 -11
- data/lib/pulse-analysis/conversion.rb +8 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd91484dc5c2d5733a0b5f969c1eb6e8a902205
|
4
|
+
data.tar.gz: 749b593cbc19c12bc1c09a01e876739161576d3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6e6cc65a0eb3c2d06c6e703daecf782d473306117a7666d0da33737ca0ca09da96b3e64da8035dc161e4306da80a225129a4ee4a6b5df87049fafaa20b397b
|
7
|
+
data.tar.gz: f01fa50e281b3675958e43cbe133492016de8609a005856ed98f513c3296c43c2c01b2edaa05acddc417ba1e83b56692abf1cd6cfe663665c4b8877b0681f5be
|
data/README.md
CHANGED
@@ -53,13 +53,13 @@ This will run the program and output something like
|
|
53
53
|
| Item | Value |
|
54
54
|
+------------------------+-------------------------+-------------+
|
55
55
|
| Sample rate | 88200 (Hertz) |
|
56
|
-
| Length |
|
57
|
-
| Tempo | 119.
|
58
|
-
| Longest period length |
|
59
|
-
| Shortest period length |
|
60
|
-
| Average period length |
|
61
|
-
| Largest abberation |
|
62
|
-
| Average abberation |
|
56
|
+
| Length | 4310 (Number of pulses) | 9m0s (Time) |
|
57
|
+
| Tempo | 119.7546 (BPM) |
|
58
|
+
| Longest period length | 11326 (Samples) | 128.41 (ms) |
|
59
|
+
| Shortest period length | 10747 (Samples) | 121.85 (ms) |
|
60
|
+
| Average period length | 11047.5949 (Samples) | 125.26 (ms) |
|
61
|
+
| Largest abberation | 544 (Samples) | 6.17 (ms) |
|
62
|
+
| Average abberation | 160.2981 (Samples) | 1.82 (ms) |
|
63
63
|
+------------------------+-------------------------+-------------+
|
64
64
|
```
|
65
65
|
|
data/lib/pulse-analysis.rb
CHANGED
@@ -22,7 +22,7 @@ require "pulse-analysis/sound"
|
|
22
22
|
|
23
23
|
module PulseAnalysis
|
24
24
|
|
25
|
-
VERSION = "0.0.
|
25
|
+
VERSION = "0.0.3"
|
26
26
|
|
27
27
|
# Analyze the given audio file with the given options and generate a report
|
28
28
|
# @param [::File, String] file_or_path File or path to audio file to run analysis on
|
@@ -3,6 +3,7 @@ module PulseAnalysis
|
|
3
3
|
class Analysis
|
4
4
|
|
5
5
|
MINIMUM_PULSES = 10
|
6
|
+
MAX_BPM = 280
|
6
7
|
|
7
8
|
attr_reader :abberations, :data, :periods, :sound
|
8
9
|
|
@@ -146,7 +147,8 @@ module PulseAnalysis
|
|
146
147
|
end
|
147
148
|
i += 1
|
148
149
|
end
|
149
|
-
abberations.
|
150
|
+
abberations.pop
|
151
|
+
abberations.shift
|
150
152
|
abberations.map(&:abs)
|
151
153
|
end
|
152
154
|
|
@@ -169,27 +171,32 @@ module PulseAnalysis
|
|
169
171
|
@length_threshold
|
170
172
|
end
|
171
173
|
|
174
|
+
def min_period_length
|
175
|
+
@sound.sample_rate * 60 / 4 / MAX_BPM
|
176
|
+
end
|
177
|
+
|
172
178
|
# Calculate periods between pulses
|
173
179
|
# @return [Array<Integer>]
|
174
180
|
def populate_periods
|
175
|
-
|
181
|
+
is_high = true
|
176
182
|
periods = []
|
177
183
|
period_index = 0
|
178
184
|
@data.each do |frame|
|
179
185
|
if frame.abs < amplitude_threshold # if pulse is low
|
180
|
-
|
181
|
-
periods[period_index] ||= 0
|
182
|
-
# count period length
|
183
|
-
periods[period_index] += 1
|
186
|
+
is_high = false
|
184
187
|
else
|
185
188
|
# pulse is high
|
186
|
-
if
|
187
|
-
|
188
|
-
|
189
|
-
|
189
|
+
if !is_high # last frame, the pulse was low
|
190
|
+
# move to next period if length is past minimum
|
191
|
+
if periods[period_index] >= min_period_length
|
192
|
+
is_high = true
|
193
|
+
period_index += 1
|
194
|
+
end
|
190
195
|
end
|
191
|
-
# if the pulse was already high, don't do anything
|
192
196
|
end
|
197
|
+
# count period length
|
198
|
+
periods[period_index] ||= 0
|
199
|
+
periods[period_index] += 1
|
193
200
|
end
|
194
201
|
prune_periods(periods)
|
195
202
|
@periods = periods
|
@@ -19,10 +19,15 @@ module PulseAnalysis
|
|
19
19
|
# @param [Integer] num_samples
|
20
20
|
# @return [String]
|
21
21
|
def num_samples_to_formatted_time(sample_rate, num_samples)
|
22
|
-
|
22
|
+
total_seconds = num_samples_to_seconds(sample_rate, num_samples)
|
23
|
+
min, sec = *total_seconds.divmod(60)
|
23
24
|
# convert seconds to int if it has no decimal value
|
24
|
-
if
|
25
|
-
sec
|
25
|
+
if sec != 0
|
26
|
+
if sec.to_i % sec == 0
|
27
|
+
sec = sec.to_i
|
28
|
+
else
|
29
|
+
sec = sec.round(2)
|
30
|
+
end
|
26
31
|
end
|
27
32
|
# only include minutes if there is a value
|
28
33
|
result = min > 0 ? "#{min}m" : ""
|