5345
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <unistd.h>
|
|
4
|
|
5 #include "config.h"
|
|
6 #include "ad_internal.h"
|
|
7
|
|
8 static ad_info_t info =
|
|
9 {
|
7410
|
10 "native GSM/MSGSM audio decoder",
|
5345
|
11 "msgsm",
|
|
12 "A'rpi",
|
|
13 "XAnim",
|
|
14 ""
|
|
15 };
|
|
16
|
|
17 LIBAD_EXTERN(msgsm)
|
|
18
|
5603
|
19 #include "xa_gsm.h"
|
5345
|
20
|
|
21 static int init(sh_audio_t *sh_audio)
|
|
22 {
|
|
23 if(!sh_audio->wf) return 0;
|
|
24 // MS-GSM audio codec:
|
|
25 GSM_Init();
|
|
26 sh_audio->channels=sh_audio->wf->nChannels;
|
|
27 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
|
|
28 // decodes 65 byte -> 320 short
|
|
29 // 1 sec: sh_audio->channels*sh_audio->samplerate samples
|
|
30 // 1 frame: 320 samples
|
7410
|
31 if(sh_audio->format==0x31 || sh_audio->format==0x32){
|
|
32 sh_audio->ds->ss_mul=65; sh_audio->ds->ss_div=320;
|
|
33 } else {
|
|
34 sh_audio->ds->ss_mul=33; sh_audio->ds->ss_div=160;
|
|
35 }
|
|
36 sh_audio->i_bps=sh_audio->ds->ss_mul*(sh_audio->channels*sh_audio->samplerate)/sh_audio->ds->ss_div; // 1:10
|
5345
|
37 return 1;
|
|
38 }
|
|
39
|
|
40 static int preinit(sh_audio_t *sh_audio)
|
|
41 {
|
|
42 sh_audio->audio_out_minsize=4*320;
|
|
43 return 1;
|
|
44 }
|
|
45
|
|
46 static void uninit(sh_audio_t *sh)
|
|
47 {
|
|
48 }
|
|
49
|
|
50 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
|
|
51 {
|
|
52 return CONTROL_UNKNOWN;
|
|
53 }
|
|
54
|
|
55 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
|
|
56 {
|
7410
|
57 if(sh_audio->format==0x31 || sh_audio->format==0x32){
|
5345
|
58 unsigned char ibuf[65]; // 65 bytes / frame
|
|
59 if(demux_read_data(sh_audio->ds,ibuf,65)!=65) return -1; // EOF
|
|
60 XA_MSGSM_Decoder(ibuf,(unsigned short *) buf); // decodes 65 byte -> 320 short
|
|
61 return 2*320;
|
7410
|
62 } else {
|
|
63 unsigned char ibuf[33]; // 33 bytes / frame
|
|
64 if(demux_read_data(sh_audio->ds,ibuf,33)!=33) return -1; // EOF
|
|
65 XA_GSM_Decoder(ibuf,(unsigned short *) buf); // decodes 33 byte -> 160 short
|
|
66 return 2*160;
|
|
67 }
|
5345
|
68 }
|