Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

63
LINES

< > BotCompany Repo | #1033050 // HamburgerAudioHaarFeature [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (6147L) is out of date.

1  
srecord noeq HamburgerAudioHaarFeature(IAudioSample sample, double start, double end) {
2  
  double[] positions = new[4];
3  
  
4  
  *(IAudioSample *sample, double... *positions) {
5  
  }
6  
  
7  
  double factor = 1;
8  
  
9  
  double length() { ret positions[3]-positions[0]; }
10  
11  
  DoubleRange meatRange() { ret doubleRange(positions[1], positions[2]; }
12  
  double meatHeight() { ret l(meatRange()); }
13  
  
14  
  double blackArea() { ret length()-meatHeight(); }
15  
  double whiteArea() { ret meatHeight(); }
16  
  
17  
  double get(int channel) {
18  
    double blackArea = blackArea();
19  
    double whiteArea = whiteArea();
20  
    
21  
    double whiteSum = sample.sampleSum(channel, positions[1], positions[2]);
22  
    double blackSum = sample.sampleSum(channel, positions[0], positions[1])
23  
      + sample.sampleSum(channel, positions[2], positions[3]);
24  
25  
    ret mul_optFor1(factor,
26  
        (doubleRatio(whiteSum, whiteArea)
27  
       - doubleRatio(blackSum, blackArea))/255.0);
28  
  }
29  
  
30  
  // 0 for transparent, 1 for white, -1 for black
31  
  double getMask(double x) {
32  
    ret x < positions[0] || x >= positions[3]
33  
      ? 0.0
34  
      : x >= positions[1] && x < positions[2]
35  
      ? factor
36  
      : -factor;
37  
  }
38  
  
39  
  Channels<Double> get() {
40  
    ret mapChannels get(sample.channels());
41  
  }
42  
  
43  
  HamburgerAudioHaarFeature inverted() {
44  
    HamburgerAudioHaarFeature f = new(sample, positions);
45  
    f.factor = -factor;
46  
    ret f;
47  
  }
48  
  
49  
  HamburgerAudioHaarFeature shifted(double ofs) {
50  
    HamburgerAudioHaarFeature f = new(sample, doubleAdd(positions, ofs));
51  
    f.factor = factor;
52  
    ret f;
53  
  }
54  
  
55  
  void pinOuter(DoubleRange r) {
56  
    positions[0] = r.start;
57  
    positions[3] = r.end;
58  
  }
59  
  
60  
  bool ok() {
61  
    ret doublesAreSorted(positions);
62  
  }
63  
}

Author comment

Began life as a copy of #1032988

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033050
Snippet name: HamburgerAudioHaarFeature [dev.]
Eternal ID of this version: #1033050/10
Text MD5: da6275e777c1b25bb4af4c2db2c34f91
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 19:32:56
Source code size: 1746 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 151 / 275
Version history: 9 change(s)
Referenced in: [show references]