示例#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;
}
示例#2
0
文件: pa.cpp 项目: dalematt/MuseScore
bool Portaudio::init()
      {
      PaError err = Pa_Initialize();
      if (err != paNoError) {
            qDebug("Portaudio initialize failed: %s", Pa_GetErrorText(err));
            return false;
            }
      initialized = true;
      if (MScore::debugMode)
            qDebug("using PortAudio Version: %s", Pa_GetVersionText());

      PaDeviceIndex idx = preferences.portaudioDevice;
      if (idx < 0)
            idx = Pa_GetDefaultOutputDevice();

      const PaDeviceInfo* di = Pa_GetDeviceInfo(idx);
      _sampleRate = int(di->defaultSampleRate);

      /* Open an audio I/O stream. */
      struct PaStreamParameters out;
      memset(&out, 0, sizeof(out));

      out.device           = idx;
      out.channelCount     = 2;
      out.sampleFormat     = paFloat32;
      out.suggestedLatency = 0.020;
      out.hostApiSpecificStreamInfo = 0;

      err = Pa_OpenStream(&stream, 0, &out, double(_sampleRate), 0, 0, paCallback, (void*)this);
      if (err != paNoError) {
            // fall back to default device:
            out.device = Pa_GetDefaultOutputDevice();
            err = Pa_OpenStream(&stream, 0, &out, double(_sampleRate), 0, 0, paCallback, (void*)this);
            if (err != paNoError) {
                  qDebug("Portaudio open stream %d failed: %s", idx, Pa_GetErrorText(err));
                  return false;
                  }
            }
      const PaStreamInfo* si = Pa_GetStreamInfo(stream);
      if (si)
            _sampleRate = int(si->sampleRate);
#ifdef USE_ALSA
      midiDriver = new AlsaMidiDriver(seq);
#endif
#ifdef USE_PORTMIDI
      midiDriver = new PortMidiDriver(seq);
#endif
      if (midiDriver && !midiDriver->init()) {
            qDebug("Init midi driver failed");
            delete midiDriver;
            midiDriver = 0;
#ifdef USE_PORTMIDI
            return true;                  // return OK for audio driver; midi is only input
#else
            return false;
#endif
            }
      return true;
      }
示例#3
0
文件: init.c 项目: andresy/lua---pa
static int pa_version(lua_State *L)
{
  int narg = lua_gettop(L);
  if(narg != 0)
    luaL_error(L, "invalid arguments: no argument expected");

  lua_pushstring(L, Pa_GetVersionText());
  return 1;
}
示例#4
0
void MidiIOPrefs::PopulateOrExchange( ShuttleGui & S ) {
   wxArrayString empty;

   S.SetBorder(2);

   S.StartStatic(_("Interface"));
   {
      S.StartMultiColumn(2);
      {
         S.Id(HostID);
         mHost = S.TieChoice(_("Host") + wxString(wxT(":")),
                             wxT("/MidiIO/Host"), 
                             wxT(""),
                             mHostNames,
                             mHostLabels);
         S.SetSizeHints(mHostNames);

         S.AddPrompt(_("Using:"));
         S.AddFixedText(wxString(Pa_GetVersionText(), wxConvLocal));
      }
      S.EndMultiColumn();
   }                              
   S.EndStatic();

   S.StartStatic(_("Playback"));
   {
      S.StartMultiColumn(2);
      {
         S.Id(PlayID);
         mPlay = S.AddChoice(_("Device") + wxString(wxT(":")),
                             wxEmptyString,
                             &empty);
      }
      S.EndMultiColumn();
   }
   S.EndStatic();

   S.StartStatic(_("Recording"));
   {
      S.StartMultiColumn(2);
      {
         S.Id(RecordID);
         mRecord = S.AddChoice(_("Device") + wxString(wxT(":")),
                               wxEmptyString,
                               &empty);

         S.Id(ChannelsID);
         /*
         mChannels = S.AddChoice(_("Channels") + wxString(wxT(":")),
                                 wxEmptyString,
                                 &empty);
         */
      }
      S.EndMultiColumn();
   }
   S.EndStatic();
}
示例#5
0
文件: command.c 项目: syb0rg/Khronos
const char* printVersionInfo(void)
{
    fprintf(stdout, BLUE_TEXT("Khronos version: %s (%s)\n"), KHRONOS_VERSION, KHRONOS_VERSION_STATE);
    fprintf(stdout, "Khronos submodule version information:\n");
    fprintf(stdout, "\t- %s\n", Pa_GetVersionText());
    fprintf(stdout, "\t- %s (%s) %s\n", TRITIUM_PROJECT_NAME, TRITIUM_PROJECT_PREFIX, TRITIUM_PROJECT_VERSION);
    fprintf(stdout, "\t- %s\n", sf_version_string());
    return "";
}
示例#6
0
文件: PhAudio.cpp 项目: EMATech/Joker
PhAudio::PhAudio() :
	_stream(NULL),
	_paInitOk(false)
{
	PaError err = Pa_Initialize();
	if(err == paNoError) {
		PHDEBUG << "Port audio initialized:" << Pa_GetVersionText();
		_paInitOk = true;
	}
	else {
		PHDEBUG << Pa_GetErrorText(err);
	}
}
示例#7
0
int main()
{
    int i;
    const PaDeviceInfo *device_info;

    Pa_Initialize();
    printf("Version: %s\n", Pa_GetVersionText());
    for( i = 0; i < Pa_GetDeviceCount(); i++ )
    {
        device_info = Pa_GetDeviceInfo(i);
        printf("Device %d: %s %s\n", i, device_info->name, Pa_GetHostApiInfo(device_info->hostApi)->name);
    }
    Pa_Terminate();
    return 0;
}
示例#8
0
static int pa_init(rsound *rsnd)
{
    char *s;
    int err;

    if (rsnd->running != 0) {
        return -1;
    } else {
        rsnd->running = 1;
        err = (int)Pa_Initialize();

        if ((s = (char*)Pa_GetVersionText()) != NULL)
            printf("%s\n", s);

        return 0;
    }
}
示例#9
0
static void logPortAudioInfo()
{
  qDebug(Pa_GetVersionText());

  PaHostApiIndex api = 0;
  const PaHostApiInfo *apiInfo;
  while ((apiInfo = Pa_GetHostApiInfo(api))) {
    qDebug("Host API: %s (%d devices)", apiInfo->name, apiInfo->deviceCount);

    int device;
    for (device = 0; device < apiInfo->deviceCount; device++) {
      PaDeviceIndex devIdx = Pa_HostApiDeviceIndexToDeviceIndex(api, device);
      if (devIdx < 0) {
        qDebug("[%02d] Error: %s", device, Pa_GetErrorText(devIdx));
        continue;
      }

      const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(devIdx);
      if (!deviceInfo) {
        qDebug("[%02d] Invalid device index", device);
        continue;
      }

      qDebug("[%02d] \"%s\" (%d)", device, deviceInfo->name, devIdx);
      qDebug("     Channels: %d in, %d out",
          deviceInfo->maxInputChannels,
          deviceInfo->maxOutputChannels);
      qDebug("     Default sample rate: %g Hz",
          deviceInfo->defaultSampleRate);
      qDebug("     Input latency: %g low, %g high",
          deviceInfo->defaultLowInputLatency,
          deviceInfo->defaultHighInputLatency);
      qDebug("     Output latency: %g low, %g high",
          deviceInfo->defaultLowOutputLatency,
          deviceInfo->defaultHighOutputLatency);
    }
    api++;
  }
}
示例#10
0
文件: version.cpp 项目: midzer/mixxx
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;
}
示例#11
0
PluginInterface::InitResult PortAudioPlugin::initialise( fugio::GlobalInterface *pApp, bool pLastChance )
{
	Q_UNUSED( pLastChance )

	mApp = pApp;

#if defined( PORTAUDIO_SUPPORTED )
	if( Pa_Initialize() != paNoError )
	{
		return( INIT_FAILED );
	}

	qInfo() << Pa_GetVersionText();
#endif

	DevicePortAudio::deviceInitialise();

	mApp->registerNodeClasses( mNodeClasses );

	mApp->registerPinClasses( mPinClasses );

	return( INIT_OK );
}
示例#12
0
// 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) ) );
}
示例#13
0
// xxx copied from ../gtk/main.c
static void
get_gui_compiled_info(GString *str)
{
  epan_get_compiled_version_info(str);

  g_string_append(str, ", ");
#ifdef HAVE_LIBPORTAUDIO
#ifdef PORTAUDIO_API_1
  g_string_append(str, "with PortAudio <= V18");
#else /* PORTAUDIO_API_1 */
  g_string_append(str, "with ");
  g_string_append(str, Pa_GetVersionText());
#endif /* PORTAUDIO_API_1 */
#else /* HAVE_LIBPORTAUDIO */
  g_string_append(str, "without PortAudio");
#endif /* HAVE_LIBPORTAUDIO */

  g_string_append(str, ", ");
#ifdef HAVE_AIRPCAP
  get_compiled_airpcap_version(str);
#else
  g_string_append(str, "without AirPcap");
#endif
}
示例#14
0
// Main deals with checking all the devices and arguments.
// It will call another function to do the actual work.
int main(int argc,char *argv[]){
	//variables
	int device_num = 0;
	int error = Pa_Initialize();
	int i = 0;
	int arg_data_count = 0;
	bool audio_get_list = false;
	bool input_wanted = false;
	int device_chosen = 0;
	const PaDeviceInfo *device_info;
	char user_select_device[8];
	PaStreamParameters input_stream_param;

	// Parse arguments
	if(argc >= 1){
		for(i = 0;i < argc;i++){
			if(arg_data_count == 0){
				// Prints a list of all audio devices.
				if(strcmp(argv[i],"-list") == 0){
					audio_get_list = true;
				}
				// Same as -list, but lets you select which one you use.
				if(strcmp(argv[i],"-input") == 0){
					audio_get_list = true;
					input_wanted = true;
				}
			} else {
				arg_data_count = arg_data_count-1;
			}
		}
	}


	/// Init
	status_message(stat_general,"SoundScale");
	status_message(stat_general,"Using PortAudio Version:");
	status_message(stat_general,(char *) Pa_GetVersionText());
	// Checks for PA and audio devices.
	if(error != paNoError){
		status_message(stat_critical,"PA DID NOT INITIALISE");
		return PA_INIT_FAIL;
	} else {
		status_message(stat_general,"PA INITIALIZED");
	}
	device_num = Pa_GetDeviceCount();
	if(device_num < 0){
		status_message(stat_critical,"ERROR - NO AUDIO DEVICES");
		return NO_AUDIO_DEVICES;
	} 

	// Audio Device selection. This can be cleaned up.
	if(audio_get_list == true){
		printf("[*] Discovered %i Audio devices\n",device_num);
		for(i = 0; i < device_num;i++){
			device_info = Pa_GetDeviceInfo(i);
			printf("[*] [%i] %s \n",i,device_info->name);
		}
		if(input_wanted == true){
			printf("[*] Please select input: ");
			scanf("%s",user_select_device);
			if(atoi(user_select_device) < device_num && atoi(user_select_device) >= 0){
				device_chosen = atoi(user_select_device);
				input_stream_param.device = device_chosen;
			} else {
				// Maybe ask user?
				input_stream_param.device = device_chosen  = Pa_GetDefaultInputDevice();
			}
		} else if(input_wanted == false){
			return SUCCESS;
		}
	} else {
		if(device_chosen > 0 && device_chosen <= device_num){
			input_stream_param.device = device_chosen;
			
		} else {
			input_stream_param.device = Pa_GetDefaultInputDevice();
			if(input_stream_param.device == paNoDevice){
				status_message(stat_critical,"NO DEFAULT INPUT DEVICE, EXITING");
				return FAILURE;
			}
		}
	}
	status_message(stat_general,"Using device:");
	device_info = Pa_GetDeviceInfo(input_stream_param.device);
	status_message(stat_general,(char *)device_info->name);
	return SUCCESS;
}
示例#15
0
文件: jpa.c 项目: rjeschke/jpa
JNIEXPORT jstring JNICALL Java_com_github_rjeschke_jpa_JPA_getVersionText(JNIEnv *env, jclass clazz)
{
    return makeString(env, (char*)Pa_GetVersionText());
}
示例#16
0
static int
actual_portaudio_initialize (DenemoPrefs * config)
{
  sample_rate = config->portaudio_sample_rate;

#ifdef _HAVE_FLUIDSYNTH_
  g_message ("Initializing Fluidsynth");
  if (fluidsynth_init (config, sample_rate))
    {
      g_warning ("Initializing Fluidsynth FAILED!");
      return -1;
    }
#endif
#ifdef _HAVE_RUBBERBAND_
  g_message ("Initializing Rubberband");
 if (rubberband_init (config))
    {
      g_warning ("Initializing Rubberband FAILED!");
      return -1;
    }
#endif
  g_unlink (recorded_audio_filename ());

  g_message ("Initializing PortAudio backend");
  g_info("PortAudio version: %s", Pa_GetVersionText());

  PaStreamParameters output_parameters;
  PaError err;

  err = Pa_Initialize ();
  if (err != paNoError)
    {
      g_warning ("Initializing PortAudio failed");
      return -1;
    }

  output_parameters.device = get_portaudio_device_index (config->portaudio_device->str);

  if (output_parameters.device == paNoDevice)
    {
      output_parameters.device =   get_portaudio_device_index ("default");
       if (output_parameters.device == paNoDevice)
        {
            g_warning("No PortAudio device %s and no default either.", config->portaudio_device->str);
            return -1;
        }
    }

  PaDeviceInfo const *info = Pa_GetDeviceInfo (output_parameters.device);

  if (!info)
    {
      g_warning ("Invalid device '%s'", config->portaudio_device->str);
      return -1;
    }

  char const *api_name = Pa_GetHostApiInfo (info->hostApi)->name;
  g_message ("Opening output device '%s: %s'", api_name, info->name);

  output_parameters.channelCount = 2;
  output_parameters.sampleFormat = paFloat32 | paNonInterleaved;
  output_parameters.suggestedLatency = Pa_GetDeviceInfo (output_parameters.device)->defaultLowOutputLatency;
  output_parameters.hostApiSpecificStreamInfo = NULL;
  err = Pa_OpenStream (&stream, NULL, &output_parameters, config->portaudio_sample_rate, config->portaudio_period_size, paNoFlag /* make this a pref??? paClipOff */ , stream_callback, NULL);
  if (err != paNoError)
    {
      g_warning ("Couldn't open output stream");
      return -1;
    }
  err = Pa_StartStream (stream);
  if (err != paNoError)
    {
      g_warning ("Couldn't start output stream");
      return -1;
    }

  return 0;
}
示例#17
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_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 */
        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.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 );
        }
    }

    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;
}
示例#18
0
bool Portaudio::init(bool)
      {
      PaError err = Pa_Initialize();
      if (err != paNoError) {
            qDebug("Portaudio initialize failed: %s", Pa_GetErrorText(err));
            return false;
            }
      initialized = true;
      if (MScore::debugMode)
            qDebug("using PortAudio Version: %s", Pa_GetVersionText());

      PaDeviceIndex idx = preferences.getInt(PREF_IO_PORTAUDIO_DEVICE);
      if (idx < 0) {
            idx = Pa_GetDefaultOutputDevice();
            qDebug("No device selected.  PortAudio detected %d devices.  Will use the default device (index %d).", Pa_GetDeviceCount(), idx);
            }

      const PaDeviceInfo* di = Pa_GetDeviceInfo(idx);

      //select default output device if no device or device without output channels have been selected
      if (di == nullptr || di->maxOutputChannels < 1)
            di = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());

      if (!di)
            return false;    // Portaudio is not properly initialized; disable audio
      _sampleRate = int(di->defaultSampleRate);

      /* Open an audio I/O stream. */
      struct PaStreamParameters out;
      memset(&out, 0, sizeof(out));

      out.device           = idx;
      out.channelCount     = 2;
      out.sampleFormat     = paFloat32;
      out.suggestedLatency = di->defaultLowOutputLatency;
      out.hostApiSpecificStreamInfo = 0;

      err = Pa_OpenStream(&stream, 0, &out, double(_sampleRate), 0, 0, paCallback, (void*)this);
      if (err != paNoError) {
            // fall back to default device:
            out.device = Pa_GetDefaultOutputDevice();
            err = Pa_OpenStream(&stream, 0, &out, double(_sampleRate), 0, 0, paCallback, (void*)this);
            if (err != paNoError) {
                  qDebug("Portaudio open stream %d failed: %s", idx, Pa_GetErrorText(err));
                  return false;
                  }
            }
      const PaStreamInfo* si = Pa_GetStreamInfo(stream);
      if (si)
            _sampleRate = int(si->sampleRate);
#ifdef USE_ALSA
      midiDriver = new AlsaMidiDriver(seq);
#endif
#ifdef USE_PORTMIDI
      midiDriver = new PortMidiDriver(seq);
#endif
      if (midiDriver && !midiDriver->init()) {
            qDebug("Init midi driver failed");
            delete midiDriver;
            midiDriver = 0;
#ifdef USE_PORTMIDI
            return true;                  // return OK for audio driver; midi is only input
#else
            return false;
#endif
            }
      return true;
      }
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;
}
示例#20
0
JNIEXPORT jstring JNICALL Java_org_jpab_PortAudio_getVersionText(JNIEnv *env, jclass paClass) {
    const char * version_text = Pa_GetVersionText();
	return env->NewString((jchar *) version_text, (jint) strlen(version_text));
}