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

Revision 1340, 4.5 kB (checked in by wagi, 16 years ago)

add test program for seting the pan.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
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
24 #include "libavc/audiosubunit/avc_function_block.h"
25 #include "libutil/serialize.h"
26 #include "libutil/cmd_serialize.h"
27
28 #include "libieee1394/ieee1394service.h"
29
30 const bool bVerbose = false;
31
32 using namespace AVC;
33 using namespace Util;
34 using namespace Util::Cmd;
35
36 short int
37 getPan( Ieee1394Service& ieee1394service, int node_id, int ffb_id,
38            FunctionBlockCmd::EControlAttribute control_attrib )
39 {
40     FunctionBlockCmd fbCmd( ieee1394service,
41                             FunctionBlockCmd::eFBT_Feature,
42                             ffb_id,
43                             control_attrib );
44     fbCmd.setNodeId( node_id );
45     fbCmd.setSubunitId( 0x00 );
46     fbCmd.setCommandType( AVCCommand::eCT_Status );
47     fbCmd.m_pFBFeature->m_audioChannelNumber = 2;
48     fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_LRBalance;
49     AVC::FunctionBlockFeatureLRBalance lr;
50     fbCmd.m_pFBFeature->m_pLRBalance = lr.clone();
51     fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = 0;
52
53     fbCmd.setVerbose( bVerbose );
54     if (bVerbose) {
55         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE );
56     }
57
58     if ( !fbCmd.fire() ) {
59         printf( "cmd failed\n" );
60     }
61
62     if ( bVerbose ) {
63         CoutSerializer se;
64         fbCmd.serialize( se );
65     }
66
67     return fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance;
68 }
69
70 bool
71 setPan( Ieee1394Service& ieee1394service, int node_id, int ffb_id, int pan )
72 {
73     FunctionBlockCmd fbCmd( ieee1394service,
74                             FunctionBlockCmd::eFBT_Feature,
75                             ffb_id,
76                             FunctionBlockCmd::eCA_Current );
77     fbCmd.setNodeId( node_id );
78     fbCmd.setSubunitId( 0x00 );
79     fbCmd.setCommandType( AVCCommand::eCT_Control );
80     fbCmd.m_pFBFeature->m_audioChannelNumber = 2;
81     fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_LRBalance;
82     AVC::FunctionBlockFeatureLRBalance lr;
83     fbCmd.m_pFBFeature->m_pLRBalance = lr.clone();
84     fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = pan;
85
86     fbCmd.setVerbose( bVerbose );
87     if (bVerbose) {
88         ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE );
89     }
90
91     bool bStatus = fbCmd.fire();
92     if ( !bStatus ) {
93         printf( "cmd failed\n" );
94     }
95
96     if ( bVerbose ) {
97         CoutSerializer se;
98         fbCmd.serialize( se );
99     }
100
101     return bStatus;
102 }
103
104 bool
105 doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id, int pan )
106 {
107     short int maxPan = getPan( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Maximum );
108     short int minPan = getPan( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Minimum );
109     short int curPan = getPan( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current );
110     printf( "max pan value = %d\n", maxPan );
111     printf( "min pan value = %d\n", minPan );
112     printf( "old pan value = %d\n", curPan );
113
114     //setPan( ieee1394service, node_id, fb_id, pan );
115
116     curPan = getPan( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current );
117     printf( "new pan value = %d\n", curPan );
118
119     return true;
120 }
121
122 ///////////////////////////
123 // main
124 //////////////////////////
125 int
126 main(int argc, char **argv)
127 {
128
129     if (argc < 4) {
130         printf("usage: NODE_ID FB_ID PAN\n");
131         exit(0);
132     }
133
134     int errno = 0;
135     char* tail;
136     int node_id = strtol( argv[1], &tail, 0 );
137     int fb_id   = strtol( argv[2], &tail, 0 );
138     int pan     = strtol( argv[3], &tail, 0 );
139
140     if (errno) {
141         perror("argument parsing failed:");
142         return -1;
143     }
144     Ieee1394Service ieee1394service;
145     if ( !ieee1394service.initialize( 0 ) ) {
146         fprintf( stderr, "could not set port on ieee1394service\n" );
147         return -1;
148     }
149
150     doApp( ieee1394service, node_id, fb_id, pan );
151
152     return 0;
153 }
Note: See TracBrowser for help on using the browser.