aubio 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aubio
2
4
  class Beats
3
-
4
5
  def initialize(aubio_source, params)
5
6
  # TODO: cleanup param dups
6
- @sample_rate = params[:sample_rate] || 44100
7
+ @sample_rate = params[:sample_rate] || 44_100
7
8
  @window_size = params[:window_size] || 1024
8
9
  @hop_size = params[:hop_size] || 512
9
10
 
@@ -40,39 +41,38 @@ module Aubio
40
41
  tempo_confidence = Api.aubio_tempo_get_confidence(@tempo)
41
42
 
42
43
  output = {
43
- :confidence => tempo_confidence,
44
- :s => tempo_seconds,
45
- :ms => tempo_milliseconds,
46
- :sample_no => tempo_samples,
47
- :total_samples => total_samples,
48
- :rel_start => tempo_samples/total_samples
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
49
50
  }
50
51
  yield output
51
52
  end
52
53
 
53
- if no_of_bytes_read != @hop_size
54
- # there's no more audio to look at
54
+ next unless no_of_bytes_read != @hop_size
55
55
 
56
- # Let's output one last tempo to mark the end of the file
57
- total_time = total_frames_counter.to_f / @sample_rate.to_f
58
- output = {
59
- :confidence => 1.0,
60
- :s => total_time,
61
- :ms => total_time/1000.0,
62
- :sample_no => total_samples,
63
- :total_samples => total_samples
64
- }
65
- yield output
56
+ # there's no more audio to look at
66
57
 
67
- # clean up
68
- Api.del_aubio_tempo(@tempo)
69
- Api.del_fvec(@sample_buffer)
70
- Api.del_fvec(@out_fvec)
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
71
68
 
72
- break
73
- end
69
+ # clean up
70
+ Api.del_aubio_tempo(@tempo)
71
+ Api.del_fvec(@sample_buffer)
72
+ Api.del_fvec(@out_fvec)
73
+
74
+ break
74
75
  end
75
76
  end
76
-
77
77
  end
78
78
  end
@@ -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["AUBIO_LIB"] || Dir["/{opt,usr}/{,local/}{lib,lib64,Cellar/aubio**,lib/arm-linux-gnueabihf}/libaubio.{*.dylib,so.*}"])
8
- fallback_names = %w(libaubio.4.2.2.dylib libaubio.so.1 aubio1.dll)
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, [ :string, :int, :int, :int ], :pointer
13
- attach_function :aubio_tempo_do, [:pointer, :pointer, :pointer], :void
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, [:pointer, :float], :int
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, [:pointer, :float], :int
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, [:int, :int, :int], :pointer
27
- attach_function :aubio_beattracking_do, [:pointer, :pointer, :pointer], :void
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, [:pointer, :pointer], :void
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, [:string, :int, :int], :pointer
34
- attach_function :aubio_source_do, [:pointer, :pointer, :pointer], :void
35
- attach_function :aubio_source_do_multi, [:pointer, :pointer, :pointer], :void
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, [:pointer, :int], :int
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, [:string, :int], :pointer
44
- attach_function :aubio_sink_preset_samplerate, [:pointer, :int], :void
45
- attach_function :aubio_sink_preset_channels, [:pointer, :int], :void
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, [:pointer, :pointer, :int], :void
49
- attach_function :aubio_sink_do_multi, [:pointer, :pointer, :int], :void
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, [:string, :int, :int, :int], :pointer
55
- attach_function :aubio_onset_do, [:pointer, :pointer, :pointer], :void
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, [:pointer, :float], :int
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, [:pointer, :float], :int
64
- attach_function :aubio_onset_set_minioi, [:pointer, :int], :int
65
- attach_function :aubio_onset_set_minioi_s, [:pointer, :int], :int
66
- attach_function :aubio_onset_set_minioi_ms, [:pointer, :float], :int
67
- attach_function :aubio_onset_set_delay, [:pointer, :int], :int
68
- attach_function :aubio_onset_set_delay_s, [:pointer, :int], :int
69
- attach_function :aubio_onset_set_delay_ms, [:pointer, :float], :int
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, [:string, :int, :int, :int], :pointer
81
- attach_function :aubio_pitch_do, [:pointer, :pointer, :pointer], :void
82
- attach_function :aubio_pitch_set_tolerance, [:pointer, :int], :int
83
- attach_function :aubio_pitch_set_unit, [:pointer, :string], :int
84
- attach_function :aubio_pitch_set_silence, [:pointer, :float], :int
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, [:pointer, :int], :float
93
- attach_function :fvec_set_sample, [:pointer, :float, :int], :void
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, [:pointer, :float], :void
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, [:pointer, :pointer], :void
100
- attach_function :fvec_copy, [:pointer, :pointer], :void
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
@@ -1,73 +1,73 @@
1
- module Aubio
2
- class Onsets
1
+ # frozen_string_literal: true
3
2
 
4
- def initialize(aubio_source, params)
3
+ module Aubio
4
+ class Onsets
5
+ def initialize(aubio_source, params)
5
6
  # TODO: cleanup param dups
6
- @sample_rate = params[:sample_rate] || 44100
7
- @window_size = params[:window_size] || 1024
8
- @hop_size = params[:hop_size] || 512
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
- @source = aubio_source
11
- @onset = Api.new_aubio_onset('default', @window_size, @hop_size, @sample_rate)
12
- Api.aubio_onset_set_minioi_ms(@onset, 12.0)
13
- Api.aubio_onset_set_threshold(@onset, 0.3)
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
- # create output for source
16
- @sample_buffer = Api.new_fvec(@hop_size)
17
- # create output for pitch and beat
18
- @out_fvec = Api.new_fvec(1)
19
- end
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
- def each
22
- return enum_for(:each) unless block_given?
22
+ def each
23
+ return enum_for(:each) unless block_given?
23
24
 
24
- total_frames_counter = 0
25
- read_buffer = FFI::MemoryPointer.new(:int)
25
+ total_frames_counter = 0
26
+ read_buffer = FFI::MemoryPointer.new(:int)
26
27
 
27
- loop do
28
- # Perform onset calculation
28
+ loop do
29
+ # Perform onset calculation
29
30
  Api.aubio_source_do(@source, @sample_buffer, read_buffer)
30
- Api.aubio_onset_do(@onset, @sample_buffer, @out_fvec)
31
+ Api.aubio_onset_do(@onset, @sample_buffer, @out_fvec)
31
32
 
32
33
  # Retrieve result
33
- onset_new_peak = Api.fvec_get_sample(@out_fvec, 0)
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
- onset_seconds = Api.aubio_onset_get_last_s(@onset)
39
- onset_milliseconds = Api.aubio_onset_get_last_ms(@onset)
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
- :s => total_time,
56
- :ms => total_time/1000.0,
57
- :start => 0,
58
- :end => 1
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
- # clean up
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
- break
68
- end
69
- end
70
- end
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
- end
69
+ break
70
+ end
71
+ end
72
+ end
73
73
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aubio
2
4
  class Pitches
3
-
4
5
  def initialize(aubio_source, params)
5
6
  # TODO: cleanup param dups
6
- @sample_rate = params[:sample_rate] || 44100
7
+ @sample_rate = params[:sample_rate] || 44_100
7
8
  @window_size = params[:window_size] || 1024
8
9
  @hop_size = params[:hop_size] || 512
9
10
 
@@ -11,9 +12,9 @@ module Aubio
11
12
  # Typical values range between 0.2 and 0.9.
12
13
  # Pitch candidates found with a confidence less than this threshold will not be selected.
13
14
  # The higher the threshold, the more confidence in the candidates.
14
- @confidence_thresh = params[:confidence_thresh] || 0.9
15
+ @confidence_thresh = params[:confidence_thresh] || 0.9
15
16
 
16
- @pitch_method = params[:pitch_method] || "yinfast"
17
+ @pitch_method = params[:pitch_method] || 'yinfast'
17
18
 
18
19
  @source = aubio_source
19
20
  @pitch = Api.new_aubio_pitch(@pitch_method, @window_size, @hop_size, @sample_rate)
@@ -44,40 +45,39 @@ module Aubio
44
45
  no_of_bytes_read = read_buffer.read_int
45
46
  total_frames_counter += no_of_bytes_read
46
47
 
47
- if (last_pitch - pitch).abs >= 1 and confidence > @confidence_thresh
48
+ if ((last_pitch - pitch).abs >= 1) && (confidence > @confidence_thresh)
48
49
  output = {
49
- :pitch => pitch,
50
- :confidence => confidence,
51
- :start => (total_frames_counter == 0 ? 1 : 0),
52
- :end => 0
50
+ pitch: pitch,
51
+ confidence: confidence,
52
+ start: (total_frames_counter == 0 ? 1 : 0),
53
+ end: 0
53
54
  }
54
55
  yield output
55
56
  end
56
57
 
57
58
  last_pitch = pitch
58
59
 
59
- if no_of_bytes_read != @hop_size
60
- # there's no more audio to look at
60
+ next unless no_of_bytes_read != @hop_size
61
61
 
62
- # Let's output one last pitch to mark the end of the file
63
- total_time = total_frames_counter.to_f / @sample_rate.to_f
64
- output = {
65
- :pitch => pitch,
66
- :confidence => confidence,
67
- :start => 0,
68
- :end => 1
69
- }
70
- yield output
62
+ # there's no more audio to look at
71
63
 
72
- # clean up
73
- Api.del_aubio_pitch(@pitch)
74
- Api.del_fvec(@sample_buffer)
75
- Api.del_fvec(@out_fvec)
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
76
73
 
77
- break
78
- end
74
+ # clean up
75
+ Api.del_aubio_pitch(@pitch)
76
+ Api.del_fvec(@sample_buffer)
77
+ Api.del_fvec(@out_fvec)
78
+
79
+ break
79
80
  end
80
81
  end
81
-
82
82
  end
83
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aubio
2
- VERSION = "0.3.3"
4
+ VERSION = '0.3.4'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aubio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Riley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -42,16 +42,30 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
46
53
  - !ruby/object:Gem::Version
47
- version: '10.0'
54
+ version: 12.3.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: ffi_gen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: ffi_gen
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -142,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
156
  - !ruby/object:Gem::Version
143
157
  version: '0'
144
158
  requirements: []
145
- rubygems_version: 3.0.3
159
+ rubygems_version: 3.1.2
146
160
  signing_key:
147
161
  specification_version: 4
148
162
  summary: Ruby bindings for the aubio audio library