annotate libao2/ao_oss.c @ 2437:de434f02dee6

more speed
author michael
date Wed, 24 Oct 2001 00:05:30 +0000
parents f91ad6d23ce9
children 981a9e5118ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
3
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include <sys/types.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8 #include <sys/stat.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
10 //#include <sys/soundcard.h>
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
11
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
12 #include "../config.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
14 #include "afmt.h"
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
15
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
16 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
17 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
18
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
19 extern int verbose;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
20
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
21 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
22 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
23 "OSS/ioctl audio output",
956
a6cecd9a1bad '-ao' switch (including '-ao help'), fixing Arpi's bug (short name 'null' for both of oss and null driver ;)
lgb
parents: 954
diff changeset
24 "oss",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
25 "A'rpi",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
26 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
27 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
28
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
29 LIBAO_EXTERN(oss)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
30
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
31 // there are some globals:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
32 // ao_samplerate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
33 // ao_channels
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
34 // ao_format
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
35 // ao_bps
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
36 // ao_outburst
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
37 // ao_buffersize
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
38
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
39 static char *dsp="/dev/dsp";
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
40 static audio_buf_info zz;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
41 static int audio_fd=-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
42
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
43 char *oss_mixer_device = "/dev/mixer";
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
44 int oss_mixer_usemaster = 0;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
45
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 // to set/get/query special features/parameters
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 static int control(int cmd,int arg){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48 switch(cmd){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 case AOCONTROL_SET_DEVICE:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
50 dsp=(char*)arg;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51 return CONTROL_OK;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
52 case AOCONTROL_QUERY_FORMAT:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
53 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
54 case AOCONTROL_GET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
55 case AOCONTROL_SET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
56 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
57 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
58 int fd, v, mcmd, devs;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
59
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
60 if(ao_format == AFMT_AC3)
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
61 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
62
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
63 if ((fd = open("/dev/mixer", O_RDONLY)) > 0)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
64 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
65 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
66 if ((devs & SOUND_MASK_PCM) && (oss_mixer_usemaster == 0))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
67 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
68 mcmd = SOUND_MIXER_READ_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
69 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
70 mcmd = SOUND_MIXER_WRITE_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
71 else if ((devs & SOUND_MASK_VOLUME) && (oss_mixer_usemaster == 1))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
72 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
73 mcmd = SOUND_MIXER_READ_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
74 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
75 mcmd = SOUND_MIXER_WRITE_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
76 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
77 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
78 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
79 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
80 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
81
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
82 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
83 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
84 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
85 vol->right = (v & 0xFF00) >> 8;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
86 vol->left = v & 0x00FF;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
87 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
88 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
89 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
90 v = ((int)vol->right << 8) | (int)vol->left;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
91 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
92 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
93 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
94 return CONTROL_OK;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
95 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
96 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
97 return CONTROL_ERROR;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
98 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
99 return CONTROL_UNKNOWN;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
100 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
101
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
102 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
103 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
104 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
105
1456
8c57a5a3c645 printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents: 1191
diff changeset
106 // printf("ao2: %d Hz %d chans %s\n",rate,channels,
8c57a5a3c645 printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents: 1191
diff changeset
107 // audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
108
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
109 if (ao_subdevice)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
110 dsp = ao_subdevice;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
111
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
112 if (verbose)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
113 printf("audio_setup: using '%s' dsp device\n", dsp);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
114
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
115 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
116 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
117 printf("Can't open audio device %s -> nosound\n",dsp);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
118 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
119 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
120
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
121 ao_format=format;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
122 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
123 if(format == AFMT_AC3 && ao_format != AFMT_AC3) {
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
124 printf("Can't set audio device %s to AC3 output\n", dsp);
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
125 return 0;
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
126 }
1079
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
127 printf("audio_setup: sample format: %s (requested: %s)\n",
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
128 audio_out_format_name(ao_format), audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
129
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
130 if(format != AFMT_AC3) {
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
131 ao_channels=channels-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
132 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
133
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
134 // set rate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
135 ao_samplerate=rate;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
136 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
137 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
138 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
139
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
140 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
141 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
142 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
143 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
144 printf("audio_setup: %d bytes/frag (config.h)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
145 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
146 ao_outburst=r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
147 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
148 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
149 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
150 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
151 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
152 if(ao_buffersize==-1) ao_buffersize=zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
153 ao_outburst=zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
154 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
155
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
156 if(ao_buffersize==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
157 // Measuring buffer size:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
158 void* data;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
159 ao_buffersize=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
160 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
161 data=malloc(ao_outburst); memset(data,0,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
162 while(ao_buffersize<0x40000){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
163 fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
164 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
165 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
166 tv.tv_sec=0; tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
167 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
168 write(audio_fd,data,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
169 ao_buffersize+=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
170 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
171 free(data);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
172 if(ao_buffersize==0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
173 printf("\n *** Your audio driver DOES NOT support select() ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
174 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
175 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
176 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
177 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
178 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
179
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
180 return 1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
181 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
182
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
183 // close audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
184 static void uninit(){
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
185 #ifdef SNDCTL_DSP_RESET
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
186 ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
187 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
188 close(audio_fd);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
189 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
190
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
191 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
192 static void reset(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
193 uninit();
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
194 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
195 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
196 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
197 return;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
198 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
199
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
200 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
201 if(ao_format != AFMT_AC3) {
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
202 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
203 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
204 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
205 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
206
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
207 // stop playing, keep buffers (for pause)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
208 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
209 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
210 // for now, just call reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
211 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
212 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
213
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
214 // resume playing, after audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
215 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
216 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
217 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
218
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
219
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
220 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
221 static int get_space(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
222 int playsize=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
223
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
224 #ifdef SNDCTL_DSP_GETOSPACE
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
225 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
226 // calculate exact buffer space:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
227 return zz.fragments*zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
228 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
229 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
230
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
231 // check buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
232 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
233 { fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
234 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
235 FD_ZERO(&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
236 FD_SET(audio_fd, &rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
237 tv.tv_sec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
238 tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
239 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
240 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
241 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
242
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
243 return ao_outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
244 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
245
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
246 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
247 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
248 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
249 static int play(void* data,int len,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
250 len/=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
251 len=write(audio_fd,data,len*ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
252 return len;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
253 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
254
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
255 static int audio_delay_method=2;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
256
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
257 // return: how many unplayed bytes are in the buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
258 static int get_delay(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
259 if(audio_delay_method==2){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
260 //
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
261 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
262 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
263 return r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
264 audio_delay_method=1; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
265 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
266 if(audio_delay_method==1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
267 // SNDCTL_DSP_GETOSPACE
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
268 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
269 return ao_buffersize-zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
270 audio_delay_method=0; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
271 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
272 return ao_buffersize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
273 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
274