root/trunk/libffado/tests/test-mixer.cpp

Revision 2802, 7.8 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free FireWire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  */
24
25 #include "libavc/avc_function_block.h"
26 #include "libavc/avc_serialize.h"
27 #include "debugmodule/debugmodule.h"
28
29 #include "libieee1394/ieee1394service.h"
30 #include <string.h>
31 #include <cerrno.h>
32
33 DECLARE_GLOBAL_DEBUG_MODULE;
34
35 const bool bVerbose = true;
36
37 bool
38 doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id )
39 {
40     FunctionBlockCmd fbCmd( ieee1394service,
41                             FunctionBlockCmd::eFBT_Processing,
42                             fb_id,
43                             FunctionBlockCmd::eCA_Current );
44     fbCmd.setNodeId( node_id );
45     fbCmd.setSubunitId( 0x00 );
46     fbCmd.setCommandType( AVCCommand::eCT_Status );
47     fbCmd.m_pFBProcessing->m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer;
48
49     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer programmable state...\n");
50
51     fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00;
52     fbCmd.m_pFBProcessing->m_inputAudioChannelNumber  = 0xff;
53     fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0xff;
54     fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector
55         = FunctionBlockProcessingEnhancedMixer::eSS_ProgramableState;
56
57     fbCmd.setVerbose( bVerbose );
58     if (bVerbose) {
59         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
60     }
61
62     if ( !fbCmd.fire() ) {
63         debugError( "cmd failed\n" );
64     }
65
66     if ( bVerbose ) {
67         CoutSerializer se;
68         fbCmd.serialize( se );
69     }
70    
71     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer level state...\n");
72    
73     fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00;
74     fbCmd.m_pFBProcessing->m_inputAudioChannelNumber  = 0x00;
75     fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0x00;
76     fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector
77         = FunctionBlockProcessingEnhancedMixer::eSS_Level;
78    
79     if ( !fbCmd.fire() ) {
80         debugError( "cmd failed\n" );
81     }
82
83     if ( bVerbose ) {
84         CoutSerializer se;
85         fbCmd.serialize( se );
86     }
87
88     return true;
89 }
90
91 bool
92 selectorGet( Ieee1394Service& ieee1394service, int node_id, int fb_id )
93 {
94     FunctionBlockCmd fbCmd( ieee1394service,
95                             FunctionBlockCmd::eFBT_Selector,
96                             fb_id,
97                             FunctionBlockCmd::eCA_Current );
98     fbCmd.setNodeId( node_id );
99     fbCmd.setSubunitId( 0x00 );
100     fbCmd.setCommandType( AVCCommand::eCT_Status );
101     fbCmd.m_pFBSelector->m_inputFbPlugNumber=0;
102
103     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting selector state...\n");
104
105     fbCmd.setVerbose( bVerbose );
106     if (bVerbose) {
107         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
108     }
109    
110     if ( !fbCmd.fire() ) {
111         debugError( "cmd failed\n" );
112     }
113
114     if ( bVerbose ) {
115         CoutSerializer se;
116         fbCmd.serialize( se );
117     }
118
119     return true;
120 }
121
122 bool
123 selectorSet( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val )
124 {
125     FunctionBlockCmd fbCmd( ieee1394service,
126                             FunctionBlockCmd::eFBT_Selector,
127                             fb_id,
128                             FunctionBlockCmd::eCA_Current );
129     fbCmd.setNodeId( node_id );
130     fbCmd.setSubunitId( 0x00 );
131     fbCmd.setCommandType( AVCCommand::eCT_Control );
132     fbCmd.m_pFBSelector->m_inputFbPlugNumber=val;
133
134     debugOutput(DEBUG_LEVEL_NORMAL, "Setting selector state to %d...\n", val);
135
136     fbCmd.setVerbose( bVerbose );
137     if (bVerbose) {
138         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
139     }
140    
141     if ( !fbCmd.fire() ) {
142         debugError( "cmd failed\n" );
143     }
144
145     if ( bVerbose ) {
146         CoutSerializer se;
147         fbCmd.serialize( se );
148     }
149
150     return true;
151 }
152
153 bool
154 volumeGet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel )
155 {
156     FunctionBlockCmd fbCmd( ieee1394service,
157                             FunctionBlockCmd::eFBT_Feature,
158                             fb_id,
159                             FunctionBlockCmd::eCA_Current );
160     fbCmd.setNodeId( node_id );
161     fbCmd.setSubunitId( 0x00 );
162     fbCmd.setCommandType( AVCCommand::eCT_Status );
163     fbCmd.m_pFBFeature->m_audioChannelNumber=channel;
164     fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume;
165     fbCmd.m_pFBFeature->m_pVolume->m_volume=0;
166
167     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting volume feature block state...\n");
168
169     fbCmd.setVerbose( bVerbose );
170     if (bVerbose) {
171         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
172     }
173    
174     if ( !fbCmd.fire() ) {
175         debugError( "cmd failed\n" );
176     }
177
178     if ( bVerbose ) {
179         CoutSerializer se;
180         fbCmd.serialize( se );
181     }
182
183     return true;
184 }
185
186 bool
187 volumeSet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel, int value )
188 {
189     FunctionBlockCmd fbCmd( ieee1394service,
190                             FunctionBlockCmd::eFBT_Feature,
191                             fb_id,
192                             FunctionBlockCmd::eCA_Current );
193     fbCmd.setNodeId( node_id );
194     fbCmd.setSubunitId( 0x00 );
195     fbCmd.setCommandType( AVCCommand::eCT_Control );
196     fbCmd.m_pFBFeature->m_audioChannelNumber=channel;
197     fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume;
198     fbCmd.m_pFBFeature->m_pVolume->m_volume=value;
199
200     debugOutput(DEBUG_LEVEL_NORMAL, "Setting volume feature block channel %d state to %d...\n", channel, value);
201
202     fbCmd.setVerbose( bVerbose );
203     if (bVerbose) {
204         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
205     }
206    
207     if ( !fbCmd.fire() ) {
208         debugError( "cmd failed\n" );
209     }
210
211     if ( bVerbose ) {
212         CoutSerializer se;
213         fbCmd.serialize( se );
214     }
215
216     return true;
217 }
218
219 ///////////////////////////
220 // main
221 //////////////////////////
222 int
223 main( int argc, char **argv )
224 {
225
226     if (argc < 4) {
227         debugError("usage: PORT NODE_ID CMD FB_ID [VAL1] [VAL2]\n");
228         exit(0);
229     }
230
231     errno = 0;
232     char* tail;
233     int port = strtol( argv[1], &tail, 0 );
234     int node_id = strtol( argv[2], &tail, 0 );
235     int cmd = strtol( argv[3], &tail, 0 );
236     int fb_id   = strtol( argv[4], &tail, 0 );
237    
238     int value1=-1;
239     int value2=-1;
240    
241     if (argc>=6)
242         value1 = strtol(argv[5], &tail, 0 );
243        
244     if (argc>=7)
245         value2 = strtol(argv[6], &tail, 0 );
246    
247     if (errno) {
248         debugError("argument parsing failed: %s\n", strerror(errno));
249         return -1;
250     }
251     Ieee1394Service ieee1394service;
252     if ( !ieee1394service.initialize( port ) ) {
253         debugError( "could not set port on ieee1394service\n" );
254         return -1;
255     }
256
257     switch(cmd) {
258     case 0:
259         doApp( ieee1394service, node_id, fb_id );
260         break;
261     case 1:
262         selectorGet( ieee1394service, node_id, fb_id );
263         break;
264     case 2:
265         selectorSet( ieee1394service, node_id, fb_id , value1 );
266         break;
267     case 3:
268         volumeGet( ieee1394service, node_id, fb_id, value1);
269         break;
270     case 4:
271         volumeSet( ieee1394service, node_id, fb_id, value1, value2);
272         break;
273     }
274
275     return 0;
276 }
Note: See TracBrowser for help on using the browser.