aubio 0.3.0 → 0.3.5
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 +5 -5
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.md +13 -2
- data/Rakefile +7 -5
- data/aubio-ffi-generator.rb +8 -6
- data/aubio.gemspec +19 -17
- data/bin/console +4 -3
- data/lib/aubio/aubio-ffi.rb +51 -49
- data/lib/aubio/beats.rb +55 -52
- data/lib/aubio/legacy_api.rb +40 -39
- data/lib/aubio/onsets.rb +52 -52
- data/lib/aubio/pitches.rb +62 -54
- data/lib/aubio/version.rb +3 -1
- data/lib/ruby_aubio.rb +132 -0
- metadata +27 -15
- data/aubio.rb +0 -467
- data/lib/aubio.rb +0 -93
data/lib/aubio.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require_relative "aubio/version"
|
2
|
-
require_relative "aubio/aubio-ffi"
|
3
|
-
require_relative "aubio/onsets"
|
4
|
-
require_relative "aubio/pitches"
|
5
|
-
require_relative "aubio/beats"
|
6
|
-
|
7
|
-
module Aubio
|
8
|
-
class AubioException < Exception; end
|
9
|
-
class FileNotFound < AubioException; end
|
10
|
-
class AlreadyClosed < AubioException; end
|
11
|
-
class InvalidAudioInput < AubioException; end
|
12
|
-
|
13
|
-
class Base
|
14
|
-
def initialize(path, params)
|
15
|
-
raise FileNotFound unless File.file?(path)
|
16
|
-
|
17
|
-
sample_rate = params[:sample_rate] || 44100
|
18
|
-
hop_size = params[:hop_size] || 512
|
19
|
-
|
20
|
-
@source = Api.new_aubio_source(path, sample_rate, hop_size)
|
21
|
-
@params = params
|
22
|
-
|
23
|
-
check_for_valid_audio_source(path)
|
24
|
-
end
|
25
|
-
|
26
|
-
def close
|
27
|
-
Api.del_aubio_source(@source)
|
28
|
-
@is_closed = true
|
29
|
-
end
|
30
|
-
|
31
|
-
def onsets
|
32
|
-
check_for_closed
|
33
|
-
|
34
|
-
Onsets.new(@source, @params).each
|
35
|
-
end
|
36
|
-
|
37
|
-
def pitches
|
38
|
-
check_for_closed
|
39
|
-
|
40
|
-
Pitches.new(@source, @params).each
|
41
|
-
end
|
42
|
-
|
43
|
-
def beats
|
44
|
-
check_for_closed
|
45
|
-
|
46
|
-
Beats.new(@source, @params).each
|
47
|
-
end
|
48
|
-
|
49
|
-
def bpm
|
50
|
-
check_for_closed
|
51
|
-
|
52
|
-
beat_locations = Beats.new(@source, @params).each.to_a
|
53
|
-
beat_periods = beat_locations.each_cons(2).map {|a,b| b[:s] - a[:s] }
|
54
|
-
|
55
|
-
return 60.0 if beat_locations.length == 1
|
56
|
-
|
57
|
-
# use interquartile median to discourage outliers
|
58
|
-
s = beat_periods.length
|
59
|
-
qrt_lower_idx = (s/4.0).floor
|
60
|
-
qrt_upper_idx = qrt_lower_idx * 3
|
61
|
-
interquartile_beat_periods = beat_periods[qrt_lower_idx..qrt_upper_idx]
|
62
|
-
|
63
|
-
# Calculate median
|
64
|
-
iqs = interquartile_beat_periods.length
|
65
|
-
|
66
|
-
iq_median_beat_period = interquartile_beat_periods.sort[(iqs/2.0).floor() - 1]
|
67
|
-
60.0 / iq_median_beat_period
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
def check_for_closed
|
72
|
-
raise AlreadyClosed if @is_closed
|
73
|
-
end
|
74
|
-
|
75
|
-
def check_for_valid_audio_source(path)
|
76
|
-
begin
|
77
|
-
@source.read_pointer
|
78
|
-
rescue FFI::NullPointerError
|
79
|
-
raise InvalidAudioInput.new(%Q{
|
80
|
-
|
81
|
-
Couldn't read file at #{path}
|
82
|
-
Did you install aubio with libsndfile support?
|
83
|
-
})
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
module Aubio
|
90
|
-
def self.open(path, params = {})
|
91
|
-
Base.new(path, params)
|
92
|
-
end
|
93
|
-
end
|