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

Revision 2008, 8.6 kB (checked in by jwoithe, 9 years ago)

rme: refine input matrix mixer channel names. Add low level support for mixer channel phase inversion and muting (untested). Add playback mixer to RME ffado-mixer.

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     switch (ctype) {
208         case RME_FF_MM_INPUT:
209             settings->input_faders[idx] = val;
210             mixerflags = settings->input_mixerflags;
211             break;
212         case RME_FF_MM_PLAYBACK:
213             settings->playback_faders[idx] = val;
214             mixerflags = settings->playback_mixerflags;
215             break;
216         case RME_FF_MM_OUTPUT:
217             settings->output_faders[src_channel] = val;
218             break;
219     }
220
221     // If the matrix channel is muted, override the fader value and
222     // set it to zero.  Note that this is different to the hardware
223     // mute control dealt with by set_hardware_channel_mute(); the
224     // latter deals with muting the output channels.
225     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_MUTED)!=0) {
226         val = 0;
227     }
228
229     // Phase inversion is effected by sending a negative volume to the
230     // hardware.  However, when transitioning from 0 (-inf dB) to -1 (-90
231     // dB), the hardware seems to first send the volume up to a much higher
232     // level before it drops down to the set point after about a tenth of a
233     // second (this also seems to be the case when switching between
234     // inversion modes).  To work around this for the moment (at least until
235     // it's understood, silently map a value of 0 to -1 when phase inversion
236     // is active.
237     if (mixerflags!=NULL && (mixerflags[idx] & FF_SWPARAM_MF_INVERTED)!=0) {
238         if (val == 0)
239             val = 1;
240         val = -val;
241     }
242
243     return set_hardware_mixergain(ctype, src_channel, dest_channel, val);
244 }
245
246 signed int
247 Device::getMixerFlags(unsigned int ctype,
248     unsigned int src_channel, unsigned int dest_channel, unsigned int flagmask) {
249
250     unsigned char *mixerflags = NULL;
251     signed int idx = getMixerGainIndex(src_channel, dest_channel);
252     if (ctype == RME_FF_MM_OUTPUT)
253         return 0;
254     if (ctype == RME_FF_MM_INPUT)
255         mixerflags = settings->input_mixerflags;
256     else
257         mixerflags = settings->playback_mixerflags;
258
259     return mixerflags[idx] & flagmask;
260 }
261
262 signed int
263 Device::setMixerFlags(unsigned int ctype,
264     unsigned int src_channel, unsigned int dest_channel,
265     unsigned int flagmask, signed int val) {
266
267     unsigned char *mixerflags = NULL;
268     signed int idx = getMixerGainIndex(src_channel, dest_channel);
269     if (ctype == RME_FF_MM_OUTPUT)
270         return 0;
271     if (ctype == RME_FF_MM_INPUT)
272         mixerflags = settings->input_mixerflags;
273     else
274         mixerflags = settings->playback_mixerflags;
275
276     if (val == 0)
277         mixerflags[idx] &= ~flagmask;
278     else
279         mixerflags[idx] |= flagmask;
280
281     if (flagmask & (FF_SWPARAM_MF_MUTED|FF_SWPARAM_MF_INVERTED)) {
282         // Mixer channel muting/inversion is handled via the gain control
283         return setMixerGain(ctype, src_channel, dest_channel,
284             getMixerGain(ctype, src_channel, dest_channel));
285     }
286     return 0;
287 }
288
289 }
Note: See TracBrowser for help on using the browser.