vo_corevideo.m: remote useless parentheses and casts
[mplayer/glamo.git] / libao2 / ao_arts.c
blobd828e7953e779253d06109e8e79a28f91a90ad6a
1 /*
2 * aRts audio output driver for MPlayer
4 * copyright (c) 2002 Michele Balistreri <brain87@gmx.net>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <artsc.h>
24 #include <stdio.h>
26 #include "config.h"
27 #include "audio_out.h"
28 #include "audio_out_internal.h"
29 #include "libaf/af_format.h"
30 #include "mp_msg.h"
32 #define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
34 /* Feel free to experiment with the following values: */
35 #define ARTS_PACKETS 10 /* Number of audio packets */
36 #define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
38 static arts_stream_t stream;
40 static const ao_info_t info =
42 "aRts audio output",
43 "arts",
44 "Michele Balistreri <brain87@gmx.net>",
48 LIBAO_EXTERN(arts)
50 static int control(int cmd, void *arg)
52 return CONTROL_UNKNOWN;
55 static int init(int rate_hz, int channels, int format, int flags)
57 int err;
58 int frag_spec;
60 if( (err=arts_init()) ) {
61 mp_tmsg(MSGT_AO, MSGL_ERR, "[AO ARTS] %s\n", arts_error_text(err));
62 return 0;
64 mp_tmsg(MSGT_AO, MSGL_INFO, "[AO ARTS] Connected to sound server.\n");
67 * arts supports 8bit unsigned and 16bit signed sample formats
68 * (16bit apparently in little endian format, even in the case
69 * when artsd runs on a big endian cpu).
71 * Unsupported formats are translated to one of these two formats
72 * using mplayer's audio filters.
74 switch (format) {
75 case AF_FORMAT_U8:
76 case AF_FORMAT_S8:
77 format = AF_FORMAT_U8;
78 break;
79 default:
80 format = AF_FORMAT_S16_LE; /* artsd always expects little endian?*/
81 break;
84 ao_data.format = format;
85 ao_data.channels = channels;
86 ao_data.samplerate = rate_hz;
87 ao_data.bps = (rate_hz*channels);
89 if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
90 ao_data.bps*=2;
92 stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "MPlayer");
94 if(stream == NULL) {
95 mp_tmsg(MSGT_AO, MSGL_ERR, "[AO ARTS] Unable to open a stream.\n");
96 arts_free();
97 return 0;
100 /* Set the stream to blocking: it will not block anyway, but it seems */
101 /* to be working better */
102 arts_stream_set(stream, ARTS_P_BLOCKING, 1);
103 frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
104 arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
105 ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
106 mp_tmsg(MSGT_AO, MSGL_INFO, "[AO ARTS] Stream opened.\n");
108 mp_tmsg(MSGT_AO, MSGL_INFO, "[AO ARTS] buffer size: %d\n",
109 ao_data.buffersize);
110 mp_tmsg(MSGT_AO, MSGL_INFO, "[AO ARTS] buffer size: %d\n",
111 arts_stream_get(stream, ARTS_P_PACKET_SIZE));
113 return 1;
116 static void uninit(int immed)
118 arts_close_stream(stream);
119 arts_free();
122 static int play(void* data,int len,int flags)
124 return arts_write(stream, data, len);
127 static void audio_pause(void)
131 static void audio_resume(void)
135 static void reset(void)
139 static int get_space(void)
141 return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
144 static float get_delay(void)
146 return ((float) (ao_data.buffersize - arts_stream_get(stream,
147 ARTS_P_BUFFER_SPACE))) / ((float) ao_data.bps);