Exemple #1
0
QStringList Version::dependencyVersions() {
    // WARNING: may be inaccurate since some come from compile-time header
    // definitions instead of the actual dynamically loaded library).
    QStringList result;
    result
            // Should be accurate.
            << QString("Qt: %1").arg(qVersion())
#ifdef __SHOUTCAST__
            // Should be accurate.
            << QString("libshout: %1").arg(shout_version(NULL, NULL, NULL))
#endif
#ifdef __PORTAUDIO__
            << QString("PortAudio: %1 %2").arg(Pa_GetVersion()).arg(Pa_GetVersionText())
#endif
            // The version of the RubberBand headers Mixxx was compiled with.
            << QString("RubberBand: %1").arg(RUBBERBAND_VERSION)
            // The version of the SoundTouch headers Mixxx was compiled with.
            << QString("SoundTouch: %1").arg(SOUNDTOUCH_VERSION)
            // The version of the TagLib headers Mixxx was compiled with.
            << QString("TagLib: %1.%2.%3").arg(QString::number(TAGLIB_MAJOR_VERSION),
                                               QString::number(TAGLIB_MINOR_VERSION),
                                               QString::number(TAGLIB_PATCH_VERSION))
            // The version of the ChromaPrint headers Mixxx was compiled with.
            << QString("ChromaPrint: %1.%2.%3").arg(QString::number(CHROMAPRINT_VERSION_MAJOR),
                                                    QString::number(CHROMAPRINT_VERSION_MINOR),
                                                    QString::number(CHROMAPRINT_VERSION_PATCH))
            // Should be accurate.
            << QString("Vorbis: %1").arg(vorbis_version_string())
            // The version of the FLAC headers Mixxx was compiled with.
            << QString("FLAC: %1").arg(FLAC__VERSION_STRING);

    return result;
}
Exemple #2
0
void print_version(void) {
	fprintf(stdout, "squeezeslave %s-%d\n", version, revision);
	fprintf(stdout, "compile flags: ");
#if defined(__APPLE__) && defined(__MACH__)
	fprintf(stdout, "osx ");
#elif defined(__WIN32__)
	fprintf(stdout, "win32 ");
#elif defined(__SUNPRO_C)
	fprintf(stdout, "solaris ");
#else
	fprintf(stdout, "linux ");
#endif
#ifndef PORTAUDIO_ALSA
	fprintf(stdout, "portaudio:1810 ");
#else
	fprintf(stdout, "portaudio:%d ", Pa_GetVersion());
#endif
#ifdef SLIMPROTO_DEBUG
	fprintf(stdout, "debug ");
#endif
#ifdef USE_SIGNALS_FOR_RESTART
	fprintf(stdout, "signals ");
#endif
#ifdef GETOPT_SUPPORTS_OPTIONAL
	fprintf(stdout, "getopt ");
#endif
#ifdef INTERACTIVE
	fprintf(stdout, "interactive ");
#endif
#ifdef DAEMONIZE
	fprintf(stdout, "daemon ");
#endif
#ifdef __BIG_ENDIAN__
	fprintf(stdout, "bigendian ");
#endif
	fprintf(stdout, "\n\n");

	fprintf (stdout,
	"Squeezeslave is licensed free of charge. There is NO WARRANTY for\n"
	"the program. This program is provided \"as is\" without warranty of\n"
	"any kind, either expressed or implied, including, but not limited\n"
       	"to, the implied warranties of merchantability and fitness for a\n"
       	"particular purpose.  The entire risk as to the quality and\n"
       	"performance of the program is with you.  Should the program prove\n"
       	"defective, you assume the cost of all necessary servicing, repair\n"
       	"or correction.\n\n"
	);

	fprintf(stdout, "Copyright (c) 2004-2007 Richard Titmuss,\n");
	fprintf(stdout, "              2008-2009 Duane Paddock.\n");
}
Exemple #3
0
QStringList Version::dependencyVersions() {
    char sndfile_version[128];
    sf_command(nullptr, SFC_GET_LIB_VERSION, sndfile_version, sizeof(sndfile_version));
    // Null-terminate just in case.
    sndfile_version[sizeof(sndfile_version) - 1] = '\0';
    // WARNING: may be inaccurate since some come from compile-time header
    // definitions instead of the actual dynamically loaded library).
    QStringList result;
    result
            // Should be accurate.
            << QString("Qt: %1").arg(qVersion())
#ifdef __BROADCAST__
            // Should be accurate.
            << QString("libshout: %1").arg(shout_version(NULL, NULL, NULL))
#endif
            << QString("PortAudio: %1 %2").arg(Pa_GetVersion()).arg(Pa_GetVersionText())
            // The version of the RubberBand headers Mixxx was compiled with.
            << QString("RubberBand: %1").arg(RUBBERBAND_VERSION)
            // The version of the SoundTouch headers Mixxx was compiled with.
            << QString("SoundTouch: %1").arg(SOUNDTOUCH_VERSION)
            // The version of the TagLib headers Mixxx was compiled with.
            << QString("TagLib: %1.%2.%3").arg(QString::number(TAGLIB_MAJOR_VERSION),
                                               QString::number(TAGLIB_MINOR_VERSION),
                                               QString::number(TAGLIB_PATCH_VERSION))
            // The version of the ChromaPrint headers Mixxx was compiled with.
            << QString("ChromaPrint: %1.%2.%3").arg(QString::number(CHROMAPRINT_VERSION_MAJOR),
                                                    QString::number(CHROMAPRINT_VERSION_MINOR),
                                                    QString::number(CHROMAPRINT_VERSION_PATCH))
            // Should be accurate.
            << QString("Vorbis: %1").arg(vorbis_version_string())
            // Should be accurate.
            << QString("libsndfile: %1").arg(sndfile_version)
            // The version of the FLAC headers Mixxx was compiled with.
            << QString("FLAC: %1").arg(FLAC__VERSION_STRING)
            << QString("libmp3lame: %1").arg(get_lame_version());

    return result;
}
// print info about the all audio devices to stdout.
void printDevicesInfo( void )
{
    PaError err;
    int numDevices;

    messagePrintf( ( "Printing audio devices information...\n" ) );

    err = Pa_Initialize();
    if( err != paNoError )
    {
        errorPrintf( ( "ERROR: Pa_Initialize returned 0x%x.\n", err ) );
        goto error;
    }

    messagePrintf( ( "PortAudio version: 0X%08X\n", Pa_GetVersion() ) );
    messagePrintf( ( "Version text: '%s'\n", Pa_GetVersionText() ) );

    numDevices = Pa_GetDeviceCount();
    if( numDevices < 0 )
    {
        errorPrintf( ( "ERROR: Pa_GetDeviceCount returned 0x%x.\n", numDevices ) );
        goto error;
    }

    messagePrintf( ( "Number of devices = %d\n", numDevices ) );

    for( int i = 0; i < numDevices; i++ )
        printDeviceInfo( i );

    Pa_Terminate();
    return;

error:
    Pa_Terminate();
    errorPrintf( ( "Error number: %d\n", err ) );
    errorPrintf( ( "Error message: %s\n", Pa_GetErrorText(err) ) );
}
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
Exemple #6
0
int main(void)
{
    int     i, numDevices, defaultDisplayed;
    const   PaDeviceInfo *deviceInfo;
    PaStreamParameters inputParameters, outputParameters;
    PaError err;

    
    Pa_Initialize();

    printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n",
            Pa_GetVersion(), Pa_GetVersionText() );

            
    numDevices = Pa_GetDeviceCount();
    if( numDevices < 0 )
    {
        printf( "ERROR: Pa_CountDevices 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 */
        printf( "Name                        = %s\n", deviceInfo->name );
        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.3f\n", deviceInfo->defaultLowInputLatency  );
        printf( "Default low output latency  = %8.3f\n", deviceInfo->defaultLowOutputLatency  );
        printf( "Default high input latency  = %8.3f\n", deviceInfo->defaultHighInputLatency  );
        printf( "Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency  );

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

            err = PaAsio_GetAvailableLatencyValues( 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_NO_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, "An error occured while using the portaudio stream\n" );
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
    return err;
}
int selectDevice()
{
    int     			i, 
						numDevices, 
						defaultDisplayed;
    const PaDeviceInfo 	*deviceInfo;
    PaStreamParameters 	inputParameters, 
						outputParameters;
	PaStream*			stream;
    PaError 			err;
	
    paTestData          data;
    int                 totalFrames;
    int                 numSamples;
    int                 numBytes;
	char 				devSelection[4];
	int					devSelectInt;

    
    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_GetAvailableLatencyValues( 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 );
        }
    } /* for numDevices */
	
	
	printf("What input device would you like to use? ");	
	fgets(devSelection, 4, stdin);
	devSelectInt	= atoi(devSelection);
	
	if(devSelectInt < numDevices)
	{
		printf("Hooray!  You chose device %s, which is within bounds.\n", devSelection);
		
		inputParameters.device	= devSelectInt;
		if(inputParameters.device == paNoDevice)
		{
			fprintf(stderr,"Error: input device at that device number.\n");
			goto error;
		} // if - no device
		
		data.maxFrameIndex = totalFrames = NUM_SECONDS * SAMPLE_RATE; /* Record for a few seconds. */
		data.frameIndex = 0;
		numSamples = totalFrames * NUM_CHANNELS;
		numBytes = numSamples * sizeof(SAMPLE);
		data.recordedSamples = (SAMPLE *) malloc( numBytes ); /* From now on, recordedSamples is initialised. */
		if( data.recordedSamples == NULL )
		{
			printf("Could not allocate record array.\n");
			goto error;
		}
		for( i=0; i<numSamples; i++ ) data.recordedSamples[i] = 0;
		
		inputParameters.channelCount = 2;                    /* stereo input */
		inputParameters.sampleFormat = PA_SAMPLE_TYPE;
		inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
		inputParameters.hostApiSpecificStreamInfo = NULL;
		
		 /* Record some audio. -------------------------------------------- */
		err = Pa_OpenStream(
				  &stream,
				  &inputParameters,
				  NULL,                  /* &outputParameters, */
				  SAMPLE_RATE,
				  FRAMES_PER_BUFFER,
				  paClipOff,      /* we won't output out of range samples so don't bother clipping them */
				  recordCallback,
				  &data );
		if( err != paNoError ) goto error;

		err = Pa_StartStream( stream );
		if( err != paNoError ) goto error;
		printf("\n=== Now recording!! Please speak into the microphone. ===\n"); fflush(stdout);

		while( ( err = Pa_IsStreamActive( stream ) ) == 1 )
		{
			Pa_Sleep(100);
			printf("index = %d; amplitude = %f\n", data.frameIndex, data.recordedSamples[data.frameIndex] ); fflush(stdout);
		}
		if( err < 0 ) goto error;

		err = Pa_CloseStream( stream );
		if( err != paNoError ) goto error;
			
	} // if - device number within bounds

    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;
} /* selectDevice */
Exemple #8
0
JNIEXPORT jint JNICALL Java_org_jpab_PortAudio_getVersion(JNIEnv *env, jclass paClass) {
	return (jint) Pa_GetVersion();
}
int main(int argc, char **argv)
{
  printf("formats==\npaInt16 = %lu\npaInt24 = %lu\npaInt32 = %lu\npaFloat32 = %lu\n",
    sizeof(paInt16), sizeof(int64_t), sizeof(paInt32), sizeof(paFloat32));
  //init ros
  ros::init(argc, argv, "audio_publisher");
  ros::NodeHandle n;
  //pub = n.advertise<std_msgs::Int16MultiArray>("audio_pub", 10);
  pub = n.advertise<publ::aud_publ>("audio_pub", 10);

  int num_device, def_i_device, def_o_device;
  const PaDeviceInfo *device_info; //structure describing PA device
  PaStreamParameters i_params, o_params; //io parameters for stream... if one then the other must be null
  PaStream *stream;
  RecData data, udata;
  int total_frames, num_samples, num_bytes;

  //total number of frames
  total_frames = NUM_SECONDS * SAMPLE_RATE;
  num_samples = total_frames * NUM_CHANNELS;
  num_bytes = num_samples * sizeof(SAMPLE);

  printf("TOTAL FRAMES: %d\nNUM. SAMPLES: %d\nNUM. BYTES: %d\n", total_frames, num_samples, num_bytes);

  data.max_frame_idx = total_frames;
  data.frame_idx = 0;
  data.recorded_samples = (SAMPLE*) malloc(num_bytes); //check if memory allocated
  if (data.recorded_samples == NULL){
    printf("ERROR!!!! COULD NOT ALLOCATE MEMORY\n");
    err = -1;
    goto error_point;
  } else printf("MEMORY CORRECTLY ALLOCATED\n");

  //SET recorded_samples ARRAY TO 0
  for (int i = 0; i < num_samples; i++) data.recorded_samples[i] = 0;

  //initializing pa
  err = Pa_Initialize();
  if(err != paNoError){//if error occured
    printf("ERROR!! Initialization failed!\n");
    goto error_point;
  }

  //if no error
  printf("portaudio version: 0x%08X\n", Pa_GetVersion());
  printf("Version text: %s\n", Pa_GetVersionText());

  num_device = Pa_GetDeviceCount();

  if(num_device < 0){
    printf("ERROR Pa_GetDeviceCount() returned %d\n", num_device);
      err = num_device;
      goto error_point;
  }

  //if num_device is fine
  printf("Number of Devices: %d\n", num_device);
  def_i_device = Pa_GetDefaultInputDevice();
  def_o_device = Pa_GetDefaultOutputDevice();
  printf("Default Input Device ID: %d\n", def_i_device);
  printf("Default Output Device ID: %d\n", def_o_device);

  //getting info on each of the devices
  for (int i = 0; i < num_device; i++){
    device_info = Pa_GetDeviceInfo(i);
    
    if (i == Pa_GetDefaultInputDevice())
      printf("---- DEFAULT INPUT DEVICE!! ----\n");
    if (i == Pa_GetDefaultOutputDevice())
      printf("**** DEFAULT OUTPUT DEVICE!! ****\n");
    


    printf("Device Name: \t%s\n", device_info->name);
    printf("Host API: \t%s\n", Pa_GetHostApiInfo(device_info->hostApi)->name);
    printf("Max Inputs: \t%d\n", device_info->maxInputChannels);
    printf("Max Outputs: \t%d\n", device_info->maxOutputChannels);
    printf("Default low input latency   = %8.4f\n", device_info->defaultLowInputLatency  );
        printf("Default low output latency  = %8.4f\n", device_info->defaultLowOutputLatency  );
        printf("Default high input latency  = %8.4f\n", device_info->defaultHighInputLatency  );
        printf("Default high output latency = %8.4f\n", device_info->defaultHighOutputLatency  );
        printf("Default Sample Rate: \t%8.2f\n", device_info->defaultSampleRate);
  }//done displaying 

  //USE FUNCTION Pa_IsFormatSupported(iparams, oparams, sample_rate)
  //RETURNS paFormatIsSupported IF THE SAMPLE RATE IS SUPPORTED
  //use the default device
  device_info = Pa_GetDeviceInfo(def_i_device);

  i_params.device = def_i_device;
  i_params.channelCount = NUM_CHANNELS;
  i_params.sampleFormat = paInt16;
  i_params.suggestedLatency = 0; //hehe I wish
  i_params.hostApiSpecificStreamInfo = NULL;
  
  if(ENABLE_PLAYBACK){
    o_params.device = def_o_device;
    o_params.channelCount = NUM_CHANNELS;
    o_params.sampleFormat = paInt16;
    o_params.suggestedLatency = 0;
    o_params.hostApiSpecificStreamInfo = NULL;
  }

  //OPENING INPUT STREAM
  err = Pa_OpenStream(&stream, &i_params, NULL, SAMPLE_RATE, 
    FRAMES_PER_BUFFER, paClipOff, recorder, &data);

  if(err != paNoError){
    printf("ERROR!! COULD NOT OPEN INPUT STREAM -- %d\n", err);
    goto error_point;
  }

  if(ENABLE_PLAYBACK){
      //OPENING OUTPUT STREAM
      err = Pa_OpenStream(&o_stream, NULL, &o_params, SAMPLE_RATE, 
        FRAMES_PER_BUFFER, paClipOff, NULL, &udata);
      if(err != paNoError){
        printf("ERROR!! COULD NOT OPEN OUTPUT STREAM -- %d\n", err);
        goto error_point;
      }
  }



  err = Pa_StartStream(stream);
  if(err != paNoError)
  {
    printf("ERROR!! COULD NOT START INPUT STREAM -- %d\n", err);
    goto error_point;
  }
  else printf("*** RECORDING ***\n");


  if(ENABLE_PLAYBACK)
  {
      //START OUTPUT STREAM
      err = Pa_StartStream(o_stream);
      if(err != paNoError)
      {
        printf("ERROR!! COULD NOT START OUTPUT STREAM -- %d\n", err);
        goto error_point;
      }
      else printf("*** PLAYBACK ***\n");
  }


  while(Pa_IsStreamActive(stream)) //while the stream is active
  {
    //maybe do some delays or whatever and output some shit
    Pa_Sleep(1000);
    printf("INDEX: %d\n", data.frame_idx);
  }

  err = Pa_CloseStream(stream);
  if(err != paNoError)
  {
    printf("ERROR!! COULD NOT CLOSE INPUT STREAM -- %d\n", err);
    goto error_point;
  }
  
  if(ENABLE_PLAYBACK)
  {
      err = Pa_CloseStream(o_stream);
      if(err != paNoError)
      {
        printf("ERROR!! COULD NOT CLOSE OUTPUT STREAM -- %d\n", err);
        goto error_point;
      }
  }


  #if WRITE_TO_FILE 
  {
    FILE *out_file;
    out_file = fopen("recorded_raw.raw", "wb");
    if(!out_file){
      printf("ERROR!! COULD NOT OPEN FILE FOR WRITING\n");
      goto error_point;
    }
    
    fwrite(data.recorded_samples, NUM_CHANNELS*sizeof(SAMPLE), total_frames, out_file);
    fclose(out_file);
    printf("WRITING TO FILE SUCCESSFUL!!\n");
  }
  #endif


  Pa_Terminate();

//FREE UP MEMORY
  if(data.recorded_samples != NULL) free(data.recorded_samples);

  printf("EXITING.... MEMORY FREED\n");
  return 0;


error_point:
  Pa_Terminate();
  printf("Exiting... ERROR CODE: %s\n",  Pa_GetErrorText(err));
  return err;
}
Exemple #10
0
JNIEXPORT jint JNICALL Java_com_github_rjeschke_jpa_JPA_getVersion(JNIEnv *env, jclass clazz)
{
    return (jint)Pa_GetVersion();
}