Libraryless. Click here for Pure Java version (4749L/27K).
1 | interface RenderFrequencySample { |
2 | public default double get aka renderFrequencySample(Complex c, double frac); |
3 | |
4 | default void subtractPeriodFrom(IAddPlateau audio, DoubleRange period, Frequency f, Complex intensity) { |
5 | int i1 = ifloor(period.start), i2 = ifloor(period.end); |
6 | new LPair<DoubleRange, Double> pairs; |
7 | for (int i = i1; i < i2; i++) |
8 | addPair(pairs, doubleRangeWithLength(i, 1), |
9 | renderPeriodSample(period, f, intensity, i, false)); |
10 | |
11 | for (DoubleRange r, double amplitude : unpair concatenateAdjacentDoubleRanges(pairs)) |
12 | audio.addPlateau(r.start, r.end, amplitude); |
13 | } |
14 | |
15 | default double renderPeriodSample(DoubleRange period, Frequency f, Complex intensity, double t, bool shouldPrint) { |
16 | double n = l(period); |
17 | Complex c = div(intensity, n); |
18 | double t2 = t-period.start; |
19 | double frac = t2/n; |
20 | if (shouldPrint) |
21 | printVars(+f, +t, interval := n, +t, +t2, frac := formatDouble2(frac), |
22 | c := renderComplexWithAngle(div(c, 32768))); |
23 | /*if (realOnly) c = complex(c.re()); |
24 | else if (imagOnly) c = complex(0, c.im());*/ |
25 | ret renderFrequencySample(c, frac); |
26 | } |
27 | |
28 | public default void addPeriodTo(double[] samples, DoubleRange period, Frequency f, Complex intensity) { |
29 | if (samples == null) ret; |
30 | subtractPeriodFrom(new IAddPlateau { |
31 | public void addPlateau(double start, double end, double intensity) { |
32 | int i1 = ifloor(start), i2 = ifloor(end); |
33 | for (int i = i1; i < i2; i++) |
34 | samples[i] += intensity; |
35 | } |
36 | }, period, f, minus(intensity)); |
37 | } |
38 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033263 |
Snippet name: | RenderFrequencySample |
Eternal ID of this version: | #1033263/28 |
Text MD5: | be250beec34999ca0f4804fd7133650d |
Transpilation MD5: | 9d606b8abc3dd93cb9c68642a22107e7 |
Author: | stefan |
Category: | javax / audio analysis |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-18 12:02:03 |
Source code size: | 1604 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 214 / 393 |
Version history: | 27 change(s) |
Referenced in: | [show references] |