Esempio n. 1
0
//============================================================
//  sdl_init
//============================================================
static int sdl_init(running_machine &machine)
{
	int         n_channels = 2;
	int         audio_latency;
	SDL_AudioSpec   aspec, obtained;
	char audio_driver[16] = "";

	if (initialized_audio)
	{
		sdl_cleanup_audio(machine);
	}

	mame_printf_verbose("Audio: Start initialization\n");
#if (SDLMAME_SDL2)
	strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver));
#else
	SDL_AudioDriverName(audio_driver, sizeof(audio_driver));
#endif
	mame_printf_verbose("Audio: Driver is %s\n", audio_driver);

	initialized_audio = 0;

	sdl_xfer_samples = SDL_XFER_SAMPLES;
	stream_in_initialized = 0;
	stream_loop = 0;

	// set up the audio specs
	aspec.freq = machine.sample_rate();
	aspec.format = AUDIO_S16SYS;    // keep endian independent
	aspec.channels = n_channels;
	aspec.samples = sdl_xfer_samples;
	aspec.callback = sdl_callback;
	aspec.userdata = 0;

	if (SDL_OpenAudio(&aspec, &obtained) < 0)
		goto cant_start_audio;

	initialized_audio = 1;
	snd_enabled = 1;

	mame_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n",
						obtained.freq, obtained.channels, obtained.samples);

	sdl_xfer_samples = obtained.samples;

	audio_latency = downcast<sdl_options &>(machine.options()).audio_latency();

	// pin audio latency
	if (audio_latency > MAX_AUDIO_LATENCY)
	{
		audio_latency = MAX_AUDIO_LATENCY;
	}
	else if (audio_latency < 1)
	{
		audio_latency = 1;
	}

	// compute the buffer sizes
	stream_buffer_size = machine.sample_rate() * 2 * sizeof(INT16) * audio_latency / MAX_AUDIO_LATENCY;
	stream_buffer_size = (stream_buffer_size / 1024) * 1024;
	if (stream_buffer_size < 1024)
		stream_buffer_size = 1024;

	// create the buffers
	if (sdl_create_buffers())
		goto cant_create_buffers;

	mame_printf_verbose("Audio: End initialization\n");
	return 0;

	// error handling
cant_create_buffers:
cant_start_audio:
	mame_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError());

	return 0;
}
Esempio n. 2
0
//============================================================
//	sdl_init
//============================================================
static int sdl_init(running_machine *machine)
{
    int			n_channels = 2;
    int			audio_latency;
    SDL_AudioSpec 	aspec, obtained;
    char audio_driver[16];

    if (initialized_audio)
    {
        sdl_cleanup_audio(machine);
    }

    initialized_audio = 0;

    sdl_xfer_samples = SDL_XFER_SAMPLES;
    stream_in_initialized = 0;
    stream_loop = 0;

    // set up the audio specs
    aspec.freq = machine->sample_rate;
    aspec.format = AUDIO_S16SYS;	// keep endian independant
    aspec.channels = n_channels;
    aspec.samples = sdl_xfer_samples;
    aspec.callback = sdl_callback;
    aspec.userdata = 0;

    if (SDL_OpenAudio(&aspec, &obtained) < 0)
        goto cant_start_audio;

    initialized_audio = 1;
    snd_enabled = 1;

#if (SDL_VERSION_ATLEAST(1,3,0))
    strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver));
#else
    SDL_AudioDriverName(audio_driver, sizeof(audio_driver));
#endif
    mame_printf_verbose("Audio initialized - driver: %s, frequency: %d, "
                        "channels: %d, samples: %d\n", audio_driver,
                        obtained.freq, obtained.channels, obtained.samples);

    sdl_xfer_samples = obtained.samples;

    audio_latency = options_get_int(mame_options(), SDLOPTION_AUDIO_LATENCY);

    // pin audio latency
    if (audio_latency > MAX_AUDIO_LATENCY)
    {
        audio_latency = MAX_AUDIO_LATENCY;
    }
    else if (audio_latency < 1)
    {
        audio_latency = 1;
    }

    // compute the buffer sizes
    stream_buffer_size = machine->sample_rate * 2 * sizeof(INT16) * audio_latency / MAX_AUDIO_LATENCY;
    stream_buffer_size = (stream_buffer_size / 1024) * 1024;
    if (stream_buffer_size < 1024)
        stream_buffer_size = 1024;

    // create the buffers
    if (sdl_create_buffers())
        goto cant_create_buffers;

    return 0;

    // error handling
cant_create_buffers:
cant_start_audio:
    return 0;
}