patest_jack_wasapi.c (9611B)
1 /** @file pa_test_jack_wasapi.c 2 @ingroup test_src 3 @brief Print out jack information for WASAPI endpoints 4 @author Reid Bishop <rbish@attglobal.net> 5 */ 6 /* 7 * $Id: pa_test_jack_wasapi.c 1368 2008-03-01 00:38:27Z rbishop $ 8 * 9 * This program uses the PortAudio Portable Audio Library. 10 * For more information see: http://www.portaudio.com/ 11 * Copyright (c) 1999-2010 Ross Bencina and Phil Burk 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files 15 * (the "Software"), to deal in the Software without restriction, 16 * including without limitation the rights to use, copy, modify, merge, 17 * publish, distribute, sublicense, and/or sell copies of the Software, 18 * and to permit persons to whom the Software is furnished to do so, 19 * subject to the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 28 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 29 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 */ 32 33 /* 34 * The text above constitutes the entire PortAudio license; however, 35 * the PortAudio community also makes the following non-binding requests: 36 * 37 * Any person wishing to distribute modifications to the Software is 38 * requested to send the modifications to the original developer so that 39 * they can be incorporated into the canonical version. It is also 40 * requested that these non-binding requests be included along with the 41 * license above. 42 */ 43 #include <stdio.h> 44 #include "portaudio.h" 45 #include "pa_win_wasapi.h" 46 47 48 /* 49 * Helper function to determine if a given enum is present in mask variable 50 * 51 */ 52 static int IsInMask(int val, int val2) 53 { 54 return ((val & val2) == val2); 55 } 56 57 /* 58 * This routine enumerates through the ChannelMapping for the IJackDescription 59 */ 60 61 static void EnumIJackChannels(int channelMapping) 62 { 63 printf("Channel Mapping: "); 64 if(channelMapping == PAWIN_SPEAKER_DIRECTOUT) 65 { 66 printf("DIRECTOUT\n"); 67 return; 68 } 69 if(IsInMask(channelMapping, PAWIN_SPEAKER_FRONT_LEFT)) 70 printf("FRONT_LEFT, "); 71 if(IsInMask(channelMapping, PAWIN_SPEAKER_FRONT_RIGHT)) 72 printf("FRONT_RIGHT, "); 73 if(IsInMask(channelMapping, PAWIN_SPEAKER_FRONT_CENTER)) 74 printf("FRONT_CENTER, "); 75 if(IsInMask(channelMapping, PAWIN_SPEAKER_LOW_FREQUENCY)) 76 printf("LOW_FREQUENCY, "); 77 if(IsInMask(channelMapping, PAWIN_SPEAKER_BACK_LEFT)) 78 printf("BACK_LEFT, "); 79 if(IsInMask(channelMapping,PAWIN_SPEAKER_BACK_RIGHT)) 80 printf("BACK_RIGHT, "); 81 if(IsInMask(channelMapping, PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER)) 82 printf("FRONT_LEFT_OF_CENTER, "); 83 if(IsInMask(channelMapping, PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER)) 84 printf("FRONT_RIGHT_OF_CENTER, "); 85 if(IsInMask(channelMapping, PAWIN_SPEAKER_BACK_CENTER)) 86 printf("BACK_CENTER, "); 87 if(IsInMask(channelMapping,PAWIN_SPEAKER_SIDE_LEFT)) 88 printf("SIDE_LEFT, "); 89 if(IsInMask(channelMapping,PAWIN_SPEAKER_SIDE_RIGHT)) 90 printf("SIDE_RIGHT, "); 91 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_CENTER)) 92 printf("TOP_CENTER, "); 93 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_FRONT_LEFT)) 94 printf("TOP_FRONT_LEFT, "); 95 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_FRONT_CENTER)) 96 printf("TOP_FRONT_CENTER, "); 97 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_FRONT_RIGHT)) 98 printf("TOP_FRONT_RIGHT, "); 99 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_BACK_LEFT)) 100 printf("TOP_BACK_LEFT, "); 101 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_BACK_CENTER)) 102 printf("TOP_BACK_CENTER, "); 103 if(IsInMask(channelMapping, PAWIN_SPEAKER_TOP_BACK_RIGHT)) 104 printf("TOP_BACK_RIGHT, "); 105 106 printf("\n"); 107 } 108 109 /* 110 * This routine enumerates through the Jack Connection Types enums for IJackDescription 111 */ 112 static void EnumIJackConnectionType(int cType) 113 { 114 printf("Connection Type: "); 115 switch(cType) 116 { 117 case eJackConnTypeUnknown: 118 printf("eJackConnTypeUnknown"); 119 break; 120 case eJackConnType3Point5mm: 121 printf("eJackConnType3Point5mm"); 122 break; 123 case eJackConnTypeQuarter: 124 printf("eJackConnTypeQuarter"); 125 break; 126 case eJackConnTypeAtapiInternal: 127 printf("eJackConnTypeAtapiInternal"); 128 break; 129 case eJackConnTypeRCA: 130 printf("eJackConnTypeRCA"); 131 break; 132 case eJackConnTypeOptical: 133 printf("eJackConnTypeOptical"); 134 break; 135 case eJackConnTypeOtherDigital: 136 printf("eJackConnTypeOtherDigital"); 137 break; 138 case eJackConnTypeOtherAnalog: 139 printf("eJackConnTypeOtherAnalog"); 140 break; 141 case eJackConnTypeMultichannelAnalogDIN: 142 printf("eJackConnTypeMultichannelAnalogDIN"); 143 break; 144 case eJackConnTypeXlrProfessional: 145 printf("eJackConnTypeXlrProfessional"); 146 break; 147 case eJackConnTypeRJ11Modem: 148 printf("eJackConnTypeRJ11Modem"); 149 break; 150 case eJackConnTypeCombination: 151 printf("eJackConnTypeCombination"); 152 break; 153 } 154 printf("\n"); 155 } 156 157 /* 158 * This routine enumerates through the GeoLocation enums for the IJackDescription 159 */ 160 static void EnumIJackGeoLocation(int iVal) 161 { 162 printf("Geometric Location: "); 163 switch(iVal) 164 { 165 case eJackGeoLocRear: 166 printf("eJackGeoLocRear"); 167 break; 168 case eJackGeoLocFront: 169 printf("eJackGeoLocFront"); 170 break; 171 case eJackGeoLocLeft: 172 printf("eJackGeoLocLeft"); 173 break; 174 case eJackGeoLocRight: 175 printf("eJackGeoLocRight"); 176 break; 177 case eJackGeoLocTop: 178 printf("eJackGeoLocTop"); 179 break; 180 case eJackGeoLocBottom: 181 printf("eJackGeoLocBottom"); 182 break; 183 case eJackGeoLocRearPanel: 184 printf("eJackGeoLocRearPanel"); 185 break; 186 case eJackGeoLocRiser: 187 printf("eJackGeoLocRiser"); 188 break; 189 case eJackGeoLocInsideMobileLid: 190 printf("eJackGeoLocInsideMobileLid"); 191 break; 192 case eJackGeoLocDrivebay: 193 printf("eJackGeoLocDrivebay"); 194 break; 195 case eJackGeoLocHDMI: 196 printf("eJackGeoLocHDMI"); 197 break; 198 case eJackGeoLocOutsideMobileLid: 199 printf("eJackGeoLocOutsideMobileLid"); 200 break; 201 case eJackGeoLocATAPI: 202 printf("eJackGeoLocATAPI"); 203 break; 204 } 205 printf("\n"); 206 } 207 208 /* 209 * This routine enumerates through the GenLocation enums for the IJackDescription 210 */ 211 static void EnumIJackGenLocation(int iVal) 212 { 213 printf("General Location: "); 214 switch(iVal) 215 { 216 case eJackGenLocPrimaryBox: 217 printf("eJackGenLocPrimaryBox"); 218 break; 219 case eJackGenLocInternal: 220 printf("eJackGenLocInternal"); 221 break; 222 case eJackGenLocSeparate: 223 printf("eJackGenLocSeparate"); 224 break; 225 case eJackGenLocOther: 226 printf("eJackGenLocOther"); 227 break; 228 } 229 printf("\n"); 230 } 231 232 /* 233 * This routine enumerates through the PortConnection enums for the IJackDescription 234 */ 235 static void EnumIJackPortConnection(int iVal) 236 { 237 printf("Port Type: "); 238 switch(iVal) 239 { 240 case eJackPortConnJack: 241 printf("eJackPortConnJack"); 242 break; 243 case eJackPortConnIntegratedDevice: 244 printf("eJackPortConnIntegratedDevice"); 245 break; 246 case eJackPortConnBothIntegratedAndJack: 247 printf("eJackPortConnBothIntegratedAndJack"); 248 break; 249 case eJackPortConnUnknown: 250 printf("eJackPortConnUnknown"); 251 break; 252 } 253 printf("\n"); 254 } 255 256 /* 257 * This routine retrieves and parses the KSJACK_DESCRIPTION structure for 258 * the provided device ID. 259 */ 260 static PaError GetJackInformation(int deviceId) 261 { 262 PaError err; 263 int i; 264 int jackCount = 0; 265 PaWasapiJackDescription jackDesc; 266 267 err = PaWasapi_GetJackCount(deviceId, &jackCount); 268 if( err != paNoError ) return err; 269 270 fprintf( stderr,"Number of Jacks: %d \n", jackCount ); 271 272 for( i = 0; i<jackCount; i++ ) 273 { 274 fprintf( stderr,"Jack #%d:\n", i ); 275 276 err = PaWasapi_GetJackDescription(deviceId, i, &jackDesc); 277 if( err != paNoError ) 278 { 279 fprintf( stderr,"Failed getting description." ); 280 continue; 281 } 282 else 283 { 284 printf("Is connected: %s\n",(jackDesc.isConnected)?"true":"false"); 285 EnumIJackChannels(jackDesc.channelMapping); 286 EnumIJackConnectionType(jackDesc.connectionType); 287 EnumIJackGeoLocation(jackDesc.geoLocation); 288 EnumIJackGenLocation(jackDesc.genLocation); 289 EnumIJackPortConnection(jackDesc.portConnection); 290 printf("Jack Color: 0x%06X\n", jackDesc.color); 291 printf("\n"); 292 } 293 } 294 return 0; 295 } 296 297 298 /*******************************************************************/ 299 int main(void); 300 int main(void) 301 { 302 PaError err; 303 const PaDeviceInfo *device; 304 int i; 305 int jackCount = 0; 306 int isInput = 0; 307 308 printf("PortAudio Test: WASAPI Jack Configuratin"); 309 err = Pa_Initialize(); 310 if( err != paNoError ) goto error; 311 312 /* Find all WASAPI devices */ 313 for( i = 0; i < Pa_GetDeviceCount(); ++i ) 314 { 315 device = Pa_GetDeviceInfo(i); 316 if( Pa_GetDeviceInfo(i)->hostApi == Pa_HostApiTypeIdToHostApiIndex(paWASAPI) ) 317 { 318 if( device->maxOutputChannels == 0 ) 319 { 320 isInput = 1; 321 } 322 printf("------------------------------------------\n"); 323 printf("Device: %s",device->name); 324 if(isInput) 325 printf(" (Input) %d Channels\n",device->maxInputChannels); 326 else 327 printf(" (Output) %d Channels\n",device->maxOutputChannels); 328 // Try to see if this WASAPI device can provide Jack information 329 err = GetJackInformation(i); 330 if( err != paNoError ) goto error; 331 } 332 } 333 Pa_Terminate(); 334 printf("Test finished.\n"); 335 return err; 336 337 error: 338 Pa_Terminate(); 339 fprintf( stderr, "An error occured while using the portaudio stream\n" ); 340 fprintf( stderr, "Error number: %d\n", err ); 341 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); 342 return err; 343 }