fix bug when bmovl can't read the whole pic at once
[mplayer/glamo.git] / libao2 / ao_sgi.c
blob77f694a3c774165d44bad8fa9762ff3883cca2ca
1 /*
2 ao_sgi - sgi/irix output plugin for MPlayer
4 22oct2001 oliver.schoenbrunner@jku.at
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <dmedia/audio.h>
12 #include "audio_out.h"
13 #include "audio_out_internal.h"
15 static ao_info_t info =
17 "sgi audio output",
18 "sgi",
19 "kopflos",
23 LIBAO_EXTERN(sgi)
26 static ALconfig ao_config;
27 static ALport ao_port;
28 static int sample_rate;
29 static int queue_size;
31 // to set/get/query special features/parameters
32 static int control(int cmd, void *arg){
34 printf("ao_sgi, control\n");
36 return -1;
39 // open & setup audio device
40 // return: 1=success 0=fail
41 static int init(int rate, int channels, int format, int flags) {
43 printf("ao_sgi, init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
45 { /* from /usr/share/src/dmedia/audio/setrate.c */
47 int fd;
48 int rv;
49 double frate;
50 ALpv x[2];
52 rv = alGetResourceByName(AL_SYSTEM, "out.analog", AL_DEVICE_TYPE);
53 if (!rv) {
54 printf("ao_sgi, play: invalid device\n");
55 return 0;
58 frate = rate;
60 x[0].param = AL_RATE;
61 x[0].value.ll = alDoubleToFixed(rate);
62 x[1].param = AL_MASTER_CLOCK;
63 x[1].value.i = AL_CRYSTAL_MCLK_TYPE;
65 if (alSetParams(rv,x, 2)<0) {
66 printf("ao_sgi, init: setparams failed: %s\n", alGetErrorString(oserror()));
67 printf("ao_sgi, init: could not set desired samplerate\n");
70 if (x[0].sizeOut < 0) {
71 printf("ao_sgi, init: AL_RATE was not accepted on the given resource\n");
74 if (alGetParams(rv,x, 1)<0) {
75 printf("ao_sgi, init: getparams failed: %s\n", alGetErrorString(oserror()));
78 if (frate != alFixedToDouble(x[0].value.ll)) {
79 printf("ao_sgi, init: samplerate is now %lf (desired rate is %lf)\n", alFixedToDouble(x[0].value.ll), frate);
81 sample_rate = (int)frate;
84 ao_data.buffersize=131072;
85 ao_data.outburst = ao_data.buffersize/16;
86 ao_data.channels = channels;
88 ao_config = alNewConfig();
90 if (!ao_config) {
91 printf("ao_sgi, init: %s\n", alGetErrorString(oserror()));
92 return 0;
95 if(channels == 2) alSetChannels(ao_config, AL_STEREO);
96 else alSetChannels(ao_config, AL_MONO);
98 alSetWidth(ao_config, AL_SAMPLE_16);
99 alSetSampFmt(ao_config, AL_SAMPFMT_TWOSCOMP);
100 alSetQueueSize(ao_config, 48000);
102 if (alSetDevice(ao_config, AL_DEFAULT_OUTPUT) < 0) {
103 printf("ao_sgi, init: %s\n", alGetErrorString(oserror()));
104 return 0;
107 ao_port = alOpenPort("mplayer", "w", ao_config);
109 if (!ao_port) {
110 printf("ao_sgi, init: Unable to open audio channel: %s\n", alGetErrorString(oserror()));
111 return 0;
114 // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
115 queue_size = alGetQueueSize(ao_config);
116 return 1;
120 // close audio device
121 static void uninit() {
123 /* TODO: samplerate should be set back to the value before mplayer was started! */
125 printf("ao_sgi, uninit: ...\n");
127 if (ao_port) {
128 while(alGetFilled(ao_port) > 0) sginap(1);
129 alClosePort(ao_port);
130 alFreeConfig(ao_config);
135 // stop playing and empty buffers (for seeking/pause)
136 static void reset() {
138 printf("ao_sgi, reset: ...\n");
142 // stop playing, keep buffers (for pause)
143 static void audio_pause() {
145 printf("ao_sgi, audio_pause: ...\n");
149 // resume playing, after audio_pause()
150 static void audio_resume() {
152 printf("ao_sgi, audio_resume: ...\n");
156 // return: how many bytes can be played without blocking
157 static int get_space() {
159 // printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_outburst);
160 // printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port));
162 return alGetFillable(ao_port)*(2*ao_data.channels);
167 // plays 'len' bytes of 'data'
168 // it should round it down to outburst*n
169 // return: number of bytes played
170 static int play(void* data, int len, int flags) {
172 // printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config);
173 // printf("channels %d\n", ao_channels);
175 alWriteFrames(ao_port, data, len/(2*ao_data.channels));
177 return len;
181 // return: delay in seconds between first and last sample in buffer
182 static float get_delay(){
184 // printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize);
186 //return 0;
187 return (float)queue_size/((float)sample_rate);