2 * ao_arts - aRts audio output driver for MPlayer
4 * Michele Balistreri <brain87@gmx.net>
6 * This driver is distribuited under terms of GPL
14 #include "audio_out.h"
15 #include "audio_out_internal.h"
16 #include "libaf/af_format.h"
20 #define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
22 /* Feel free to experiment with the following values: */
23 #define ARTS_PACKETS 10 /* Number of audio packets */
24 #define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
26 static arts_stream_t stream
;
28 static ao_info_t info
=
32 "Michele Balistreri <brain87@gmx.net>",
38 static int control(int cmd
, void *arg
)
40 return(CONTROL_UNKNOWN
);
43 static int init(int rate_hz
, int channels
, int format
, int flags
)
48 if( (err
=arts_init()) ) {
49 mp_msg(MSGT_AO
, MSGL_ERR
, MSGTR_AO_ARTS_CantInit
, arts_error_text(err
));
52 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_ServerConnect
);
55 * arts supports 8bit unsigned and 16bit signed sample formats
56 * (16bit apparently in little endian format, even in the case
57 * when artsd runs on a big endian cpu).
59 * Unsupported formats are translated to one of these two formats
60 * using mplayer's audio filters.
65 format
= AF_FORMAT_U8
;
68 format
= AF_FORMAT_S16_LE
; /* artsd always expects little endian?*/
72 ao_data
.format
= format
;
73 ao_data
.channels
= channels
;
74 ao_data
.samplerate
= rate_hz
;
75 ao_data
.bps
= (rate_hz
*channels
);
77 if(format
!= AF_FORMAT_U8
&& format
!= AF_FORMAT_S8
)
80 stream
=arts_play_stream(rate_hz
, OBTAIN_BITRATE(format
), channels
, "MPlayer");
83 mp_msg(MSGT_AO
, MSGL_ERR
, MSGTR_AO_ARTS_CantOpenStream
);
88 /* Set the stream to blocking: it will not block anyway, but it seems */
89 /* to be working better */
90 arts_stream_set(stream
, ARTS_P_BLOCKING
, 1);
91 frag_spec
= ARTS_PACKET_SIZE_LOG2
| ARTS_PACKETS
<< 16;
92 arts_stream_set(stream
, ARTS_P_PACKET_SETTINGS
, frag_spec
);
93 ao_data
.buffersize
= arts_stream_get(stream
, ARTS_P_BUFFER_SIZE
);
94 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_StreamOpen
);
96 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_BufferSize
,
98 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_BufferSize
,
99 arts_stream_get(stream
, ARTS_P_PACKET_SIZE
));
104 static void uninit(int immed
)
106 arts_close_stream(stream
);
110 static int play(void* data
,int len
,int flags
)
112 return arts_write(stream
, data
, len
);
115 static void audio_pause(void)
119 static void audio_resume(void)
123 static void reset(void)
127 static int get_space(void)
129 return arts_stream_get(stream
, ARTS_P_BUFFER_SPACE
);
132 static float get_delay(void)
134 return ((float) (ao_data
.buffersize
- arts_stream_get(stream
,
135 ARTS_P_BUFFER_SPACE
))) / ((float) ao_data
.bps
);