-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSuperClip.java
102 lines (93 loc) · 2.78 KB
/
SuperClip.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import fallk.logmaster.HLogger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import java.io.ByteArrayInputStream;
class SuperClip implements Runnable {
private int skiprate;
private Thread cliper;
public int stoped;
private SourceDataLine source;
private ByteArrayInputStream stream;
public SuperClip(byte abyte0[], int i, int j) {
skiprate = 0;
stoped = 1;
source = null;
stoped = 2;
skiprate = j;
stream = new ByteArrayInputStream(abyte0, 0, i);
}
@Override
public void run() {
boolean flag = false;
try {
final AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, skiprate, 16, 1, 2, skiprate, false);
final DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
source = (SourceDataLine) AudioSystem.getLine(info);
source.open(audioFormat);
source.start();
} catch (Exception exception) {
exception.printStackTrace();
stoped = 1;
}
while (stoped == 0) {
try {
if (source.available() < skiprate || !flag) {
byte abyte0[] = new byte[skiprate];
int i = stream.read(abyte0, 0, abyte0.length);
if (i == -1) {
stream.reset();
stream.read(abyte0, 0, abyte0.length);
}
source.write(abyte0, 0, abyte0.length);
flag = true;
}
} catch (Exception exception1) {
HLogger.error("play error: " + exception1);
stoped = 1;
}
try {
Thread.sleep(200L);
} catch (InterruptedException interruptedexception) {
}
}
source.stop();
source.close();
source = null;
stoped = 2;
}
public void play() {
if (stoped == 2) {
stoped = 0;
try {
stream.reset();
} catch (Exception exception) {
}
cliper = new Thread(this);
cliper.start();
}
}
public void resume() {
if (stoped == 2) {
stoped = 0;
cliper = new Thread(this);
cliper.start();
}
}
public void stop() {
if (stoped == 0) {
stoped = 1;
if (source != null) {
source.stop();
}
}
}
public void close() {
try {
stream.close();
stream = null;
} catch (Exception exception) {
}
}
}