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

Revision 2803, 4.5 kB (checked in by jwoithe, 3 years ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

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