adpcmtask.c
3.1 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <abi.h>
/* #include <os.h>*/
#include <stdio.h>
/* Size value come from u-code assembly, locations are arbitrary,
but should be used for load command in simulator.
The command list is written by this program and sits right after
the task header in DRAM, which is loaded at 0x00000000
*/
#define AUD_UCODE_POINTER 0x7000
#define AUD_UCODE_SIZE 4095 /* In bytes */
#define AUD_PDATA_POINTER 0x8000
#define AUD_PDATA_SIZE 1536 /* In bytes */
#define ADPCM_TABLE_LOC 48
#define ADPCM_TABLE_SIZE (8*16)
#define AUD_CL_POINTER (ADPCM_TABLE_LOC + ADPCM_TABLE_SIZE)
short adpcmtable[][16] = {
{0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0,
1920, 1800, 1688, 1582, 1483, 1390, 1304, 1222},
{-1920, -3660, -5177, -6437, -7418, -8105, -8496, -8597,
3904, 5522, 6866, 7912, 8645, 9062, 9170, 8985},
{-1664, -2990, -4021, -4795, -5350, -5717, -5925, -6002,
3680, 4949, 5902, 6584, 7036, 7293, 7388, 7349}
};
main(int argc, char *argv[])
{
Task tlist, *tlistp;
Acmd alist[4096], *alistp;
int w0, w1, i, outpoint, inpoint, clcount;
FILE *outp;
if((outp = fopen(argv[1], "w")) == NULL){
fprintf(stderr,"Can't open %s\n",argv[1]);
exit(1);
}
tlistp = &tlist;
alistp = alist;
clcount = 0;
inpoint = 0; /* Bitstream pointer in bytes */
outpoint = 0; /* Decoded output pointer in bytes */
aSegment(alistp++, 0, 0xa000); /* Input bistream */
aSegment(alistp++, 1, 0x100000); /* Output stream */
aSegment(alistp++, 2, 0x8fa0); /* ADPCM state */
aSegment(alistp++, 3, 0x0);
aLoadADPCM(alistp++, ADPCM_TABLE_SIZE-1, 3<<26 | ADPCM_TABLE_LOC);
aSetBuffer(alistp++, 0, 0, 0, 184); /* 180 + 4 to force 8 byte length */
aLoadBuffer(alistp++, inpoint); /* Address in bytes */
aSetBuffer(alistp++, 0, 0, 1280, 640); /* 40 frames of 16 samples */
aADPCMdec(alistp++, A_INIT, 1, (2<<26));
aSetBuffer(alistp++, 0, 0, 656<<1, 640); /* 40 frames of 16 samples */
aSaveBuffer(alistp++, 1<<26 | outpoint);
outpoint += 640;
inpoint += 180;
for (i=0; i<100; i++){
aSetBuffer(alistp++, 0, 0, 0, 184);
aLoadBuffer(alistp++, inpoint - (inpoint % 8));
aSetBuffer(alistp++, 0,(inpoint % 8), 1280, 640);
aADPCMdec(alistp++, 0, 1, (2<<26));
aSetBuffer(alistp++, 0, 0, 656<<1, 640);
aSaveBuffer(alistp++, 1<<26 | outpoint);
outpoint += 640;
inpoint += 180;
}
clcount = (int) (alistp - alist);
fprintf(stderr,"Command list length: %d\n",clcount);
alistp = alist;
tlistp->t.dl = AUD_CL_POINTER;
tlistp->t.len = clcount*8;
tlistp->t.type = M_AUDTASK | ((AUD_UCODE_SIZE)<<12);
tlistp->t.ucode = (unsigned long *) AUD_UCODE_POINTER;
tlistp->t.ucode_data = (unsigned long *) AUD_PDATA_POINTER;
tlistp->t.ucode_data_len = AUD_PDATA_SIZE;
fwrite(tlistp, 1, 48, outp);
fwrite(adpcmtable, 1, ADPCM_TABLE_SIZE, outp);
for (i=0; i<clcount; i++){
w0 = alistp->words.w0;
w1 = alistp->words.w1;
fwrite(&w0, 1, 4, outp);
fwrite(&w1, 1, 4, outp);
alistp++;
}
fclose(outp);
}