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/beats.rb
CHANGED
@@ -1,75 +1,78 @@
|
|
1
|
-
|
2
|
-
class Beats
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
module Aubio
|
4
|
+
class Beats
|
5
|
+
def initialize(aubio_source, params)
|
5
6
|
# TODO: cleanup param dups
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
@sample_rate = params[:sample_rate] || 44_100
|
8
|
+
@window_size = params[:window_size] || 1024
|
9
|
+
@hop_size = params[:hop_size] || 512
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
@source = aubio_source
|
12
|
+
@tempo = Api.new_aubio_tempo('specdiff', @window_size, @hop_size, @sample_rate)
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# create output for source
|
15
|
+
@sample_buffer = Api.new_fvec(@hop_size)
|
16
|
+
# create output for beat
|
17
|
+
@out_fvec = Api.new_fvec(1)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
def each
|
21
|
+
return enum_for(:each) unless block_given?
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
total_frames_counter = 0
|
24
|
+
read_buffer = FFI::MemoryPointer.new(:int)
|
25
|
+
total_samples = Api.aubio_source_get_duration(@source).to_f
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
loop do
|
28
|
+
# Perform tempo calculation
|
27
29
|
Api.aubio_source_do(@source, @sample_buffer, read_buffer)
|
28
|
-
|
30
|
+
Api.aubio_tempo_do(@tempo, @sample_buffer, @out_fvec)
|
29
31
|
|
30
32
|
# Retrieve result
|
31
|
-
|
33
|
+
is_beat = Api.fvec_get_sample(@out_fvec, 0)
|
32
34
|
no_of_bytes_read = read_buffer.read_int
|
33
35
|
total_frames_counter += no_of_bytes_read
|
34
36
|
|
35
37
|
if is_beat > 0.0
|
36
|
-
|
37
|
-
|
38
|
+
tempo_samples = Api.aubio_tempo_get_last(@tempo)
|
39
|
+
tempo_seconds = Api.aubio_tempo_get_last_s(@tempo)
|
40
|
+
tempo_milliseconds = Api.aubio_tempo_get_last_ms(@tempo)
|
38
41
|
tempo_confidence = Api.aubio_tempo_get_confidence(@tempo)
|
39
42
|
|
40
|
-
output = {
|
41
|
-
:confidence => tempo_confidence,
|
42
|
-
:s => tempo_seconds,
|
43
|
-
:ms => tempo_milliseconds,
|
44
|
-
:start => (tempo_seconds == 0.0 ? 1 : 0),
|
45
|
-
:end => 0
|
46
|
-
}
|
47
|
-
yield output
|
48
|
-
end
|
49
|
-
|
50
|
-
if no_of_bytes_read != @hop_size
|
51
|
-
# there's no more audio to look at
|
52
|
-
|
53
|
-
# Let's output one last tempo to mark the end of the file
|
54
|
-
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
55
43
|
output = {
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
44
|
+
confidence: tempo_confidence,
|
45
|
+
s: tempo_seconds,
|
46
|
+
ms: tempo_milliseconds,
|
47
|
+
sample_no: tempo_samples,
|
48
|
+
total_samples: total_samples,
|
49
|
+
rel_start: tempo_samples / total_samples
|
61
50
|
}
|
62
51
|
yield output
|
52
|
+
end
|
63
53
|
|
64
|
-
|
65
|
-
Api.del_aubio_tempo(@tempo)
|
66
|
-
Api.del_fvec(@sample_buffer)
|
67
|
-
Api.del_fvec(@out_fvec)
|
54
|
+
next unless no_of_bytes_read != @hop_size
|
68
55
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
56
|
+
# there's no more audio to look at
|
57
|
+
|
58
|
+
# Let's output one last tempo to mark the end of the file
|
59
|
+
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
60
|
+
output = {
|
61
|
+
confidence: 1.0,
|
62
|
+
s: total_time,
|
63
|
+
ms: total_time / 1000.0,
|
64
|
+
sample_no: total_samples,
|
65
|
+
total_samples: total_samples
|
66
|
+
}
|
67
|
+
yield output
|
68
|
+
|
69
|
+
# clean up
|
70
|
+
Api.del_aubio_tempo(@tempo)
|
71
|
+
Api.del_fvec(@sample_buffer)
|
72
|
+
Api.del_fvec(@out_fvec)
|
73
73
|
|
74
|
-
|
74
|
+
break
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
75
78
|
end
|
data/lib/aubio/legacy_api.rb
CHANGED
@@ -1,72 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ffi'
|
2
4
|
|
3
5
|
module Aubio
|
4
6
|
module LegacyApi #:nodoc
|
5
7
|
extend FFI::Library
|
6
8
|
# idea inspired by https://github.com/qoobaa/magic/blob/master/lib/magic/api.rb
|
7
|
-
lib_paths = Array(ENV[
|
8
|
-
fallback_names = %w
|
9
|
+
lib_paths = Array(ENV['AUBIO_LIB'] || Dir['/{opt,usr}/{,local/}{lib,lib64,Cellar/aubio**,lib/arm-linux-gnueabihf}/libaubio.{*.dylib,so.*}'])
|
10
|
+
fallback_names = %w[libaubio.4.2.2.dylib libaubio.so.1 aubio1.dll]
|
9
11
|
ffi_lib(lib_paths + fallback_names)
|
10
12
|
|
11
13
|
# tempo
|
12
|
-
attach_function :new_aubio_tempo, [
|
13
|
-
attach_function :aubio_tempo_do, [
|
14
|
+
attach_function :new_aubio_tempo, %i[string int int int], :pointer
|
15
|
+
attach_function :aubio_tempo_do, %i[pointer pointer pointer], :void
|
14
16
|
attach_function :aubio_tempo_get_last, [:pointer], :int
|
15
17
|
attach_function :aubio_tempo_get_last_s, [:pointer], :float
|
16
18
|
attach_function :aubio_tempo_get_last_ms, [:pointer], :float
|
17
|
-
attach_function :aubio_tempo_set_silence, [
|
19
|
+
attach_function :aubio_tempo_set_silence, %i[pointer float], :int
|
18
20
|
attach_function :aubio_tempo_get_silence, [:pointer], :float
|
19
|
-
attach_function :aubio_tempo_set_threshold, [
|
21
|
+
attach_function :aubio_tempo_set_threshold, %i[pointer float], :int
|
20
22
|
attach_function :aubio_tempo_get_threshold, [:pointer], :float
|
21
23
|
attach_function :aubio_tempo_get_bpm, [:pointer], :float
|
22
24
|
attach_function :aubio_tempo_get_confidence, [:pointer], :float
|
23
25
|
attach_function :del_aubio_tempo, [:pointer], :void
|
24
26
|
|
25
27
|
# beattracking / misc
|
26
|
-
attach_function :new_aubio_beattracking, [
|
27
|
-
attach_function :aubio_beattracking_do, [
|
28
|
+
attach_function :new_aubio_beattracking, %i[int int int], :pointer
|
29
|
+
attach_function :aubio_beattracking_do, %i[pointer pointer pointer], :void
|
28
30
|
attach_function :aubio_beattracking_get_bpm, [:pointer], :float
|
29
|
-
attach_function :aubio_filter_do, [
|
31
|
+
attach_function :aubio_filter_do, %i[pointer pointer], :void
|
30
32
|
attach_function :new_aubio_filter_a_weighting, [:int], :pointer
|
31
33
|
|
32
34
|
# source
|
33
|
-
attach_function :new_aubio_source, [
|
34
|
-
attach_function :aubio_source_do, [
|
35
|
-
attach_function :aubio_source_do_multi, [
|
35
|
+
attach_function :new_aubio_source, %i[string int int], :pointer
|
36
|
+
attach_function :aubio_source_do, %i[pointer pointer pointer], :void
|
37
|
+
attach_function :aubio_source_do_multi, %i[pointer pointer pointer], :void
|
36
38
|
attach_function :aubio_source_get_samplerate, [:pointer], :int
|
37
39
|
attach_function :aubio_source_get_channels, [:pointer], :int
|
38
|
-
attach_function :aubio_source_seek, [
|
40
|
+
attach_function :aubio_source_seek, %i[pointer int], :int
|
39
41
|
attach_function :aubio_source_close, [:pointer], :int
|
40
42
|
attach_function :del_aubio_source, [:pointer], :void
|
41
43
|
|
42
44
|
# sink
|
43
|
-
attach_function :new_aubio_sink, [
|
44
|
-
attach_function :aubio_sink_preset_samplerate, [
|
45
|
-
attach_function :aubio_sink_preset_channels, [
|
45
|
+
attach_function :new_aubio_sink, %i[string int], :pointer
|
46
|
+
attach_function :aubio_sink_preset_samplerate, %i[pointer int], :void
|
47
|
+
attach_function :aubio_sink_preset_channels, %i[pointer int], :void
|
46
48
|
attach_function :aubio_sink_get_samplerate, [:pointer], :int
|
47
49
|
attach_function :aubio_sink_get_channels, [:pointer], :int
|
48
|
-
attach_function :aubio_sink_do, [
|
49
|
-
attach_function :aubio_sink_do_multi, [
|
50
|
+
attach_function :aubio_sink_do, %i[pointer pointer int], :void
|
51
|
+
attach_function :aubio_sink_do_multi, %i[pointer pointer int], :void
|
50
52
|
attach_function :aubio_sink_close, [:pointer], :int
|
51
53
|
attach_function :del_aubio_sink, [:pointer], :void
|
52
54
|
|
53
55
|
# onset
|
54
|
-
attach_function :new_aubio_onset, [
|
55
|
-
attach_function :aubio_onset_do, [
|
56
|
+
attach_function :new_aubio_onset, %i[string int int int], :pointer
|
57
|
+
attach_function :aubio_onset_do, %i[pointer pointer pointer], :void
|
56
58
|
attach_function :aubio_onset_get_last, [:pointer], :int
|
57
59
|
attach_function :aubio_onset_get_last_s, [:pointer], :float
|
58
60
|
attach_function :aubio_onset_get_last_ms, [:pointer], :float
|
59
|
-
attach_function :aubio_onset_set_silence, [
|
61
|
+
attach_function :aubio_onset_set_silence, %i[pointer float], :int
|
60
62
|
attach_function :aubio_onset_get_silence, [:pointer], :float
|
61
63
|
attach_function :aubio_onset_get_descriptor, [:pointer], :float
|
62
64
|
attach_function :aubio_onset_get_thresholded_descriptor, [:pointer], :float
|
63
|
-
attach_function :aubio_onset_set_threshold, [
|
64
|
-
attach_function :aubio_onset_set_minioi, [
|
65
|
-
attach_function :aubio_onset_set_minioi_s, [
|
66
|
-
attach_function :aubio_onset_set_minioi_ms, [
|
67
|
-
attach_function :aubio_onset_set_delay, [
|
68
|
-
attach_function :aubio_onset_set_delay_s, [
|
69
|
-
attach_function :aubio_onset_set_delay_ms, [
|
65
|
+
attach_function :aubio_onset_set_threshold, %i[pointer float], :int
|
66
|
+
attach_function :aubio_onset_set_minioi, %i[pointer int], :int
|
67
|
+
attach_function :aubio_onset_set_minioi_s, %i[pointer int], :int
|
68
|
+
attach_function :aubio_onset_set_minioi_ms, %i[pointer float], :int
|
69
|
+
attach_function :aubio_onset_set_delay, %i[pointer int], :int
|
70
|
+
attach_function :aubio_onset_set_delay_s, %i[pointer int], :int
|
71
|
+
attach_function :aubio_onset_set_delay_ms, %i[pointer float], :int
|
70
72
|
attach_function :aubio_onset_get_minioi, [:pointer], :int
|
71
73
|
attach_function :aubio_onset_get_minioi_s, [:pointer], :float
|
72
74
|
attach_function :aubio_onset_get_minioi_ms, [:pointer], :float
|
@@ -77,11 +79,11 @@ module Aubio
|
|
77
79
|
attach_function :del_aubio_onset, [:pointer], :void
|
78
80
|
|
79
81
|
# pitch
|
80
|
-
attach_function :new_aubio_pitch, [
|
81
|
-
attach_function :aubio_pitch_do, [
|
82
|
-
attach_function :aubio_pitch_set_tolerance, [
|
83
|
-
attach_function :aubio_pitch_set_unit, [
|
84
|
-
attach_function :aubio_pitch_set_silence, [
|
82
|
+
attach_function :new_aubio_pitch, %i[string int int int], :pointer
|
83
|
+
attach_function :aubio_pitch_do, %i[pointer pointer pointer], :void
|
84
|
+
attach_function :aubio_pitch_set_tolerance, %i[pointer int], :int
|
85
|
+
attach_function :aubio_pitch_set_unit, %i[pointer string], :int
|
86
|
+
attach_function :aubio_pitch_set_silence, %i[pointer float], :int
|
85
87
|
attach_function :aubio_pitch_get_silence, [:pointer], :float
|
86
88
|
attach_function :aubio_pitch_get_confidence, [:pointer], :float
|
87
89
|
attach_function :del_aubio_pitch, [:pointer], :void
|
@@ -89,16 +91,15 @@ module Aubio
|
|
89
91
|
# new fvec
|
90
92
|
attach_function :new_fvec, [:int], :pointer
|
91
93
|
attach_function :del_fvec, [:pointer], :void
|
92
|
-
attach_function :fvec_get_sample, [
|
93
|
-
attach_function :fvec_set_sample, [
|
94
|
+
attach_function :fvec_get_sample, %i[pointer int], :float
|
95
|
+
attach_function :fvec_set_sample, %i[pointer float int], :void
|
94
96
|
attach_function :fvec_get_data, [:pointer], :float
|
95
97
|
attach_function :fvec_print, [:pointer], :void
|
96
|
-
attach_function :fvec_set_all, [
|
98
|
+
attach_function :fvec_set_all, %i[pointer float], :void
|
97
99
|
attach_function :fvec_zeros, [:pointer], :void
|
98
100
|
attach_function :fvec_rev, [:pointer], :void
|
99
|
-
attach_function :fvec_weight, [
|
100
|
-
attach_function :fvec_copy, [
|
101
|
+
attach_function :fvec_weight, %i[pointer pointer], :void
|
102
|
+
attach_function :fvec_copy, %i[pointer pointer], :void
|
101
103
|
attach_function :fvec_ones, [:pointer], :void
|
102
|
-
|
103
104
|
end
|
104
105
|
end
|
data/lib/aubio/onsets.rb
CHANGED
@@ -1,73 +1,73 @@
|
|
1
|
-
|
2
|
-
class Onsets
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
module Aubio
|
4
|
+
class Onsets
|
5
|
+
def initialize(aubio_source, params)
|
5
6
|
# TODO: cleanup param dups
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
@sample_rate = params[:sample_rate] || 44_100
|
8
|
+
@window_size = params[:window_size] || 1024
|
9
|
+
@hop_size = params[:hop_size] || 512
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
@source = aubio_source
|
12
|
+
@onset = Api.new_aubio_onset('default', @window_size, @hop_size, @sample_rate)
|
13
|
+
Api.aubio_onset_set_minioi_ms(@onset, 12.0)
|
14
|
+
Api.aubio_onset_set_threshold(@onset, 0.3)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
# create output for source
|
17
|
+
@sample_buffer = Api.new_fvec(@hop_size)
|
18
|
+
# create output for pitch and beat
|
19
|
+
@out_fvec = Api.new_fvec(1)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def each
|
23
|
+
return enum_for(:each) unless block_given?
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
total_frames_counter = 0
|
26
|
+
read_buffer = FFI::MemoryPointer.new(:int)
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
loop do
|
29
|
+
# Perform onset calculation
|
29
30
|
Api.aubio_source_do(@source, @sample_buffer, read_buffer)
|
30
|
-
|
31
|
+
Api.aubio_onset_do(@onset, @sample_buffer, @out_fvec)
|
31
32
|
|
32
33
|
# Retrieve result
|
33
|
-
|
34
|
+
onset_new_peak = Api.fvec_get_sample(@out_fvec, 0)
|
34
35
|
no_of_bytes_read = read_buffer.read_int
|
35
36
|
total_frames_counter += no_of_bytes_read
|
36
37
|
|
37
38
|
if onset_new_peak > 0.0
|
38
|
-
|
39
|
-
|
40
|
-
output = {
|
41
|
-
:s => onset_seconds,
|
42
|
-
:ms => onset_milliseconds,
|
43
|
-
:start => (onset_seconds == 0.0 ? 1 : 0),
|
44
|
-
:end => 0
|
45
|
-
}
|
46
|
-
yield output
|
47
|
-
end
|
48
|
-
|
49
|
-
if no_of_bytes_read != @hop_size
|
50
|
-
# there's no more audio to look at
|
51
|
-
|
52
|
-
# Let's output one last onset to mark the end of the file
|
53
|
-
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
39
|
+
onset_seconds = Api.aubio_onset_get_last_s(@onset)
|
40
|
+
onset_milliseconds = Api.aubio_onset_get_last_ms(@onset)
|
54
41
|
output = {
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
42
|
+
s: onset_seconds,
|
43
|
+
ms: onset_milliseconds,
|
44
|
+
start: (onset_seconds == 0.0 ? 1 : 0),
|
45
|
+
end: 0
|
59
46
|
}
|
60
47
|
yield output
|
48
|
+
end
|
61
49
|
|
62
|
-
|
63
|
-
Api.del_aubio_onset(@onset)
|
64
|
-
Api.del_fvec(@sample_buffer)
|
65
|
-
Api.del_fvec(@out_fvec)
|
50
|
+
next unless no_of_bytes_read != @hop_size
|
66
51
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
52
|
+
# there's no more audio to look at
|
53
|
+
|
54
|
+
# Let's output one last onset to mark the end of the file
|
55
|
+
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
56
|
+
output = {
|
57
|
+
s: total_time,
|
58
|
+
ms: total_time / 1000.0,
|
59
|
+
start: 0,
|
60
|
+
end: 1
|
61
|
+
}
|
62
|
+
yield output
|
63
|
+
|
64
|
+
# clean up
|
65
|
+
Api.del_aubio_onset(@onset)
|
66
|
+
Api.del_fvec(@sample_buffer)
|
67
|
+
Api.del_fvec(@out_fvec)
|
71
68
|
|
72
|
-
|
69
|
+
break
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
73
|
end
|
data/lib/aubio/pitches.rb
CHANGED
@@ -1,34 +1,43 @@
|
|
1
|
-
|
2
|
-
class Pitches
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
module Aubio
|
4
|
+
class Pitches
|
5
|
+
def initialize(aubio_source, params)
|
5
6
|
# TODO: cleanup param dups
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
7
|
+
@sample_rate = params[:sample_rate] || 44_100
|
8
|
+
@window_size = params[:window_size] || 1024
|
9
|
+
@hop_size = params[:hop_size] || 512
|
10
|
+
|
11
|
+
# Set the tolerance for the pitch detection algorithm.
|
12
|
+
# Typical values range between 0.2 and 0.9.
|
13
|
+
# Pitch candidates found with a confidence less than this threshold will not be selected.
|
14
|
+
# The higher the threshold, the more confidence in the candidates.
|
15
|
+
@confidence_thresh = params[:confidence_thresh] || 0.9
|
16
|
+
|
17
|
+
@pitch_method = params[:pitch_method] || 'yinfast'
|
18
|
+
|
19
|
+
@source = aubio_source
|
20
|
+
@pitch = Api.new_aubio_pitch(@pitch_method, @window_size, @hop_size, @sample_rate)
|
21
|
+
Api.aubio_pitch_set_unit(@pitch, 'midi')
|
22
|
+
Api.aubio_pitch_set_tolerance(@pitch, @confidence_thresh)
|
23
|
+
|
24
|
+
# create output for source
|
25
|
+
@sample_buffer = Api.new_fvec(@hop_size)
|
26
|
+
# create output for pitch and beat
|
27
|
+
@out_fvec = Api.new_fvec(1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def each
|
31
|
+
return enum_for(:each) unless block_given?
|
32
|
+
|
33
|
+
total_frames_counter = 0
|
34
|
+
read_buffer = FFI::MemoryPointer.new(:int)
|
26
35
|
last_pitch = 0
|
27
36
|
|
28
|
-
|
29
|
-
|
37
|
+
loop do
|
38
|
+
# Perform pitch calculation
|
30
39
|
Api.aubio_source_do(@source, @sample_buffer, read_buffer)
|
31
|
-
|
40
|
+
Api.aubio_pitch_do(@pitch, @sample_buffer, @out_fvec)
|
32
41
|
|
33
42
|
# Retrieve result
|
34
43
|
pitch = Api.fvec_get_sample(@out_fvec, 0)
|
@@ -36,40 +45,39 @@ module Aubio
|
|
36
45
|
no_of_bytes_read = read_buffer.read_int
|
37
46
|
total_frames_counter += no_of_bytes_read
|
38
47
|
|
39
|
-
if (last_pitch - pitch).abs >= 1
|
40
|
-
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
|
48
|
+
if ((last_pitch - pitch).abs >= 1) && (confidence > @confidence_thresh)
|
49
|
+
output = {
|
50
|
+
pitch: pitch,
|
51
|
+
confidence: confidence,
|
52
|
+
start: (total_frames_counter == 0 ? 1 : 0),
|
53
|
+
end: 0
|
54
|
+
}
|
46
55
|
yield output
|
47
|
-
|
56
|
+
end
|
48
57
|
|
49
58
|
last_pitch = pitch
|
50
59
|
|
51
|
-
|
52
|
-
# there's no more audio to look at
|
60
|
+
next unless no_of_bytes_read != @hop_size
|
53
61
|
|
54
|
-
|
55
|
-
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
56
|
-
output = {
|
57
|
-
:pitch => pitch,
|
58
|
-
:confidence => confidence,
|
59
|
-
:start => 0,
|
60
|
-
:end => 1
|
61
|
-
}
|
62
|
-
yield output
|
62
|
+
# there's no more audio to look at
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
# Let's output one last pitch to mark the end of the file
|
65
|
+
total_time = total_frames_counter.to_f / @sample_rate.to_f
|
66
|
+
output = {
|
67
|
+
pitch: pitch,
|
68
|
+
confidence: confidence,
|
69
|
+
start: 0,
|
70
|
+
end: 1
|
71
|
+
}
|
72
|
+
yield output
|
68
73
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
# clean up
|
75
|
+
Api.del_aubio_pitch(@pitch)
|
76
|
+
Api.del_fvec(@sample_buffer)
|
77
|
+
Api.del_fvec(@out_fvec)
|
73
78
|
|
74
|
-
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
75
83
|
end
|