adpcmobj.c
1.28 KB
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
#include <abi.h>
#include <stdio.h>
#define ADPCMVSIZE 16
#define FRAMEBYTES 9
static int segin;
static int dramin;
static int segstate;
static int statep;
static int lastsam;
static int first_time;
int adpcmsetdram(int seg, int dram)
{
segin = seg;
dramin = dram;
}
int adpcminit(int seg, int astate)
{
first_time = 1;
statep = astate;
lastsam = 0;
segstate = seg;
}
Acmd *adpcmdec(Acmd *cp, int dmemin, int dmemout, int nsam,
unsigned char flags, int gain, int *outp)
{
Acmd *cl = cp;
int tsam;
int nframes;
int nbytes;
if (lastsam)
tsam = nsam - ADPCMVSIZE + lastsam; /* How many to ask for */
else
tsam = nsam;
nframes = (tsam+ADPCMVSIZE-1)/ADPCMVSIZE;
nbytes = nframes*FRAMEBYTES + (dramin % 8);
aSetBuffer(cl++, 0, dmemin, 0, nbytes + 8 - (nbytes % 8));
aLoadBuffer(cl++, (segin<<26) + dramin - (dramin % 8));
aSetBuffer(cl++, 0, dmemin + (dramin % 8), dmemout, tsam<<1);
if (first_time){
aADPCMdec(cl++, A_INIT | flags, gain, (segstate<<26) + statep);
first_time=0;
} else
aADPCMdec(cl++, flags, gain, (segstate<<26) + statep);
if (lastsam)
*outp = (lastsam<<1) + dmemout;
else
*outp = dmemout + (ADPCMVSIZE<<1);
lastsam = (nsam + lastsam) % ADPCMVSIZE;
dramin += FRAMEBYTES*nframes;
return(cl);
}