root/trunk/libffado/src/rme/rme_avdevice_settings.cpp

Revision 2032, 9.4 kB (checked in by jwoithe, 9 years ago)

rme: implement SPDIF input mode selection via ffado-mixer. Whether this has the desired effect on the device remains to be seen - I do not have anything to test the mode of the optical port right now.

Line 
1 /*
2  * Copyright (C) 2005-2009 by Jonathan Woithe
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "rme/rme_avdevice.h"
24 #include "rme/fireface_def.h"
25
26 #include "debugmodule/debugmodule.h"
27
28 namespace Rme {
29
30 signed int
31 Device::getPhantom(unsigned int channel) {
32
33     if (channel > 3) {
34         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d phantom power not supported\n", channel);
35         return -1;
36     }
37
38     return settings->mic_phantom[channel] != 0;
39 }
40
41 signed int
42 Device::setPhantom(unsigned int channel, unsigned int status) {
43
44     if (channel > 3) {
45         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d phantom power not supported\n", channel);
46         return -1;
47     }
48
49     settings->mic_phantom[channel] = (status != 0);
50     set_hardware_params();
51
52     return 0;
53 }
54
55 signed int
56 Device::getInputLevel(void) {
57     return settings->input_level;
58 }
59
60 signed int
61 Device::setInputLevel(unsigned int level) {
62
63     if (level<FF_SWPARAM_ILEVEL_LOGAIN || level>FF_SWPARAM_ILEVEL_m10dBV) {
64         debugOutput(DEBUG_LEVEL_WARNING, "Invalid input level ID %d\n", level);
65         return -1;
66     }
67     settings->input_level = level;
68     set_hardware_params();
69
70     return 0;
71 }
72
73 signed int
74 Device::getOutputLevel(void) {
75     return settings->output_level;
76 }
77
78 signed int
79 Device::setOutputLevel(unsigned int level) {
80
81     if (level<FF_SWPARAM_OLEVEL_HIGAIN || level>FF_SWPARAM_OLEVEL_m10dBV) {
82         debugOutput(DEBUG_LEVEL_WARNING, "Invalid output level ID %d\n", level);
83         return -1;
84     }
85     settings->output_level = level;
86     set_hardware_params();
87
88     return 0;
89 }
90
91 signed int
92 Device::getPhonesLevel(void) {
93     return settings->phones_level;
94 }
95
96 signed int
97 Device::setPhonesLevel(unsigned int level) {
98
99     if (level<FF_SWPARAM_PHONESLEVEL_HIGAIN || level>FF_SWPARAM_PHONESLEVEL_m10dBV) {
100         debugOutput(DEBUG_LEVEL_WARNING, "Invalid phones level ID %d\n", level);
101         return -1;
102     }
103     settings->phones_level = level;
104     set_hardware_params();
105
106     return 0;
107 }
108
109 signed int
110 Device::getInputPadOpt(unsigned int channel) {
111     if (m_rme_model!=RME_MODEL_FIREFACE400 || channel<3 || channel>4) {
112         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d input pad option not supported for model %d\n", channel, m_rme_model);
113         return -1;
114     }
115     return settings->ff400_input_pad[channel-3] != 0;
116 }
117
118 signed int
119 Device::setInputPadOpt(unsigned int channel, unsigned int status) {
120     if (m_rme_model!=RME_MODEL_FIREFACE400 || channel<3 || channel>4) {
121         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d input pad option not supported for model %d\n", channel, m_rme_model);
122         return -1;
123     }
124     settings->ff400_input_pad[channel-3] = (status != 0);
125     set_hardware_params();
126     return 0;
127 }
128
129 signed int
130 Device::getInputInstrOpt(unsigned int channel) {
131     if (m_rme_model!=RME_MODEL_FIREFACE400 || channel<3 || channel>4) {
132         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d input instrument option not supported for model %d\n", channel, m_rme_model);
133         return -1;
134     }
135     return settings->ff400_instr_input[channel-3] != 0;
136 }
137
138 signed int
139 Device::setInputInstrOpt(unsigned int channel, unsigned int status) {
140     if (m_rme_model!=RME_MODEL_FIREFACE400 || channel<3 || channel>4) {
141         debugOutput(DEBUG_LEVEL_WARNING, "Channel %d input instrument option not supported for model %d\n", channel, m_rme_model);
142         return -1;
143     }
144     settings->ff400_instr_input[channel-3] = (status != 0);
145     set_hardware_params();
146     return 0;
147 }
148
149 signed int
150 Device::getSpdifInputMode(void) {
151     return settings->spdif_input_mode;
152 }
153
154 signed int
155 Device::setSpdifInputMode(signed int mode) {
156     settings->spdif_input_mode = mode;
157     set_hardware_params();
158     return 0;
159 }
160
161 signed int
162 Device::getAmpGain(unsigned int index) {
163     if (m_rme_model != RME_MODEL_FIREFACE400) {
164         debugOutput(DEBUG_LEVEL_WARNING, "Amp gains only supported on FF400\n");
165         return -1;
166     }
167     if (index > 21) {
168         debugOutput(DEBUG_LEVEL_WARNING, "Amp gain index %d invalid\n", index);
169          return -1;
170     }
171     return settings->amp_gains[index];
172 }
173
174 signed int
175 Device::setAmpGain(unsigned int index, signed int val) {
176
177     if (m_rme_model != RME_MODEL_FIREFACE400) {
178         debugOutput(DEBUG_LEVEL_WARNING, "Amp gains only supported on FF400\n");
179         return -1;
180     }
181     if (index > 21) {
182         debugOutput(DEBUG_LEVEL_WARNING, "Amp gain index %d invalid\n", index);
183          return -1;
184     }
185     settings->amp_gains[index] = val & 0xff;
186     return set_hardware_ampgain(index, val);
187 }
188
189 signed int
190 Device::getMixerGainIndex(unsigned int src_channel, unsigned int dest_channel) {
191     return dest_channel*RME_FF800_MAX_CHANNELS + src_channel;
192 }
193
194 signed int
195 Device::getMixerGain(unsigned int ctype,
196     unsigned int src_channel, unsigned int dest_channel) {
197
198     signed int idx = getMixerGainIndex(src_channel, dest_channel);
199     switch (ctype) {
200         case RME_FF_MM_INPUT:
201             return settings->input_faders[idx];
202             break;
203         case RME_FF_MM_PLAYBACK:
204             return settings->playback_faders[idx];
205             break;
206         case RME_FF_MM_OUTPUT:
207             return settings->output_faders[src_channel];
208             break;
209     }
210     return 0;
211 }
212
213 signed int
214 Device::setMixerGain(unsigned int ctype,
215     unsigned int src_channel, unsigned int dest_channel, signed int val) {
216
217     unsigned char *mixerflags = NULL;
218     signed int idx = getMixerGainIndex(src_channel, dest_channel);
219
220     switch (ctype) {
221         case RME_FF_MM_INPUT:
222             settings->input_faders[idx] = val;
223             mixerflags = settings->input_mixerflags;
224             break;
225         case RME_FF_MM_PLAYBACK:
226             settings->playback_faders[idx] = val;
227             mixerflags = settings->playback_mixerflags;
228             break;
229         case RME_FF_MM_OUTPUT:
230             settings->output_faders[src_channel] = val;
231             mixerflags = settings->output_mixerflags;
232             break;
233     }
234
235     // If the matrix channel is muted, override the fader value and
236     // set it to zero.  Note that this is different to the hardware
237     // mute control dealt with by set_hardware_channel_mute(); the
238     // latter deals with a muting separate from the mixer.
239     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_MUTED)!=0) {
240         val = 0;
241     }
242
243     // Phase inversion is effected by sending a negative volume to the
244     // hardware.  However, when transitioning from 0 (-inf dB) to -1 (-90
245     // dB), the hardware seems to first send the volume up to a much higher
246     // level before it drops down to the set point after about a tenth of a
247     // second (this also seems to be the case when switching between
248     // inversion modes).  To work around this for the moment (at least until
249     // it's understood, silently map a value of 0 to -1 when phase inversion
250     // is active.
251     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_INVERTED)!=0) {
252         if (val == 0)
253             val = 1;
254         val = -val;
255     }
256
257     return set_hardware_mixergain(ctype, src_channel, dest_channel, val);
258 }
259
260 signed int
261 Device::getMixerFlags(unsigned int ctype,
262     unsigned int src_channel, unsigned int dest_channel, unsigned int flagmask) {
263
264     unsigned char *mixerflags = NULL;
265     signed int idx = getMixerGainIndex(src_channel, dest_channel);
266     if (ctype == RME_FF_MM_OUTPUT) {
267         mixerflags = settings->output_mixerflags;
268         idx = src_channel;
269     } else
270     if (ctype == RME_FF_MM_INPUT)
271         mixerflags = settings->input_mixerflags;
272     else
273         mixerflags = settings->playback_mixerflags;
274
275     return mixerflags[idx] & flagmask;
276 }
277
278 signed int
279 Device::setMixerFlags(unsigned int ctype,
280     unsigned int src_channel, unsigned int dest_channel,
281     unsigned int flagmask, signed int val) {
282
283     unsigned char *mixerflags = NULL;
284     signed int idx = getMixerGainIndex(src_channel, dest_channel);
285     if (ctype == RME_FF_MM_OUTPUT) {
286         mixerflags = settings->output_mixerflags;
287         idx = src_channel;
288     } else
289     if (ctype == RME_FF_MM_INPUT)
290         mixerflags = settings->input_mixerflags;
291     else
292         mixerflags = settings->playback_mixerflags;
293
294 // FIXME: When switching inversion modes, the hardware seems to a channel to
295 // full volume for about 1/10 sec.  Attempt to avoid this by temporarily
296 // muting the channel.  This doesn't seem to work though.
297 //    if (flagmask & FF_SWPARAM_MF_INVERTED)
298 //        set_hardware_mixergain(ctype, src_channel, dest_channel, 0);
299
300     if (val == 0)
301         mixerflags[idx] &= ~flagmask;
302     else
303         mixerflags[idx] |= flagmask;
304
305     if (flagmask & (FF_SWPARAM_MF_MUTED|FF_SWPARAM_MF_INVERTED)) {
306         // Mixer channel muting/inversion is handled via the gain control
307         return setMixerGain(ctype, src_channel, dest_channel,
308             getMixerGain(ctype, src_channel, dest_channel));
309     }
310     return 0;
311 }
312
313 }
Note: See TracBrowser for help on using the browser.