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

22
LINES

< > BotCompany Repo | #1007026 // captureAudioFromLine

JavaX fragment (include)

static void captureAudioFromLine(DataLine line, AudioFormat format) ctex {
  if (!line instanceof TargetDataLine)
    fail(getClassName(line));
  TargetDataLine tdl = cast line;
  tdl.open(format);
  tdl.start();
  int total = 0, n;
  int seconds = 2;
  int bytesPerSecond = iround(format.getSampleSizeInBits()*format.getChannels()*format.getSampleRate()/8);
  print("Bytes per second: " + bytesPerSecond);
  int bytesWanted = seconds*bytesPerSecond;
  byte[] buf = new byte[1024];
  while (total < bytesWanted && (n = tdl.read(buf, 0, min(l(buf), bytesWanted-total))) > 0) {
    total += n;
    short[] exp = format.isBigEndian()
      ? shortArrayFromBytes(buf, 0, n)
      : shortArrayFromBytes_littleEndian(buf, 0, n);
    print(structure(subArray(exp, 0, 10)));
    print("Bytes read from line: " + total + ". min: " + min(exp) + ". max: " + max(exp));
  }
  tdl.close();
}

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: 382 / 419
Version history: 10 change(s)
Referenced in: [show references]