Beispiel #1
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;
}
Beispiel #2
0
/* Initialize the music players with a certain desired audio format */
int open_music(SDL_AudioSpec *mixer)
{
#ifdef WAV_MUSIC
	if ( WAVStream_Init(mixer) == 0 ) {
		add_music_decoder("WAVE");
	}
#endif
#ifdef MODPLUG_MUSIC
	if ( modplug_init(mixer) == 0 ) {
		add_music_decoder("MODPLUG");
	}
#endif
#ifdef MOD_MUSIC
	if ( MOD_init(mixer) == 0 ) {
		add_music_decoder("MIKMOD");
	}
#endif
#ifdef MID_MUSIC
#ifdef USE_TIMIDITY_MIDI
	samplesize = mixer->size / mixer->samples;
	if ( Timidity_Init(mixer->freq, mixer->format,
	                    mixer->channels, mixer->samples) == 0 ) {
		timidity_ok = 1;
		add_music_decoder("TIMIDITY");
	} else {
		timidity_ok = 0;
	}
#endif
#ifdef USE_FLUIDSYNTH_MIDI
	if ( fluidsynth_init(mixer) == 0 ) {
		fluidsynth_ok = 1;
		add_music_decoder("FLUIDSYNTH");
	} else {
		fluidsynth_ok = 0;
	}
#endif
#ifdef USE_NATIVE_MIDI
#ifdef USE_FLUIDSYNTH_MIDI
	native_midi_ok = !fluidsynth_ok;
	if ( native_midi_ok )
#endif
#ifdef USE_TIMIDITY_MIDI
		native_midi_ok = !timidity_ok;
	if ( !native_midi_ok ) {
		native_midi_ok = (getenv("SDL_NATIVE_MUSIC") != NULL);
	}
	if ( native_midi_ok )
#endif
		native_midi_ok = native_midi_detect();
	if ( native_midi_ok )
		add_music_decoder("NATIVEMIDI");
#endif
#endif
#ifdef OGG_MUSIC
	if ( OGG_init(mixer) == 0 ) {
		add_music_decoder("OGG");
	}
#endif
#ifdef FLAC_MUSIC
	if ( FLAC_init(mixer) == 0 ) {
		add_music_decoder("FLAC");
	}
#endif
#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
	/* Keep a copy of the mixer */
	used_mixer = *mixer;
	add_music_decoder("MP3");
#endif

	music_playing = NULL;
	music_stopped = 0;
	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);

	/* Calculate the number of ms for each callback */
	ms_per_step = (int) (((float)mixer->samples * 1000.0) / mixer->freq);

	return(0);
}