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

Revision 969, 7.7 kB (checked in by ppalmers, 16 years ago)

fixes #85

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
32 DECLARE_GLOBAL_DEBUG_MODULE;
33
34 const bool bVerbose = true;
35
36 bool
37 doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id )
38 {
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;
47
48     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer programmable state...\n");
49
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;
55
56     fbCmd.setVerbose( bVerbose );
57     if (bVerbose) {
58         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
59     }
60
61     if ( !fbCmd.fire() ) {
62         debugError( "cmd failed\n" );
63     }
64
65     if ( bVerbose ) {
66         CoutSerializer se;
67         fbCmd.serialize( se );
68     }
69    
70     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer level state...\n");
71    
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;
77    
78     if ( !fbCmd.fire() ) {
79         debugError( "cmd failed\n" );
80     }
81
82     if ( bVerbose ) {
83         CoutSerializer se;
84         fbCmd.serialize( se );
85     }
86
87     return true;
88 }
89
90 bool
91 selectorGet( Ieee1394Service& ieee1394service, int node_id, int fb_id )
92 {
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;
101
102     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting selector state...\n");
103
104     fbCmd.setVerbose( bVerbose );
105     if (bVerbose) {
106         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
107     }
108    
109     if ( !fbCmd.fire() ) {
110         debugError( "cmd failed\n" );
111     }
112
113     if ( bVerbose ) {
114         CoutSerializer se;
115         fbCmd.serialize( se );
116     }
117
118     return true;
119 }
120
121 bool
122 selectorSet( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val )
123 {
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;
132
133     debugOutput(DEBUG_LEVEL_NORMAL, "Setting selector state to %d...\n", val);
134
135     fbCmd.setVerbose( bVerbose );
136     if (bVerbose) {
137         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
138     }
139    
140     if ( !fbCmd.fire() ) {
141         debugError( "cmd failed\n" );
142     }
143
144     if ( bVerbose ) {
145         CoutSerializer se;
146         fbCmd.serialize( se );
147     }
148
149     return true;
150 }
151
152 bool
153 volumeGet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel )
154 {
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;
165
166     debugOutput(DEBUG_LEVEL_NORMAL, "Requesting volume feature block state...\n");
167
168     fbCmd.setVerbose( bVerbose );
169     if (bVerbose) {
170         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
171     }
172    
173     if ( !fbCmd.fire() ) {
174         debugError( "cmd failed\n" );
175     }
176
177     if ( bVerbose ) {
178         CoutSerializer se;
179         fbCmd.serialize( se );
180     }
181
182     return true;
183 }
184
185 bool
186 volumeSet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel, int value )
187 {
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;
198
199     debugOutput(DEBUG_LEVEL_NORMAL, "Setting volume feature block channel %d state to %d...\n", channel, value);
200
201     fbCmd.setVerbose( bVerbose );
202     if (bVerbose) {
203         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
204     }
205    
206     if ( !fbCmd.fire() ) {
207         debugError( "cmd failed\n" );
208     }
209
210     if ( bVerbose ) {
211         CoutSerializer se;
212         fbCmd.serialize( se );
213     }
214
215     return true;
216 }
217
218 ///////////////////////////
219 // main
220 //////////////////////////
221 int
222 main( int argc, char **argv )
223 {
224
225     if (argc < 4) {
226         debugError("usage: PORT NODE_ID CMD FB_ID [VAL1] [VAL2]\n");
227         exit(0);
228     }
229
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 );
236    
237     int value1=-1;
238     int value2=-1;
239    
240     if (argc>=6)
241         value1 = strtol(argv[5], &tail, 0 );
242        
243     if (argc>=7)
244         value2 = strtol(argv[6], &tail, 0 );
245    
246     if (errno) {
247         debugError("argument parsing failed: %s\n", strerror(errno));
248         return -1;
249     }
250     Ieee1394Service ieee1394service;
251     if ( !ieee1394service.initialize( port ) ) {
252         debugError( "could not set port on ieee1394service\n" );
253         return -1;
254     }
255
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;
272     }
273
274     return 0;
275 }
Note: See TracBrowser for help on using the browser.