Download Jar. Libraryless. Click here for Pure Java version (3051L/21K).
1 | !7 |
2 | |
3 | static int DEFAULT_INTERNAL_BUFSIZ = 40960, DEFAULT_EXTERNAL_BUFSIZ = 40960; |
4 | |
5 | p { |
6 | temp WAVDecoder decoder = new(newFileInputStream(loadLibrary(#1400093))); |
7 | new L<short[]> chunks; |
8 | while licensed { |
9 | short[] buf = new short[4096]; |
10 | int n = decoder.readStereoSamples(buf); |
11 | if (n <= 0) break; |
12 | chunks.add(subArray(buf, 0, n)); |
13 | } |
14 | short[] samples = concatShortArrays(chunks); |
15 | new AudioLoop(javaSound_cdQuality(), DEFAULT_INTERNAL_BUFSIZ, DEFAULT_EXTERNAL_BUFSIZ, samples).start(); |
16 | } |
17 | |
18 | sclass AudioLoop extends Thread { |
19 | TargetDataLine in; |
20 | SourceDataLine out; |
21 | new Flag stopFlag; |
22 | int externalBufferSize; |
23 | byte[] buf; |
24 | short[] samples; |
25 | |
26 | *(AudioFormat format, int internalBufferSize, int *externalBufferSize, short[] *samples) { |
27 | out = javaSound_outputLine(format, internalBufferSize); |
28 | buf = new byte[internalBufferSize]; |
29 | } |
30 | |
31 | public void start { out.start°; super.start°; } |
32 | void stopPlaying { out.close°; stopFlag.raise°; } // "stop()" was taken |
33 | |
34 | int sampleIndex = 0; |
35 | void nextSamples(short[] pair) { |
36 | pair[0] = samples[sampleIndex]; |
37 | pair[1] = samples[sampleIndex+1]; |
38 | sampleIndex = (sampleIndex+2) % l(samples); |
39 | } |
40 | |
41 | public void run° { |
42 | short[] pair = new short[2]; |
43 | while (licensed() && !stopFlag.isUp()) { |
44 | for (int i = 0; i < l(buf); i += 4) { |
45 | nextSamples(pair); |
46 | buf[i] = (byte) pair[0]; |
47 | buf[i+1] = (byte) (pair[0] >> 8); |
48 | buf[i+2] = (byte) pair[1]; |
49 | buf[i+3] = (byte) (pair[1] >> 8); |
50 | } |
51 | |
52 | //print("Writing " + l(buf) + " bytes"); |
53 | int n = out.write(buf, 0, l(buf)); |
54 | if (n != l(buf)) print("huh: " + n + " of " + l(buf)); |
55 | } |
56 | } |
57 | } |
Began life as a copy of #1016683
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: | #1016684 |
Snippet name: | Play Stereo Loop From WAV Spike (OK) |
Eternal ID of this version: | #1016684/5 |
Text MD5: | 9a9873ce2d6938a1a40df5f6deb2fa39 |
Transpilation MD5: | 8c2df96444375417d21f10b30c1ff760 |
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:31:55 |
Source code size: | 1736 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 470 / 1093 |
Version history: | 4 change(s) |
Referenced in: | [show references] |