ebur128_stream 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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/LICENSE-APACHE +201 -0
- data/LICENSE-MIT +21 -0
- data/README.md +256 -0
- data/Rakefile +31 -0
- data/ebur128_stream.gemspec +50 -0
- data/ext/ebur128_stream/Cargo.lock +359 -0
- data/ext/ebur128_stream/Cargo.toml +21 -0
- data/ext/ebur128_stream/build.rs +5 -0
- data/ext/ebur128_stream/src/analyzer.rs +159 -0
- data/ext/ebur128_stream/src/error.rs +57 -0
- data/ext/ebur128_stream/src/lib.rs +123 -0
- data/ext/ebur128_stream/src/normalize.rs +121 -0
- data/ext/ebur128_stream/src/report.rs +52 -0
- data/ext/ebur128_stream/src/samples.rs +209 -0
- data/ext/ebur128_stream/src/snapshot.rs +49 -0
- data/lib/ebur128_stream/version.rb +5 -0
- data/lib/ebur128_stream.rb +68 -0
- data/sample/analyze-microphone.rb +110 -0
- data/sample/analyze-planar-data.rb +38 -0
- data/sample/analyze-wavefile.rb +77 -0
- data/sample/normalize.rb +35 -0
- data/sig/ebur128_stream.rbs +69 -0
- data/test/helper.rb +18 -0
- data/test/test_analizer.rb +114 -0
- data/test/test_ebur128_stream.rb +13 -0
- data/test/test_normalize_report.rb +35 -0
- data/test/test_normalizer.rb +49 -0
- data/test/test_report.rb +34 -0
- data/test/test_snapshot.rb +36 -0
- metadata +177 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5e663b52995c5192e4b47a4145aee4e3dfda21b672535936ec2d656222fd53a5
|
|
4
|
+
data.tar.gz: f4e93dc095c81083b82d5addcbced0ce3639978a729f3f0850ab611ae5b65ffd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0e9cef3cd6887b4ce0ac16cbf7f7dea6be2ad9a8e0e48680cb8479b511b042227a96f07b7a309e8678469a69c274a8b74a7a4e776f64d0ba63fbb6d8e06b9bea
|
|
7
|
+
data.tar.gz: f6437a5df89c7877cfc24c59c4a30d384c6c41cb2dedf72a5e06735f994897da10c4602d8cd3f32fdc37ec37f1276775561dce2212cace8bf5bfec49de748902
|
data/.gitignore
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/_yardoc/
|
|
4
|
+
/coverage/
|
|
5
|
+
/doc/
|
|
6
|
+
/pkg/
|
|
7
|
+
/html/
|
|
8
|
+
/spec/reports/
|
|
9
|
+
/tmp/
|
|
10
|
+
*.bundle
|
|
11
|
+
*.so
|
|
12
|
+
*.o
|
|
13
|
+
*.a
|
|
14
|
+
mkmf.log
|
|
15
|
+
target/
|
|
16
|
+
Gemfile.lock
|
|
17
|
+
/vendor/bundle/
|
|
18
|
+
ext/ebur128_stream/.rustc_info.json
|
|
19
|
+
ext/ebur128_stream/release/
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Vanja Modrinjak
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vanja Modrinjak
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# EBUR128Stream
|
|
2
|
+
|
|
3
|
+
A Ruby binding for [ebur128-stream][rust-impl], a streaming, zero-allocation EBU R128 loudness measurement in pure Rust.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bundle add ebur128_stream
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install ebur128_stream
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "ebur128_stream"
|
|
23
|
+
|
|
24
|
+
include EBUR128Stream
|
|
25
|
+
|
|
26
|
+
analyzer = Analyzer.new(
|
|
27
|
+
channels: [:left, :right],
|
|
28
|
+
sample_rate: 48_000,
|
|
29
|
+
modes: [:integrated, :true_peak]
|
|
30
|
+
)
|
|
31
|
+
analyzer.push_interleaved samples
|
|
32
|
+
|
|
33
|
+
report = analyzer.finalize
|
|
34
|
+
report.integrated_lufs # => -8.030723453035735
|
|
35
|
+
report.true_peak_dbtp # => 20.01377283514713
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
EBUR128Stream provides two main classes:
|
|
39
|
+
|
|
40
|
+
* [Analyzer](#analyzer) analyzes audio data and reports loudness.
|
|
41
|
+
* [Normalizer](#normalizer) analyzes audio data and applies the calibrated gain.
|
|
42
|
+
|
|
43
|
+
<a name="analyzer"></a>
|
|
44
|
+
### Analyzer
|
|
45
|
+
|
|
46
|
+
EBUR128Stream::Analyzer is a streaming EBU R128 loudness analyzer. It reads audio data and reports statistics such as integrated LUFS, dBTP.
|
|
47
|
+
|
|
48
|
+
It provides a streaming API, which means you can push chunks of audio data incrementally and get the current status (EBUR128Stream::Snapshot) and the final report (EBUR128Stream::Report).
|
|
49
|
+
|
|
50
|
+
### Initialization
|
|
51
|
+
|
|
52
|
+
First, initialize EBUR128Stream::Analyzer:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
analyzer = EBUR128Stream::Analyzer.new(
|
|
56
|
+
# Required. Supports :left, :right, :center, :left_surround, :right_surround, :lfe, :other.
|
|
57
|
+
channels: [:left, :right],
|
|
58
|
+
|
|
59
|
+
# Optional. Must be one of 22_050, 32_000, 44_100, 48_000, 88_200, 96_000, 192_000. Defaults to 48_000.
|
|
60
|
+
sample_rate: 48_000,
|
|
61
|
+
|
|
62
|
+
# Optional. Supports :integrated, :momentary, :short_term, :true_peak, :lra, :all. Defaults to [:all].
|
|
63
|
+
modes: [:all],
|
|
64
|
+
|
|
65
|
+
# Optional. Hint at audio length in seconds so that buffer is allocated first.
|
|
66
|
+
expected_duration: 60
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
See [Rust documentation](https://docs.rs/ebur128-stream/latest/ebur128_stream/struct.AnalyzerBuilder.html) for details on arguments.
|
|
71
|
+
|
|
72
|
+
### Pushing samples
|
|
73
|
+
|
|
74
|
+
Then, push audio samples to EBUR128Stream::Analyzer#push_interleaved or EBUR128Stream::Analyzer#push_planar as you get them:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
while samples = get_samples
|
|
78
|
+
analyzer.push_interleaved(samples)
|
|
79
|
+
# Or, analyzer.push_planar samples
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Interleaved samples looks like this:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
[L1, R1, L2, R2, L3, R3, ...]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
(*Note* that it's not a 2-D array (`[[L1, R1], [L2, R2], ...]`) but a flat array.)
|
|
90
|
+
|
|
91
|
+
Planar samples looks like this:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
[[L1, L2, L3, ...], [R1, R2, R3, ...]]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
In addition to 1-D or 2-D `Array`s, EBUR128Stream::Analyzer#push_interleaved and EBUR128Stream::Analyzer#push_planar accept MemoryView producers such as:
|
|
98
|
+
|
|
99
|
+
* `Gst::Sample` from [GStreamer][] gem
|
|
100
|
+
* `Torch::Tensor` from [TorchAudio][] or [TorchCodec][] gem (w/ [NDAV::TorchTensor][])
|
|
101
|
+
* `Numo::NArray` from [Numo::NArray][] or [Numo::NArray Alternative][] gem when generating and processing audio data with it (w/ [NDAV::Numo::NArray][])
|
|
102
|
+
|
|
103
|
+
TorchAudio example here:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
samples, sample_rate = TorchAudio.load("path/to/audio")
|
|
107
|
+
analyzer.push_planar(samples)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Snapshots
|
|
111
|
+
|
|
112
|
+
At any point during streaming, you can get the current statistics (EBUR128Stream::Snapshot) by calling EBUR128Stream::Analyzer#snapshot:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
snapshot = analyzer.snapshot
|
|
116
|
+
|
|
117
|
+
snapshot.programme_duration_seconds #=> Current duration
|
|
118
|
+
snapshot.momentary_lufs #=> Loudness sliding 400ms window in LUFS
|
|
119
|
+
snapshot.short_term_lufs #=> Loudness sliding 3s window in LUFS
|
|
120
|
+
snapshot.integrated_lufs #=> Loudness so far in LUFS
|
|
121
|
+
snapshot.true_peak_dbtp #=> True peak so far in dBTP
|
|
122
|
+
snapshot.loudness_range_lu #=> Loudness range in LU
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The attributes may be `nil` when there are not enough samples or when the corresponding mode was not specified at initialization.
|
|
126
|
+
|
|
127
|
+
EBUR128Stream::Snapshot implements `#to_h`:
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
snapshot.to_h #=> {momentary_lufs: ..., short_term_lufs: ..., ...}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Also, `#deconstruct_keys` is implemented:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
snapshot.deconstruct_keys(nil) #=> {momentary_lufs: ..., short_term_lufs: ..., ...}
|
|
137
|
+
|
|
138
|
+
case analyzer.snapshot
|
|
139
|
+
in EBUR128Stream::Snapshot[true_peak_dbtp: 1.0..] => snapshot
|
|
140
|
+
$stderr.puts "High true peak found at #{snapshot.programme_duration_seconds}s: #{snapshot.true_peak_dbtp} dBTP"
|
|
141
|
+
else
|
|
142
|
+
# noop
|
|
143
|
+
end
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Finalization
|
|
147
|
+
|
|
148
|
+
Finally, call EBUR128Stream::Analyzer#finalize to complete the analysis and get the report:
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
report = analyzer.finalize
|
|
152
|
+
|
|
153
|
+
report.programme_duration_seconds #=> Total duration in seconds
|
|
154
|
+
report.integrated_lufs
|
|
155
|
+
report.loudness_range_lu
|
|
156
|
+
report.true_peak_dbtp
|
|
157
|
+
report.momentary_max_lufs #=> Maximum momentary loudness in LUFS
|
|
158
|
+
report.short_term_max_lufs #=> Maximum short term loudness in LUFS
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
EBUR128Stream::Report also implements `#to_h` and `#deconstruct_keys` like EBUR128Stream::Snapshot.
|
|
162
|
+
|
|
163
|
+
<a name="normalizer"></a>
|
|
164
|
+
### Normalizer
|
|
165
|
+
|
|
166
|
+
EBUR128Stream::Normalizer analyzes audio data and normalizes it to the target loudness in place.
|
|
167
|
+
|
|
168
|
+
#### Initialization
|
|
169
|
+
|
|
170
|
+
Initialize EBUR128Stream::Normalizer with target loudness.
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
normalizer = EBUR128Stream::Normalizer.new(
|
|
174
|
+
# Required.
|
|
175
|
+
sample_rate: 48_000,
|
|
176
|
+
|
|
177
|
+
# Required.
|
|
178
|
+
channels: [:left, :right],
|
|
179
|
+
|
|
180
|
+
# Optional. Target loudness in LUFS. Defaults to -23.0.
|
|
181
|
+
target_lufs: -14.0,
|
|
182
|
+
|
|
183
|
+
# Optional. Cap the post-normalisation true peak at this dBTP value.
|
|
184
|
+
true_peak_ceiling_dbtp: -1.0,
|
|
185
|
+
)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### Normalization
|
|
189
|
+
|
|
190
|
+
Pass interleaved samples to EBUR128Stream::Normalizer#normalize_in_place:
|
|
191
|
+
|
|
192
|
+
```ruby
|
|
193
|
+
report = normalizer.normalize_in_place(interleaved_samples)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
*Note* that it modifies the passed `Array` in place as the method name implies.
|
|
197
|
+
|
|
198
|
+
This returns EBUR128Stream::NormalizeReport:
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
report.measured_integrated_lufs #=> Measured integrated loudness before normalization.
|
|
202
|
+
report.measured_true_peak_dbtp # Measured true peak before normalization, in dBTP.
|
|
203
|
+
report.target_lufs #=> Target loudness, in LUFS.
|
|
204
|
+
report.true_peak_ceiling_dbtp #=> True peak ceiling in dBTP.
|
|
205
|
+
report.applied_gain_db #=> Gain that was actually applied in dB.
|
|
206
|
+
report.limited_by_true_peak #=> true if the gain was attenuated to honour the true peak ceiling.
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
EBUR128Stream::NormalizeReport also implements `#to_h` and `deconstruct_keys`.
|
|
210
|
+
|
|
211
|
+
Additionally, it accepts MemoryView as a `samples` argument. The MemoryView must be writable.
|
|
212
|
+
|
|
213
|
+
## Examples
|
|
214
|
+
|
|
215
|
+
Complete examples are available in the sample directory.
|
|
216
|
+
|
|
217
|
+
* sample/analyze-wavefile.rb - A basic example of analyzing audio from wave file using pure-Ruby [WaveFile][] gem.
|
|
218
|
+
* sample/analyze-microphone.rb - An example that displays microphone loudness in real time.
|
|
219
|
+
* sample/analyze-planar-data.rb - An example of analyzing planar audio data instead of interleaved data.
|
|
220
|
+
* sample/normalize.rb - An example of normalizing audio data to desired loudness and saving it to a file.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bundle exec rake console` for an interactive prompt that will allow you to experiment.
|
|
225
|
+
|
|
226
|
+
To release a new version, update the version number in `version.rb`, 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).
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vanjamodrinjak21/ebur128_stream. Mention @KitaitiMakoto for issues and pull requests related to the Ruby binding.
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
Licensed under either of
|
|
235
|
+
|
|
236
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
237
|
+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
238
|
+
|
|
239
|
+
at your option.
|
|
240
|
+
|
|
241
|
+
## See also
|
|
242
|
+
|
|
243
|
+
* [Rust crate][rust-impl]
|
|
244
|
+
* [BS.1770][]
|
|
245
|
+
|
|
246
|
+
[rust-impl]: https://github.com/vanjamodrinjak21/ebur128-stream
|
|
247
|
+
[Analyzer]: rdoc-ref:EBUR128Stream::Analyzer
|
|
248
|
+
[BS.1770]: https://www.itu.int/rec/R-REC-BS.1770
|
|
249
|
+
[GStreamer]: https://github.com/ruby-gnome/ruby-gnome/tree/main/gstreamer
|
|
250
|
+
[TorchAudio]: https://github.com/ankane/torchaudio-ruby
|
|
251
|
+
[TorchCodec]: https://github.com/ankane/torchcodec-ruby
|
|
252
|
+
[Numo::NArray]: https://ruby-numo.github.io/numo-narray/
|
|
253
|
+
[Numo::NArray Alternative]: https://github.com/yoshoku/numo-narray-alt
|
|
254
|
+
[WaveFile]: https://wavefilegem.com/
|
|
255
|
+
[NDAV::TorchTensor]: https://gitlab.com/KitaitiMakoto/ndav-torch-tensor
|
|
256
|
+
[NDAV::Numo::NArray]: https://gitlab.com/KitaitiMakoto/ndav-numo-narray
|
data/Rakefile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rubygems/tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
require "kar/dsl"
|
|
6
|
+
require "rdoc/task"
|
|
7
|
+
|
|
8
|
+
GEMSPEC = Gem::Specification.load("ebur128_stream.gemspec")
|
|
9
|
+
|
|
10
|
+
LICENSE_FILES = FileList["LICENSE-APACHE", "LICENSE-MIT"]
|
|
11
|
+
LICENSE_FILES.each do |license|
|
|
12
|
+
file license => "../../#{license}" do |t|
|
|
13
|
+
copy t.source, t.name
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Gem::Tasks.new
|
|
18
|
+
|
|
19
|
+
cargo "ebur128_stream"
|
|
20
|
+
|
|
21
|
+
Rake::TestTask.new(test: :cargo)
|
|
22
|
+
RDoc::Task.new
|
|
23
|
+
|
|
24
|
+
task default: :test
|
|
25
|
+
|
|
26
|
+
task sync_version: ["lib/ebur128_stream/version.rb", "ext/ebur128_stream/Cargo.toml"] do |t|
|
|
27
|
+
require_relative t.sources[0]
|
|
28
|
+
sh "cargo", "set-version", "--manifest-path", t.sources[1], "--offline", EBUR128Stream::VERSION
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
task build: [:sync_version, :cargo] + LICENSE_FILES
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/ebur128_stream/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "ebur128_stream"
|
|
7
|
+
spec.version = EBUR128Stream::VERSION
|
|
8
|
+
spec.authors = ["Kitaiti Makoto"]
|
|
9
|
+
spec.email = ["KitaitiMakoto@gmail.com"]
|
|
10
|
+
spec.licenses = ["Apache-2.0", "MIT"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Streaming, zero-allocation EBU R128 loudness measurement."
|
|
13
|
+
spec.description = "Ruby binding for Streaming, zero-allocation EBU R128 loudness measurement in pure Rust."
|
|
14
|
+
spec.homepage = "https://github.com/KitaitiMakoto/ebur128-stream/tree/main/bindings/ruby"
|
|
15
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/KitaitiMakoto/ebur128-stream/tree/main/bindings/ruby"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/KitaitiMakoto/ebur128-stream/tree/main/bindings/ruby/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Uncomment the line below to require MFA for gem pushes.
|
|
22
|
+
# This helps protect your gem from supply chain attacks by ensuring
|
|
23
|
+
# no one can publish a new version without multi-factor authentication.
|
|
24
|
+
# See: https://guides.rubygems.org/mfa-requirement-opt-in/
|
|
25
|
+
# spec.metadata["rubygems_mfa_required"] = "true"
|
|
26
|
+
|
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
29
|
+
gemspec = File.basename(__FILE__)
|
|
30
|
+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
|
|
31
|
+
ls.readlines("\x0", chomp: true)
|
|
32
|
+
end + ["LICENSE-APACHE", "LICENSE-MIT"]
|
|
33
|
+
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
|
34
|
+
spec.require_paths = ["lib"]
|
|
35
|
+
spec.extensions = ["ext/ebur128_stream/Cargo.toml"]
|
|
36
|
+
|
|
37
|
+
# Uncomment to register a new dependency of your gem
|
|
38
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
39
|
+
|
|
40
|
+
spec.add_development_dependency "irb"
|
|
41
|
+
spec.add_development_dependency "rake"
|
|
42
|
+
spec.add_development_dependency "test-unit"
|
|
43
|
+
spec.add_development_dependency "rubygems-tasks"
|
|
44
|
+
spec.add_development_dependency "kar"
|
|
45
|
+
spec.add_development_dependency "numo-narray-alt"
|
|
46
|
+
spec.add_development_dependency "ndav-numo-narray"
|
|
47
|
+
|
|
48
|
+
# For more information and examples about making a new gem, check out our
|
|
49
|
+
# guide at: https://guides.rubygems.org/make-your-own-gem/
|
|
50
|
+
end
|