-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVoxInputStream.java
75 lines (64 loc) · 1.91 KB
/
VoxInputStream.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
/*
* Copyright (c) 2003 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
package vavi.sound.adpcm.vox;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteOrder;
import vavi.sound.adpcm.AdpcmInputStream;
import vavi.sound.adpcm.Codec;
/**
* Vox InputStream.
*
* @author <a href="mailto:[email protected]">Naohide Sano</a> (nsano)
* @version 0.00 030816 nsano initial version <br>
*/
public class VoxInputStream extends AdpcmInputStream {
@Override
protected Codec getCodec() {
return new Vox();
}
/**
* {@link vavi.io.BitInputStream} is 4bit big endian fixed
* TODO vox is big endian ?
*/
public VoxInputStream(InputStream in, ByteOrder byteOrder) {
super(in, byteOrder, 4, ByteOrder.BIG_ENDIAN);
}
@Override
public int available() throws IOException {
//logger.log(Level.TRACE, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0)));
return (in.available() * 2) + (rest ? 1 : 0);
}
/**
* TODO endian
*/
@Override
public int read() throws IOException {
//logger.log(Level.TRACE, in);
if (!rest) {
int adpcm = in.read();
if (adpcm == -1) {
return -1;
}
current = decoder.decode(adpcm) * 16; // TODO check!!!
rest = true;
//logger.log(Level.TRACE, "1: " + StringUtil.toHex2(current & 0xff));
if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) {
return (current & 0xff00) >> 8;
} else {
return current & 0xff;
}
} else {
rest = false;
//logger.log(Level.TRACE, "2: " + StringUtil.toHex2((current & 0xff00) >> 8));
if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) {
return current & 0xff;
} else {
return (current & 0xff00) >> 8;
}
}
}
}