-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQOABase.java
67 lines (57 loc) · 1.43 KB
/
QOABase.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
// Generated automatically with "fut". Do not edit.
/**
* Common part of the "Quite OK Audio" format encoder and decoder.
*/
public abstract class QOABase
{
protected int frameHeader;
/**
* Maximum number of channels supported by the format.
*/
public static final int MAX_CHANNELS = 8;
/**
* Returns the number of audio channels.
*/
public final int getChannels()
{
return this.frameHeader >> 24;
}
/**
* Returns the sample rate in Hz.
*/
public final int getSampleRate()
{
return this.frameHeader & 16777215;
}
protected static final int SLICE_SAMPLES = 20;
protected static final int MAX_FRAME_SLICES = 256;
/**
* Maximum number of samples per frame.
*/
public static final int MAX_FRAME_SAMPLES = 5120;
protected final int getFrameBytes(int sampleCount)
{
int slices = (sampleCount + 19) / 20;
return 8 + getChannels() * (16 + slices * 8);
}
protected static final short[] SCALE_FACTORS = { 1, 7, 21, 45, 84, 138, 211, 304, 421, 562, 731, 928, 1157, 1419, 1715, 2048 };
protected static int dequantize(int quantized, int scaleFactor)
{
int dequantized;
switch (quantized >> 1) {
case 0:
dequantized = (scaleFactor * 3 + 2) >> 2;
break;
case 1:
dequantized = (scaleFactor * 5 + 1) >> 1;
break;
case 2:
dequantized = (scaleFactor * 9 + 1) >> 1;
break;
default:
dequantized = scaleFactor * 7;
break;
}
return (quantized & 1) != 0 ? -dequantized : dequantized;
}
}