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

22
LINES

< > BotCompany Repo | #1007026 // captureAudioFromLine

JavaX fragment (include)

1  
static void captureAudioFromLine(DataLine line, AudioFormat format) ctex {
2  
  if (!line instanceof TargetDataLine)
3  
    fail(getClassName(line));
4  
  TargetDataLine tdl = cast line;
5  
  tdl.open(format);
6  
  tdl.start();
7  
  int total = 0, n;
8  
  int seconds = 2;
9  
  int bytesPerSecond = iround(format.getSampleSizeInBits()*format.getChannels()*format.getSampleRate()/8);
10  
  print("Bytes per second: " + bytesPerSecond);
11  
  int bytesWanted = seconds*bytesPerSecond;
12  
  byte[] buf = new byte[1024];
13  
  while (total < bytesWanted && (n = tdl.read(buf, 0, min(l(buf), bytesWanted-total))) > 0) {
14  
    total += n;
15  
    short[] exp = format.isBigEndian()
16  
      ? shortArrayFromBytes(buf, 0, n)
17  
      : shortArrayFromBytes_littleEndian(buf, 0, n);
18  
    print(structure(subArray(exp, 0, 10)));
19  
    print("Bytes read from line: " + total + ". min: " + min(exp) + ". max: " + max(exp));
20  
  }
21  
  tdl.close();
22  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007026
Snippet name: captureAudioFromLine
Eternal ID of this version: #1007026/11
Text MD5: 8b65eb3d4e6dd807fbe92976392a2844
Author: stefan
Category: javax / audio
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-25 20:24:16
Source code size: 899 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 452 / 489
Version history: 10 change(s)
Referenced in: [show references]