src/osd/sdl/sound.c
| r966 | r967 | |
| 37 | 37 | //============================================================ |
| 38 | 38 | |
| 39 | 39 | // number of samples per SDL callback |
| 40 | | static int sdl_xfer_samples = 512; |
| 40 | #define SDL_XFER_SAMPLES (512) |
| 41 | |
| 42 | static int sdl_xfer_samples = SDL_XFER_SAMPLES; |
| 41 | 43 | static int stream_in_initialized = 0; |
| 42 | 44 | static int stream_loop = 0; |
| 43 | 45 | |
| r966 | r967 | |
| 48 | 50 | // LOCAL VARIABLES |
| 49 | 51 | //============================================================ |
| 50 | 52 | |
| 51 | | static int attenuation = 0; |
| 53 | static int attenuation = 0; |
| 52 | 54 | |
| 53 | | static int initialized_audio; |
| 55 | static int initialized_audio = 0; |
| 54 | 56 | static int buf_locked; |
| 55 | 57 | |
| 56 | 58 | static INT8 *stream_buffer; |
| r966 | r967 | |
| 75 | 77 | // PROTOTYPES |
| 76 | 78 | //============================================================ |
| 77 | 79 | |
| 78 | | static int sdl_init(void); |
| 79 | | static void sdl_kill(void); |
| 80 | static int sdl_init(running_machine *machine); |
| 81 | static void sdl_kill(running_machine *machine); |
| 80 | 82 | static int sdl_create_buffers(void); |
| 81 | 83 | static void sdl_destroy_buffers(void); |
| 82 | 84 | static void sdl_cleanup_audio(running_machine *machine); |
| r966 | r967 | |
| 95 | 97 | if (Machine->sample_rate != 0) |
| 96 | 98 | { |
| 97 | 99 | // attempt to initialize SDL |
| 98 | | if (sdl_init()) |
| 100 | if (sdl_init(machine)) |
| 99 | 101 | return; |
| 100 | 102 | |
| 101 | 103 | add_exit_callback(machine, sdl_cleanup_audio); |
| r966 | r967 | |
| 114 | 116 | static void sdl_cleanup_audio(running_machine *machine) |
| 115 | 117 | { |
| 116 | 118 | // if nothing to do, don't do it |
| 117 | | if (Machine->sample_rate == 0) |
| 119 | if (machine->sample_rate == 0) |
| 118 | 120 | return; |
| 119 | 121 | |
| 120 | 122 | // kill the buffers and dsound |
| 121 | | sdl_kill(); |
| 123 | sdl_kill(machine); |
| 122 | 124 | sdl_destroy_buffers(); |
| 123 | 125 | |
| 124 | 126 | // print out over/underflow stats |
| r966 | r967 | |
| 452 | 454 | //============================================================ |
| 453 | 455 | // sdl_init |
| 454 | 456 | //============================================================ |
| 455 | | static int sdl_init(void) |
| 457 | static int sdl_init(running_machine *machine) |
| 456 | 458 | { |
| 457 | 459 | int n_channels = 2; |
| 458 | 460 | int audio_latency; |
| 459 | 461 | SDL_AudioSpec aspec, obtained; |
| 460 | 462 | char audio_driver[16]; |
| 461 | 463 | |
| 464 | if (initialized_audio) |
| 465 | { |
| 466 | sdl_cleanup_audio(machine); |
| 467 | } |
| 468 | |
| 462 | 469 | initialized_audio = 0; |
| 463 | 470 | |
| 471 | sdl_xfer_samples = SDL_XFER_SAMPLES; |
| 472 | stream_in_initialized = 0; |
| 473 | stream_loop = 0; |
| 474 | |
| 464 | 475 | // set up the audio specs |
| 465 | | aspec.freq = Machine->sample_rate; |
| 476 | aspec.freq = machine->sample_rate; |
| 466 | 477 | aspec.format = AUDIO_S16SYS; // keep endian independant |
| 467 | 478 | aspec.channels = n_channels; |
| 468 | 479 | aspec.samples = sdl_xfer_samples; |
| r966 | r967 | |
| 518 | 529 | // sdl_kill |
| 519 | 530 | //============================================================ |
| 520 | 531 | |
| 521 | | static void sdl_kill(void) |
| 532 | static void sdl_kill(running_machine *machine) |
| 522 | 533 | { |
| 523 | 534 | if (initialized_audio) |
| 535 | { |
| 536 | mame_printf_debug("sdl_kill: closing audio\n"); |
| 537 | |
| 524 | 538 | SDL_CloseAudio(); |
| 539 | } |
| 525 | 540 | } |
| 526 | 541 | |
| 527 | 542 | |
| r966 | r967 | |
| 532 | 547 | |
| 533 | 548 | static int sdl_create_buffers(void) |
| 534 | 549 | { |
| 535 | | #if LOG_SOUND |
| 536 | | fprintf(sound_log, "sdl_create_buffers: creating stream buffer of %d bytes\n", stream_buffer_size); |
| 537 | | #endif |
| 550 | mame_printf_verbose("sdl_create_buffers: creating stream buffer of %d bytes\n", stream_buffer_size); |
| 551 | |
| 538 | 552 | stream_buffer = (INT8 *)malloc(stream_buffer_size); |
| 539 | 553 | memset(stream_buffer, 0, stream_buffer_size); |
| 540 | 554 | stream_playpos = 0; |