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

45
LINES

< > BotCompany Repo | #1016678 // Sine Signal Test [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1038L/8K).

1  
!7
2  
3  
// Original source: AudioLoop from jsresources.org
4  
5  
static int DEFAULT_INTERNAL_BUFSIZ = 40960, DEFAULT_EXTERNAL_BUFSIZ = 40960;
6  
7  
p {
8  
  new AudioLoop(javaSound_cdQuality(), DEFAULT_INTERNAL_BUFSIZ, DEFAULT_EXTERNAL_BUFSIZ).start();
9  
}
10  
11  
sclass AudioLoop extends Thread {
12  
  TargetDataLine in;
13  
  SourceDataLine out;
14  
  new Flag stopFlag;
15  
  int externalBufferSize;
16  
  byte[] buf;
17  
  
18  
  *(AudioFormat format, int internalBufferSize, int *externalBufferSize) {
19  
    out = javaSound_outputLine(format, internalBufferSize);
20  
    buf = new byte[internalBufferSize];
21  
  }
22  
  
23  
  public void start { out.start°; super.start°; }
24  
  void stopPlaying { out.close°; stopFlag.raise°; } // "stop()" was taken
25  
  
26  
  long count;
27  
  double nextSample() {
28  
    ret Math.sin(count++/44100.0*440*2*pi())*0.5;
29  
  }
30  
31  
  public void run° {
32  
    while (licensed() && !stopFlag.isUp()) {
33  
      for (int i = 0; i < l(buf); i += 4) {
34  
        double f = nextSample();
35  
        int x = iround(max(0, min(1, f))*32767);
36  
        buf[i] = buf[i+2] = (byte) x;
37  
        buf[i+1] = buf[i+3] = (byte) (x >> 8);
38  
      }
39  
      
40  
      print("Writing " + l(buf) + " bytes");
41  
      int n = out.write(buf, 0, l(buf));
42  
      if (n != l(buf)) print("huh: " + n + " of " + l(buf));
43  
    }
44  
  }
45  
}

Author comment

Began life as a copy of #1009287

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: #1016678
Snippet name: Sine Signal Test [OK]
Eternal ID of this version: #1016678/13
Text MD5: 6e3d2051c8089e53f0491b5cf029e760
Transpilation MD5: 179baf12cfccba091e41bb70c219a6f6
Author: stefan
Category: javax / sound
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-28 00:13:04
Source code size: 1281 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 415 / 1067
Version history: 12 change(s)
Referenced in: [show references]