annotate libao2/ao_sun.c @ 1041:4b3b2bf1c82b

SUN-Solaris audio out
author arpi_esp
date Wed, 06 Jun 2001 19:10:47 +0000
parents
children cab5ba9ffc6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1041
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
3
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
7 #include <sys/types.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
8 #include <sys/stat.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
10 #include <sys/audioio.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
11 #ifdef __svr4__
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
12 #include <stropts.h>
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
13 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
14
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
15 #include "../config.h"
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
16
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
17 #include "audio_out.h"
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
18 #include "audio_out_internal.h"
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
19
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
20 static ao_info_t info =
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
21 {
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
22 "Sun audio output",
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
23 "sun",
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
24 "jk@tools.de",
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
25 ""
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
26 };
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
27
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
28 LIBAO_EXTERN(sun)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
29
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
30
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
31 #ifndef AUDIO_PRECISION_8
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
32 #define AUDIO_PRECISION_8 8
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
33 #define AUDIO_PRECISION_16 16
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
34 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
35
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
36
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
37 // there are some globals:
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
38 // ao_samplerate
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
39 // ao_channels
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
40 // ao_format
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
41 // ao_bps
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
42 // ao_outburst
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
43 // ao_buffersize
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
44
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
45 static char *dsp="/dev/audio";
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
46 static int queued_bursts = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
47 static int audio_fd=-1;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
48
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
49 // to set/get/query special features/parameters
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
50 static int control(int cmd,int arg){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
51 switch(cmd){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
52 case AOCONTROL_SET_DEVICE:
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
53 dsp=(char*)arg;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
54 return CONTROL_OK;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
55 case AOCONTROL_QUERY_FORMAT:
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
56 return CONTROL_TRUE;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
57 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
58 return CONTROL_UNKNOWN;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
59 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
60
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
61 // open & setup audio device
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
62 // return: 1=success 0=fail
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
63 static int init(int rate,int channels,int format,int flags){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
64
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
65 audio_info_t info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
66 int byte_per_sec;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
67
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
68 printf("ao2: %d Hz %d chans 0x%X\n",rate,channels,format);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
69
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
70 audio_fd=open(dsp, O_WRONLY);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
71 if(audio_fd<0){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
72 printf("Can't open audio device %s -> nosound\n",dsp);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
73 return 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
74 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
75
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
76 ioctl(audio_fd, AUDIO_DRAIN, 0);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
77
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
78 AUDIO_INITINFO(&info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
79 info.play.encoding = ao_format = format;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
80 info.play.precision = (format==AUDIO_ENCODING_LINEAR? AUDIO_PRECISION_16:AUDIO_PRECISION_8);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
81 info.play.channels = ao_channels = channels;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
82 --ao_channels;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
83 info.play.sample_rate = ao_samplerate = rate;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
84 info.play.samples = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
85 info.play.eof = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
86 if(ioctl (audio_fd, AUDIO_SETINFO, &info)<0)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
87 printf("audio_setup: your card doesn't support %d Hz samplerate\n",rate);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
88 byte_per_sec = (channels
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
89 * (format==AUDIO_ENCODING_LINEAR ? 16 : 8)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
90 * rate);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
91 ao_outburst=byte_per_sec > 100000 ? 16384 : 8192;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
92 queued_bursts = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
93
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
94 if(ao_buffersize==-1){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
95 // Measuring buffer size:
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
96 void* data;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
97 ao_buffersize=0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
98 #ifdef HAVE_AUDIO_SELECT
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
99 data=malloc(ao_outburst); memset(data,0,ao_outburst);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
100 while(ao_buffersize<0x40000){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
101 fd_set rfds;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
102 struct timeval tv;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
103 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
104 tv.tv_sec=0; tv.tv_usec = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
105 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
106 write(audio_fd,data,ao_outburst);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
107 ao_buffersize+=ao_outburst;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
108 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
109 free(data);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
110 if(ao_buffersize==0){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
111 printf("\n *** Your audio driver DOES NOT support select() ***\n");
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
112 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
113 return 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
114 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
115 #ifdef __svr4__
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
116 ioctl(audio_fd, I_FLUSH, FLUSHW);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
117 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
118 ioctl(audio_fd, AUDIO_DRAIN, 0);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
119 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
120 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
121
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
122 return 1;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
123 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
124
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
125 // close audio device
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
126 static void uninit(){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
127 close(audio_fd);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
128 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
129
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
130 // stop playing and empty buffers (for seeking/pause)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
131 static void reset(){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
132 audio_info_t info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
133
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
134 #ifdef __svr4__
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
135 ioctl(audio_fd, I_FLUSH, FLUSHW);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
136 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
137 uninit();
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
138 audio_fd=open(dsp, O_WRONLY);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
139 if(audio_fd<0){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
140 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
141 return;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
142 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
143
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
144 ioctl(audio_fd, AUDIO_DRAIN, 0);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
145
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
146 AUDIO_INITINFO(&info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
147 info.play.encoding = ao_format;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
148 info.play.precision = (ao_format==AUDIO_ENCODING_LINEAR? AUDIO_PRECISION_16:AUDIO_PRECISION_8);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
149 info.play.channels = ao_channels+1;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
150 info.play.sample_rate = ao_samplerate;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
151 info.play.samples = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
152 info.play.eof = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
153 ioctl (audio_fd, AUDIO_SETINFO, &info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
154 queued_bursts = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
155 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
156
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
157 // stop playing, keep buffers (for pause)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
158 static void audio_pause()
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
159 {
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
160 struct audio_info info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
161 AUDIO_INITINFO(&info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
162 info.play.pause = 1;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
163 ioctl(audio_fd, AUDIO_SETINFO, &info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
164 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
165
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
166 // resume playing, after audio_pause()
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
167 static void audio_resume()
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
168 {
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
169 struct audio_info info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
170 AUDIO_INITINFO(&info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
171 info.play.pause = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
172 ioctl(audio_fd, AUDIO_SETINFO, &info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
173 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
174
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
175
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
176 // return: how many bytes can be played without blocking
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
177 static int get_space(){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
178 int playsize=ao_outburst;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
179
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
180 // check buffer
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
181 #ifdef HAVE_AUDIO_SELECT
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
182 { fd_set rfds;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
183 struct timeval tv;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
184 FD_ZERO(&rfds);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
185 FD_SET(audio_fd, &rfds);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
186 tv.tv_sec = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
187 tv.tv_usec = 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
188 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
189 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
190 #endif
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
191
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
192 {
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
193 audio_info_t info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
194 ioctl(audio_fd, AUDIO_GETINFO, &info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
195 if(queued_bursts - info.play.eof > 2)
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
196 return 0;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
197 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
198 return ao_outburst;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
199 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
200
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
201 // plays 'len' bytes of 'data'
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
202 // it should round it down to outburst*n
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
203 // return: number of bytes played
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
204 static int play(void* data,int len,int flags){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
205 len/=ao_outburst;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
206 len=write(audio_fd,data,len*ao_outburst);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
207 if(len>0) {
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
208 queued_bursts ++;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
209 write(audio_fd,data,0);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
210 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
211 return len;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
212 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
213
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
214 static int audio_delay_method=2;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
215
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
216 // return: how many unplayed bytes are in the buffer
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
217 static int get_delay(){
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
218 int q;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
219 audio_info_t info;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
220 ioctl(audio_fd, AUDIO_GETINFO, &info);
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
221 return (queued_bursts - info.play.eof) * ao_outburst;
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
222 }
4b3b2bf1c82b SUN-Solaris audio out
arpi_esp
parents:
diff changeset
223