10 #include "libavutil/common.h"
13 #include "audio_out.h"
14 #include "audio_out_internal.h"
15 #include "libaf/af_format.h"
16 #include "libmpdemux/mpeg_packetizer.h"
19 static ao_info_t info
=
23 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
30 static int last_freq_id
= -1;
33 // to set/get/query special features/parameters
34 static int control(int cmd
,void *arg
){
36 case AOCONTROL_GET_VOLUME
:
38 ao_control_vol_t
* vol
= (ao_control_vol_t
*)arg
;
39 vol
->left
= vol
->right
= volume
* 19.0 / 100.0;
43 case AOCONTROL_SET_VOLUME
:
47 ao_control_vol_t
* vol
= (ao_control_vol_t
*)arg
;
48 // We need this trick because the volume stepping is often too small
49 diff
= ((vol
->left
+vol
->right
) / 2 - (volume
*19.0/100.0)) * 19.0 / 100.0;
50 v
.arg
= volume
+ (diff
> 0 ? ceil(diff
) : floor(diff
));
51 if(v
.arg
> 19) v
.arg
= 19;
52 if(v
.arg
< 0) v
.arg
= 0;
55 if( ioctl(dxr2_fd
,DXR2_IOC_SET_AUDIO_VOLUME
,&v
) < 0) {
56 mp_msg(MSGT_AO
,MSGL_ERR
,MSGTR_AO_DXR2_SetVolFailed
,volume
);
64 return CONTROL_UNKNOWN
;
70 // open & setup audio device
71 // return: 1=success 0=fail
72 static int init(int rate
,int channels
,int format
,int flags
){
79 ao_data
.outburst
=2048;
80 ao_data
.samplerate
=rate
;
81 ao_data
.channels
=channels
;
82 ao_data
.buffersize
=2048;
84 ao_data
.format
=format
;
89 freq_id
=DXR2_AUDIO_FREQ_48
;
92 freq_id
=DXR2_AUDIO_FREQ_96
;
95 freq_id
=DXR2_AUDIO_FREQ_441
;
98 freq_id
=DXR2_AUDIO_FREQ_32
;
101 freq_id
=DXR2_AUDIO_FREQ_2205
;
103 #ifdef DXR2_AUDIO_FREQ_24
104 // This is not yet in the dxr2 driver CVS
105 // you can get the patch at
106 // http://www.tdiedrich.de/~ranma/patches/dxr2.pcm1723.20020513
108 freq_id
=DXR2_AUDIO_FREQ_24
;
111 freq_id
=DXR2_AUDIO_FREQ_64
;
114 freq_id
=DXR2_AUDIO_FREQ_882
;
118 mp_msg(MSGT_AO
,MSGL_ERR
,MSGTR_AO_DXR2_UnsupSamplerate
,rate
);
125 // close audio device
126 static void uninit(int immed
){
130 // stop playing and empty buffers (for seeking/pause)
131 static void reset(void){
135 // stop playing, keep buffers (for pause)
136 static void audio_pause(void)
138 // for now, just call reset();
142 // resume playing, after audio_pause()
143 static void audio_resume(void)
148 // return: how many bytes can be played without blocking
149 static int get_space(void){
150 float x
=(float)(vo_pts
-ao_data
.pts
)/90000.0;
153 y
=freq
*4*x
;y
/=ao_data
.outburst
;y
*=ao_data
.outburst
;
158 static void dxr2_send_lpcm_packet(unsigned char* data
,int len
,int id
,unsigned int timestamp
,int freq_id
)
160 extern int write_dxr2(const unsigned char *data
, int len
);
163 mp_msg(MSGT_AO
,MSGL_ERR
,"DXR2 fd is not valid\n");
167 if(last_freq_id
!= freq_id
) {
168 ioctl(dxr2_fd
, DXR2_IOC_SET_AUDIO_SAMPLE_FREQUENCY
, &freq_id
);
169 last_freq_id
= freq_id
;
172 send_mpeg_lpcm_packet (data
, len
, id
, timestamp
, freq_id
, write_dxr2
);
175 // plays 'len' bytes of 'data'
176 // it should round it down to outburst*n
177 // return: number of bytes played
178 static int play(void* data
,int len
,int flags
){
179 extern int write_dxr2(const unsigned char *data
, int len
);
181 // MPEG and AC3 don't work :-(
182 if(ao_data
.format
==AF_FORMAT_MPEG2
)
183 send_mpeg_ps_packet (data
, len
, 0xC0, ao_data
.pts
, 2, write_dxr2
);
184 else if(ao_data
.format
==AF_FORMAT_AC3
)
185 send_mpeg_ps_packet (data
, len
, 0x80, ao_data
.pts
, 2, write_dxr2
);
188 //unsigned short *s=data;
190 #ifndef WORDS_BIGENDIAN
191 for(i
=0;i
<len
/2;i
++) s
[i
] = bswap_16(s
[i
]);
193 dxr2_send_lpcm_packet(data
,len
,0xA0,ao_data
.pts
-10000,freq_id
);
198 // return: delay in seconds between first and last sample in buffer
199 static float get_delay(void){