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

37
LINES

< > BotCompany Repo | #1017158 // Blip On Noise [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 206K of libraries. Click here for Pure Java version (14860L/105K).

1  
!7
2  
3  
import static x30_pkg.x30_util.VF1;
4  
5  
sclass BlipOnNoise > DynPrintLog {
6  
  float threshold = 40f;
7  
  int forcedDelay = 2000;
8  
  
9  
  transient VF1<short[]> audioListener;
10  
  transient float lastVolume;
11  
  transient Q q;
12  
  transient long delayUntil;
13  
  
14  
  void start {
15  
    ownTimer(q = startQ());
16  
    audioListener = voidfunc(short[] data) {
17  
      temp enter();
18  
      
19  
      // Quickly calculate the volume
20  
      final float vol = shortSamplesToPercentVolume(data);
21  
      
22  
      // Do everything else in our own thread
23  
      q.add(r {
24  
        //print("vol: " + vol);
25  
        if (now() > delayUntil && vol >= threshold && lastVolume < threshold) {
26  
          delayUntil = now()+forcedDelay;
27  
          blip();
28  
          printWithTime("Got noise (" + iround(vol) + "%)");
29  
        }
30  
        lastVolume = vol;
31  
      });
32  
    };
33  
    
34  
    // Link to audio input module
35  
    dm_addAudioListener(audioListener);
36  
  }
37  
}

Author comment

Began life as a copy of #1017157

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017158
Snippet name: Blip On Noise [Dyn Module]
Eternal ID of this version: #1017158/15
Text MD5: 21828ed7ab40b2c7f681829eb3f0e952
Transpilation MD5: 6d5edff4115ced3aa6c1bf907539a620
Author: stefan
Category: javax / audio
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-07 15:16:43
Source code size: 936 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 338 / 588
Version history: 14 change(s)
Referenced in: [show references]