annotate libmpcodecs/ad_dk4adpcm.c @ 5408:f9cd6381e327

reworked ADPCM decoders; changes include: * fixed MS IMA ADPCM * dissolved adpcm.c/.h into appropriate ad_* decoders * DK4 audio is handled directly by IMA ADPCM decoder (this obsoletes ad_dk4adpcm.c)
author melanson
date Sat, 30 Mar 2002 22:27:45 +0000
parents a9f3df4ee465
children b3d1348b251f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
1 #include <stdio.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
2 #include <stdlib.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
3 #include <unistd.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
4
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
5 #include "config.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
6 #include "ad_internal.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
7
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
8 static ad_info_t info =
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
9 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
10 "Duck DK4 ADPCM (rogue format number) audio decoder",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
11 "dk4adpcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
12 AFM_DK4ADPCM,
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
13 "Nick Kurshev",
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
14 "Mike Melanson",
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
15 "This format number was used by Duck Corp. but not officially registered with Microsoft"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
16 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
17
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
18 LIBAD_EXTERN(dk4adpcm)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
19
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
20 #define DK4_ADPCM_PREAMBLE_SIZE 4
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
21
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
22 static int preinit(sh_audio_t *sh_audio)
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
23 {
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
24 sh_audio->audio_out_minsize =
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
25 (((sh_audio->wf->nBlockAlign - DK4_ADPCM_PREAMBLE_SIZE) * 2) + 1) * 4;
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
26 sh_audio->ds->ss_div =
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
27 ((sh_audio->wf->nBlockAlign - DK4_ADPCM_PREAMBLE_SIZE) * 2) + 1;
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
28 sh_audio->ds->ss_mul=sh_audio->wf->nBlockAlign;
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
29
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
30 return 1;
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
31 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
32
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
33 static int init(sh_audio_t *sh_audio)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
34 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
35 sh_audio->channels=sh_audio->wf->nChannels;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
36 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
37 sh_audio->i_bps = sh_audio->wf->nBlockAlign *
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
38 (sh_audio->channels*sh_audio->samplerate) /
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
39 (((sh_audio->wf->nBlockAlign - DK4_ADPCM_PREAMBLE_SIZE) * 2) + 1);
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
40
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
41 if ((sh_audio->a_in_buffer =
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
42 (unsigned char *)malloc(sh_audio->ds->ss_mul)) == NULL)
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
43 return 0;
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
44
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
45 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
46 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
47
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
48 static void uninit(sh_audio_t *sh_audio)
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
49 {
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
50 free(sh_audio->a_in_buffer);
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
51 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
52
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
53 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
54 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
55 // TODO!
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
56 return CONTROL_UNKNOWN;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
57 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
58
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
59 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
60 {
5353
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
61 if (demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
62 sh_audio->wf->nBlockAlign) !=
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
63 sh_audio->wf->nBlockAlign)
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
64 return -1; /* EOF */
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
65
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
66 return 2 * dk4_adpcm_decode_block((unsigned short*)buf,
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
67 sh_audio->a_in_buffer,
a9f3df4ee465 fixed up this audio decoder too
melanson
parents: 5340
diff changeset
68 sh_audio->wf->nChannels, sh_audio->wf->nBlockAlign);
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
69 }