Debian Codegraph @

src/libout123/modules/hp.c

raw
1 /*
2 hp: audio output for HP-UX
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 Michael Hipp
7 */
8
9 #include "../out123_int.h"
10 #include <fcntl.h>
11 #include <sys/audio.h>
12 #include "../../common/debug.h"
13
14
15 static int set_rate(out123_handle *ao)
16 {
17 if(ao->rate >= 0) {
18 return ioctl(ao->fn,AUDIO_SET_SAMPLE_RATE,ao->rate);
19 } else {
20 return 0;
21 }
22 }
23
24 static int set_channels(out123_handle *ao)
25 {
26 if(ao->channels<0) return 0;
27 return ioctl(ao->fn,AUDIO_SET_CHANNELS,ao->channels);
28 }
29
30 static int set_format(out123_handle *ao)
31 {
32 int fmt;
33
34 switch(ao->format) {
35 case -1:
36 case MPG123_ENC_SIGNED_16:
37 default:
38 fmt = MPG123_ENC_LINEAR16BIT;
39 break;
40 case MPG123_ENC_UNSIGNED_8:
41 if(!AOQUIET)
42 error("unsigned 8 bit linear not supported");
43 return -1;
44 case MPG123_ENC_SIGNED_8:
45 if(!AOQUIET)
46 error("signed 8 bit linear not supported");
47 return -1;
48 case MPG123_ENC_ALAW_8:
49 fmt = MPG123_ENC_ALAW;
50 break;
51 case MPG123_ENC_ULAW_8:
52 fmt = MPG123_ENC_ULAW;
53 break;
54 }
55 return ioctl(ao->fn,AUDIO_SET_DATA_FORMAT,fmt);
56 }
57
58 static int get_formats(out123_handle *ao)
59 {
60 return MPG123_ENC_SIGNED_16;
61 }
62
63 static int reset_parameters(out123_handle *ao)
64 {
65 int ret;
66 ret = set_format(ai);
67 if(ret >= 0)
68 ret = set_channels_hp(ai);
69 if(ret >= 0)
70 ret = set_rate_hp(ai);
71 return ret;
72 }
73
74
75 static int open_hp(out123_handle *ao)
76 {
77 struct audio_describe ades;
78 struct audio_gain again;
79 int i,audio;
80
81 ao->fn = open("/dev/audio",O_RDWR);
82
83 if(ao->fn < 0)
84 return -1;
85
86
87 ioctl(ao->fn,AUDIO_DESCRIBE,&ades);
88
89 if(ao->gain != -1)
90 {
91 if(ao->gain > ades.max_transmit_gain)
92 {
93 if(!AOQUIET)
94 error("your gainvalue was to high -> set to maximum.");
95 ao->gain = ades.max_transmit_gain;
96 }
97 if(ao->gain < ades.min_transmit_gain)
98 {
99 if(!AOQUIET)
100 error("your gainvalue was to low -> set to minimum.");
101 ao->gain = ades.min_transmit_gain;
102 }
103 again.channel_mask = AUDIO_CHANNEL_0 | AUDIO_CHANNEL_1;
104 ioctl(ao->fn,AUDIO_GET_GAINS,&again);
105 again.cgain[0].transmit_gain = ao->gain;
106 again.cgain[1].transmit_gain = ao->gain;
107 again.channel_mask = AUDIO_CHANNEL_0 | AUDIO_CHANNEL_1;
108 ioctl(ao->fn,AUDIO_SET_GAINS,&again);
109 }
110
111 if(ao->flags != -1)
112 {
113 if(ao->flags & OUT123_INTERNAL_SPEAKER)
114 ioctl(ao->fn,AUDIO_SET_OUTPUT,OUT123_SPEAKER);
115 else if(ao->flags & OUT123_HEADPHONES)
116 ioctl(ao->fn,AUDIO_SET_OUTPUT,OUT123_HEADPHONE);
117 else if(ao->flags & OUT123_LINE_OUT)
118 ioctl(ao->fn,AUDIO_SET_OUTPUT,OUT123_LINE);
119 }
120
121 if(ao->rate == -1)
122 ao->rate = 44100;
123
124 for(i=0;i<ades.nrates;i++)
125 {
126 if(ao->rate == ades.sample_rate[i])
127 break;
128 }
129 if(i == ades.nrates)
130 {
131 if(!AOQUIET)
132 error1("Can't set sample-rate to %ld.\n",ao->rate);
133 i = 0;
134 }
135
136 if(reset_parameters(ai) < 0)
137 return -1;
138
139 return ao->fn;
140 }
141
142
143
144 static int write_hp(out123_handle *ao,unsigned char *buf,int len)
145 {
146 return write(ao->fn,buf,len);
147 }
148
149 static int close_hp(out123_handle *ao)
150 {
151 close (ao->fn);
152 return 0;
153 }
154
155 static void flush_hp(out123_handle *ao)
156 {
157 }
158
159
160
161 static int init_hp(out123_handle* ao)
162 {
163 if (ao==NULL) return -1;
164
165 /* Set callbacks */
166 ao->open = open_hp;
167 ao->flush = flush_hp;
168 ao->write = write_hp;
169 ao->get_formats = get_formats_hp;
170 ao->close = close_hp;
171
172 /* Success */
173 return 0;
174 }
175
176
177
178 /*
179 Module information data structure
180 */
181 mpg123_module_t mpg123_output_module_info = {
182 /* api_version */ MPG123_MODULE_API_VERSION,
183 /* name */ "hp",
184 /* description */ "Output audio HP-UX",
185 /* revision */ "$Rev:$",
186 /* handle */ NULL,
187
188 /* init_output */ init_hp,
189 };