dsprb 2.0.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa50ef5e7332169aacc296720f303cc7f5160a43e9bc56f7fd964efd86b90404
4
- data.tar.gz: fb948d7001cc0f53e39d09146c71c6b79dc90cb2d1945e5b78b99e8405ffd875
3
+ metadata.gz: dfb830b28024449122b3fd1accc7a7ae89950d40c8b670c50695e534ab1d91aa
4
+ data.tar.gz: 4b8f553765a4d5e45670c732bf62f34213367f5bd980d133f0b5f59d7b22464c
5
5
  SHA512:
6
- metadata.gz: c72b16fbd04e9c142957c442da128e24a3493f1924ed79f0edcbac87f23888c8b2b97e57c3821a640248f37aa8a48ed8b906b79d55d12528374754b79ae1a4a7
7
- data.tar.gz: dc938d6930712e3c7605f767592f99713792481df22d4b788ef0c25559c2ff398cd62face9e070b84274ede4f09d1eb10514ec7e233b8c481be0efdce5b0d871
6
+ metadata.gz: '069f86099b4c64483d4236f484155a96050e6d087608cd9de149acdcaad8e59a23591a3939a048dc5de302ccac8bd355ccd677798389a3b86f4fe381aeb95819'
7
+ data.tar.gz: 960ff76214e8d42f2c9ffe8fe628433c379e3f06e8822dbfcfee4d4501c60ef95a91a0e2f26abfd5f049f91548ee1ced7f91b8bc990f380374c2165cc8aebdea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,135 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.1 — 2026-12-07
4
+
5
+ - `Formants` no longer takes a real root of the predictor polynomial for a resonance. The root
6
+ finder leaves a real root with an imaginary part near 1e-38 on some platforms and exactly zero
7
+ on others, so with `edge_margin: 0.0` a formant at 0 Hz was reported on one and not on the
8
+ other. Results with the default margin are unchanged.
9
+
10
+ ## 2.1.0 — 2026-12-06
11
+
12
+ Accuracy release. Formant frequencies and pitch estimates change; feature values computed with
13
+ 2.0.0 are not comparable with those of this release. Reference measurements below use Praat
14
+ 6.1.38 through Parselmouth 0.4.7 on citation-form syllables at 22050 Hz from three voices: the
15
+ Ministry of Education dictionary voice and the female and male CNS11643 voices. This library
16
+ was run at a 5512.5 Hz ceiling, Praat's Burg analysis at 5500 Hz for the first two voices and
17
+ 5000 Hz for the male voice.
18
+
19
+ ### Fixed
20
+
21
+ - The constants of `Biquad` and `SpectralMoments` are defined on those classes, as the signatures
22
+ declare: `DSP::Biquad::BUTTERWORTH_Q`, `DSP::SpectralMoments::DEFAULT_LOW_HZ` and the rest. They
23
+ were defined on `DSP` itself.
24
+ - `Formants` reports formants from the roots of the predictor polynomial instead of the maxima
25
+ of the all-pole envelope. The envelope of a back rounded vowel often has one maximum for F1
26
+ and F2, and the 250 Hz merge then dropped the weaker one, so F3 was reported as F2. A root
27
+ r e^{iω} above the real axis gives a resonance at ω fs / 2π with bandwidth −ln(r) fs / π.
28
+ Roots within 50 Hz of 0 or Nyquist are discarded, as Praat's Burg analysis does. Roots wider
29
+ than 1000 Hz are discarded too; Praat applies no bandwidth limit, but our Hamming-window
30
+ autocorrelation fit places its spare pole pair, typically 1100–3500 Hz wide, in the F1–F2
31
+ gap of [i]. Of the roots matching a Praat formant with a Praat bandwidth under 600 Hz, 99 %
32
+ are narrower than 595 Hz (F1), 651 Hz (F2) and 1052 Hz (F3).
33
+
34
+ Absolute F1 and F2 difference from Praat (Burg, 5 formants, ceiling 5500 Hz), median and
35
+ 90th percentile of per-token medians over 30–70 % of the voiced span, Ministry voice:
36
+
37
+ | Vowel | n | F1 2.0.0 | F1 2.1.0 | F2 2.0.0 | F2 2.1.0 |
38
+ | ----- | --- | -------- | -------- | ----------- | --------- |
39
+ | [i] | 80 | 6 / 23 | 3 / 14 | 89 / 2004 | 74 / 1809 |
40
+ | [e] | 80 | 6 / 20 | 6 / 20 | 6 / 21 | 4 / 11 |
41
+ | [a] | 80 | 25 / 612 | 29 / 88 | 23 / 1400 | 12 / 79 |
42
+ | [o] | 77 | 35 / 134 | 9 / 28 | 1617 / 2849 | 7 / 95 |
43
+ | [u] | 80 | 7 / 31 | 5 / 18 | 116 / 2556 | 6 / 35 |
44
+ | [y] | 80 | 3 / 7 | 3 / 8 | 27 / 104 | 12 / 36 |
45
+
46
+ Over all 1047 tokens of the three voices, the median difference falls from 11 to 7 Hz for F1
47
+ and from 42 to 11 Hz for F2, the 90th percentile from 111 to 41 Hz and from 2313 to 155 Hz.
48
+ The share of [u] tokens with F2 above 1600 Hz falls from 50 % to 6 % for the Ministry voice
49
+ (Praat 5 %), from 62 % to 12 % for the female CNS voice (Praat 10 %) and from 93 % to 34 % for
50
+ the male CNS voice, for which Praat gives 11 % at 5000 Hz and 23 % at 5500 Hz. The median [u]
51
+ F2 of the Ministry voice moves from 1594 to 813 Hz; Praat gives 818 Hz. The remaining [i] F2
52
+ differences are mostly Praat's: in 25 of 80 Ministry [i] tokens Praat reports a pole wider
53
+ than 1 kHz between F1 and F2 as F2, against 2 of 80 here.
54
+
55
+ - `Yin` accumulates the cumulative mean normalized difference from lag 1, as the YIN paper
56
+ defines it, instead of from the shortest lag searched, and a dip at the shortest lag can be
57
+ chosen. Harmonic signals between about 440 Hz and the 500 Hz default maximum were reported an
58
+ octave low (470 Hz as 235 Hz). The lags below the search range enter the normalization only
59
+ as their sum, which one pass over the window computes from running sums, so the early stop at
60
+ the first qualifying dip is kept.
61
+
62
+ Synthetic vowels, f0 80–500 Hz in 10 Hz steps, 22050 Hz input, 1978 frames per row:
63
+
64
+ | Working rate | Vowel | Gross 2.0.0 | Gross 2.1.0 | Octave 2.0.0 | Octave 2.1.0 | Median 2.0.0 | Median 2.1.0 |
65
+ | ------------ | ----- | ----------- | ----------- | ------------ | ------------ | ------------ | ------------ |
66
+ | 5512.5 Hz | [a] | 12.2 % | 2.8 % | 228 | 6 | 0.17 % | 0.10 % |
67
+ | 5512.5 Hz | [i] | 12.5 % | 3.2 % | 232 | 6 | 0.24 % | 0.10 % |
68
+ | 11025 Hz | [a] | 7.3 % | 2.4 % | 144 | 3 | 0.07 % | 0.04 % |
69
+ | 11025 Hz | [i] | 11.0 % | 3.2 % | 203 | 6 | 0.07 % | 0.04 % |
70
+
71
+ Gross errors count frames more than 20 % off or unvoiced, octave errors frames at half or twice
72
+ the true f0, and the median is the relative error of voiced frames. Most remaining gross errors
73
+ are the frames at exactly 500 Hz: parabolic refinement on the normalized difference places them
74
+ 0.1–0.4 % above the maximum, and they are reported unvoiced. White, red, brown and low-passed
75
+ noise, 60 Hz hum, digital silence and dither stay unvoiced.
76
+
77
+ Against Praat's autocorrelation pitch on 60 recordings, frames an octave apart fall from 42 to
78
+ 22 for 25 high level-tone syllables of the female CNS voice and from 57 to 8 for 15 of its
79
+ falling-tone syllables; 10 male CNS syllables go from 14 to 16 and 10 Ministry syllables stay
80
+ at 0.
81
+
82
+ - `DSP.mfcc` defaults its transform size to the smallest power of two that holds a frame. A
83
+ 25 ms frame at 22050 Hz is 551 samples, and the former 512 point default read only the first
84
+ 512 of them. At 16 kHz the default stays 512.
85
+
86
+ ### Changed
87
+
88
+ - Requires Ruby 3.4 or later.
89
+ - `Mfcc#sequence` raises `ArgumentError` when the spectrum is shorter than a frame, with both
90
+ lengths in the message: `FFT size must be at least 551, got 512`.
91
+ - `Spectrum.new` and `Fourier::Real.new` reject a size that is not a power of two.
92
+ `Spectrum.new(1025)` used to construct, then compute a 1024 point transform of frames up to
93
+ 1024 samples and raise on longer ones.
94
+ - `Formants::Peak` gains `bandwidth`, in Hz. `Peak#amplitude` is the log envelope level at the
95
+ root frequency rather than at the nearest grid point.
96
+ - `Formants::DEFAULT_EDGE_MARGIN_HZ` is 50 Hz, as in Praat, instead of 150 Hz. On the reference
97
+ recordings the two values give the same formants.
98
+ - `Mfcc.for` without `size:` sizes the transform for a 25 ms frame at the given rate.
99
+ - Relicensed from WTFPL to MIT.
100
+
101
+ ### Added
102
+
103
+ - `DSP::Polynomial.roots`, the roots of a real polynomial by the Aberth-Ehrlich iteration from a
104
+ fixed starting circle, with at most 100 sweeps.
105
+ - `DSP::Mfcc.size_for(length)`, the transform size for a frame of `length` samples.
106
+ - `Formants::MAXIMUM_BANDWIDTH_HZ`.
107
+ - `CITATION.cff`.
108
+
109
+ ### Deprecated
110
+
111
+ - `Formants.new(separation:)` and `Formants.new(resolution:)` are ignored, along with
112
+ `DEFAULT_SEPARATION_HZ` and `DEFAULT_RESOLUTION`; `resolution:` must still be at least 2. The
113
+ envelope grid and the peak merging they tuned are gone.
114
+ - `Mfcc::DEFAULT_SIZE` is no longer the default.
115
+
116
+ ### Performance
117
+
118
+ Ruby 4.0 with YJIT, 22050 Hz input, best of 5 to 15 runs; the `Yin` rows are medians over four
119
+ interleaved rounds:
120
+
121
+ | Operation | 2.0.0 | 2.1.0 |
122
+ | --------------------------------------------- | ------- | ------- |
123
+ | `Formants#call` per 25 ms frame, 2228 frames | 307 us | 289 us |
124
+ | `Yin#call` over 60 corpus recordings | 627 ms | 636 ms |
125
+ | `Yin#call`, 2 s synthetic vowel at 120–180 Hz | 24.5 ms | 25.9 ms |
126
+ | `Yin#call`, 2 s synthetic vowel at 300–400 Hz | 9.3 ms | 9.0 ms |
127
+ | `Yin#call`, 2 s white noise | 38.9 ms | 40.0 ms |
128
+
129
+ The extra pass over each frame costs about one lag of the difference function: 1.4 % on the
130
+ corpus recordings, up to 6 % where the period is long and the search runs far. A whole
131
+ pronunciation grade, formants included, takes 2–5 % less time than with 2.0.0.
132
+
3
133
  ## 2.0.0 — 2026-08-21
4
134
 
5
135
  Performance release. Every value the library produces is unchanged: across a battery of 34
data/CITATION.cff ADDED
@@ -0,0 +1,30 @@
1
+ cff-version: 1.2.0
2
+ title: "dsprb: speech signal analysis in pure Ruby"
3
+ message: "If you use this software, please cite it."
4
+ type: software
5
+ authors:
6
+ - family-names: Patin
7
+ given-names: Den
8
+ alias: 丁丹旭
9
+ email: hi@dpat.in
10
+ orcid: "https://orcid.org/0009-0009-6496-382X"
11
+ affiliation: Independent researcher
12
+ city: Taipei
13
+ country: TW
14
+ repository-code: "https://github.com/taiwancards/dsprb"
15
+ repository-artifact: "https://rubygems.org/gems/dsprb"
16
+ abstract: >-
17
+ Computes acoustic features of speech from numeric signals in Ruby without native extensions:
18
+ power spectra, mel-frequency cepstral coefficients, YIN fundamental frequency tracks, formant
19
+ frequencies and bandwidths from the roots of the linear prediction polynomial, spectral moments
20
+ and short-term energy. It also decodes PCM and IEEE float WAV files and provides biquad filters
21
+ and windowed-sinc decimation for conditioning a signal before analysis.
22
+ keywords:
23
+ - speech analysis
24
+ - acoustic phonetics
25
+ - signal processing
26
+ - formant estimation
27
+ - fundamental frequency
28
+ license: MIT
29
+ version: 2.1.1
30
+ date-released: "2026-12-07"
data/LICENSE CHANGED
@@ -1,13 +1,19 @@
1
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
- Version 2, December 2004
1
+ MIT License
3
2
 
4
- Copyright (C) 2026 Den Patin <hi@dpat.in>
3
+ Copyright (c) 2026 Den Patin 丁丹旭 <hi@dpat.in>
5
4
 
6
- Everyone is permitted to copy and distribute verbatim or modified
7
- copies of this license document, and changing it is allowed as long
8
- as the name is changed.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
+ software and associated documentation files (the "Software"), to deal in the Software
7
+ without restriction, including without limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
+ to whom the Software is furnished to do so, subject to the following conditions:
9
10
 
10
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
12
13
 
13
- 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+ DEALINGS IN THE SOFTWARE.