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

21
LINES

< > BotCompany Repo | #1019662 // decodeWAVToMonoSamples

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3479L/20K).

static short[] decodeWAVToMonoSamples(File wavFile) ctex {
  temp WAVDecoder decoder = new(newFileInputStream(wavFile));
  ret decodeWAVToMonoSamples(decoder, wavFile);
}

// weird signature
static short[] decodeWAVToMonoSamples(WAVDecoder decoder, File wavFile) {
  ret decodeWAVToMonoSamples(decoder);
}

static short[] decodeWAVToMonoSamples(WAVDecoder decoder, long maxSamples default Int.MAX_VALUE) ctex {
  new L<short[]> chunks;
  while ping (maxSamples > 0) {
    short[] buf = new short[(int) min(maxSamples, 4096)];
    int n = decoder.readMonoSamples(buf);
    if (n <= 0) break;
    chunks.add(subArray(buf, 0, n));
    maxSamples -= n;
  }
  ret concatShortArrays(chunks);
}

Author comment

Began life as a copy of #1016685

download  show line numbers  debug dex  old transpilations   

Travelled to 11 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019662
Snippet name: decodeWAVToMonoSamples
Eternal ID of this version: #1019662/6
Text MD5: 4381157c770c1dbc638f5dc5addb1ffe
Transpilation MD5: 92338ae60a577f52bd3a94cfd1206a40
Author: stefan
Category: javax / sound
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-03 01:22:14
Source code size: 707 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 292 / 398
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1024592 - decodeWAVToMonoSamples_iterator
#1032404 - extractMonoSamplesFromWAV