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.

srecord noeq HamburgerAudioHaarFeature(IAudioSample sample, double start, double end) {
  double[] positions = new[4];
  
  *(IAudioSample *sample, double... *positions) {
  }
  
  double factor = 1;
  
  double length() { ret positions[3]-positions[0]; }

  DoubleRange meatRange() { ret doubleRange(positions[1], positions[2]; }
  double meatHeight() { ret l(meatRange()); }
  
  double blackArea() { ret length()-meatHeight(); }
  double whiteArea() { ret meatHeight(); }
  
  double get(int channel) {
    double blackArea = blackArea();
    double whiteArea = whiteArea();
    
    double whiteSum = sample.sampleSum(channel, positions[1], positions[2]);
    double blackSum = sample.sampleSum(channel, positions[0], positions[1])
      + sample.sampleSum(channel, positions[2], positions[3]);

    ret mul_optFor1(factor,
        (doubleRatio(whiteSum, whiteArea)
       - doubleRatio(blackSum, blackArea))/255.0);
  }
  
  // 0 for transparent, 1 for white, -1 for black
  double getMask(double x) {
    ret x < positions[0] || x >= positions[3]
      ? 0.0
      : x >= positions[1] && x < positions[2]
      ? factor
      : -factor;
  }
  
  Channels<Double> get() {
    ret mapChannels get(sample.channels());
  }
  
  HamburgerAudioHaarFeature inverted() {
    HamburgerAudioHaarFeature f = new(sample, positions);
    f.factor = -factor;
    ret f;
  }
  
  HamburgerAudioHaarFeature shifted(double ofs) {
    HamburgerAudioHaarFeature f = new(sample, doubleAdd(positions, ofs));
    f.factor = factor;
    ret f;
  }
  
  void pinOuter(DoubleRange r) {
    positions[0] = r.start;
    positions[3] = r.end;
  }
  
  bool ok() {
    ret doublesAreSorted(positions);
  }
}

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: 152 / 275
Version history: 9 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)