pulse-analysis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2096207caf47213e3ff1269eb285e3faf91a789a
4
- data.tar.gz: ba8476091f123079a2ceaf66804797e1f881aa14
3
+ metadata.gz: 3bd91484dc5c2d5733a0b5f969c1eb6e8a902205
4
+ data.tar.gz: 749b593cbc19c12bc1c09a01e876739161576d3e
5
5
  SHA512:
6
- metadata.gz: 1a34470268195debecad448f598950504333451dd49f8da0db220690199db2a05986b7eef8ddedf0d7ab8cf7ff5f273f2ada47a91ec196421cb1bb6ea74e14af
7
- data.tar.gz: c27d19ef642453bba21843abd6368a870e302fa4e5165b29cf9930a6019bfdb776287b4ca184252358d69518b7dfd091aef35189d48aa72077ee6d4e524dd1b9
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 | 4311 (Number of pulses) | 9m0s (Time) |
57
- | Tempo | 119.9371 (BPM) |
58
- | Longest period length | 11289 (Samples) | 127.99 (MS) |
59
- | Shortest period length | 10687 (Samples) | 121.17 (MS) |
60
- | Average period length | 11030.7838 (Samples) | 125.07 (MS) |
61
- | Largest abberation | 543 (Samples) | 6.16 (MS) |
62
- | Average abberation | 155.5279 (Samples) | 1.76 (MS) |
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
 
@@ -22,7 +22,7 @@ require "pulse-analysis/sound"
22
22
 
23
23
  module PulseAnalysis
24
24
 
25
- VERSION = "0.0.2"
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.reject!(&:zero?)
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
- is_low = false
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
- is_low = true
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 is_low # last frame, the pulse was low
187
- is_low = false
188
- # move to next period
189
- period_index += 1
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
- min, sec = *num_samples_to_seconds(sample_rate, num_samples).divmod(60)
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 !sec == 0 && sec.to_i % sec == 0
25
- sec = sec.to_i
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" : ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo