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