int main(void)
{
    int     i, numDevices, defaultDisplayed;
    const   PaDeviceInfo *deviceInfo;
    PaStreamParameters inputParameters, outputParameters;
    PaError err;

    
    err = Pa_Initialize();
    if( err != paNoError )
    {
        printf( "ERROR: Pa_Initialize returned 0x%x\n", err );
        goto error;
    }
    
    printf( "PortAudio version: 0x%08X\n", Pa_GetVersion());
    printf( "Version text: '%s'\n", Pa_GetVersionInfo()->versionText );

    numDevices = Pa_GetDeviceCount();
    if( numDevices < 0 )
    {
        printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices );
        err = numDevices;
        goto error;
    }
    
    printf( "Number of devices = %d\n", numDevices );
    for( i=0; i<numDevices; i++ )
    {
        deviceInfo = Pa_GetDeviceInfo( i );
        printf( "--------------------------------------- device #%d\n", i );
                
    /* Mark global and API specific default devices */
        defaultDisplayed = 0;
        if( i == Pa_GetDefaultInputDevice() )
        {
            printf( "[ Default Input" );
            defaultDisplayed = 1;
        }
        else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
        {
            const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
            printf( "[ Default %s Input", hostInfo->name );
            defaultDisplayed = 1;
        }
        
        if( i == Pa_GetDefaultOutputDevice() )
        {
            printf( (defaultDisplayed ? "," : "[") );
            printf( " Default Output" );
            defaultDisplayed = 1;
        }
        else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
        {
            const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
            printf( (defaultDisplayed ? "," : "[") );                
            printf( " Default %s Output", hostInfo->name );
            defaultDisplayed = 1;
        }

        if( defaultDisplayed )
            printf( " ]\n" );

    /* print device info fields */
#ifdef WIN32
        {   /* Use wide char on windows, so we can show UTF-8 encoded device names */
            wchar_t wideName[MAX_PATH];
            MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1);
            wprintf( L"Name                        = %s\n", wideName );
        }
#else
        printf( "Name                        = %s\n", deviceInfo->name );
#endif
        printf( "Host API                    = %s\n",  Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
        printf( "Max inputs = %d", deviceInfo->maxInputChannels  );
        printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels  );

        printf( "Default low input latency   = %8.4f\n", deviceInfo->defaultLowInputLatency  );
        printf( "Default low output latency  = %8.4f\n", deviceInfo->defaultLowOutputLatency  );
        printf( "Default high input latency  = %8.4f\n", deviceInfo->defaultHighInputLatency  );
        printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency  );

#ifdef WIN32
#if PA_USE_ASIO
/* ASIO specific latency information */
        if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
            long minLatency, maxLatency, preferredLatency, granularity;

            err = PaAsio_GetAvailableBufferSizes( i,
		            &minLatency, &maxLatency, &preferredLatency, &granularity );

            printf( "ASIO minimum buffer size    = %ld\n", minLatency  );
            printf( "ASIO maximum buffer size    = %ld\n", maxLatency  );
            printf( "ASIO preferred buffer size  = %ld\n", preferredLatency  );

            if( granularity == -1 )
                printf( "ASIO buffer granularity     = power of 2\n" );
            else
                printf( "ASIO buffer granularity     = %ld\n", granularity  );
        }
#endif /* PA_USE_ASIO */
#endif /* WIN32 */

        printf( "Default sample rate         = %8.2f\n", deviceInfo->defaultSampleRate );

    /* poll for standard sample rates */
        inputParameters.device = i;
        inputParameters.channelCount = deviceInfo->maxInputChannels;
        inputParameters.sampleFormat = paInt16;
        inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
        inputParameters.hostApiSpecificStreamInfo = NULL;
        
        outputParameters.device = i;
        outputParameters.channelCount = deviceInfo->maxOutputChannels;
        outputParameters.sampleFormat = paInt16;
        outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
        outputParameters.hostApiSpecificStreamInfo = NULL;

        if( inputParameters.channelCount > 0 )
        {
            printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n",
                    inputParameters.channelCount );
            PrintSupportedStandardSampleRates( &inputParameters, NULL );
        }

        if( outputParameters.channelCount > 0 )
        {
            printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n",
                    outputParameters.channelCount );
            PrintSupportedStandardSampleRates( NULL, &outputParameters );
        }

        if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 )
        {
            printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
                    inputParameters.channelCount, outputParameters.channelCount );
            PrintSupportedStandardSampleRates( &inputParameters, &outputParameters );
        }
    }

    Pa_Terminate();

    printf("----------------------------------------------\n");
    return 0;

error:
    Pa_Terminate();
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
    return err;
} // main
Example #2
0
PaError IPortAudio::configure_InputDevice(long FrameSize)
{
#if defined(TARGET_WINDOWS)
  // configure HostAPI audio channels
  if(m_UsedInputHostAPI == paASIO)
  { // Configure ASIO device
    m_InputParameters.hostApiSpecificStreamInfo = new PaAsioStreamInfo;
    memset(m_InputParameters.hostApiSpecificStreamInfo, 0, sizeof(PaAsioStreamInfo));

    ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->size = sizeof(PaAsioStreamInfo);
    ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->hostApiType = paASIO;
    ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->version = 1;
    ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->flags = paAsioUseChannelSelectors;

    ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->channelSelectors = new int[m_InputParameters.channelCount];

    for(int ch = 0; ch < m_InputParameters.channelCount; ch++)
    {
      ((PaAsioStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->channelSelectors[ch] = ch;
    }
  }
  else if(m_UsedInputHostAPI == paWASAPI)
  {
    if(m_InputParameters.channelCount < m_InputDeviceInfo.deviceInfo->maxInputChannels)
    { // try to set WASAPI exclusive mode
      m_InputParameters.hostApiSpecificStreamInfo = new PaWasapiStreamInfo;
      memset(m_InputParameters.hostApiSpecificStreamInfo, 0, sizeof(PaWasapiStreamInfo));

      ((PaWasapiStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->hostApiType = paWASAPI;
      ((PaWasapiStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->version = 1;
      ((PaWasapiStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->size = sizeof(PaWasapiStreamInfo);
      ((PaWasapiStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->flags = paWinWasapiExclusive;
      PaWinWaveFormat waveFormat;
      if(PaWasapi_GetDeviceDefaultFormat(&waveFormat, sizeof(PaWinWaveFormat), m_InputDeviceInfo.paDeviceIdx) < 0)
      {
        return paIncompatibleHostApiSpecificStreamInfo;
      }

      // TODO: check how to set channelMask and how to use waveFormat information
      //((PaWasapiStreamInfo*)m_InputParameters.hostApiSpecificStreamInfo)->channelMask = 
    }
    else
    {
      m_InputParameters.hostApiSpecificStreamInfo = NULL;
    }
  }
  else
  {
    m_InputParameters.hostApiSpecificStreamInfo = NULL;
  }

  // configure device latency/bufferSize
  if(m_UsedInputHostAPI == paASIO)
  {
    long minBufferSizeFrames;
    long maxBufferSizeFrames;
    long preferredBufferSizeFrames;
    long granularity;
    PaError paErr = PaAsio_GetAvailableBufferSizes(m_InputParameters.device, &minBufferSizeFrames, &maxBufferSizeFrames, &preferredBufferSizeFrames, &granularity);
    if(paErr != paNoError)
    {
      return paErr;
    }

    cout << "ASIO minimum buffer size " << minBufferSizeFrames << endl;
    cout << "ASIO maximum buffer size " << maxBufferSizeFrames << endl;
    cout << "ASIO preferred buffer size " << preferredBufferSizeFrames << endl;

    if(granularity == -1)
    {
      cout << "ASIO buffer granularity is power of 2" << endl;
    }
    else
    {
      cout << "ASIO buffer granularity: " << granularity << endl;
    }

    if(FrameSize < 0)
    { 
      m_InputFrameSize = (unsigned long)preferredBufferSizeFrames;
    }
    else if(FrameSize > maxBufferSizeFrames)
    {
      m_InputFrameSize = (unsigned long)maxBufferSizeFrames;
    }
    else
    {
      m_InputFrameSize = (unsigned long)FrameSize;
    }
  }
  else
  {
    if(FrameSize <= 0)
    {
      FrameSize = 2048;
    }
    else
    {
      m_InputFrameSize = FrameSize;
    }

  }
#endif


  return paNoError;
}