[BeBoB/MAudio] Add PreSonus::FireboxDevice class to support functionality to switch...
[ffado.git] / libffado / tests / test-mixer.cpp
blob807bd7ba635abb4470e5e404a58999b964b996d1
1 /*
2 * Copyright (C) 2005-2008 by Daniel Wagner
3 * Copyright (C) 2005-2008 by Pieter Palmers
5 * This file is part of FFADO
6 * FFADO = Free Firewire (pro-)audio drivers for linux
8 * FFADO is based upon FreeBoB.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) version 3 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "libavc/avc_function_block.h"
26 #include "libavc/avc_serialize.h"
27 #include "debugmodule/debugmodule.h"
29 #include "libieee1394/ieee1394service.h"
30 #include <string.h>
32 DECLARE_GLOBAL_DEBUG_MODULE;
34 const bool bVerbose = true;
36 bool
37 doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id )
39 FunctionBlockCmd fbCmd( ieee1394service,
40 FunctionBlockCmd::eFBT_Processing,
41 fb_id,
42 FunctionBlockCmd::eCA_Current );
43 fbCmd.setNodeId( node_id );
44 fbCmd.setSubunitId( 0x00 );
45 fbCmd.setCommandType( AVCCommand::eCT_Status );
46 fbCmd.m_pFBProcessing->m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer;
48 debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer programmable state...\n");
50 fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00;
51 fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0xff;
52 fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0xff;
53 fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector
54 = FunctionBlockProcessingEnhancedMixer::eSS_ProgramableState;
56 fbCmd.setVerbose( bVerbose );
57 if (bVerbose) {
58 ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
61 if ( !fbCmd.fire() ) {
62 debugError( "cmd failed\n" );
65 if ( bVerbose ) {
66 CoutSerializer se;
67 fbCmd.serialize( se );
70 debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer level state...\n");
72 fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00;
73 fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0x00;
74 fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0x00;
75 fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector
76 = FunctionBlockProcessingEnhancedMixer::eSS_Level;
78 if ( !fbCmd.fire() ) {
79 debugError( "cmd failed\n" );
82 if ( bVerbose ) {
83 CoutSerializer se;
84 fbCmd.serialize( se );
87 return true;
90 bool
91 selectorGet( Ieee1394Service& ieee1394service, int node_id, int fb_id )
93 FunctionBlockCmd fbCmd( ieee1394service,
94 FunctionBlockCmd::eFBT_Selector,
95 fb_id,
96 FunctionBlockCmd::eCA_Current );
97 fbCmd.setNodeId( node_id );
98 fbCmd.setSubunitId( 0x00 );
99 fbCmd.setCommandType( AVCCommand::eCT_Status );
100 fbCmd.m_pFBSelector->m_inputFbPlugNumber=0;
102 debugOutput(DEBUG_LEVEL_NORMAL, "Requesting selector state...\n");
104 fbCmd.setVerbose( bVerbose );
105 if (bVerbose) {
106 ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
109 if ( !fbCmd.fire() ) {
110 debugError( "cmd failed\n" );
113 if ( bVerbose ) {
114 CoutSerializer se;
115 fbCmd.serialize( se );
118 return true;
121 bool
122 selectorSet( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val )
124 FunctionBlockCmd fbCmd( ieee1394service,
125 FunctionBlockCmd::eFBT_Selector,
126 fb_id,
127 FunctionBlockCmd::eCA_Current );
128 fbCmd.setNodeId( node_id );
129 fbCmd.setSubunitId( 0x00 );
130 fbCmd.setCommandType( AVCCommand::eCT_Control );
131 fbCmd.m_pFBSelector->m_inputFbPlugNumber=val;
133 debugOutput(DEBUG_LEVEL_NORMAL, "Setting selector state to %d...\n", val);
135 fbCmd.setVerbose( bVerbose );
136 if (bVerbose) {
137 ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
140 if ( !fbCmd.fire() ) {
141 debugError( "cmd failed\n" );
144 if ( bVerbose ) {
145 CoutSerializer se;
146 fbCmd.serialize( se );
149 return true;
152 bool
153 volumeGet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel )
155 FunctionBlockCmd fbCmd( ieee1394service,
156 FunctionBlockCmd::eFBT_Feature,
157 fb_id,
158 FunctionBlockCmd::eCA_Current );
159 fbCmd.setNodeId( node_id );
160 fbCmd.setSubunitId( 0x00 );
161 fbCmd.setCommandType( AVCCommand::eCT_Status );
162 fbCmd.m_pFBFeature->m_audioChannelNumber=channel;
163 fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume;
164 fbCmd.m_pFBFeature->m_pVolume->m_volume=0;
166 debugOutput(DEBUG_LEVEL_NORMAL, "Requesting volume feature block state...\n");
168 fbCmd.setVerbose( bVerbose );
169 if (bVerbose) {
170 ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
173 if ( !fbCmd.fire() ) {
174 debugError( "cmd failed\n" );
177 if ( bVerbose ) {
178 CoutSerializer se;
179 fbCmd.serialize( se );
182 return true;
185 bool
186 volumeSet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel, int value )
188 FunctionBlockCmd fbCmd( ieee1394service,
189 FunctionBlockCmd::eFBT_Feature,
190 fb_id,
191 FunctionBlockCmd::eCA_Current );
192 fbCmd.setNodeId( node_id );
193 fbCmd.setSubunitId( 0x00 );
194 fbCmd.setCommandType( AVCCommand::eCT_Control );
195 fbCmd.m_pFBFeature->m_audioChannelNumber=channel;
196 fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume;
197 fbCmd.m_pFBFeature->m_pVolume->m_volume=value;
199 debugOutput(DEBUG_LEVEL_NORMAL, "Setting volume feature block channel %d state to %d...\n", channel, value);
201 fbCmd.setVerbose( bVerbose );
202 if (bVerbose) {
203 ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
206 if ( !fbCmd.fire() ) {
207 debugError( "cmd failed\n" );
210 if ( bVerbose ) {
211 CoutSerializer se;
212 fbCmd.serialize( se );
215 return true;
218 ///////////////////////////
219 // main
220 //////////////////////////
222 main( int argc, char **argv )
225 if (argc < 4) {
226 debugError("usage: PORT NODE_ID CMD FB_ID [VAL1] [VAL2]\n");
227 exit(0);
230 int errno = 0;
231 char* tail;
232 int port = strtol( argv[1], &tail, 0 );
233 int node_id = strtol( argv[2], &tail, 0 );
234 int cmd = strtol( argv[3], &tail, 0 );
235 int fb_id = strtol( argv[4], &tail, 0 );
237 int value1=-1;
238 int value2=-1;
240 if (argc>=6)
241 value1 = strtol(argv[5], &tail, 0 );
243 if (argc>=7)
244 value2 = strtol(argv[6], &tail, 0 );
246 if (errno) {
247 debugError("argument parsing failed: %s\n", strerror(errno));
248 return -1;
250 Ieee1394Service ieee1394service;
251 if ( !ieee1394service.initialize( port ) ) {
252 debugError( "could not set port on ieee1394service\n" );
253 return -1;
256 switch(cmd) {
257 case 0:
258 doApp( ieee1394service, node_id, fb_id );
259 break;
260 case 1:
261 selectorGet( ieee1394service, node_id, fb_id );
262 break;
263 case 2:
264 selectorSet( ieee1394service, node_id, fb_id , value1 );
265 break;
266 case 3:
267 volumeGet( ieee1394service, node_id, fb_id, value1);
268 break;
269 case 4:
270 volumeSet( ieee1394service, node_id, fb_id, value1, value2);
271 break;
274 return 0;