Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / wav / wave_gsm610.c
bloba0c703c90dd8c834066a1b2e5a2aadec3cdc5bfe
1 /*
2 * wave.datatype
3 * (c) Fredrik Wikstrom
4 */
6 #include "wave_gsm610.h"
7 #include "gsm/private.h"
9 struct GSM610_Format {
10 UWORD formatTag;
11 WORD numChannels;
12 LONG samplesPerSec;
13 LONG avgBytesPerSec;
14 WORD blockAlign; /* amount to read for each block */
15 WORD bitsPerSample;
17 WORD extraSize; /* 2 */
18 WORD samplesPerBlock;
21 struct gsmstate {
22 gsm handle;
23 gsm_signal *samples;
26 DEC_SETUPPROTO(SetupGSM610) {
27 //int valP = 1;
28 struct GSM610_Format * fmt;
29 struct gsmstate * state;
31 fmt = (struct GSM610_Format *)data->fmt;
33 if (fmt->numChannels != 1)
34 return ERROR_NOT_IMPLEMENTED;
36 data->state = state = AllocVec(sizeof(*state), MEMF_CLEAR);
37 if (!state) return ERROR_NO_FREE_STORE;
39 // state->handle = gsm_create();
40 state->handle = (gsm)AllocMem(sizeof(struct gsm_state), MEMF_CLEAR);
41 if (!state->handle)
42 return ERROR_NO_FREE_STORE;
43 state->handle->nrp=40;
45 // gsm_option(state->handle, GSM_OPT_WAV49, &valP);
46 state->handle->wav_fmt = TRUE;
48 fmt->blockAlign = 65;
49 if (fmt->extraSize == 0 || fmt->samplesPerBlock == 0)
50 data->blockFrames = 320;
51 else if (fmt->extraSize == 2)
52 data->blockFrames = read_le16(&fmt->samplesPerBlock);
53 else
54 return NOTOK;
56 state->samples = AllocVec(2*data->blockFrames, MEMF_CLEAR);
57 if (!state->samples)
58 return ERROR_NO_FREE_STORE;
60 return OK;
63 DEC_CLEANUPPROTO(CleanupGSM610) {
64 struct gsmstate * state;
66 state = (struct gsmstate *)data->state;
68 FreeVec(state->samples);
70 // gsm_destroy(state->handle);
71 if (state->handle) FreeMem(state->handle, sizeof(struct gsm_state));
73 FreeVec(state);
76 DECODERPROTO(DecodeGSM610) {
77 struct gsmstate * state;
78 gsm_signal *buff;
79 LONG ch, fr;
80 state = (struct gsmstate *)data->state;
82 for (ch = 0; ch < fmt->numChannels; ch++) {
83 /* decode the long 33 byte half */
84 if (gsm_decode(state->handle, Src, state->samples) < 0) {
85 return 0;
87 /* decode the short 32 byte half */
88 if (gsm_decode(state->handle, Src+33, state->samples+160) < 0) {
89 return 0;
91 buff = state->samples;
92 for (fr = 0; fr < numFrames; fr++) {
93 *Dst[ch]++ = (*buff++)>> 8;
97 return numFrames;