1 // SAMPLE audio decoder - you can use this file as template when creating new codec!
8 #include "ad_internal.h"
10 static ad_info_t info
= {
11 "RealAudio 1.0 and 2.0 native decoder",
14 "http://www.honeypot.net/audio",
15 "Decoders taken from a public domain Amiga player"
20 #include "native/common1428.h"
24 static int preinit(sh_audio_t
*sh
) {
25 sh
->samplerate
=sh
->wf
->nSamplesPerSec
;
26 sh
->samplesize
=sh
->wf
->wBitsPerSample
/8;
27 sh
->channels
=sh
->wf
->nChannels
;
28 sh
->sample_format
=AFMT_S16_LE
;
31 case mmioFOURCC('1','4','_','4'):
32 mp_msg(MSGT_DECAUDIO
,MSGL_INFO
,"[ra1428] RealAudio 1.0 (14_4)\n");
35 case mmioFOURCC('2','8','_','8'):
36 mp_msg(MSGT_DECAUDIO
,MSGL_INFO
,"[ra1428] RealAudio 2.0 (28_8)\n");
40 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,"[ra1428] Unhandled format in preinit: %x\n", sh
->format
);
44 sh
->audio_out_minsize
=128000; // no idea how to get... :(
45 sh
->audio_in_minsize
=((short*)(sh
->wf
+1))[1]*sh
->wf
->nBlockAlign
;
47 return 1; // return values: 1=OK 0=ERROR
52 static int init(sh_audio_t
*sh
) {
54 case mmioFOURCC('1','4','_','4'):
55 sh
->context
= init_144();
57 case mmioFOURCC('2','8','_','8'):
58 sh
->context
= init_288();
61 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,"[ra1428] Unhandled format in init: %x\n", sh
->format
);
65 return 1; // return values: 1=OK 0=ERROR
70 static void uninit(sh_audio_t
*sh
) {
72 case mmioFOURCC('1','4','_','4'):
73 free_144((Real_144
*)sh
->context
);
75 case mmioFOURCC('2','8','_','8'):
76 free_288((Real_288
*)sh
->context
);
79 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,"[ra1428] Unhandled format in uninit: %x\n", sh
->format
);
86 static int decode_audio(sh_audio_t
*sh
,unsigned char *buf
,int minlen
,int maxlen
) {
87 int w
=sh
->wf
->nBlockAlign
;
88 int h
=((short*)(sh
->wf
+1))[1];
89 int cfs
=((short*)(sh
->wf
+1))[3];
92 if(sh
->a_in_buffer_len
<=0){
94 case mmioFOURCC('1','4','_','4'):
95 demux_read_data(sh
->ds
, sh
->a_in_buffer
, sh
->wf
->nBlockAlign
);
97 sh
->a_in_buffer_len
=sh
->wf
->nBlockAlign
;
99 case mmioFOURCC('2','8','_','8'):
100 for (j
= 0; j
< h
; j
++)
101 for (i
= 0; i
< h
/2; i
++)
102 demux_read_data(sh
->ds
, sh
->a_in_buffer
+i
*2*w
+j
*cfs
, cfs
);
103 sh
->a_in_buffer_size
=
104 sh
->a_in_buffer_len
=sh
->wf
->nBlockAlign
*h
;
107 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,"[ra1428] Unhandled format in decode_audio: %x\n", sh
->format
);
112 switch (sh
->format
) {
113 case mmioFOURCC('1','4','_','4'):
114 decode_144((Real_144
*)sh
->context
,sh
->a_in_buffer
+sh
->a_in_buffer_size
-sh
->a_in_buffer_len
,(signed short*)buf
);
116 case mmioFOURCC('2','8','_','8'):
117 decode_288((Real_288
*)sh
->context
,sh
->a_in_buffer
+sh
->a_in_buffer_size
-sh
->a_in_buffer_len
,(signed short*)buf
);
120 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,"[ra1428] Unhandled format in init: %x\n", sh
->format
);
124 sh
->a_in_buffer_len
-=cfs
;
126 return AUDIOBLOCK
*2; // return value: number of _bytes_ written to output buffer,
127 // or -1 for EOF (or uncorrectable error)
130 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...){
131 // various optional functions you MAY implement:
133 case ADCTRL_RESYNC_STREAM
:
134 // it is called once after seeking, to resync.
135 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call!
138 case ADCTRL_SKIP_FRAME
:
139 // it is called to skip (jump over) small amount (1/10 sec or 1 frame)
140 // of audio data - used to sync audio to video after seeking
141 // if you don't return CONTROL_TRUE, it will defaults to:
142 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet
146 return CONTROL_UNKNOWN
;