aubio 0.1.0

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.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aubio"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative "aubio/version"
2
+ require_relative "aubio/api"
3
+ require_relative "aubio/onsets"
4
+
5
+ module Aubio
6
+ class Base
7
+ class FileNotFound < Exception; end
8
+
9
+ def initialize(path, params)
10
+ raise FileNotFound unless File.file?(path)
11
+
12
+ sample_rate = params[:sample_rate] || 44100
13
+ hop_size = params[:hop_size] || 512
14
+
15
+ @source = Api.new_aubio_source(path, sample_rate, hop_size)
16
+ @params = params
17
+ end
18
+
19
+ def onsets
20
+ Onsets.new(@source, @params).each
21
+ end
22
+ end
23
+ end
24
+
25
+ module Aubio
26
+ def self.open(path, params = {})
27
+ Base.new(path, params)
28
+ end
29
+ end
@@ -0,0 +1,104 @@
1
+ require 'ffi'
2
+
3
+ module Aubio
4
+ module Api #:nodoc
5
+ extend FFI::Library
6
+ # 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**}/libaubio.{*.dylib,so.*}"])
8
+ fallback_names = %w(libaubio.4.2.2.dylib libaubio.so.1 aubio1.dll)
9
+ ffi_lib(lib_paths + fallback_names)
10
+
11
+ # 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 :aubio_tempo_get_last, [:pointer], :int
15
+ attach_function :aubio_tempo_get_last_s, [:pointer], :float
16
+ attach_function :aubio_tempo_get_last_ms, [:pointer], :float
17
+ attach_function :aubio_tempo_set_silence, [:pointer, :float], :int
18
+ attach_function :aubio_tempo_get_silence, [:pointer], :float
19
+ attach_function :aubio_tempo_set_threshold, [:pointer, :float], :int
20
+ attach_function :aubio_tempo_get_threshold, [:pointer], :float
21
+ attach_function :aubio_tempo_get_bpm, [:pointer], :float
22
+ attach_function :aubio_tempo_get_confidence, [:pointer], :float
23
+ attach_function :del_aubio_tempo, [:pointer], :void
24
+
25
+ # 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 :aubio_beattracking_get_bpm, [:pointer], :float
29
+ attach_function :aubio_filter_do, [:pointer, :pointer], :void
30
+ attach_function :new_aubio_filter_a_weighting, [:int], :pointer
31
+
32
+ # 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
36
+ attach_function :aubio_source_get_samplerate, [:pointer], :int
37
+ attach_function :aubio_source_get_channels, [:pointer], :int
38
+ attach_function :aubio_source_seek, [:pointer, :int], :int
39
+ attach_function :aubio_source_close, [:pointer], :int
40
+ attach_function :del_aubio_source, [:pointer], :void
41
+
42
+ # 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
46
+ attach_function :aubio_sink_get_samplerate, [:pointer], :int
47
+ 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_close, [:pointer], :int
51
+ attach_function :del_aubio_sink, [:pointer], :void
52
+
53
+ # 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 :aubio_onset_get_last, [:pointer], :int
57
+ attach_function :aubio_onset_get_last_s, [:pointer], :float
58
+ attach_function :aubio_onset_get_last_ms, [:pointer], :float
59
+ attach_function :aubio_onset_set_silence, [:pointer, :float], :int
60
+ attach_function :aubio_onset_get_silence, [:pointer], :float
61
+ attach_function :aubio_onset_get_descriptor, [:pointer], :float
62
+ 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
70
+ attach_function :aubio_onset_get_minioi, [:pointer], :int
71
+ attach_function :aubio_onset_get_minioi_s, [:pointer], :float
72
+ attach_function :aubio_onset_get_minioi_ms, [:pointer], :float
73
+ attach_function :aubio_onset_get_delay, [:pointer], :int
74
+ attach_function :aubio_onset_get_delay_s, [:pointer], :float
75
+ attach_function :aubio_onset_get_delay_ms, [:pointer], :float
76
+ attach_function :aubio_onset_get_threshold, [:pointer], :float
77
+ attach_function :del_aubio_onset, [:pointer], :void
78
+
79
+ # 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
85
+ attach_function :aubio_pitch_get_silence, [:pointer], :float
86
+ attach_function :aubio_pitch_get_confidence, [:pointer], :float
87
+ attach_function :del_aubio_pitch, [:pointer], :void
88
+
89
+ # new fvec
90
+ attach_function :new_fvec, [:int], :pointer
91
+ 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_data, [:pointer], :float
95
+ attach_function :fvec_print, [:pointer], :void
96
+ attach_function :fvec_set_all, [:pointer, :float], :void
97
+ attach_function :fvec_zeros, [:pointer], :void
98
+ 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_ones, [:pointer], :void
102
+
103
+ end
104
+ end
@@ -0,0 +1,60 @@
1
+ module Aubio
2
+ class Onsets
3
+
4
+ def initialize(aubio_source, params)
5
+ # 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
9
+
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)
14
+
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
20
+
21
+ def each
22
+ return enum_for(:each) unless block_given?
23
+
24
+ total_frames_counter = 0
25
+ tmp_read = FFI::MemoryPointer.new(:int)
26
+
27
+ loop do
28
+ # Perform onset calculation
29
+ Api.aubio_source_do(@source, @sample_buffer, tmp_read)
30
+ Api.aubio_onset_do(@onset, @sample_buffer, @out_fvec)
31
+
32
+ # Retrieve result
33
+ onset_new_peak = Api.fvec_get_sample(@out_fvec, 0)
34
+
35
+ if onset_new_peak > 0.0
36
+ onset_seconds = Api.aubio_onset_get_last_s(@onset)
37
+ onset_milliseconds = Api.aubio_onset_get_last_ms(@onset)
38
+ # TODO: implement relative here
39
+ output = {
40
+ :s => onset_seconds,
41
+ :ms => onset_milliseconds
42
+ }
43
+ yield output
44
+ end
45
+
46
+ read = tmp_read.read_int
47
+ total_frames_counter += read
48
+ if(read != @hop_size) then
49
+ # clean up
50
+ Api.del_aubio_source(@source)
51
+ Api.del_fvec(@sample_buffer)
52
+ Api.del_fvec(@out_fvec)
53
+
54
+ break
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Aubio
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aubio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xavier Riley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: Aubio is a tool designed for the extraction of annotations from audio
70
+ signals. Its features include segmenting a sound file before each of its attacks,
71
+ performing pitch detection, tapping the beat and producing midi streams from live
72
+ audio.
73
+ email:
74
+ - xavriley@hotmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - aubio.gemspec
87
+ - aubio.rb
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/aubio.rb
91
+ - lib/aubio/api.rb
92
+ - lib/aubio/onsets.rb
93
+ - lib/aubio/version.rb
94
+ homepage: https://github.com/xavriley/ruby-aubio
95
+ licenses:
96
+ - GNU GPL v3.0
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby bindings for the aubio audio library
118
+ test_files: []
119
+ has_rdoc: