Mercurial > mplayer.hg
annotate libao2/ao_sgi.c @ 13016:61d0fd8411cc
Missing quotes added
author | wight |
---|---|
date | Fri, 13 Aug 2004 17:12:45 +0000 |
parents | 99798c3cdb93 |
children | c1955840883d |
rev | line source |
---|---|
2451 | 1 /* |
2 ao_sgi - sgi/irix output plugin for MPlayer | |
3 | |
4 22oct2001 oliver.schoenbrunner@jku.at | |
5 | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <dmedia/audio.h> | |
11 | |
12 #include "audio_out.h" | |
13 #include "audio_out_internal.h" | |
14 | |
15 static ao_info_t info = | |
16 { | |
17 "sgi audio output", | |
18 "sgi", | |
19 "kopflos", | |
20 "" | |
21 }; | |
22 | |
23 LIBAO_EXTERN(sgi) | |
24 | |
25 | |
26 static ALconfig ao_config; | |
27 static ALport ao_port; | |
11323 | 28 static int sample_rate; |
29 static int queue_size; | |
2451 | 30 |
31 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
3095
diff
changeset
|
32 static int control(int cmd, void *arg){ |
2451 | 33 |
34 printf("ao_sgi, control\n"); | |
35 | |
36 return -1; | |
37 } | |
38 | |
39 // open & setup audio device | |
40 // return: 1=success 0=fail | |
41 static int init(int rate, int channels, int format, int flags) { | |
42 | |
43 printf("ao_sgi, init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); | |
44 | |
45 { /* from /usr/share/src/dmedia/audio/setrate.c */ | |
46 | |
47 int fd; | |
48 int rv; | |
49 double frate; | |
50 ALpv x[2]; | |
51 | |
52 rv = alGetResourceByName(AL_SYSTEM, "out.analog", AL_DEVICE_TYPE); | |
53 if (!rv) { | |
54 printf("ao_sgi, play: invalid device\n"); | |
55 return 0; | |
56 } | |
57 | |
58 frate = rate; | |
11323 | 59 |
2451 | 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; | |
64 | |
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"); | |
68 } | |
69 | |
70 if (x[0].sizeOut < 0) { | |
71 printf("ao_sgi, init: AL_RATE was not accepted on the given resource\n"); | |
72 } | |
73 | |
74 if (alGetParams(rv,x, 1)<0) { | |
75 printf("ao_sgi, init: getparams failed: %s\n", alGetErrorString(oserror())); | |
76 } | |
77 | |
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); | |
80 } | |
11323 | 81 sample_rate = (int)frate; |
2451 | 82 } |
83 | |
3095 | 84 ao_data.buffersize=131072; |
85 ao_data.outburst = ao_data.buffersize/16; | |
86 ao_data.channels = channels; | |
2451 | 87 |
88 ao_config = alNewConfig(); | |
89 | |
90 if (!ao_config) { | |
91 printf("ao_sgi, init: %s\n", alGetErrorString(oserror())); | |
92 return 0; | |
93 } | |
94 | |
95 if(channels == 2) alSetChannels(ao_config, AL_STEREO); | |
96 else alSetChannels(ao_config, AL_MONO); | |
97 | |
98 alSetWidth(ao_config, AL_SAMPLE_16); | |
99 alSetSampFmt(ao_config, AL_SAMPFMT_TWOSCOMP); | |
100 alSetQueueSize(ao_config, 48000); | |
101 | |
102 if (alSetDevice(ao_config, AL_DEFAULT_OUTPUT) < 0) { | |
103 printf("ao_sgi, init: %s\n", alGetErrorString(oserror())); | |
104 return 0; | |
105 } | |
106 | |
107 ao_port = alOpenPort("mplayer", "w", ao_config); | |
108 | |
109 if (!ao_port) { | |
110 printf("ao_sgi, init: Unable to open audio channel: %s\n", alGetErrorString(oserror())); | |
111 return 0; | |
112 } | |
113 | |
114 // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config); | |
11323 | 115 queue_size = alGetQueueSize(ao_config); |
2451 | 116 return 1; |
117 | |
118 } | |
119 | |
120 // close audio device | |
12145 | 121 static void uninit(int immed) { |
2451 | 122 |
123 /* TODO: samplerate should be set back to the value before mplayer was started! */ | |
124 | |
125 printf("ao_sgi, uninit: ...\n"); | |
126 | |
127 if (ao_port) { | |
128 while(alGetFilled(ao_port) > 0) sginap(1); | |
129 alClosePort(ao_port); | |
130 alFreeConfig(ao_config); | |
131 } | |
132 | |
133 } | |
134 | |
135 // stop playing and empty buffers (for seeking/pause) | |
136 static void reset() { | |
137 | |
138 printf("ao_sgi, reset: ...\n"); | |
139 | |
140 } | |
141 | |
142 // stop playing, keep buffers (for pause) | |
143 static void audio_pause() { | |
144 | |
145 printf("ao_sgi, audio_pause: ...\n"); | |
146 | |
147 } | |
148 | |
149 // resume playing, after audio_pause() | |
150 static void audio_resume() { | |
151 | |
152 printf("ao_sgi, audio_resume: ...\n"); | |
153 | |
154 } | |
155 | |
156 // return: how many bytes can be played without blocking | |
157 static int get_space() { | |
158 | |
159 // printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_outburst); | |
160 // printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port)); | |
161 | |
3095 | 162 return alGetFillable(ao_port)*(2*ao_data.channels); |
2451 | 163 |
164 } | |
165 | |
166 | |
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) { | |
171 | |
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); | |
174 | |
3095 | 175 alWriteFrames(ao_port, data, len/(2*ao_data.channels)); |
2451 | 176 |
177 return len; | |
178 | |
179 } | |
180 | |
3095 | 181 // return: delay in seconds between first and last sample in buffer |
182 static float get_delay(){ | |
2451 | 183 |
184 // printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize); | |
185 | |
11323 | 186 //return 0; |
187 return (float)queue_size/((float)sample_rate); | |
2451 | 188 } |
189 | |
190 | |
191 | |
192 | |
193 | |
194 |