diff options
Diffstat (limited to 'src/osd/modules/sound')
| -rw-r--r-- | src/osd/modules/sound/direct_sound.c | 32 | ||||
| -rw-r--r-- | src/osd/modules/sound/js_sound.c | 52 | ||||
| -rw-r--r-- | src/osd/modules/sound/none.c | 20 | ||||
| -rw-r--r-- | src/osd/modules/sound/sdl_sound.c | 270 | ||||
| -rw-r--r-- | src/osd/modules/sound/sound_module.h | 14 |
5 files changed, 194 insertions, 194 deletions
diff --git a/src/osd/modules/sound/direct_sound.c b/src/osd/modules/sound/direct_sound.c index 95e033b3351..bd30d730ee7 100644 --- a/src/osd/modules/sound/direct_sound.c +++ b/src/osd/modules/sound/direct_sound.c @@ -51,26 +51,26 @@ class sound_direct_sound : public osd_module, public sound_module { public: - sound_direct_sound() - : osd_module(OSD_SOUND_PROVIDER, "dsound"), sound_module() - { - } - virtual ~sound_direct_sound() { } + sound_direct_sound() + : osd_module(OSD_SOUND_PROVIDER, "dsound"), sound_module() + { + } + virtual ~sound_direct_sound() { } - virtual int init(); - virtual void exit(); + virtual int init(); + virtual void exit(); - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); - virtual void set_mastervolume(int attenuation); + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); + virtual void set_mastervolume(int attenuation); private: - HRESULT dsound_init(); - void dsound_kill(); - HRESULT dsound_create_buffers(); - void dsound_destroy_buffers(); - void copy_sample_data(const INT16 *data, int bytes_to_copy); + HRESULT dsound_init(); + void dsound_kill(); + HRESULT dsound_create_buffers(); + void dsound_destroy_buffers(); + void copy_sample_data(const INT16 *data, int bytes_to_copy); }; @@ -448,7 +448,7 @@ void sound_direct_sound::dsound_destroy_buffers(void) } #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_direct_sound, OSD_SOUND_PROVIDER, "dsound") + MODULE_NOT_SUPPORTED(sound_direct_sound, OSD_SOUND_PROVIDER, "dsound") #endif MODULE_DEFINITION(SOUND_DSOUND, sound_direct_sound) diff --git a/src/osd/modules/sound/js_sound.c b/src/osd/modules/sound/js_sound.c index f3e11785633..93d76a22c4f 100644 --- a/src/osd/modules/sound/js_sound.c +++ b/src/osd/modules/sound/js_sound.c @@ -19,36 +19,36 @@ class sound_js : public osd_module, public sound_module { public: - sound_js() - : osd_module(OSD_SOUND_PROVIDER, "js"), sound_module() - { - } - virtual ~sound_js() { } - - virtual int init(); - virtual void exit(); - - // sound_module - - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) - { - EM_ASM_ARGS({ - // Forward audio stream update on to JS backend implementation. - jsmess_update_audio_stream($1, $2); - }, (unsigned int)buffer, samples_this_frame); - } - virtual void set_mastervolume(int attenuation) - { - EM_ASM_ARGS({ - // Forward volume update on to JS backend implementation. - jsmess_set_mastervolume($0); - }, attenuation); - } + sound_js() + : osd_module(OSD_SOUND_PROVIDER, "js"), sound_module() + { + } + virtual ~sound_js() { } + + virtual int init(); + virtual void exit(); + + // sound_module + + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) + { + EM_ASM_ARGS({ + // Forward audio stream update on to JS backend implementation. + jsmess_update_audio_stream($1, $2); + }, (unsigned int)buffer, samples_this_frame); + } + virtual void set_mastervolume(int attenuation) + { + EM_ASM_ARGS({ + // Forward volume update on to JS backend implementation. + jsmess_set_mastervolume($0); + }, attenuation); + } }; #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js") + MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js") #endif MODULE_DEFINITION(SOUND_JS, sound_js) diff --git a/src/osd/modules/sound/none.c b/src/osd/modules/sound/none.c index e0173d39d59..501b064afab 100644 --- a/src/osd/modules/sound/none.c +++ b/src/osd/modules/sound/none.c @@ -14,19 +14,19 @@ class sound_none : public osd_module, public sound_module { public: - sound_none() - : osd_module(OSD_SOUND_PROVIDER, "none"), sound_module() - { - } - virtual ~sound_none() { } + sound_none() + : osd_module(OSD_SOUND_PROVIDER, "none"), sound_module() + { + } + virtual ~sound_none() { } - virtual int init() { return 0; } - virtual void exit() { } + virtual int init() { return 0; } + virtual void exit() { } - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) { } - virtual void set_mastervolume(int attenuation) { } + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) { } + virtual void set_mastervolume(int attenuation) { } }; diff --git a/src/osd/modules/sound/sdl_sound.c b/src/osd/modules/sound/sdl_sound.c index bb46e9f6b91..1c80ab85082 100644 --- a/src/osd/modules/sound/sdl_sound.c +++ b/src/osd/modules/sound/sdl_sound.c @@ -43,53 +43,53 @@ class sound_sdl : public osd_module, public sound_module { public: - friend void sdl_callback(void *userdata, Uint8 *stream, int len); + friend void sdl_callback(void *userdata, Uint8 *stream, int len); - // number of samples per SDL callback - static const int SDL_XFER_SAMPLES = 512; + // number of samples per SDL callback + static const int SDL_XFER_SAMPLES = 512; - sound_sdl() - : osd_module(OSD_SOUND_PROVIDER, "sdl"), sound_module(), - stream_in_initialized(0), - stream_loop(0), - attenuation(0) - { - sdl_xfer_samples = SDL_XFER_SAMPLES; - } - virtual ~sound_sdl() { } + sound_sdl() + : osd_module(OSD_SOUND_PROVIDER, "sdl"), sound_module(), + stream_in_initialized(0), + stream_loop(0), + attenuation(0) + { + sdl_xfer_samples = SDL_XFER_SAMPLES; + } + virtual ~sound_sdl() { } - virtual int init(); - virtual void exit(); + virtual int init(); + virtual void exit(); - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); - virtual void set_mastervolume(int attenuation); + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); + virtual void set_mastervolume(int attenuation); private: - int lock_buffer(bool is_throttled, long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2); - void unlock_buffer(void); - void att_memcpy(void *dest, const INT16 *data, int bytes_to_copy); - void copy_sample_data(bool is_throttled, const INT16 *data, int bytes_to_copy); - int sdl_create_buffers(void); - void sdl_destroy_buffers(void); + int lock_buffer(bool is_throttled, long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2); + void unlock_buffer(void); + void att_memcpy(void *dest, const INT16 *data, int bytes_to_copy); + void copy_sample_data(bool is_throttled, const INT16 *data, int bytes_to_copy); + int sdl_create_buffers(void); + void sdl_destroy_buffers(void); - int sdl_xfer_samples; - int stream_in_initialized; - int stream_loop; - int attenuation; + int sdl_xfer_samples; + int stream_in_initialized; + int stream_loop; + int attenuation; - int buf_locked; + int buf_locked; - INT8 *stream_buffer; - volatile INT32 stream_playpos; + INT8 *stream_buffer; + volatile INT32 stream_playpos; - UINT32 stream_buffer_size; - UINT32 stream_buffer_in; + UINT32 stream_buffer_size; + UINT32 stream_buffer_in; - // buffer over/underflow counts - int buffer_underflows; - int buffer_overflows; + // buffer over/underflow counts + int buffer_underflows; + int buffer_overflows; }; @@ -354,7 +354,7 @@ void sound_sdl::set_mastervolume(int _attenuation) //============================================================ static void sdl_callback(void *userdata, Uint8 *stream, int len) { - sound_sdl *thiz = (sound_sdl *) userdata; + sound_sdl *thiz = (sound_sdl *) userdata; int len1, len2, sb_in; sb_in = thiz->stream_buffer_in; @@ -379,20 +379,20 @@ static void sdl_callback(void *userdata, Uint8 *stream, int len) len2 = 0; } - memcpy(stream, thiz->stream_buffer + thiz->stream_playpos, len1); - memset(thiz->stream_buffer + thiz->stream_playpos, 0, len1); // no longer needed - if (len2) - { - memcpy(stream+len1, thiz->stream_buffer, len2); - memset(thiz->stream_buffer, 0, len2); // no longer needed - } + memcpy(stream, thiz->stream_buffer + thiz->stream_playpos, len1); + memset(thiz->stream_buffer + thiz->stream_playpos, 0, len1); // no longer needed + if (len2) + { + memcpy(stream+len1, thiz->stream_buffer, len2); + memset(thiz->stream_buffer, 0, len2); // no longer needed + } // move the play cursor - thiz->stream_playpos += len1 + len2; + thiz->stream_playpos += len1 + len2; if (thiz->stream_playpos >= thiz->stream_buffer_size) { - thiz->stream_playpos -= thiz->stream_buffer_size; + thiz->stream_playpos -= thiz->stream_buffer_size; thiz->stream_loop = 0; if (LOG_SOUND) @@ -416,81 +416,81 @@ int sound_sdl::init() SDL_AudioSpec aspec, obtained; char audio_driver[16] = ""; - if (LOG_SOUND) - sound_log = fopen(SDLMAME_SOUND_LOG, "w"); - - // skip if sound disabled - if (sample_rate() != 0) - { - if (SDL_InitSubSystem(SDL_INIT_AUDIO)) { - osd_printf_error("Could not initialize SDL %s\n", SDL_GetError()); - return -1; - } - - osd_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 - osd_printf_verbose("Audio: Driver is %s\n", audio_driver); - - sdl_xfer_samples = SDL_XFER_SAMPLES; - stream_in_initialized = 0; - stream_loop = 0; - - // set up the audio specs - aspec.freq = sample_rate(); - aspec.format = AUDIO_S16SYS; // keep endian independent - aspec.channels = n_channels; - aspec.samples = sdl_xfer_samples; - aspec.callback = sdl_callback; - aspec.userdata = this; - - if (SDL_OpenAudio(&aspec, &obtained) < 0) - goto cant_start_audio; - - osd_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n", - obtained.freq, obtained.channels, obtained.samples); - - sdl_xfer_samples = obtained.samples; - - audio_latency = m_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 = (sample_rate() * 2 * sizeof(INT16) * (2 + audio_latency)) / 30; - 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; - - // set the startup volume - set_mastervolume(attenuation); - osd_printf_verbose("Audio: End initialization\n"); - return 0; - - // error handling - cant_create_buffers: - cant_start_audio: - osd_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError()); - - return -1; - } - - return 0; + if (LOG_SOUND) + sound_log = fopen(SDLMAME_SOUND_LOG, "w"); + + // skip if sound disabled + if (sample_rate() != 0) + { + if (SDL_InitSubSystem(SDL_INIT_AUDIO)) { + osd_printf_error("Could not initialize SDL %s\n", SDL_GetError()); + return -1; + } + + osd_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 + osd_printf_verbose("Audio: Driver is %s\n", audio_driver); + + sdl_xfer_samples = SDL_XFER_SAMPLES; + stream_in_initialized = 0; + stream_loop = 0; + + // set up the audio specs + aspec.freq = sample_rate(); + aspec.format = AUDIO_S16SYS; // keep endian independent + aspec.channels = n_channels; + aspec.samples = sdl_xfer_samples; + aspec.callback = sdl_callback; + aspec.userdata = this; + + if (SDL_OpenAudio(&aspec, &obtained) < 0) + goto cant_start_audio; + + osd_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n", + obtained.freq, obtained.channels, obtained.samples); + + sdl_xfer_samples = obtained.samples; + + audio_latency = m_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 = (sample_rate() * 2 * sizeof(INT16) * (2 + audio_latency)) / 30; + 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; + + // set the startup volume + set_mastervolume(attenuation); + osd_printf_verbose("Audio: End initialization\n"); + return 0; + + // error handling + cant_create_buffers: + cant_start_audio: + osd_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError()); + + return -1; + } + + return 0; } @@ -501,27 +501,27 @@ int sound_sdl::init() void sound_sdl::exit() { - // if nothing to do, don't do it - if (sample_rate() == 0) - return; + // if nothing to do, don't do it + if (sample_rate() == 0) + return; - osd_printf_verbose("sdl_kill: closing audio\n"); + osd_printf_verbose("sdl_kill: closing audio\n"); SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); - // kill the buffers - sdl_destroy_buffers(); + // kill the buffers + sdl_destroy_buffers(); - // print out over/underflow stats - if (buffer_overflows || buffer_underflows) - osd_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); + // print out over/underflow stats + if (buffer_overflows || buffer_underflows) + osd_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); - if (LOG_SOUND) - { - fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); - fclose(sound_log); - } + if (LOG_SOUND) + { + fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); + fclose(sound_log); + } } @@ -555,7 +555,7 @@ void sound_sdl::sdl_destroy_buffers(void) #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") + MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") #endif MODULE_DEFINITION(SOUND_SDL, sound_sdl) diff --git a/src/osd/modules/sound/sound_module.h b/src/osd/modules/sound/sound_module.h index d339af55973..087ace0a714 100644 --- a/src/osd/modules/sound/sound_module.h +++ b/src/osd/modules/sound/sound_module.h @@ -18,17 +18,17 @@ class sound_module { public: - sound_module() : m_sample_rate(0), m_audio_latency(1) { } + sound_module() : m_sample_rate(0), m_audio_latency(1) { } - virtual ~sound_module() { } + virtual ~sound_module() { } - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) = 0; - virtual void set_mastervolume(int attenuation) = 0; + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) = 0; + virtual void set_mastervolume(int attenuation) = 0; - int sample_rate() { return m_sample_rate; } + int sample_rate() { return m_sample_rate; } - int m_sample_rate; - int m_audio_latency; + int m_sample_rate; + int m_audio_latency; }; #endif /* FONT_MODULE_H_ */ |
