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

Revision 2021, 9.2 kB (checked in by jwoithe, 9 years ago)

matrixmixer: complete initial implementation of optional mute functionality. A graphical indication of mute state (beyond the toggled menu item) is still needed.
matrixmixer: implement optional phase inversion interface. Again, a graphical indication of this state is still required.
rme: make use of the mute/invert functionality of the matrix mixer. Currently this is only connected for the input faders.

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::getAmpGain(unsigned int index) {
151     if (m_rme_model != RME_MODEL_FIREFACE400) {
152         debugOutput(DEBUG_LEVEL_WARNING, "Amp gains only supported on FF400\n");
153         return -1;
154     }
155     if (index > 21) {
156         debugOutput(DEBUG_LEVEL_WARNING, "Amp gain index %d invalid\n", index);
157          return -1;
158     }
159     return settings->amp_gains[index];
160 }
161
162 signed int
163 Device::setAmpGain(unsigned int index, signed int val) {
164
165     if (m_rme_model != RME_MODEL_FIREFACE400) {
166         debugOutput(DEBUG_LEVEL_WARNING, "Amp gains only supported on FF400\n");
167         return -1;
168     }
169     if (index > 21) {
170         debugOutput(DEBUG_LEVEL_WARNING, "Amp gain index %d invalid\n", index);
171          return -1;
172     }
173     settings->amp_gains[index] = val & 0xff;
174     return set_hardware_ampgain(index, val);
175 }
176
177 signed int
178 Device::getMixerGainIndex(unsigned int src_channel, unsigned int dest_channel) {
179     return dest_channel*RME_FF800_MAX_CHANNELS + src_channel;
180 }
181
182 signed int
183 Device::getMixerGain(unsigned int ctype,
184     unsigned int src_channel, unsigned int dest_channel) {
185
186     signed int idx = getMixerGainIndex(src_channel, dest_channel);
187     switch (ctype) {
188         case RME_FF_MM_INPUT:
189             return settings->input_faders[idx];
190             break;
191         case RME_FF_MM_PLAYBACK:
192             return settings->playback_faders[idx];
193             break;
194         case RME_FF_MM_OUTPUT:
195             return settings->output_faders[src_channel];
196             break;
197     }
198     return 0;
199 }
200
201 signed int
202 Device::setMixerGain(unsigned int ctype,
203     unsigned int src_channel, unsigned int dest_channel, signed int val) {
204
205     unsigned char *mixerflags = NULL;
206     signed int idx = getMixerGainIndex(src_channel, dest_channel);
207
208     switch (ctype) {
209         case RME_FF_MM_INPUT:
210             settings->input_faders[idx] = val;
211             mixerflags = settings->input_mixerflags;
212             break;
213         case RME_FF_MM_PLAYBACK:
214             settings->playback_faders[idx] = val;
215             mixerflags = settings->playback_mixerflags;
216             break;
217         case RME_FF_MM_OUTPUT:
218             settings->output_faders[src_channel] = val;
219             mixerflags = settings->output_mixerflags;
220             break;
221     }
222
223     // If the matrix channel is muted, override the fader value and
224     // set it to zero.  Note that this is different to the hardware
225     // mute control dealt with by set_hardware_channel_mute(); the
226     // latter deals with a muting separate from the mixer.
227     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_MUTED)!=0) {
228         val = 0;
229     }
230
231     // Phase inversion is effected by sending a negative volume to the
232     // hardware.  However, when transitioning from 0 (-inf dB) to -1 (-90
233     // dB), the hardware seems to first send the volume up to a much higher
234     // level before it drops down to the set point after about a tenth of a
235     // second (this also seems to be the case when switching between
236     // inversion modes).  To work around this for the moment (at least until
237     // it's understood, silently map a value of 0 to -1 when phase inversion
238     // is active.
239     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_INVERTED)!=0) {
240         if (val == 0)
241             val = 1;
242         val = -val;
243     }
244
245 fprintf(stderr, "val=%d\n", val);
246     return set_hardware_mixergain(ctype, src_channel, dest_channel, val);
247 }
248
249 signed int
250 Device::getMixerFlags(unsigned int ctype,
251     unsigned int src_channel, unsigned int dest_channel, unsigned int flagmask) {
252
253     unsigned char *mixerflags = NULL;
254     signed int idx = getMixerGainIndex(src_channel, dest_channel);
255     if (ctype == RME_FF_MM_OUTPUT) {
256         mixerflags = settings->output_mixerflags;
257         idx = src_channel;
258     } else
259     if (ctype == RME_FF_MM_INPUT)
260         mixerflags = settings->input_mixerflags;
261     else
262         mixerflags = settings->playback_mixerflags;
263
264     return mixerflags[idx] & flagmask;
265 }
266
267 signed int
268 Device::setMixerFlags(unsigned int ctype,
269     unsigned int src_channel, unsigned int dest_channel,
270     unsigned int flagmask, signed int val) {
271
272     unsigned char *mixerflags = NULL;
273     signed int idx = getMixerGainIndex(src_channel, dest_channel);
274     if (ctype == RME_FF_MM_OUTPUT) {
275         mixerflags = settings->output_mixerflags;
276         idx = src_channel;
277     } else
278     if (ctype == RME_FF_MM_INPUT)
279         mixerflags = settings->input_mixerflags;
280     else
281         mixerflags = settings->playback_mixerflags;
282
283 // FIXME: When switching inversion modes, the hardware seems to a channel to
284 // full volume for about 1/10 sec.  Attempt to avoid this by temporarily
285 // muting the channel.  This doesn't seem to work though.
286 //    if (flagmask & FF_SWPARAM_MF_INVERTED)
287 //        set_hardware_mixergain(ctype, src_channel, dest_channel, 0);
288
289     if (val == 0)
290         mixerflags[idx] &= ~flagmask;
291     else
292         mixerflags[idx] |= flagmask;
293
294     if (flagmask & (FF_SWPARAM_MF_MUTED|FF_SWPARAM_MF_INVERTED)) {
295         // Mixer channel muting/inversion is handled via the gain control
296         return setMixerGain(ctype, src_channel, dest_channel,
297             getMixerGain(ctype, src_channel, dest_channel));
298     }
299     return 0;
300 }
301
302 }
Note: See TracBrowser for help on using the browser.