Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / wav / wave_g72x.c
blobaf347e0f488c4bb82f9019d45f900124b466c19b
1 /*
2 * wave.datatype
3 * (c) Fredrik Wikstrom
4 */
6 #include <proto/exec.h>
7 #include "wave_g72x.h"
8 #include "g72x/g72x.h"
9 #include "bitpack.h"
10 #include "endian.h"
12 struct G72x_Format {
13 UWORD formatTag;
14 WORD numChannels;
15 LONG samplesPerSec;
16 LONG avgBytesPerSec;
17 WORD blockAlign; /* amount to read for each block */
18 WORD bitsPerSample;
20 WORD extraSize; /* 2 */
21 WORD auxSize;
24 struct WAV_G72x_state {
25 struct g72x_state stat[MAX_CHANNELS];
26 int (*decoder)(int code, struct g72x_state *state_ptr);
29 DEC_SETUPPROTO(SetupG72x) {
30 struct G72x_Format * fmt;
31 struct WAV_G72x_state * state;
32 LONG ch;
33 fmt = (struct G72x_Format *)data->fmt;
35 if (fmt->extraSize != 2)
36 return NOTOK;
37 //if (fmt->numChannels != 1)
38 // return ERROR_NOT_IMPLEMENTED;
40 fmt->auxSize = le2nat16(fmt->auxSize);
42 data->state = state = (struct WAV_G72x_state *)AllocVec(sizeof(*state), MEMF_CLEAR);
43 if (!state) return ERROR_NO_FREE_STORE;
45 for (ch = 0; ch < fmt->numChannels; ch++)
46 g72x_init_state(&state->stat[ch]);
48 switch (fmt->formatTag) {
49 case WAVE_FORMAT_G721_ADPCM:
50 switch (fmt->bitsPerSample) {
51 case 4:
52 fmt->blockAlign = 64*fmt->numChannels + fmt->auxSize;
53 state->decoder = g721_decoder;
54 break;
55 default:
56 return DTERROR_UNKNOWN_COMPRESSION;
58 break;
59 case WAVE_FORMAT_G723_ADPCM:
60 switch (fmt->bitsPerSample) {
61 case 2:
62 fmt->blockAlign = 32*fmt->numChannels + fmt->auxSize;
63 state->decoder = g723_16_decoder;
64 break;
65 case 3:
66 fmt->blockAlign = 48*fmt->numChannels + fmt->auxSize;
67 state->decoder = g723_24_decoder;
68 break;
69 case 5:
70 fmt->blockAlign = 80*fmt->numChannels + fmt->auxSize;
71 state->decoder = g723_40_decoder;
72 break;
73 default:
74 return DTERROR_UNKNOWN_COMPRESSION;
76 break;
77 default:
78 return DTERROR_UNKNOWN_COMPRESSION;
80 data->blockFrames = 128;
81 return OK;
84 /*DEC_CLEANUPPROTO(CleanupG72x) {
85 struct ClassBase * libBase;
86 struct WAV_G72x_state * state;
87 libBase = data->libBase;
88 state = (struct WAV_G72x_state *)data->state;
89 FreeVec(state);
90 }*/
92 DECODERPROTO(DecodeG72x) {
93 struct WAV_G72x_state * state;
94 BitPack_buffer bp;
95 LONG fr, ch;
96 state = (struct WAV_G72x_state *)data->state;
97 bitpack_init(&bp, Src+((struct G72x_Format *)fmt)->auxSize, 0);
98 for (fr = 0; fr < numFrames; fr++) {
99 for (ch = 0; ch < fmt->numChannels; ch++) {
100 *Dst[ch]++ =
101 (state->decoder(bitpack_read_msb(&bp, fmt->bitsPerSample), &state->stat[ch]) >> 8);
104 return numFrames;