Debian Codegraph @

src/libout123/modules/mint.c

raw
1 /*
2 mint: audio output for MINT
3
4 copyright ?-2020 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Petr Stehlik
7 */
8
9 #include "../out123_int.h"
10
11 /* derived from LINUX, VOXWARE and SUN for MiNT Audio Device by Petr Stehlik */
12 #include <fcntl.h>
13 #include <ioctl.h>
14 #include <audios.h>
15 #include "../../common/debug.h"
16
17 /* Globals */
18 /* extern int outburst; */
19 int real_rate_printed = 0;
20
21
22
23 static int rate_best_match(out123_handle *ao)
24 {
25 int ret,dsp_rate;
26
27 if(!ai || ao->fn < 0 || ao->rate < 0)
28 return -1;
29
30 dsp_rate = ao->rate;
31 ret = ioctl(ao->fn,AIOCSSPEED, (void *)dsp_rate);
32 ret = ioctl(ao->fn,AIOCGSPEED,&dsp_rate);
33 if(ret < 0) return ret;
34 ao->rate = dsp_rate;
35 return 0;
36 }
37
38 static int set_rate(out123_handle *ao)
39 {
40 int dsp_rate = ao->rate;
41
42 if(ao->rate >= 0) {
43 int ret, real_rate;
44 ret = ioctl(ao->fn, AIOCSSPEED, (void *)dsp_rate);
45 if (ret >= 0 && !real_rate_printed) {
46 ioctl(ao->fn,AIOCGSPEED,&real_rate);
47 if (real_rate != dsp_rate) {
48 if(!AOQUIET)
49 fprintf(stderr, "Replay rate: %d Hz\n", real_rate);
50 real_rate_printed = 1;
51 }
52 }
53 return ret;
54 }
55
56 return 0;
57 }
58
59 static int set_channels(out123_handle *ao)
60 {
61 int chan = ao->channels;
62
63 if(ao->channels < 1) return 0;
64
65 return ioctl(ao->fn, AIOCSCHAN, (void *)chan);
66 }
67
68 static int set_format(out123_handle *ao)
69 {
70 int fmts;
71
72 if(ao->format == -1)
73 return 0;
74
75 switch(ao->format) {
76 case MPG123_ENC_SIGNED_16:
77 default:
78 fmts = AFMT_S16;
79 break;
80 case MPG123_ENC_UNSIGNED_8:
81 fmts = AFMT_U8;
82 break;
83 case MPG123_ENC_SIGNED_8:
84 fmts = AFMT_S8;
85 break;
86 case MPG123_ENC_ULAW_8:
87 fmts = AFMT_ULAW;
88 break;
89 }
90
91 return ioctl(ao->fn, AIOCSFMT, (void *)fmts);
92 }
93
94 static int reset_parameters(out123_handle *ao)
95 {
96 int ret;
97 ret = ioctl(ao->fn,AIOCRESET,NULL);
98 if(ret >= 0) ret = set_format(ai);
99 if(ret >= 0) ret = set_channels(ai);
100 if(ret >= 0) ret = set_rate(ai);
101 return ret;
102 }
103
104
105
106 static int open_mint(out123_handle *ao)
107 {
108 const char *dev = ao->device;
109
110 if(!ai) return -1;
111 if(!dev)
112 dev = "/dev/audio";
113
114 ao->fn = open(dev,O_WRONLY);
115
116 if(ao->fn < 0)
117 {
118 if(!AOQUIET)
119 error1("Can't open %s!",dev);
120 return -1;
121 }
122 /* ioctl(ao->fn, AIOCGBLKSIZE, &outburst);
123 if(outburst > MAXOUTBURST)
124 outburst = MAXOUTBURST; */
125 if(audio_reset_parameters(ai) < 0) {
126 close(ao->fn);
127 return -1;
128 }
129
130 return ao->fn;
131 }
132
133 static int get_formats_mint(out123_handle *ao)
134 {
135 int ret = 0;
136 int fmts;
137
138 if(ioctl(ao->fn,AIOCGFMTS,&fmts) < 0)
139 return -1;
140
141 if(fmts & AFMT_ULAW)
142 ret |= MPG123_ENC_ULAW_8;
143 if(fmts & AFMT_S16)
144 ret |= MPG123_ENC_SIGNED_16;
145 if(fmts & AFMT_U8)
146 ret |= MPG123_ENC_UNSIGNED_8;
147 if(fmts & AFMT_S8)
148 ret |= MPG123_ENC_SIGNED_8;
149
150 return ret;
151 }
152
153 static int write_mint(out123_handle *ao,unsigned char *buf,int len)
154 {
155 return write(ao->fn,buf,len);
156 }
157
158 static int close_mint(out123_handle *ao)
159 {
160 close (ao->fn);
161 return 0;
162 }
163
164 static void flush_mint(out123_handle *ao)
165 {
166 }
167
168
169 static int init_mint(out123_handle* ao)
170 {
171 if (ao==NULL) return -1;
172
173 /* Set callbacks */
174 ao->open = open_mint;
175 ao->flush = flush_mint;
176 ao->write = write_mint;
177 ao->get_formats = get_formats_mint;
178 ao->close = close_mint;
179
180 /* Success */
181 return 0;
182 }
183
184
185
186
187
188 /*
189 Module information data structure
190 */
191 mpg123_module_t mpg123_output_module_info = {
192 /* api_version */ MPG123_MODULE_API_VERSION,
193 /* name */ "mint",
194 /* description */ "Audio output for MINT.",
195 /* revision */ "$Rev:$",
196 /* handle */ NULL,
197
198 /* init_output */ init_mint,
199 };
200
201