annotate libao2/ao_sgi.c @ 19689:b187da3ed321

fix charset issues and a little wording
author kraymer
date Tue, 05 Sep 2006 16:09:49 +0000
parents 99e20a22d5d0
children 85f669a84e7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
1 /*
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
2 ao_sgi - sgi/irix output plugin for MPlayer
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
3
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
4 22oct2001 oliver.schoenbrunner@jku.at
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
5
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
6 */
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
7
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
8 #include <stdio.h>
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
9 #include <stdlib.h>
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
10 #include <unistd.h>
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
11 #include <errno.h>
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
12 #include <dmedia/audio.h>
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
13
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
14 #include "audio_out.h"
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
15 #include "audio_out_internal.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13549
diff changeset
16 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13549
diff changeset
17 #include "help_mp.h"
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
18 #include "libaf/af_format.h"
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
19
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
20 static ao_info_t info =
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
21 {
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
22 "sgi audio output",
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
23 "sgi",
13549
4604fc855b3a fixing authors
alex
parents: 13383
diff changeset
24 "Oliver Schoenbrunner",
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
25 ""
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
26 };
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
27
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
28 LIBAO_EXTERN(sgi)
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
29
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
30
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
31 static ALconfig ao_config;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
32 static ALport ao_port;
11323
c6758363a238 A-V sync fix by Timo Kanera <timo@kanera.de>.
diego
parents: 9633
diff changeset
33 static int sample_rate;
c6758363a238 A-V sync fix by Timo Kanera <timo@kanera.de>.
diego
parents: 9633
diff changeset
34 static int queue_size;
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
35 static int bytes_per_frame;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
36
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
37 /**
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
38 * \param [in/out] format
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
39 * \param [out] width
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
40 *
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
41 * \return the closest matching SGI AL sample format
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
42 *
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
43 * \note width is set to required per-channel sample width
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
44 * format is updated to match the SGI AL sample format
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
45 */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
46 static int fmt2sgial(int *format, int *width) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
47 int smpfmt = AL_SAMPFMT_TWOSCOMP;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
48
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
49 /* SGI AL only supports float and signed integers in native
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
50 * endianess. If this is something else, we must rely on the audio
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
51 * filter to convert it to a compatible format. */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
52
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
53 /* 24-bit audio is supported, but only with 32-bit alignment.
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
54 * mplayer's 24-bit format is packed, unfortunately.
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
55 * So we must upgrade 24-bit requests to 32 bits. Then we drop the
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
56 * lowest 8 bits during playback. */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
57
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
58 switch(*format) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
59 case AF_FORMAT_U8:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
60 case AF_FORMAT_S8:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
61 *width = AL_SAMPLE_8;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
62 *format = AF_FORMAT_S8;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
63 break;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
64
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
65 case AF_FORMAT_U16_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
66 case AF_FORMAT_U16_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
67 case AF_FORMAT_S16_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
68 case AF_FORMAT_S16_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
69 *width = AL_SAMPLE_16;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
70 *format = AF_FORMAT_S16_NE;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
71 break;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
72
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
73 case AF_FORMAT_U24_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
74 case AF_FORMAT_U24_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
75 case AF_FORMAT_S24_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
76 case AF_FORMAT_S24_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
77 case AF_FORMAT_U32_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
78 case AF_FORMAT_U32_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
79 case AF_FORMAT_S32_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
80 case AF_FORMAT_S32_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
81 *width = AL_SAMPLE_24;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
82 *format = AF_FORMAT_S32_NE;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
83 break;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
84
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
85 case AF_FORMAT_FLOAT_LE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
86 case AF_FORMAT_FLOAT_BE:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
87 *width = 4;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
88 *format = AF_FORMAT_FLOAT_NE;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
89 smpfmt = AL_SAMPFMT_FLOAT;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
90 break;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
91
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
92 default:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
93 *width = AL_SAMPLE_16;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
94 *format = AF_FORMAT_S16_NE;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
95 break;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
96
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
97 }
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
98
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
99 return smpfmt;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
100 }
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
101
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
102 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 3095
diff changeset
103 static int control(int cmd, void *arg){
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
104
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
105 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_INFO);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
106
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
107 switch(cmd) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
108 case AOCONTROL_QUERY_FORMAT:
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
109 /* Do not reject any format: return the closest matching
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
110 * format if the request is not supported natively. */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
111 return CONTROL_TRUE;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
112 }
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
113
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
114 return CONTROL_UNKNOWN;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
115 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
116
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
117 // open & setup audio device
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
118 // return: 1=success 0=fail
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
119 static int init(int rate, int channels, int format, int flags) {
14249
8f59f661f317 hopefully final fix
alex
parents: 14123
diff changeset
120
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
121 int smpwidth, smpfmt;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
122 int rv = AL_DEFAULT_OUTPUT;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
123
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
124 smpfmt = fmt2sgial(&format, &smpwidth);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
125
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14255
diff changeset
126 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_InitInfo, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
127
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
128 { /* from /usr/share/src/dmedia/audio/setrate.c */
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
129
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
130 double frate, realrate;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
131 ALpv x[2];
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
132
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
133 if(ao_subdevice) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
134 rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
135 if (!rv) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
136 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InvalidDevice);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
137 return 0;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
138 }
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
139 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
140
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
141 frate = rate;
11323
c6758363a238 A-V sync fix by Timo Kanera <timo@kanera.de>.
diego
parents: 9633
diff changeset
142
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
143 x[0].param = AL_RATE;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
144 x[0].value.ll = alDoubleToFixed(rate);
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
145 x[1].param = AL_MASTER_CLOCK;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
146 x[1].value.i = AL_CRYSTAL_MCLK_TYPE;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
147
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
148 if (alSetParams(rv,x, 2)<0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
149 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetParms_Samplerate, alGetErrorString(oserror()));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
150 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
151
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
152 if (x[0].sizeOut < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
153 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetAlRate);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
154 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
155
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
156 if (alGetParams(rv,x, 1)<0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
157 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantGetParms, alGetErrorString(oserror()));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
158 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
159
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
160 realrate = alFixedToDouble(x[0].value.ll);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
161 if (frate != realrate) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
162 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_SampleRateInfo, realrate, frate);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
163 }
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
164 sample_rate = (int)realrate;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
165 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
166
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
167 bytes_per_frame = channels * smpwidth;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
168
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
169 ao_data.samplerate = sample_rate;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
170 ao_data.channels = channels;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
171 ao_data.format = format;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
172 ao_data.bps = sample_rate * bytes_per_frame;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2451
diff changeset
173 ao_data.buffersize=131072;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2451
diff changeset
174 ao_data.outburst = ao_data.buffersize/16;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
175
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
176 ao_config = alNewConfig();
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
177
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
178 if (!ao_config) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
179 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
180 return 0;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
181 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
182
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
183 if(alSetChannels(ao_config, channels) < 0 ||
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
184 alSetWidth(ao_config, smpwidth) < 0 ||
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
185 alSetSampFmt(ao_config, smpfmt) < 0 ||
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
186 alSetQueueSize(ao_config, sample_rate) < 0 ||
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
187 alSetDevice(ao_config, rv) < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
188 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
189 return 0;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
190 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
191
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
192 ao_port = alOpenPort("mplayer", "w", ao_config);
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
193
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
194 if (!ao_port) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
195 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitOpenAudioFailed, alGetErrorString(oserror()));
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
196 return 0;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
197 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
198
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
199 // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
11323
c6758363a238 A-V sync fix by Timo Kanera <timo@kanera.de>.
diego
parents: 9633
diff changeset
200 queue_size = alGetQueueSize(ao_config);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
201 return 1;
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
202
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
203 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
204
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
205 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 11323
diff changeset
206 static void uninit(int immed) {
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
207
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
208 /* TODO: samplerate should be set back to the value before mplayer was started! */
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
209
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
210 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Uninit);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
211
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
212 if (ao_config) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
213 alFreeConfig(ao_config);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
214 ao_config = NULL;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
215 }
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
216
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
217 if (ao_port) {
14849
d313f591d1a4 aos should respect the immed uninit flag (quit immediatly vs waiting till file
reimar
parents: 14264
diff changeset
218 if (!immed)
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
219 while(alGetFilled(ao_port) > 0) sginap(1);
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
220 alClosePort(ao_port);
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
221 ao_port = NULL;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
222 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
223
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
224 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
225
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
226 // stop playing and empty buffers (for seeking/pause)
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16667
diff changeset
227 static void reset(void) {
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
228
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
229 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Reset);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
230
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
231 alDiscardFrames(ao_port, queue_size);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
232 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
233
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
234 // stop playing, keep buffers (for pause)
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16667
diff changeset
235 static void audio_pause(void) {
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
236
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
237 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_PauseInfo);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
238
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
239 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
240
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
241 // resume playing, after audio_pause()
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16667
diff changeset
242 static void audio_resume(void) {
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
243
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
244 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_ResumeInfo);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
245
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
246 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
247
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
248 // return: how many bytes can be played without blocking
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16667
diff changeset
249 static int get_space(void) {
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
250
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
251 // printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_data.outburst);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
252 // printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port));
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
253
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
254 return alGetFillable(ao_port) * bytes_per_frame;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
255
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
256 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
257
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
258
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
259 // plays 'len' bytes of 'data'
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
260 // it should round it down to outburst*n
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
261 // return: number of bytes played
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
262 static int play(void* data, int len, int flags) {
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
263
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
264 /* Always process data in quadword-aligned chunks (64-bits). */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
265 const int plen = len / (sizeof(uint64_t) * bytes_per_frame);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
266 const int framecount = plen * sizeof(uint64_t);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
267
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
268 // printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config);
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
269 // printf("channels %d\n", ao_data.channels);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
270
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
271 if(ao_data.format == AF_FORMAT_S32_NE) {
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
272 /* The zen of this is explained in fmt2sgial() */
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
273 int32_t *smpls = data;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
274 const int32_t *smple = smpls + (framecount * ao_data.channels);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
275 while(smpls < smple)
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
276 *smpls++ >>= 8;
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
277 }
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
278
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
279 alWriteFrames(ao_port, data, framecount);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
280
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
281 return framecount * bytes_per_frame;
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
282
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
283 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
284
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2451
diff changeset
285 // return: delay in seconds between first and last sample in buffer
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16667
diff changeset
286 static float get_delay(void){
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
287
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
288 // printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize);
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
289
16667
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
290 // return (float)queue_size/((float)sample_rate);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
291 const int outstanding = alGetFilled(ao_port);
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
292 return (float)((outstanding < 0) ? queue_size : outstanding) /
27a2bc4aad72 General bug fixes, like missing includes, formats that were incorrectly
reimar
parents: 14849
diff changeset
293 ((float)sample_rate);
2451
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
294 }
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
295
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
296
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
297
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
298
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
299
a56bf9c0e76f SGI audio driver by oliver.schoenbrunner@jku.at
arpi
parents:
diff changeset
300