quant.c
723 Bytes
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
#include "vadpcm.h"
short
qsample(float x, int scale)
{
if (x>0)
return (short) (x/(float) scale + 0.4999999);
else
return (short) (x/(float) scale - 0.4999999);
}
void
clamp(int fs, float *e, int *ie, int bits)
{
int i;
float ulevel, llevel;
llevel = - (float) (1L<<(bits-1));
ulevel = -llevel - 1;
for(i=0; i<fs; i++){
if (e[i]>ulevel)
e[i] = ulevel;
if (e[i]<llevel)
e[i] = llevel;
if (e[i]>0)
ie[i] = (int) (e[i]+0.5);
else
ie[i] = (int) (e[i]-0.5);
}
}
int
clip(int ix, int llevel, int ulevel)
{
if ((ix<llevel) || (ix>ulevel)){
if (ix<llevel) return llevel;
if (ix>ulevel) return ulevel;
}
return ix;
}