autoeq_loader 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +9 -0
- data/autoeq-loader.gemspec +21 -0
- data/examples/readme.rb +16 -0
- data/examples/show-all.rb +9 -0
- data/lib/autoeq_loader.rb +63 -0
- data/test/autoeq_test.rb +47 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 346a6e9bed32516e67ec52fd7123d6023548e11dbe4bbbfc9295e07b227766c1
|
4
|
+
data.tar.gz: a5339c5c4445c26093c7ad78e1204dffe8688bcc84552d6bcc0ced67bbf2e5f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60f4c8c38347d0f1155fed40cfbe03fe2a09c51d4a4564b074e82550075b00981658cdb0f8bb76fa1e3f63ddf7ebb200ee5c2aee07c8ca1e381dae7e820e3a6a
|
7
|
+
data.tar.gz: b45151fa222fc2892aac9afa4eaaf47304bb3da09fbd5251d41e737e3abfcbf4202cb58727a2de26cf06433d769890a2fc45dfb3374a7bc6e63a2a74d118c69f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 John Labovitz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# AutoEQ::Loader
|
2
|
+
|
3
|
+
This is a Ruby gem that works with the collection of headphone equalizations generated by the [AutoEQ](https://autoeq.app) project. With the gem, you can load the full set of equalizations, find one or more equalizations by name, and generate **audio filter** strings. These strings can then be used with projects like [MPV](https://mpv.io), [FFmpeg](https://ffmpeg.org), or other projects that use [libavfilter](https://ffmpeg.org/libavfilter.html) to process audio. Canonical information about filters can be found at [FFmpeg Filters Documentation](https://ffmpeg.org/ffmpeg-filters.html).
|
4
|
+
|
5
|
+
You will need to have AutoEQ's `results` directory stored somewhere on your system. You can get it by cloning the [AutoEQ Git repository](https://github.com/jaakkopasanen/AutoEq) or by downloading one of the [releases](https://github.com/jaakkopasanen/AutoEq/tags). Then you will find the `results` directory in the top level. Consult the [README file](https://github.com/jaakkopasanen/AutoEq/blob/master/results/README.md) there for details on the results.
|
6
|
+
|
7
|
+
This gem uses the `ParametricEQ.txt` files from the `results` directory, each of which contain:
|
8
|
+
|
9
|
+
- A relative volume (aka 'preamp') to adjust the audio, to compensate for equalizations that effectively change the overall volume.
|
10
|
+
- One or more EQ filters that describe the type, frequency, gain, and width of a particular equalization to apply.
|
11
|
+
|
12
|
+
The `load_equalizers` class method returns an array of equalizers found in the specified directory, each of which has a name derived from the filename. There's no attempt to interpret or modify the names, so it's best to consult the original files if you're unsure of the naming conventions.
|
13
|
+
|
14
|
+
An equalizer is converted to an audio filter string simply by calling its `#to_s` method, or by interpreting it a string context that will implicitly call `#to_s`. A filter string looks like this:
|
15
|
+
|
16
|
+
```
|
17
|
+
volume=-3.8dB,equalizer=f=105:g=1.4:w=0.7:t=q,equalizer=f=8313:g=2.9:w=1.52:t=q,equalizer=f=126:g=-2.0:w=0.83:t=q,equalizer=f=3198:g=3.4:w=2.66:t=q,equalizer=f=2019:g=-2.0:w=1.8:t=q,equalizer=f=10000:g=-5.2:w=0.7:t=q,equalizer=f=529:g=-1.0:w=1.59:t=q,equalizer=f=1042:g=1.1:w=2.59:t=q,equalizer=f=5337:g=-1.5:w=4.59:t=q,equalizer=f=6646:g=2.8:w=5.93:t=q
|
18
|
+
```
|
19
|
+
|
20
|
+
The actual EQ file for each equalizer is loaded lazily, only when the `#to_s` method is called.
|
21
|
+
|
22
|
+
The `#to_s` method has one optional parameter: a boolean to indicate whether the equalizer should be enabled or not. If enabled (the default), then both a volume filter and an equalizer filter is returned. If disabled, only the volume filter is returned. This is to handle cases where an equalizer may be toggled off or on, but maintain the overall volume level.
|
23
|
+
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Install the gem and add to your application's `Gemfile` by executing:
|
28
|
+
|
29
|
+
$ bundle add autoeq_loader
|
30
|
+
|
31
|
+
If Bundler is not being used to manage dependencies, install the gem by executing:
|
32
|
+
|
33
|
+
$ gem install autoeq_loader
|
34
|
+
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'autoeq_loader'
|
40
|
+
|
41
|
+
# load the equalizers
|
42
|
+
equalizers = AutoEQLoader.load_equalizers('~/src/AutoEQ/results')
|
43
|
+
|
44
|
+
# find an equalizer for the FiiO FH7 headphones
|
45
|
+
eq = equalizers.find { |e| e.name =~ /fh7/i }
|
46
|
+
|
47
|
+
# show its name
|
48
|
+
puts eq.name
|
49
|
+
|
50
|
+
# run MPV with the filter
|
51
|
+
system(
|
52
|
+
'mpv',
|
53
|
+
"--af=#{eq.to_s}",
|
54
|
+
'my-music-file.mp4')
|
55
|
+
```
|
56
|
+
|
57
|
+
See the [`examples`](examples) directory for more.
|
58
|
+
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
|
63
|
+
|
64
|
+
To release a new version, update the version number in `autoeq-loader.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jslabovitz/autoeq_loader.
|
70
|
+
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'autoeq_loader'
|
3
|
+
s.version = '0.1'
|
4
|
+
s.author = 'John Labovitz'
|
5
|
+
s.email = 'johnl@johnlabovitz.com'
|
6
|
+
|
7
|
+
s.summary = %q{Loads AutoEQ measurements and makes audio filters}
|
8
|
+
s.description = %q{AutoEQLoader loads AutoEQ measurements and makes audio filters.}
|
9
|
+
s.homepage = 'http://github.com/jslabovitz/autoeq_loader'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
|
+
s.require_path = 'lib'
|
16
|
+
|
17
|
+
s.add_development_dependency 'bundler', '~> 2.4'
|
18
|
+
s.add_development_dependency 'minitest', '~> 5.18'
|
19
|
+
s.add_development_dependency 'minitest-power_assert', '~> 0.3'
|
20
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
21
|
+
end
|
data/examples/readme.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'autoeq_loader'
|
2
|
+
|
3
|
+
# load the equalizers
|
4
|
+
equalizers = AutoEQLoader.load_equalizers('~/src/AutoEQ/results')
|
5
|
+
|
6
|
+
# find an equalizer for the FiiO FH7 headphones
|
7
|
+
eq = equalizers.find { |e| e.name =~ /fh7/i }
|
8
|
+
|
9
|
+
# show its name
|
10
|
+
puts eq.name
|
11
|
+
|
12
|
+
# run MPV with the filter
|
13
|
+
system(
|
14
|
+
'mpv',
|
15
|
+
"--af=#{eq.to_s}",
|
16
|
+
'my-music-file.mp4')
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class AutoEQLoader
|
2
|
+
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def self.load_equalizers(dir)
|
6
|
+
dir = File.expand_path(dir)
|
7
|
+
Dir.glob('**/*ParametricEQ.txt', base: dir, sort: false).map do |file|
|
8
|
+
new(File.join(dir, file))
|
9
|
+
end.sort
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(file)
|
13
|
+
@file = file
|
14
|
+
@name = File.basename(File.dirname(file))
|
15
|
+
@volume_filter = @equalizer_filters = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def load
|
19
|
+
@volume_filter = VolumeFilter.new(0.0)
|
20
|
+
@equalizer_filters = []
|
21
|
+
File.open(@file) do |io|
|
22
|
+
io.readlines.map { |l| l.sub(/#.*/, '') }.map(&:strip).reject(&:empty?).each do |line|
|
23
|
+
case line
|
24
|
+
when /^Preamp: ([-.\d]+) dB$/
|
25
|
+
@volume_filter = VolumeFilter.new($1.to_f)
|
26
|
+
when /^Filter \d+: ON .+? Fc (\d+) Hz Gain ([-.\d]+) dB Q ([-.\d]+)$/
|
27
|
+
@equalizer_filters << ParametricEqualizerFilter.new($1.to_i, $2.to_f, $3.to_f, 'q')
|
28
|
+
else
|
29
|
+
warn "#{@file}: Ignoring unknown eq line: #{line.inspect}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def <=>(other)
|
36
|
+
@name <=> other.name
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s(enabled=true)
|
40
|
+
load unless @volume_filter
|
41
|
+
[
|
42
|
+
@volume_filter,
|
43
|
+
enabled ? @equalizer_filters : nil,
|
44
|
+
].flatten.compact.map(&:to_s).join(',')
|
45
|
+
end
|
46
|
+
|
47
|
+
class VolumeFilter < Struct.new(:volume)
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"volume=#{volume}dB"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class ParametricEqualizerFilter < Struct.new(:f, :g, :w, :t)
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"equalizer=%s" % %w[f g w t].map { |k| '%s=%s' % [k, send(k)] }.join(':')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/autoeq_test.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/power_assert'
|
5
|
+
|
6
|
+
require 'autoeq_loader'
|
7
|
+
|
8
|
+
class AutoEQLoader
|
9
|
+
|
10
|
+
class Test < MiniTest::Test
|
11
|
+
|
12
|
+
SourceDir = '~/src/AutoEQ/results'
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@equalizers = AutoEQLoader.load_equalizers(SourceDir)
|
16
|
+
@eq = @equalizers.find { |e| e.name =~ /fh7/i }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_load
|
20
|
+
assert { @equalizers }
|
21
|
+
assert { !@equalizers.empty? }
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find
|
25
|
+
assert { @eq }
|
26
|
+
assert { @eq.name == 'FiiO FH7' }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_enabled
|
30
|
+
assert { @eq }
|
31
|
+
filter = @eq.to_s
|
32
|
+
assert { filter =~ /^volume=[\-\.\d+]+dB,equalizer=f/ }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_disabled
|
36
|
+
assert { @eq }
|
37
|
+
filter = @eq.to_s(false)
|
38
|
+
assert { filter =~ /^volume=[\-\.\d+]+dB$/ }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_load_all
|
42
|
+
@equalizers.map(&:load)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autoeq_loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Labovitz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.18'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-power_assert
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
description: AutoEQLoader loads AutoEQ measurements and makes audio filters.
|
70
|
+
email: johnl@johnlabovitz.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- autoeq-loader.gemspec
|
81
|
+
- examples/readme.rb
|
82
|
+
- examples/show-all.rb
|
83
|
+
- lib/autoeq_loader.rb
|
84
|
+
- test/autoeq_test.rb
|
85
|
+
homepage: http://github.com/jslabovitz/autoeq_loader
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.4.13
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Loads AutoEQ measurements and makes audio filters
|
108
|
+
test_files:
|
109
|
+
- test/autoeq_test.rb
|