diff --git a/Makefile.common b/Makefile.common index 66ef85993d..6a7b0fe1bd 100644 --- a/Makefile.common +++ b/Makefile.common @@ -62,7 +62,7 @@ endif ifneq ($(findstring Linux,$(OS)),) LIBS += -lrt JOYCONFIG_LIBS += -lrt - OBJ += input/linuxraw_input.o input/linuxraw_joypad.o + OBJ += input/drivers/linuxraw_input.o input/drivers_joypad/linuxraw_joypad.o endif ifeq ($(findstring Haiku,$(OS)),) @@ -85,8 +85,8 @@ endif # General object files OBJ += frontend/frontend.o \ - frontend/frontend_context.o \ - frontend/platform/platform_null.o \ + frontend/frontend_driver.o \ + frontend/drivers/platform_null.o \ libretro_version_1.o \ retroarch.o \ runloop.o \ @@ -96,26 +96,33 @@ OBJ += frontend/frontend.o \ libretro-sdk/string/string_list.o \ file_ops.o \ libretro-sdk/file/file_path.o \ - rarch_compr_file_path.o \ hash.o \ + audio/audio_driver.o \ + input/input_driver.o \ + gfx/video_driver.o \ + osk/osk_driver.o \ + camera/camera_driver.o \ + menu/menu_driver.o \ + location/location_driver.o \ driver.o \ settings.o \ settings_list.o \ settings_data.o \ dynamic.o \ dynamic_dummy.o \ - message_queue.o \ + libretro-sdk/queues/message_queue.o \ rewind.o \ gfx/gfx_common.o \ - gfx/fonts/bitmapfont.o \ + gfx/drivers_font_renderer/bitmapfont.o \ input/input_autodetect.o \ - input/input_context.o \ + input/input_joypad_driver.o \ + input/input_joypad.o \ input/input_common.o \ input/input_keymaps.o \ input/keyboard_line.o \ - input/overlay.o \ + input/input_overlay.o \ patch.o \ - fifo_buffer.o \ + libretro-sdk/queues/fifo_buffer.o \ core_options.o \ libretro-sdk/compat/compat.o \ cheats.o \ @@ -124,30 +131,30 @@ OBJ += frontend/frontend.o \ libretro-sdk/file/config_file_userdata.o \ screenshot.o \ libretro-sdk/gfx/scaler/scaler.o \ - gfx/shader/shader_null.o \ - gfx/shader/shader_context.o \ - gfx/shader/shader_parse.o \ + gfx/drivers_shader/shader_null.o \ + gfx/video_shader_driver.o \ + gfx/video_shader_parse.o \ libretro-sdk/gfx/scaler/pixconv.o \ libretro-sdk/gfx/scaler/scaler_int.o \ libretro-sdk/gfx/scaler/scaler_filter.o \ gfx/image/image_rpng.o \ - gfx/fonts/fonts.o \ + gfx/font_renderer_driver.o \ gfx/video_filter.o \ - audio/resamplers/resampler.o \ - audio/dsp_filter.o \ - audio/resamplers/sinc.o \ - audio/resamplers/nearest.o \ - audio/resamplers/cc_resampler.o \ - location/nulllocation.o \ - camera/nullcamera.o \ - gfx/nullgfx.o \ - audio/nullaudio.o \ - input/nullinput.o \ - input/nullinput_joypad.o \ - input/osk/nullosk.o \ + audio/audio_resampler_driver.o \ + audio/audio_dsp_filter.o \ + audio/drivers_resampler/sinc.o \ + audio/drivers_resampler/nearest.o \ + audio/drivers_resampler/cc_resampler.o \ + location/drivers/nulllocation.o \ + camera/drivers/nullcamera.o \ + gfx/drivers/nullgfx.o \ + audio/drivers/nullaudio.o \ + input/drivers/nullinput.o \ + input/drivers_joypad/nullinput_joypad.o \ + osk/drivers/nullosk.o \ playlist.o \ movie.o \ - record/ffemu.o \ + record/record_driver.o \ performance.o # RarchDB @@ -167,45 +174,45 @@ endif ifeq ($(HAVE_PYTHON), 1) DEFINES += $(PYTHON_CFLAGS) -Wno-unused-parameter LIBS += $(PYTHON_LIBS) - OBJ += gfx/py_state/py_state.o + OBJ += gfx/video_state_python.o endif ifeq ($(HAVE_EMSCRIPTEN), 1) -OBJ += frontend/platform/platform_emscripten.o \ - input/rwebinput_input.o \ - audio/rwebaudio.o \ - camera/rwebcam.o +OBJ += frontend/drivers/platform_emscripten.o \ + input/drivers/rwebinput_input.o \ + audio/drivers/rwebaudio.o \ + camera/drivers/rwebcam.o endif # Audio # ifeq ($(HAVE_COREAUDIO), 1) - OBJ += audio/coreaudio.o + OBJ += audio/drivers/coreaudio.o LIBS += -framework CoreServices -framework CoreAudio -framework AudioUnit endif ifeq ($(HAVE_OSS), 1) - OBJ += audio/oss.o + OBJ += audio/drivers/oss.o endif ifeq ($(HAVE_OSS_BSD), 1) - OBJ += audio/oss.o + OBJ += audio/drivers/oss.o endif ifeq ($(HAVE_ALSA), 1) - OBJ += audio/alsa.o audio/alsathread.o + OBJ += audio/drivers/alsa.o audio/drivers/alsathread.o LIBS += $(ALSA_LIBS) DEFINES += $(ALSA_CFLAGS) endif ifeq ($(HAVE_ROAR), 1) - OBJ += audio/roar.o + OBJ += audio/drivers/roar.o LIBS += $(ROAR_LIBS) DEFINES += $(ROAR_CFLAGS) endif ifeq ($(HAVE_AL), 1) - OBJ += audio/openal.o + OBJ += audio/drivers/openal.o ifeq ($(OSX),1) LIBS += -framework OpenAL else @@ -214,13 +221,13 @@ ifeq ($(HAVE_AL), 1) endif ifeq ($(HAVE_JACK),1) - OBJ += audio/jack.o + OBJ += audio/drivers/jack.o LIBS += $(JACK_LIBS) DEFINES += $(JACK_CFLAGS) endif ifeq ($(HAVE_PULSE), 1) - OBJ += audio/pulse.o + OBJ += audio/drivers/pulse.o LIBS += $(PULSE_LIBS) DEFINES += $(PULSE_CFLAGS) endif @@ -236,13 +243,13 @@ ifeq ($(HAVE_RSOUND), 1) endif ifeq ($(HAVE_DSOUND), 1) - OBJ += audio/dsound.o + OBJ += audio/drivers/dsound.o DEFINES += -DHAVE_DSOUND LIBS += -ldxguid -ldsound endif ifeq ($(HAVE_XAUDIO), 1) - OBJ += audio/xaudio.o audio/xaudio-c/xaudio-c.o + OBJ += audio/drivers/xaudio.o audio/drivers/xaudio-c.o DEFINES += -DHAVE_XAUDIO LIBS += -lole32 endif @@ -250,8 +257,8 @@ endif # Audio Resamplers ifeq ($(HAVE_NEON),1) - OBJ += audio/resamplers/sinc_neon.o - OBJ += audio/resamplers/cc_resampler_neon.o + OBJ += audio/drivers_resampler/sinc_neon.o + OBJ += audio/drivers_resampler/cc_resampler_neon.o # When compiled without this, tries to attempt to compile sinc lerp, # which will error out # @@ -261,33 +268,33 @@ ifeq ($(HAVE_NEON),1) DEFINES += -DSINC_LOWER_QUALITY endif -OBJ += audio/utils.o +OBJ += audio/audio_utils.o ifeq ($(HAVE_NEON),1) - OBJ += audio/utils_neon.o + OBJ += audio/audio_utils_neon.o endif ifeq ($(HAVE_RGUI), 1) - OBJ += menu/disp/rgui.o + OBJ += menu/drivers_display/rgui.o DEFINES += -DHAVE_MENU -DHAVE_RGUI HAVE_MENU_COMMON = 1 ifeq ($(HAVE_GLUI), 1) - OBJ += menu/disp/glui.o + OBJ += menu/drivers_display/glui.o DEFINES += -DHAVE_GLUI endif ifeq ($(HAVE_XMB), 1) - OBJ += menu/disp/xmb.o + OBJ += menu/drivers_display/xmb.o DEFINES += -DHAVE_XMB endif ifeq ($(HAVE_LAKKA), 1) - OBJ += menu/backend/menu_lakka_backend.o \ - menu/disp/lakka.o + OBJ += menu/drivers_backend/menu_lakka_backend.o \ + menu/drivers_display/lakka.o DEFINES += -DHAVE_LAKKA endif endif ifeq ($(HAVE_MENU_COMMON), 1) - OBJ += menu/backend/menu_common_backend.o \ - menu/menu_input_line_cb.o \ + OBJ += menu/drivers_backend/menu_common_backend.o \ + menu/menu_input.o \ menu/menu.o \ menu/menu_common_list.o \ menu/menu_navigation.o \ @@ -300,7 +307,7 @@ ifeq ($(HAVE_MENU_COMMON), 1) endif ifeq ($(HAVE_FREETYPE), 1) - OBJ += gfx/fonts/freetype.o + OBJ += gfx/drivers_font_renderer/freetype.o LIBS += $(FREETYPE_LIBS) DEFINES += $(FREETYPE_CFLAGS) endif @@ -320,7 +327,7 @@ endif #Input ifeq ($(HAVE_WAYLAND), 1) - #OBJ += input/wayland.o + #OBJ += input/drivers/wayland.o DEFINES += $(WAYLAND_CFLAGS) LIBS += $(WAYLAND_LIBS) endif @@ -328,18 +335,18 @@ endif ifeq ($(HAVE_DINPUT), 1) LIBS += -ldinput8 -ldxguid -lole32 DEFINES += -DHAVE_DINPUT - OBJ += input/dinput.o + OBJ += input/drivers/dinput.o JOYCONFIG_LIBS += -ldinput8 -ldxguid -lole32 endif ifeq ($(HAVE_WINXINPUT), 1) DEFINES += -DHAVE_WINXINPUT -DHAVE_BUILTIN_AUTOCONFIG - OBJ += input/winxinput_joypad.o \ + OBJ += input/drivers_joypad/winxinput_joypad.o \ input/autoconf/builtin_win.o endif ifeq ($(HAVE_X11), 1) - OBJ += input/x11_input.o gfx/context/x11_common.o input/keyboard_event_x11.o + OBJ += input/drivers/x11_input.o gfx/drivers_context/x11_common.o input/keyboard_event_x11.o LIBS += $(X11_LIBS) $(XEXT_LIBS) $(XF86VM_LIBS) $(XINERAMA_LIBS) DEFINES += $(X11_CFLAGS) $(XEXT_CFLAGS) $(XF86VM_CFLAGS) $(XINERAMA_CFLAGS) endif @@ -354,61 +361,61 @@ ifeq ($(HAVE_UDEV), 1) DEFINES += $(UDEV_CFLAGS) LIBS += $(UDEV_LIBS) JOYCONFIG_LIBS += $(UDEV_LIBS) - OBJ += input/udev_input.o input/udev_joypad.o + OBJ += input/drivers/udev_input.o input/drivers_joypad/udev_joypad.o endif ifeq ($(HAVE_PARPORT), 1) - OBJ += input/parport_joypad.o + OBJ += input/drivers_joypad/parport_joypad.o endif # Video # ifeq ($(HAVE_OPENGL), 1) DEFINES += -DHAVE_OPENGL -DHAVE_GLSL - OBJ += gfx/gl.o \ + OBJ += gfx/drivers/gl.o \ gfx/gl_common.o \ - gfx/gfx_context.o \ - gfx/context/gfx_null_ctx.o \ - gfx/fonts/gl_font.o \ - gfx/fonts/gl_raster_font.o \ + gfx/video_context_driver.o \ + gfx/drivers_context/gfx_null_ctx.o \ + gfx/font_gl_driver.o \ + gfx/drivers_font/gl_raster_font.o \ libretro-sdk/gfx/math/matrix_4x4.o \ - gfx/state_tracker.o \ + gfx/video_state_tracker.o \ libretro-sdk/glsym/rglgen.o ifeq ($(HAVE_KMS), 1) - OBJ += gfx/context/drm_egl_ctx.o + OBJ += gfx/drivers_context/drm_egl_ctx.o DEFINES += $(GBM_CFLAGS) $(DRM_CFLAGS) $(EGL_CFLAGS) LIBS += $(GBM_LIBS) $(DRM_LIBS) $(EGL_LIBS) endif ifeq ($(HAVE_VIDEOCORE), 1) - OBJ += gfx/context/vc_egl_ctx.o + OBJ += gfx/drivers_context/vc_egl_ctx.o DEFINES += $(EGL_CFLAGS) LIBS += $(EGL_LIBS) endif ifeq ($(HAVE_EMSCRIPTEN), 1) - OBJ += gfx/context/emscriptenegl_ctx.o + OBJ += gfx/drivers_context/emscriptenegl_ctx.o endif ifeq ($(HAVE_MALI_FBDEV), 1) - OBJ += gfx/context/mali_fbdev_ctx.o + OBJ += gfx/drivers_context/mali_fbdev_ctx.o DEFINES += $(EGL_CFLAGS) LIBS += $(EGL_LIBS) endif ifeq ($(HAVE_VIVANTE_FBDEV), 1) - OBJ += gfx/context/vivante_fbdev_ctx.o + OBJ += gfx/drivers_context/vivante_fbdev_ctx.o DEFINES += $(EGL_CFLAGS) LIBS += $(EGL_LIBS) endif ifeq ($(HAVE_X11), 1) ifeq ($(HAVE_GLES), 0) - OBJ += gfx/context/glx_ctx.o + OBJ += gfx/drivers_context/glx_ctx.o endif ifeq ($(HAVE_EGL), 1) - OBJ += gfx/context/xegl_ctx.o + OBJ += gfx/drivers_context/xegl_ctx.o DEFINES += $(EGL_CFLAGS) LIBS += $(EGL_LIBS) endif @@ -416,7 +423,7 @@ ifeq ($(HAVE_OPENGL), 1) ifeq ($(HAVE_WAYLAND), 1) ifeq ($(HAVE_EGL), 1) - OBJ += gfx/context/wayland_ctx.o + OBJ += gfx/drivers_context/wayland_ctx.o endif endif @@ -434,13 +441,13 @@ ifeq ($(HAVE_OPENGL), 1) LIBS += -framework OpenGL else ifneq ($(findstring Win32,$(OS)),) LIBS += -lopengl32 -lgdi32 -lcomdlg32 - OBJ += gfx/context/wgl_ctx.o + OBJ += gfx/drivers_context/wgl_ctx.o else LIBS += -lGL endif endif - OBJ += gfx/shader/shader_glsl.o + OBJ += gfx/drivers_shader/shader_glsl.o DEFINES += -DHAVE_GLSL endif @@ -449,10 +456,10 @@ ifeq ($(HAVE_SDL2), 1) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl_gfx.o input/sdl_input.o input/sdl_joypad.o audio/sdl_audio.o + OBJ += gfx/drivers/sdl_gfx.o input/drivers/sdl_input.o input/drivers_joypad/sdl_joypad.o audio/drivers/sdl_audio.o ifeq ($(HAVE_OPENGL), 1) - OBJ += gfx/context/sdl_gl_ctx.o + OBJ += gfx/drivers_context/sdl_gl_ctx.o endif JOYCONFIG_LIBS += $(SDL_LIBS) @@ -461,10 +468,10 @@ ifeq ($(HAVE_SDL), 1) endif ifeq ($(HAVE_SDL2), 1) - OBJ += gfx/sdl2_gfx.o input/sdl_input.o input/sdl_joypad.o audio/sdl_audio.o + OBJ += gfx/drivers/sdl2_gfx.o input/drivers/sdl_input.o input/drivers_joypad/sdl_joypad.o audio/drivers/sdl_audio.o ifeq ($(HAVE_OPENGL), 1) - OBJ += gfx/context/sdl_gl_ctx.o + OBJ += gfx/drivers_context/sdl_gl_ctx.o endif JOYCONFIG_LIBS += $(SDL2_LIBS) @@ -474,30 +481,30 @@ ifeq ($(HAVE_SDL2), 1) endif ifeq ($(HAVE_OMAP), 1) - OBJ += gfx/omap_gfx.o + OBJ += gfx/drivers/omap_gfx.o endif ifeq ($(HAVE_EXYNOS), 1) - OBJ += gfx/exynos_gfx.o mem/neon/memcpy-neon.o + OBJ += gfx/drivers/exynos_gfx.o mem/neon/memcpy-neon.o LIBS += $(DRM_LIBS) $(EXYNOS_LIBS) DEFINES += $(DRM_CFLAGS) $(EXYNOS_CFLAGS) endif ifeq ($(HAVE_VG), 1) - OBJ += gfx/vg.o libretro-sdk/gfx/math/matrix_3x3.o + OBJ += gfx/drivers/vg.o libretro-sdk/gfx/math/matrix_3x3.o DEFINES += $(VG_CFLAGS) LIBS += $(VG_LIBS) endif ifeq ($(HAVE_XVIDEO), 1) - OBJ += gfx/xvideo.o + OBJ += gfx/drivers/xvideo.o LIBS += $(XVIDEO_LIBS) DEFINES += $(XVIDEO_CFLAGS) endif ifeq ($(HAVE_CG), 1) DEFINES += -DHAVE_CG - OBJ += gfx/shader/shader_gl_cg.o + OBJ += gfx/drivers_shader/shader_gl_cg.o LIBS += $(CG_LIBS) endif @@ -505,9 +512,9 @@ ifeq ($(HAVE_D3D9), 1) OBJ += gfx/d3d/d3d.o \ gfx/d3d/render_chain.o \ gfx/d3d/d3d_wrapper.o \ - gfx/fonts/d3d_font.o \ - gfx/fonts/d3d_w32_font.o \ - gfx/context/d3d_ctx.o + gfx/font_d3d_driver.o \ + gfx/drivers_font/d3d_w32_font.o \ + gfx/drivers_context/d3d_ctx.o DEFINES += -DHAVE_WIN32_D3D9 LIBS += -ld3d9 -ld3dx9 -ldxguid @@ -598,7 +605,7 @@ endif # Camera ifeq ($(HAVE_V4L2),1) - OBJ += camera/video4linux2.o + OBJ += camera/drivers/video4linux2.o DEFINES += -DHAVE_V4L2 endif @@ -622,7 +629,7 @@ endif # Record ifeq ($(HAVE_FFMPEG), 1) - OBJ += record/ffmpeg.o + OBJ += record/drivers/ffmpeg.o LIBS += $(AVCODEC_LIBS) $(AVFORMAT_LIBS) $(AVUTIL_LIBS) $(SWSCALE_LIBS) $(FFMPEG_LIBS) DEFINES += $(AVCODEC_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS) DEFINES += -DHAVE_FFMPEG -Iffmpeg diff --git a/Makefile.emscripten b/Makefile.emscripten index b1835ceb9b..46648d76cd 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -69,16 +69,16 @@ clean: rm -f menu/*.o rm -f menu/disp/*.o rm -f audio/*.o - rm -f audio/xaudio-c/*.o rm -f compat/*.o rm -f compat/rxml/*.o rm -f conf/*.o rm -f gfx/scaler/*.o rm -f gfx/*.o rm -f gfx/d3d/*.o - rm -f gfx/context/*.o + rm -f gfx/drivers_context/*.o rm -f gfx/math/*.o - rm -f gfx/fonts/*.o + rm -f gfx/drivers_font/*.o + rm -f gfx/drivers_font_renderer/*.o rm -f gfx/py_state/*.o rm -f gfx/rpng/*.o rm -f gfx/glsym/*.o diff --git a/Makefile.openpandora b/Makefile.openpandora index f837719d3f..04f82f0a97 100644 --- a/Makefile.openpandora +++ b/Makefile.openpandora @@ -10,7 +10,7 @@ TARGET := retroarch-pandora LDDIRS = -L. -L$(PNDSDK)/usr/lib INCDIRS = -I. -I$(PNDSDK)/usr/include -OBJ = griffin/griffin.o audio/resamplers/sinc_neon.o audio/utils_neon.o +OBJ = griffin/griffin.o audio/resamplers/sinc_neon.o audio/audio_utils_neon.o LDFLAGS = -L$(PNDSDK)/usr/lib -Wl,-rpath,$(PNDSDK)/usr/lib LIBS = -lGLESv2 -lEGL -ldl -lm -lpthread -lrt -lasound diff --git a/Makefile.pandora b/Makefile.pandora index 6ba39ef28e..1e3194ba18 100644 --- a/Makefile.pandora +++ b/Makefile.pandora @@ -40,8 +40,9 @@ clean: rm -f audio/*.o rm -f conf/*.o rm -f gfx/*.o - rm -f gfx/fonts/*.o - rm -f gfx/context/*.o + rm -f gfx/drivers_font/*.o + rm -f gfx/drivers_font_renderer/*.o + rm -f gfx/drivers_context/*.o rm -f gfx/py_state/*.o rm -f compat/*.o rm -f record/*.o diff --git a/Makefile.ps3.salamander b/Makefile.ps3.salamander index 2c37b89f03..9f936e83e7 100644 --- a/Makefile.ps3.salamander +++ b/Makefile.ps3.salamander @@ -18,8 +18,8 @@ endif STRIP = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-strip.exe -PPU_CFLAGS += -I. -Ilibretro-sdk/include -D__CELLOS_LV2__ -DIS_SALAMANDER -DRARCH_CONSOLE -DHAVE_SYSUTILS -DHAVE_SYSMODULES -DHAVE_RARCH_EXEC -DRARCH_INTERNAL -PPU_SRCS = frontend/frontend_salamander.c frontend/frontend_context.c frontend/platform/platform_ps3.c frontend/platform/platform_null.c libretro-sdk/file/file_path.c libretro-sdk/file/dir_list.c libretro-sdk/string/string_list.c libretro-sdk/compat/compat.c libretro-sdk/file/config_file.c +PPU_CFLAGS += -I. -Ilibretro-sdk/include -D__CELLOS_LV2__ -DIS_SALAMANDER -DRARCH_CONSOLE -DHAVE_SYSUTILS -DHAVE_SYSMODULES -DHAVE_RARCH_EXEC +PPU_SRCS = frontend/frontend_salamander.c frontend/frontend_driver.c frontend/drivers/platform_ps3.c frontend/drivers/platform_null.c libretro-sdk/file/file_path.c libretro-sdk/file/dir_list.c libretro-sdk/string/string_list.c libretro-sdk/compat/compat.c libretro-sdk/file/config_file.c ifeq ($(HAVE_LOGGER), 1) PPU_CFLAGS += -DHAVE_LOGGER -Ilogger/netlogger diff --git a/Makefile.psp1.salamander b/Makefile.psp1.salamander index ff6f4ee75f..2eef884ca2 100644 --- a/Makefile.psp1.salamander +++ b/Makefile.psp1.salamander @@ -14,7 +14,7 @@ INCDIR = $(PSPPATH)/include libretro-sdk/include CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math ASFLAGS = $(CFLAGS) -RARCH_DEFINES = -DPSP -DIS_SALAMANDER -DRARCH_CONSOLE -DRARCH_INTERNAL +RARCH_DEFINES = -DPSP -DIS_SALAMANDER -DRARCH_CONSOLE LIBDIR = LDFLAGS = @@ -31,7 +31,7 @@ PSP_EBOOT_TITLE = RetroArch PSP_EBOOT_ICON = psp1/ICON0.PNG PSP_EBOOT_PIC1 = psp1/PIC1.PNG -OBJS = frontend/frontend_salamander.o frontend/frontend_context.o frontend/platform/platform_psp.o frontend/platform/platform_null.o libretro-sdk/file/file_path.o libretro-sdk/string/string_list.o libretro-sdk/file/dir_list.o libretro-sdk/compat/compat.o libretro-sdk/file/config_file.o psp1/kernel_functions.o +OBJS = frontend/frontend_salamander.o frontend/frontend_driver.o frontend/drivers/platform_psp.o frontend/drivers/platform_null.o libretro-sdk/file/file_path.o libretro-sdk/string/string_list.o libretro-sdk/file/dir_list.o libretro-sdk/compat/compat.o libretro-sdk/file/config_file.o psp1/kernel_functions.o PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak diff --git a/Makefile.wii.salamander b/Makefile.wii.salamander index 24dca9907e..3a164175c6 100644 --- a/Makefile.wii.salamander +++ b/Makefile.wii.salamander @@ -39,7 +39,7 @@ LIBS := -lfat -lwiiuse -logc -lbte APP_BOOTER_DIR = wii/app_booter -OBJ = frontend/frontend_salamander.o frontend/frontend_context.o frontend/platform/platform_gx.o frontend/platform/platform_wii.o frontend/platform/platform_null.o libretro-sdk/file/file_path.o libretro-sdk/string/string_list.o libretro-sdk/file/dir_list.o libretro-sdk/compat/compat.o libretro-sdk/file/config_file.o $(APP_BOOTER_DIR)/app_booter.binobj +OBJ = frontend/frontend_salamander.o frontend/frontend_driver.o frontend/drivers/platform_gx.o frontend/drivers/platform_wii.o frontend/drivers/platform_null.o libretro-sdk/file/file_path.o libretro-sdk/string/string_list.o libretro-sdk/file/dir_list.o libretro-sdk/compat/compat.o libretro-sdk/file/config_file.o $(APP_BOOTER_DIR)/app_booter.binobj ifeq ($(HAVE_LOGGER), 1) CFLAGS += -DHAVE_LOGGER diff --git a/android/phoenix/jni/Android.mk b/android/phoenix/jni/Android.mk index c6a2607c8d..cb419b46df 100644 --- a/android/phoenix/jni/Android.mk +++ b/android/phoenix/jni/Android.mk @@ -28,9 +28,9 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) ifeq ($(HAVE_NEON),1) LOCAL_CFLAGS += -D__ARM_NEON__ - LOCAL_SRC_FILES += $(RARCH_DIR)/audio/utils_neon.S.neon - LOCAL_SRC_FILES += $(RARCH_DIR)/audio/resamplers/sinc_neon.S.neon - LOCAL_SRC_FILES += $(RARCH_DIR)/audio/resamplers/cc_resampler_neon.S.neon + LOCAL_SRC_FILES += $(RARCH_DIR)/audio/audio_utils_neon.S.neon + LOCAL_SRC_FILES += $(RARCH_DIR)/audio/drivers_resampler/sinc_neon.S.neon + LOCAL_SRC_FILES += $(RARCH_DIR)/audio/drivers_resampler/cc_resampler_neon.S.neon endif LOCAL_CFLAGS += -DSINC_LOWER_QUALITY diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 3e92909530..f1e781d7be 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -19,7 +19,7 @@ #include #import "../common/RetroArch_Apple.h" -#include "../../input/apple_input.h" +#include "../../input/drivers/apple_input.h" #include "../../frontend/frontend.h" #include "../../menu/menu.h" #include "../../retroarch.h" diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 62865589fb..4288ee0d2f 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -17,7 +17,7 @@ #import #import "../common/RetroArch_Apple.h" #include "../../settings_data.h" -#include "../../input/apple_input.h" +#include "../../input/drivers/apple_input.h" #include "../../driver.h" #include "../../input/input_common.h" @@ -72,7 +72,7 @@ static void* const associated_name_tag = (void*)&associated_name_tag; int32_t idx = self.setting->index ? self.setting->index - 1 : 0; if ((value = apple_input_find_any_key())) - BINDFOR(*[self setting]).key = input_translate_keysym_to_rk(value); + BINDFOR(*[self setting]).key = input_keymaps_translate_keysym_to_rk(value); else if ((value = apple_input_find_any_button(idx)) >= 0) BINDFOR(*[self setting]).joykey = value; else if ((value = apple_input_find_any_axis(idx))) diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m index fc94a4bcdd..eefed22215 100644 --- a/apple/common/apple_gamecontroller.m +++ b/apple/common/apple_gamecontroller.m @@ -17,7 +17,7 @@ #include "RetroArch_Apple.h" #import #include "apple_gamecontroller.h" -#include "../../input/apple_input.h" +#include "../../input/drivers/apple_input.h" static BOOL apple_gamecontroller_available(void) { diff --git a/apple/common/apple_gfx_context.c.inl b/apple/common/apple_gfx_context.c.inl index 6832360cce..83b91e1260 100644 --- a/apple/common/apple_gfx_context.c.inl +++ b/apple/common/apple_gfx_context.c.inl @@ -4,7 +4,7 @@ #endif #include "../../gfx/gfx_common.h" -#include "../../gfx/gfx_context.h" +#include "../../gfx/video_context_driver.h" #include "../../gfx/gl_common.h" //#define HAVE_NSOPENGL diff --git a/apple/iOS/RetroArch_iOS.xcodeproj/project.pbxproj b/apple/iOS/RetroArch_iOS.xcodeproj/project.pbxproj index bbf1d7f6f7..fbab903463 100644 --- a/apple/iOS/RetroArch_iOS.xcodeproj/project.pbxproj +++ b/apple/iOS/RetroArch_iOS.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 501232C8192E5FB00063A359 /* apple_gamecontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 501232C7192E5FB00063A359 /* apple_gamecontroller.m */; }; 501232CA192E5FC40063A359 /* griffin.c in Sources */ = {isa = PBXBuildFile; fileRef = 501232C9192E5FC40063A359 /* griffin.c */; }; 501232CC192E5FDC0063A359 /* sinc_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 501232CB192E5FDC0063A359 /* sinc_neon.S */; }; - 501232CE192E5FE30063A359 /* utils_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 501232CD192E5FE30063A359 /* utils_neon.S */; }; + 501232CE192E5FE30063A359 /* audio_utils_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 501232CD192E5FE30063A359 /* audio_utils_neon.S */; }; 501232D6192E60580063A359 /* platform.m in Sources */ = {isa = PBXBuildFile; fileRef = 501232D5192E60580063A359 /* platform.m */; }; 501232D8192E605F0063A359 /* browser.m in Sources */ = {isa = PBXBuildFile; fileRef = 501232D7192E605F0063A359 /* browser.m */; }; 501232DA192E606D0063A359 /* menu.m in Sources */ = {isa = PBXBuildFile; fileRef = 501232D9192E606D0063A359 /* menu.m */; }; @@ -42,8 +42,8 @@ /* Begin PBXFileReference section */ 501232C7192E5FB00063A359 /* apple_gamecontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = apple_gamecontroller.m; path = ../common/apple_gamecontroller.m; sourceTree = ""; }; 501232C9192E5FC40063A359 /* griffin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = griffin.c; path = ../../griffin/griffin.c; sourceTree = ""; }; - 501232CB192E5FDC0063A359 /* sinc_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = sinc_neon.S; path = ../../audio/resamplers/sinc_neon.S; sourceTree = ""; }; - 501232CD192E5FE30063A359 /* utils_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = utils_neon.S; path = ../../audio/utils_neon.S; sourceTree = ""; }; + 501232CB192E5FDC0063A359 /* sinc_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = sinc_neon.S; path = ../../audio/drivers_resampler/sinc_neon.S; sourceTree = ""; }; + 501232CD192E5FE30063A359 /* audio_utils_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; name = audio_utils_neon.S; path = ../../audio/audio_utils_neon.S; sourceTree = ""; }; 501232D5192E60580063A359 /* platform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = platform.m; sourceTree = ""; }; 501232D7192E605F0063A359 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = ""; }; 501232D9192E606D0063A359 /* menu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = menu.m; sourceTree = ""; }; @@ -52,7 +52,7 @@ 5073C587196C0BA40026E146 /* RAGameView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RAGameView.m; path = ../common/RAGameView.m; sourceTree = SOURCE_ROOT; }; 5073C588196C0BA40026E146 /* utility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = utility.m; path = ../common/utility.m; sourceTree = SOURCE_ROOT; }; 50CCC827185E0E7D001F5BC8 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; - 50D00E8D19D117C400EBA71E /* cc_resampler_neon.S */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; name = cc_resampler_neon.S; path = ../../audio/resamplers/cc_resampler_neon.S; sourceTree = ""; }; + 50D00E8D19D117C400EBA71E /* cc_resampler_neon.S */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; name = cc_resampler_neon.S; path = ../../audio/drivers_resampler/cc_resampler_neon.S; sourceTree = ""; }; 50E7189E184B88AA001956CE /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; }; 6949E72219FABADC00CC7F42 /* CFExtensions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CFExtensions.m; path = ../common/CFExtensions.m; sourceTree = ""; }; 696012F119F3389A006A1088 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; }; @@ -201,7 +201,7 @@ 96AFAEE516C1DC73009DE44C /* audio */ = { isa = PBXGroup; children = ( - 501232CD192E5FE30063A359 /* utils_neon.S */, + 501232CD192E5FE30063A359 /* audio_utils_neon.S */, 501232CB192E5FDC0063A359 /* sinc_neon.S */, ); name = audio; @@ -312,7 +312,7 @@ 501232DA192E606D0063A359 /* menu.m in Sources */, 501232D8192E605F0063A359 /* browser.m in Sources */, 501232D6192E60580063A359 /* platform.m in Sources */, - 501232CE192E5FE30063A359 /* utils_neon.S in Sources */, + 501232CE192E5FE30063A359 /* audio_utils_neon.S in Sources */, 501232C8192E5FB00063A359 /* apple_gamecontroller.m in Sources */, 5073C58A196C0BA40026E146 /* RAGameView.m in Sources */, 501232CC192E5FDC0063A359 /* sinc_neon.S in Sources */, diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index c0f90d7485..3725cf2905 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -18,13 +18,13 @@ #include "../common/RetroArch_Apple.h" #include "../../input/input_common.h" #include "../../input/input_keymaps.h" -#include "../../input/apple_input.h" +#include "../../input/drivers/apple_input.h" #include #include "menu.h" #include "../../menu/menu.h" #include "../../menu/menu_entries.h" -#include "../../menu/disp/shared.h" +#include "../../menu/drivers_display/shared.h" /*********************************************/ /* RunActionSheet */ @@ -558,7 +558,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U idx = self.setting->index - 1; if ((value = apple_input_find_any_key())) - BINDFOR(*self.setting).key = input_translate_keysym_to_rk(value); + BINDFOR(*self.setting).key = input_keymaps_translate_keysym_to_rk(value); else if ((value = apple_input_find_any_button(idx)) >= 0) BINDFOR(*self.setting).joykey = value; else if ((value = apple_input_find_any_axis(idx))) @@ -717,7 +717,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U - (void)menuBack { - apply_deferred_settings(); + menu_apply_deferred_settings(); menu_list_pop_stack(driver.menu->menu_list); [self menuRefresh]; [self reloadData]; diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 26d69520c6..a4013e5c03 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -17,7 +17,7 @@ #include #include "../common/RetroArch_Apple.h" -#include "../../input/apple_input.h" +#include "../../input/drivers/apple_input.h" #include "../../settings_data.h" #include "../common/apple_gamecontroller.h" #include "menu.h" @@ -27,7 +27,7 @@ #include "bluetooth/btdynamic.h" #include "bluetooth/btpad.h" -#include "../../menu/disp/ios.h" +#include "../../menu/drivers_display/ios.h" id apple_platform; diff --git a/audio/audio_driver.c b/audio/audio_driver.c new file mode 100644 index 0000000000..c98aac1956 --- /dev/null +++ b/audio/audio_driver.c @@ -0,0 +1,383 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2015 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include "audio_driver.h" +#include "audio_utils.h" +#include "audio_thread_wrapper.h" +#include "../driver.h" +#include "../general.h" +#include "../retroarch.h" + +static const audio_driver_t *audio_drivers[] = { +#ifdef HAVE_ALSA + &audio_alsa, +#ifndef __QNX__ + &audio_alsathread, +#endif +#endif +#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD) + &audio_oss, +#endif +#ifdef HAVE_RSOUND + &audio_rsound, +#endif +#ifdef HAVE_COREAUDIO + &audio_coreaudio, +#endif +#ifdef HAVE_AL + &audio_openal, +#endif +#ifdef HAVE_SL + &audio_opensl, +#endif +#ifdef HAVE_ROAR + &audio_roar, +#endif +#ifdef HAVE_JACK + &audio_jack, +#endif +#if defined(HAVE_SDL) || defined(HAVE_SDL2) + &audio_sdl, +#endif +#ifdef HAVE_XAUDIO + &audio_xa, +#endif +#ifdef HAVE_DSOUND + &audio_dsound, +#endif +#ifdef HAVE_PULSE + &audio_pulse, +#endif +#ifdef __CELLOS_LV2__ + &audio_ps3, +#endif +#ifdef XENON + &audio_xenon360, +#endif +#ifdef GEKKO + &audio_gx, +#endif +#ifdef EMSCRIPTEN + &audio_rwebaudio, +#endif +#ifdef PSP + &audio_psp1, +#endif + &audio_null, + NULL, +}; + +/** + * compute_audio_buffer_statistics: + * + * Computes audio buffer statistics. + * + **/ +static void compute_audio_buffer_statistics(void) +{ + unsigned i, low_water_size, high_water_size, avg, stddev; + float avg_filled, deviation; + uint64_t accum = 0, accum_var = 0; + unsigned low_water_count = 0, high_water_count = 0; + unsigned samples = min(g_extern.measure_data.buffer_free_samples_count, + AUDIO_BUFFER_FREE_SAMPLES_COUNT); + + if (samples < 3) + return; + + for (i = 1; i < samples; i++) + accum += g_extern.measure_data.buffer_free_samples[i]; + + avg = accum / (samples - 1); + + for (i = 1; i < samples; i++) + { + int diff = avg - g_extern.measure_data.buffer_free_samples[i]; + accum_var += diff * diff; + } + + stddev = (unsigned)sqrt((double)accum_var / (samples - 2)); + avg_filled = 1.0f - (float)avg / g_extern.audio_data.driver_buffer_size; + deviation = (float)stddev / g_extern.audio_data.driver_buffer_size; + + low_water_size = g_extern.audio_data.driver_buffer_size * 3 / 4; + high_water_size = g_extern.audio_data.driver_buffer_size / 4; + + for (i = 1; i < samples; i++) + { + if (g_extern.measure_data.buffer_free_samples[i] >= low_water_size) + low_water_count++; + else if (g_extern.measure_data.buffer_free_samples[i] <= high_water_size) + high_water_count++; + } + + RARCH_LOG("Average audio buffer saturation: %.2f %%, standard deviation (percentage points): %.2f %%.\n", + avg_filled * 100.0, deviation * 100.0); + RARCH_LOG("Amount of time spent close to underrun: %.2f %%. Close to blocking: %.2f %%.\n", + (100.0 * low_water_count) / (samples - 1), + (100.0 * high_water_count) / (samples - 1)); +} + +/** + * audio_driver_find_handle: + * @index : index of driver to get handle to. + * + * Returns: handle to audio driver at index. Can be NULL + * if nothing found. + **/ +const void *audio_driver_find_handle(int index) +{ + const void *drv = audio_drivers[index]; + if (!drv) + return NULL; + return drv; +} + +/** + * audio_driver_find_ident: + * @index : index of driver to get handle to. + * + * Returns: Human-readable identifier of audio driver at index. Can be NULL + * if nothing found. + **/ +const char *audio_driver_find_ident(int index) +{ + const audio_driver_t *drv = audio_drivers[index]; + if (!drv) + return NULL; + return drv->ident; +} + +/** + * config_get_audio_driver_options: + * + * Get an enumerated list of all audio driver names, separated by '|'. + * + * Returns: string listing of all audio driver names, separated by '|'. + **/ +const char* config_get_audio_driver_options(void) +{ + union string_list_elem_attr attr; + unsigned i; + char *options = NULL; + int options_len = 0; + struct string_list *options_l = string_list_new(); + + attr.i = 0; + + for (i = 0; audio_driver_find_handle(i); i++) + { + const char *opt = audio_driver_find_ident(i); + options_len += strlen(opt) + 1; + string_list_append(options_l, opt, attr); + } + + options = (char*)calloc(options_len, sizeof(char)); + + string_list_join_concat(options, options_len, options_l, "|"); + + string_list_free(options_l); + options_l = NULL; + + return options; +} + +void find_audio_driver(void) +{ + int i = find_driver_index("audio_driver", g_settings.audio.driver); + if (i >= 0) + driver.audio = (const audio_driver_t*)audio_driver_find_handle(i); + else + { + unsigned d; + RARCH_ERR("Couldn't find any audio driver named \"%s\"\n", + g_settings.audio.driver); + RARCH_LOG_OUTPUT("Available audio drivers are:\n"); + for (d = 0; audio_driver_find_handle(d); d++) + RARCH_LOG_OUTPUT("\t%s\n", audio_driver_find_ident(d)); + RARCH_WARN("Going to default to first audio driver...\n"); + + driver.audio = (const audio_driver_t*)audio_driver_find_handle(0); + + if (!driver.audio) + rarch_fail(1, "find_audio_driver()"); + } +} + +void uninit_audio(void) +{ + if (driver.audio_data && driver.audio) + driver.audio->free(driver.audio_data); + + free(g_extern.audio_data.conv_outsamples); + g_extern.audio_data.conv_outsamples = NULL; + g_extern.audio_data.data_ptr = 0; + + free(g_extern.audio_data.rewind_buf); + g_extern.audio_data.rewind_buf = NULL; + + if (!g_settings.audio.enable) + { + driver.audio_active = false; + return; + } + + rarch_resampler_freep(&driver.resampler, + &driver.resampler_data); + + free(g_extern.audio_data.data); + g_extern.audio_data.data = NULL; + + free(g_extern.audio_data.outsamples); + g_extern.audio_data.outsamples = NULL; + + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); + + compute_audio_buffer_statistics(); +} + +void init_audio(void) +{ + size_t outsamples_max, max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2; + + audio_convert_init_simd(); + + /* Resource leaks will follow if audio is initialized twice. */ + if (driver.audio_data) + return; + + /* Accomodate rewind since at some point we might have two full buffers. */ + outsamples_max = max_bufsamples * AUDIO_MAX_RATIO * + g_settings.slowmotion_ratio; + + /* Used for recording even if audio isn't enabled. */ + rarch_assert(g_extern.audio_data.conv_outsamples = + (int16_t*)malloc(outsamples_max * sizeof(int16_t))); + + g_extern.audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING; + g_extern.audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING; + g_extern.audio_data.chunk_size = + g_extern.audio_data.block_chunk_size; + + /* Needs to be able to hold full content of a full max_bufsamples + * in addition to its own. */ + rarch_assert(g_extern.audio_data.rewind_buf = (int16_t*) + malloc(max_bufsamples * sizeof(int16_t))); + g_extern.audio_data.rewind_size = max_bufsamples; + + if (!g_settings.audio.enable) + { + driver.audio_active = false; + return; + } + + find_audio_driver(); +#ifdef HAVE_THREADS + if (g_extern.system.audio_callback.callback) + { + RARCH_LOG("Starting threaded audio driver ...\n"); + if (!rarch_threaded_audio_init(&driver.audio, &driver.audio_data, + *g_settings.audio.device ? g_settings.audio.device : NULL, + g_settings.audio.out_rate, g_settings.audio.latency, + driver.audio)) + { + RARCH_ERR("Cannot open threaded audio driver ... Exiting ...\n"); + rarch_fail(1, "init_audio()"); + } + } + else +#endif + { + driver.audio_data = driver.audio->init(*g_settings.audio.device ? + g_settings.audio.device : NULL, + g_settings.audio.out_rate, g_settings.audio.latency); + } + + if (!driver.audio_data) + { + RARCH_ERR("Failed to initialize audio driver. Will continue without audio.\n"); + driver.audio_active = false; + } + + g_extern.audio_data.use_float = false; + if (driver.audio_active && driver.audio->use_float(driver.audio_data)) + g_extern.audio_data.use_float = true; + + if (!g_settings.audio.sync && driver.audio_active) + { + rarch_main_command(RARCH_CMD_AUDIO_SET_NONBLOCKING_STATE); + g_extern.audio_data.chunk_size = + g_extern.audio_data.nonblock_chunk_size; + } + + if (g_extern.audio_data.in_rate <= 0.0f) + { + /* Should never happen. */ + RARCH_WARN("Input rate is invalid (%.3f Hz). Using output rate (%u Hz).\n", + g_extern.audio_data.in_rate, g_settings.audio.out_rate); + g_extern.audio_data.in_rate = g_settings.audio.out_rate; + } + + g_extern.audio_data.orig_src_ratio = + g_extern.audio_data.src_ratio = + (double)g_settings.audio.out_rate / g_extern.audio_data.in_rate; + + if (!rarch_resampler_realloc(&driver.resampler_data, + &driver.resampler, + g_settings.audio.resampler, g_extern.audio_data.orig_src_ratio)) + { + RARCH_ERR("Failed to initialize resampler \"%s\".\n", + g_settings.audio.resampler); + driver.audio_active = false; + } + + rarch_assert(g_extern.audio_data.data = (float*) + malloc(max_bufsamples * sizeof(float))); + + g_extern.audio_data.data_ptr = 0; + + rarch_assert(g_settings.audio.out_rate < + g_extern.audio_data.in_rate * AUDIO_MAX_RATIO); + rarch_assert(g_extern.audio_data.outsamples = (float*) + malloc(outsamples_max * sizeof(float))); + + g_extern.audio_data.rate_control = false; + if (!g_extern.system.audio_callback.callback && driver.audio_active && + g_settings.audio.rate_control) + { + if (driver.audio->buffer_size && driver.audio->write_avail) + { + g_extern.audio_data.driver_buffer_size = + driver.audio->buffer_size(driver.audio_data); + g_extern.audio_data.rate_control = true; + } + else + RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n"); + } + + rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); + + g_extern.measure_data.buffer_free_samples_count = 0; + + if (driver.audio_active && !g_extern.audio_data.mute && + g_extern.system.audio_callback.callback) + { + /* Threaded driver is initially stopped. */ + driver.audio->start(driver.audio_data); + } +} diff --git a/audio/audio_driver.h b/audio/audio_driver.h new file mode 100644 index 0000000000..91fc2a8139 --- /dev/null +++ b/audio/audio_driver.h @@ -0,0 +1,117 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2015 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __AUDIO_DRIVER__H +#define __AUDIO_DRIVER__H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct audio_driver +{ + void *(*init)(const char *device, unsigned rate, unsigned latency); + + ssize_t (*write)(void *data, const void *buf, size_t size); + + bool (*stop)(void *data); + + bool (*start)(void *data); + + /* Is the audio driver currently running? */ + bool (*alive)(void *data); + + /* Should we care about blocking in audio thread? Fast forwarding. */ + void (*set_nonblock_state)(void *data, bool toggle); + + void (*free)(void *data); + + /* Defines if driver will take standard floating point samples, + * or int16_t samples. */ + bool (*use_float)(void *data); + + /* Human-readable identifier. */ + const char *ident; + + /* Optional. */ + size_t (*write_avail)(void *data); + + size_t (*buffer_size)(void *data); +} audio_driver_t; + +extern audio_driver_t audio_rsound; +extern audio_driver_t audio_oss; +extern audio_driver_t audio_alsa; +extern audio_driver_t audio_alsathread; +extern audio_driver_t audio_roar; +extern audio_driver_t audio_openal; +extern audio_driver_t audio_opensl; +extern audio_driver_t audio_jack; +extern audio_driver_t audio_sdl; +extern audio_driver_t audio_xa; +extern audio_driver_t audio_pulse; +extern audio_driver_t audio_dsound; +extern audio_driver_t audio_coreaudio; +extern audio_driver_t audio_xenon360; +extern audio_driver_t audio_ps3; +extern audio_driver_t audio_gx; +extern audio_driver_t audio_psp1; +extern audio_driver_t audio_rwebaudio; +extern audio_driver_t audio_null; + +/** + * audio_driver_find_handle: + * @index : index of driver to get handle to. + * + * Returns: handle to audio driver at index. Can be NULL + * if nothing found. + **/ +const void *audio_driver_find_handle(int index); + +/** + * audio_driver_find_ident: + * @index : index of driver to get handle to. + * + * Returns: Human-readable identifier of audio driver at index. Can be NULL + * if nothing found. + **/ +const char *audio_driver_find_ident(int index); + +/** + * config_get_audio_driver_options: + * + * Get an enumerated list of all audio driver names, separated by '|'. + * + * Returns: string listing of all audio driver names, separated by '|'. + **/ +const char* config_get_audio_driver_options(void); + +void find_audio_driver(void); + +void uninit_audio(void); + +void init_audio(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/audio/dsp_filter.c b/audio/audio_dsp_filter.c similarity index 99% rename from audio/dsp_filter.c rename to audio/audio_dsp_filter.c index 946b8260d3..fc74b1ca24 100644 --- a/audio/dsp_filter.c +++ b/audio/audio_dsp_filter.c @@ -16,7 +16,7 @@ #include "../performance.h" -#include "dsp_filter.h" +#include "audio_dsp_filter.h" #include "../dynamic.h" #include #include "audio_filters/dspfilter.h" diff --git a/audio/dsp_filter.h b/audio/audio_dsp_filter.h similarity index 95% rename from audio/dsp_filter.h rename to audio/audio_dsp_filter.h index 4a401d2456..6532328e8e 100644 --- a/audio/dsp_filter.h +++ b/audio/audio_dsp_filter.h @@ -14,8 +14,8 @@ * If not, see . */ -#ifndef RARCH_DSP_FILTER_H__ -#define RARCH_DSP_FILTER_H__ +#ifndef __AUDIO_DSP_FILTER_H__ +#define __AUDIO_DSP_FILTER_H__ #ifdef __cplusplus extern "C" { diff --git a/audio/resamplers/resampler.c b/audio/audio_resampler_driver.c similarity index 79% rename from audio/resamplers/resampler.c rename to audio/audio_resampler_driver.c index a364b6ee71..22ecd00687 100644 --- a/audio/resamplers/resampler.c +++ b/audio/audio_resampler_driver.c @@ -14,12 +14,15 @@ * If not, see . */ -#include "resampler.h" +#include "audio_resampler_driver.h" #ifdef RARCH_INTERNAL -#include "../../performance.h" +#include "../performance.h" #endif #include #include +#ifndef DONT_HAVE_STRING_LIST +#include +#endif static const rarch_resampler_t *resampler_drivers[] = { &sinc_resampler, @@ -56,44 +59,37 @@ static int find_resampler_driver_index(const char *ident) return -1; } -#if !defined(RESAMPLER_TEST) && defined(RARCH_INTERNAL) -#include -#include "../../general.h" - /** - * find_prev_resampler_driver: + * audio_resampler_driver_find_handle: + * @index : index of driver to get handle to. * - * Finds previous driver in resampler driver array. + * Returns: handle to audio resampler driver at index. Can be NULL + * if nothing found. **/ -void find_prev_resampler_driver(void) +const void *audio_resampler_driver_find_handle(int index) { - int i = find_resampler_driver_index(g_settings.audio.resampler); - - if (i > 0) - strlcpy(g_settings.audio.resampler, resampler_drivers[i - 1]->ident, - sizeof(g_settings.audio.resampler)); - else - RARCH_WARN("Couldn't find any previous resampler driver (current one: \"%s\").\n", - driver.resampler->ident); + const void *drv = resampler_drivers[index]; + if (!drv) + return NULL; + return drv; } /** - * find_next_resampler_driver: + * audio_resampler_driver_find_ident: + * @index : index of driver to get handle to. * - * Finds next driver in resampler driver array. + * Returns: Human-readable identifier of audio resampler driver at index. + * Can be NULL if nothing found. **/ -void find_next_resampler_driver(void) +const char *audio_resampler_driver_find_ident(int index) { - int i = find_resampler_driver_index(g_settings.audio.resampler); - - if (i >= 0 && resampler_drivers[i + 1]) - strlcpy(g_settings.audio.resampler, resampler_drivers[i + 1]->ident, - sizeof(g_settings.audio.resampler)); - else - RARCH_WARN("Couldn't find any next resampler driver (current one: \"%s\").\n", - driver.resampler->ident); + const rarch_resampler_t *drv = resampler_drivers[index]; + if (!drv) + return NULL; + return drv->ident; } +#ifndef DONT_HAVE_STRING_LIST /** * config_get_audio_resampler_driver_options: * @@ -104,16 +100,16 @@ void find_next_resampler_driver(void) const char* config_get_audio_resampler_driver_options(void) { union string_list_elem_attr attr; + unsigned i; char *options = NULL; - int option_k = 0; int options_len = 0; struct string_list *options_l = string_list_new(); attr.i = 0; - for (option_k = 0; resampler_drivers[option_k]; option_k++) + for (i = 0; resampler_drivers[i]; i++) { - const char *opt = resampler_drivers[option_k]->ident; + const char *opt = resampler_drivers[i]->ident; options_len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } diff --git a/audio/resamplers/resampler.h b/audio/audio_resampler_driver.h similarity index 85% rename from audio/resamplers/resampler.h rename to audio/audio_resampler_driver.h index cef79242bb..ad88d9a372 100644 --- a/audio/resamplers/resampler.h +++ b/audio/audio_resampler_driver.h @@ -15,8 +15,8 @@ */ -#ifndef __RARCH_RESAMPLER_H -#define __RARCH_RESAMPLER_H +#ifndef __AUDIO_RESAMPLER_DRIVER_H +#define __AUDIO_RESAMPLER_DRIVER_H #ifdef __cplusplus extern "C" { @@ -143,6 +143,35 @@ extern rarch_resampler_t sinc_resampler; extern rarch_resampler_t CC_resampler; extern rarch_resampler_t nearest_resampler; +#ifndef DONT_HAVE_STRING_LIST +/** + * config_get_audio_resampler_driver_options: + * + * Get an enumerated list of all resampler driver names, separated by '|'. + * + * Returns: string listing of all resampler driver names, separated by '|'. + **/ +const char* config_get_audio_resampler_driver_options(void); +#endif + +/** + * audio_resampler_driver_find_handle: + * @index : index of driver to get handle to. + * + * Returns: handle to audio resampler driver at index. Can be NULL + * if nothing found. + **/ +const void *audio_resampler_driver_find_handle(int index); + +/** + * audio_resampler_driver_find_ident: + * @index : index of driver to get handle to. + * + * Returns: Human-readable identifier of audio resampler driver at index. + * Can be NULL if nothing found. + **/ +const char *audio_resampler_driver_find_ident(int index); + /** * rarch_resampler_realloc: * @re : Resampler handle diff --git a/audio/audio_thread_wrapper.c b/audio/audio_thread_wrapper.c index ac5dbde9a0..00927f57fc 100644 --- a/audio/audio_thread_wrapper.c +++ b/audio/audio_thread_wrapper.c @@ -18,7 +18,7 @@ #include #include "../general.h" #include "../performance.h" -#include "../fifo_buffer.h" +#include #include #include diff --git a/audio/utils.c b/audio/audio_utils.c similarity index 99% rename from audio/utils.c rename to audio/audio_utils.c index 916540fd5d..d492f43c1c 100644 --- a/audio/utils.c +++ b/audio/audio_utils.c @@ -15,7 +15,7 @@ */ #include -#include "utils.h" +#include "audio_utils.h" #include "../performance.h" diff --git a/audio/utils.h b/audio/audio_utils.h similarity index 100% rename from audio/utils.h rename to audio/audio_utils.h diff --git a/audio/utils_neon.S b/audio/audio_utils_neon.S similarity index 100% rename from audio/utils_neon.S rename to audio/audio_utils_neon.S diff --git a/audio/alsa.c b/audio/drivers/alsa.c similarity index 99% rename from audio/alsa.c rename to audio/drivers/alsa.c index da60885209..fa98672166 100644 --- a/audio/alsa.c +++ b/audio/drivers/alsa.c @@ -14,10 +14,10 @@ */ -#include "../driver.h" +#include "../../driver.h" #include #include -#include "../general.h" +#include "../../general.h" #define TRY_ALSA(x) if (x < 0) { \ goto error; \ diff --git a/audio/alsa_qsa.c b/audio/drivers/alsa_qsa.c similarity index 99% rename from audio/alsa_qsa.c rename to audio/drivers/alsa_qsa.c index 3d5fe60752..6fb522bbde 100644 --- a/audio/alsa_qsa.c +++ b/audio/drivers/alsa_qsa.c @@ -14,8 +14,8 @@ * If not, see . */ -#include "../general.h" -#include "../driver.h" +#include "../../general.h" +#include "../../driver.h" #define ALSA_PCM_NEW_HW_PARAMS_API #define ALSA_PCM_NEW_SW_PARAMS_API diff --git a/audio/alsathread.c b/audio/drivers/alsathread.c similarity index 98% rename from audio/alsathread.c rename to audio/drivers/alsathread.c index ef7f92ae00..359603a219 100644 --- a/audio/alsathread.c +++ b/audio/drivers/alsathread.c @@ -15,12 +15,12 @@ */ -#include "../driver.h" +#include "../../driver.h" #include #include -#include "../general.h" +#include "../../general.h" #include -#include "../fifo_buffer.h" +#include #define TRY_ALSA(x) if (x < 0) { \ goto error; \ @@ -284,9 +284,9 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size) static bool alsa_thread_alive(void *data) { alsa_thread_t *alsa = (alsa_thread_t*)data; - if (alsa) - return !alsa->is_paused; - return false; + if (!alsa) + return false; + return !alsa->is_paused; } static bool alsa_thread_stop(void *data) diff --git a/audio/coreaudio.c b/audio/drivers/coreaudio.c similarity index 93% rename from audio/coreaudio.c rename to audio/drivers/coreaudio.c index 95208bc66a..84e09ae8db 100644 --- a/audio/coreaudio.c +++ b/audio/drivers/coreaudio.c @@ -14,10 +14,9 @@ * If not, see . */ - -#include "../driver.h" -#include "../general.h" -#include "../fifo_buffer.h" +#include "../../driver.h" +#include "../../general.h" +#include #include #include #include @@ -55,6 +54,7 @@ static bool g_interrupted; static void coreaudio_free(void *data) { coreaudio_t *dev = (coreaudio_t*)data; + if (!dev) return; @@ -82,7 +82,10 @@ static OSStatus audio_write_cb(void *userdata, const AudioTimeStamp *time_stamp, UInt32 bus_number, UInt32 number_frames, AudioBufferList *io_data) { + void *outbuf; + unsigned write_avail; coreaudio_t *dev = (coreaudio_t*)userdata; + (void)time_stamp; (void)bus_number; (void)number_frames; @@ -92,10 +95,11 @@ static OSStatus audio_write_cb(void *userdata, if (io_data->mNumberBuffers != 1) return noErr; - unsigned write_avail = io_data->mBuffers[0].mDataByteSize; - void *outbuf = io_data->mBuffers[0].mData; + write_avail = io_data->mBuffers[0].mDataByteSize; + outbuf = io_data->mBuffers[0].mData; pthread_mutex_lock(&dev->lock); + if (fifo_read_avail(dev->buffer) < write_avail) { *action_flags = kAudioUnitRenderAction_OutputIsSilence; @@ -119,6 +123,8 @@ static OSStatus audio_write_cb(void *userdata, #ifdef OSX static void choose_output_device(coreaudio_t *dev, const char* device) { + unsigned i; + AudioDeviceID *devices; AudioObjectPropertyAddress propaddr = { kAudioHardwarePropertyDevices, @@ -126,14 +132,14 @@ static void choose_output_device(coreaudio_t *dev, const char* device) kAudioObjectPropertyElementMaster }; - UInt32 size = 0; + UInt32 size = 0, deviceCount; if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, 0, &size) != noErr) return; - UInt32 deviceCount = size / sizeof(AudioDeviceID); - AudioDeviceID *devices = malloc(size); + deviceCount = size / sizeof(AudioDeviceID); + devices = (AudioDeviceID*)malloc(size); if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, 0, &size, devices) != noErr) @@ -143,7 +149,7 @@ static void choose_output_device(coreaudio_t *dev, const char* device) propaddr.mSelector = kAudioDevicePropertyDeviceName; size = 1024; - for (unsigned i = 0; i < deviceCount; i ++) + for (i = 0; i < deviceCount; i ++) { char device_name[1024]; device_name[0] = 0; @@ -174,6 +180,10 @@ static void coreaudio_interrupt_listener(void *data, UInt32 interrupt_state) static void *coreaudio_init(const char *device, unsigned rate, unsigned latency) { + static bool session_initialized = false; + UInt32 i_size; + + (void)session_initialized; (void)device; coreaudio_t *dev = (coreaudio_t*)calloc(1, sizeof(*dev)); @@ -184,7 +194,6 @@ static void *coreaudio_init(const char *device, pthread_cond_init(&dev->cond, NULL); #ifdef IOS - static bool session_initialized = false; if (!session_initialized) { session_initialized = true; @@ -249,7 +258,7 @@ static void *coreaudio_init(const char *device, goto error; /* Check returned audio format. */ - UInt32 i_size = sizeof(real_desc);; + i_size = sizeof(real_desc);; if (AudioUnitGetProperty(dev->dev, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &real_desc, &i_size) != noErr) goto error; @@ -333,9 +342,11 @@ static ssize_t coreaudio_write(void *data, const void *buf_, size_t size) while (!g_interrupted && size > 0) { + size_t write_avail; + pthread_mutex_lock(&dev->lock); - size_t write_avail = fifo_write_avail(dev->buffer); + write_avail = fifo_write_avail(dev->buffer); if (write_avail > size) write_avail = size; @@ -374,14 +385,16 @@ static void coreaudio_set_nonblock_state(void *data, bool state) static bool coreaudio_alive(void *data) { coreaudio_t *dev = (coreaudio_t*)data; - if (dev) - return !dev->is_paused; - return false; + if (!dev) + return false; + return !dev->is_paused; } static bool coreaudio_stop(void *data) { coreaudio_t *dev = (coreaudio_t*)data; + if (!dev) + return false; dev->is_paused = (AudioOutputUnitStop(dev->dev) == noErr) ? true : false; return dev->is_paused ? true : false; } @@ -389,6 +402,8 @@ static bool coreaudio_stop(void *data) static bool coreaudio_start(void *data) { coreaudio_t *dev = (coreaudio_t*)data; + if (!dev) + return false; dev->is_paused = (AudioOutputUnitStart(dev->dev) == noErr) ? false : true; return dev->is_paused ? false : true; } @@ -401,10 +416,13 @@ static bool coreaudio_use_float(void *data) static size_t coreaudio_write_avail(void *data) { + size_t avail; coreaudio_t *dev = (coreaudio_t*)data; + pthread_mutex_lock(&dev->lock); - size_t avail = fifo_write_avail(dev->buffer); + avail = fifo_write_avail(dev->buffer); pthread_mutex_unlock(&dev->lock); + return avail; } diff --git a/audio/dsound.c b/audio/drivers/dsound.c similarity index 84% rename from audio/dsound.c rename to audio/drivers/dsound.c index 83d65b97de..f30c0bad7e 100644 --- a/audio/dsound.c +++ b/audio/drivers/dsound.c @@ -39,7 +39,7 @@ static DSMIXBINVOLUMEPAIR dsmbvp[8] = { static DSMIXBINS dsmb; #endif -#include "../driver.h" +#include "../../driver.h" #include #include #include @@ -52,8 +52,8 @@ static DSMIXBINS dsmb; #include #endif #include -#include "../fifo_buffer.h" -#include "../general.h" +#include +#include "../../general.h" typedef struct dsound { @@ -93,21 +93,25 @@ struct audio_lock DWORD size2; }; -static inline bool grab_region(dsound_t *ds, DWORD write_ptr, struct audio_lock *region) +static inline bool grab_region(dsound_t *ds, DWORD write_ptr, + struct audio_lock *region) { - HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0); + const char *err; + HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, + ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0); + if (res == DSERR_BUFFERLOST) { res = IDirectSoundBuffer_Restore(ds->dsb); if (res != DS_OK) return false; - res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0); + res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, + ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0); if (res != DS_OK) return false; } - const char *err; switch (res) { case DSERR_BUFFERLOST: @@ -143,34 +147,43 @@ static inline void release_region(dsound_t *ds, const struct audio_lock *region) static DWORD CALLBACK dsound_thread(PVOID data) { + DWORD write_ptr; dsound_t *ds = (dsound_t*)data; + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - DWORD write_ptr; get_positions(ds, NULL, &write_ptr); write_ptr = (write_ptr + ds->buffer_size / 2) % ds->buffer_size; while (ds->thread_alive) { - DWORD read_ptr; + struct audio_lock region; + DWORD read_ptr, avail, fifo_avail; get_positions(ds, &read_ptr, NULL); - DWORD avail = write_avail(read_ptr, write_ptr, ds->buffer_size); + avail = write_avail(read_ptr, write_ptr, ds->buffer_size); EnterCriticalSection(&ds->crit); - DWORD fifo_avail = fifo_read_avail(ds->buffer); + fifo_avail = fifo_read_avail(ds->buffer); LeaveCriticalSection(&ds->crit); - // No space to write, or we don't have data in our fifo, but we can wait some time before it underruns ... if (avail < CHUNK_SIZE || ((fifo_avail < CHUNK_SIZE) && (avail < ds->buffer_size / 2))) { + /* No space to write, or we don't have data in our fifo, + * but we can wait some time before it underruns ... */ + Sleep(1); - // We could opt for using the notification interface, - // but it is not guaranteed to work, so use high priority sleeping patterns. :( + + /* We could opt for using the notification interface, + * but it is not guaranteed to work, so use high + * priority sleeping patterns. + */ } - else if (fifo_avail < CHUNK_SIZE) // Got space to write, but nothing in FIFO (underrun), fill block with silence. + else if (fifo_avail < CHUNK_SIZE) { - struct audio_lock region; + /* Got space to write, but nothing in FIFO (underrun), + * fill block with silence. */ + if (!grab_region(ds, write_ptr, ®ion)) { ds->thread_alive = false; @@ -184,9 +197,10 @@ static DWORD CALLBACK dsound_thread(PVOID data) release_region(ds, ®ion); write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size; } - else // All is good. Pull from it and notify FIFO :D + else { - struct audio_lock region; + /* All is good. Pull from it and notify FIFO. */ + if (!grab_region(ds, write_ptr, ®ion)) { ds->thread_alive = false; @@ -213,13 +227,13 @@ static DWORD CALLBACK dsound_thread(PVOID data) static void dsound_stop_thread(dsound_t *ds) { - if (ds->thread) - { - ds->thread_alive = false; - WaitForSingleObject(ds->thread, INFINITE); - CloseHandle(ds->thread); - ds->thread = NULL; - } + if (!ds->thread) + return; + + ds->thread_alive = false; + WaitForSingleObject(ds->thread, INFINITE); + CloseHandle(ds->thread); + ds->thread = NULL; } static bool dsound_start_thread(dsound_t *ds) @@ -237,11 +251,12 @@ static bool dsound_start_thread(dsound_t *ds) static void dsound_clear_buffer(dsound_t *ds) { - IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); void *ptr; DWORD size; + IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); - if (IDirectSoundBuffer_Lock(ds->dsb, 0, 0, &ptr, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER) == DS_OK) + if (IDirectSoundBuffer_Lock(ds->dsb, 0, 0, &ptr, &size, + NULL, NULL, DSBLOCK_ENTIREBUFFER) == DS_OK) { memset(ptr, 0, size); IDirectSoundBuffer_Unlock(ds->dsb, ptr, size, NULL, 0); @@ -251,34 +266,35 @@ static void dsound_clear_buffer(dsound_t *ds) static void dsound_free(void *data) { dsound_t *ds = (dsound_t*)data; - if (ds) + + if (!ds) + return; + + if (ds->thread) { - if (ds->thread) - { - ds->thread_alive = false; - WaitForSingleObject(ds->thread, INFINITE); - CloseHandle(ds->thread); - } - - DeleteCriticalSection(&ds->crit); - - if (ds->dsb) - { - IDirectSoundBuffer_Stop(ds->dsb); - IDirectSoundBuffer_Release(ds->dsb); - } - - if (ds->ds) - IDirectSound_Release(ds->ds); - - if (ds->event) - CloseHandle(ds->event); - - if (ds->buffer) - fifo_free(ds->buffer); - - free(ds); + ds->thread_alive = false; + WaitForSingleObject(ds->thread, INFINITE); + CloseHandle(ds->thread); } + + DeleteCriticalSection(&ds->crit); + + if (ds->dsb) + { + IDirectSoundBuffer_Stop(ds->dsb); + IDirectSoundBuffer_Release(ds->dsb); + } + + if (ds->ds) + IDirectSound_Release(ds->ds); + + if (ds->event) + CloseHandle(ds->event); + + if (ds->buffer) + fifo_free(ds->buffer); + + free(ds); } struct dsound_dev @@ -291,7 +307,9 @@ struct dsound_dev static BOOL CALLBACK enumerate_cb(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOID context) { struct dsound_dev *dev = (struct dsound_dev*)context; + RARCH_LOG("\t%u: %s\n", dev->total_count, desc); + if (dev->device == dev->total_count) dev->guid = guid; dev->total_count++; @@ -303,8 +321,8 @@ static void *dsound_init(const char *device, unsigned rate, unsigned latency) WAVEFORMATEX wfx = {0}; DSBUFFERDESC bufdesc = {0}; struct dsound_dev dev = {0}; - dsound_t *ds = (dsound_t*)calloc(1, sizeof(*ds)); + if (!ds) goto error; @@ -384,14 +402,17 @@ error: static bool dsound_stop(void *data) { dsound_t *ds = (dsound_t*)data; + dsound_stop_thread(ds); ds->is_paused = (IDirectSoundBuffer_Stop(ds->dsb) == DS_OK) ? true : false; + return (ds->is_paused) ? true : false; } static bool dsound_start(void *data) { dsound_t *ds = (dsound_t*)data; + dsound_clear_buffer(ds); if (!dsound_start_thread(ds)) @@ -404,30 +425,34 @@ static bool dsound_start(void *data) static bool dsound_alive(void *data) { dsound_t *ds = (dsound_t*)data; - if (ds) - return !ds->is_paused; - return false; + + if (!ds) + return false; + return !ds->is_paused; } static void dsound_set_nonblock_state(void *data, bool state) { dsound_t *ds = (dsound_t*)data; - ds->nonblock = state; + if (ds) + ds->nonblock = state; } static ssize_t dsound_write(void *data, const void *buf_, size_t size) { + size_t written = 0; dsound_t *ds = (dsound_t*)data; const uint8_t *buf = (const uint8_t*)buf_; if (!ds->thread_alive) return -1; - size_t written = 0; while (size > 0) { + size_t avail; + EnterCriticalSection(&ds->crit); - size_t avail = fifo_write_avail(ds->buffer); + avail = fifo_write_avail(ds->buffer); if (avail > size) avail = size; @@ -450,9 +475,11 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size) static size_t dsound_write_avail(void *data) { + size_t avail; dsound_t *ds = (dsound_t*)data; + EnterCriticalSection(&ds->crit); - size_t avail = fifo_write_avail(ds->buffer); + avail = fifo_write_avail(ds->buffer); LeaveCriticalSection(&ds->crit); return avail; } diff --git a/audio/gx_audio.c b/audio/drivers/gx_audio.c similarity index 90% rename from audio/gx_audio.c rename to audio/drivers/gx_audio.c index 7f99831da9..439ea8d0eb 100644 --- a/audio/gx_audio.c +++ b/audio/drivers/gx_audio.c @@ -14,10 +14,10 @@ * If not, see . */ -#include "../driver.h" +#include "../../driver.h" #include #include -#include "../general.h" +#include "../../general.h" #include #ifdef GEKKO @@ -27,7 +27,7 @@ #include #endif -#include "../gfx/gx/sdk_defines.h" +#include "../../gfx/drivers/gx_sdk_defines.h" #define CHUNK_FRAMES 64 #define CHUNK_SIZE (CHUNK_FRAMES * sizeof(uint32_t)) @@ -63,20 +63,20 @@ static void dma_callback(void) { gx_audio_t *wa = (gx_audio_t*)gx_audio_data; - if (!stop_audio) - { - /* Erase last chunk to avoid repeating audio. */ - memset(wa->data[wa->dma_busy], 0, CHUNK_SIZE); + if (stop_audio) + return; - wa->dma_busy = wa->dma_next; - wa->dma_next = (wa->dma_next + 1) & (BLOCKS - 1); + /* Erase last chunk to avoid repeating audio. */ + memset(wa->data[wa->dma_busy], 0, CHUNK_SIZE); - DCFlushRange(wa->data[wa->dma_next], CHUNK_SIZE); + wa->dma_busy = wa->dma_next; + wa->dma_next = (wa->dma_next + 1) & (BLOCKS - 1); - AIInitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE); + DCFlushRange(wa->data[wa->dma_next], CHUNK_SIZE); - OSSignalCond(wa->cond); - } + AIInitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE); + + OSSignalCond(wa->cond); } static void *gx_audio_init(const char *device, @@ -135,6 +135,7 @@ static ssize_t gx_audio_write(void *data, const void *buf_, size_t size) while (frames) { size_t to_write = CHUNK_FRAMES - wa->write_ptr; + if (frames < to_write) to_write = frames; @@ -178,15 +179,17 @@ static void gx_audio_set_nonblock_state(void *data, bool state) { gx_audio_t *wa = (gx_audio_t*)data; - if (!wa) - return; - - wa->nonblock = state; + if (wa) + wa->nonblock = state; } static bool gx_audio_start(void *data) { gx_audio_t *wa = (gx_audio_t*)data; + + if (!wa) + return false; + AIStartDMA(); wa->is_paused = false; return true; @@ -195,9 +198,9 @@ static bool gx_audio_start(void *data) static bool gx_audio_alive(void *data) { gx_audio_t *wa = (gx_audio_t*)data; - if (wa) - return !wa->is_paused; - return false; + if (!wa) + return false; + return !wa->is_paused; } static void gx_audio_free(void *data) diff --git a/audio/jack.c b/audio/drivers/jack.c similarity index 89% rename from audio/jack.c rename to audio/drivers/jack.c index 4f63f40c0c..63228b1cd2 100644 --- a/audio/jack.c +++ b/audio/drivers/jack.c @@ -14,9 +14,9 @@ */ -#include "../driver.h" +#include "../../driver.h" #include -#include "../general.h" +#include "../../general.h" #include #include @@ -46,18 +46,18 @@ typedef struct jack static int process_cb(jack_nframes_t nframes, void *data) { int i; - jack_nframes_t f; + jack_nframes_t f, avail[2], min_avail; jack_t *jd = (jack_t*)data; + if (nframes <= 0) { pthread_cond_signal(&jd->cond); return 0; } - jack_nframes_t avail[2]; avail[0] = jack_ringbuffer_read_space(jd->buffer[0]); avail[1] = jack_ringbuffer_read_space(jd->buffer[1]); - jack_nframes_t min_avail = ((avail[0] < avail[1]) ? avail[0] : avail[1]) / sizeof(jack_default_audio_sample_t); + min_avail = ((avail[0] < avail[1]) ? avail[0] : avail[1]) / sizeof(jack_default_audio_sample_t); if (min_avail > nframes) min_avail = nframes; @@ -69,9 +69,7 @@ static int process_cb(jack_nframes_t nframes, void *data) jack_ringbuffer_read(jd->buffer[i], (char*)out, min_avail * sizeof(jack_default_audio_sample_t)); for (f = min_avail; f < nframes; f++) - { out[f] = 0.0f; - } } pthread_cond_signal(&jd->cond); return 0; @@ -80,6 +78,10 @@ static int process_cb(jack_nframes_t nframes, void *data) static void shutdown_cb(void *data) { jack_t *jd = (jack_t*)data; + + if (!jd) + return; + jd->shutdown = true; pthread_cond_signal(&jd->cond); } @@ -88,8 +90,8 @@ static int parse_ports(char **dest_ports, const char **jports) { int i; char *save; - const char *con = strtok_r(g_settings.audio.device, ",", &save); int parsed = 0; + const char *con = strtok_r(g_settings.audio.device, ",", &save); if (con) dest_ports[parsed++] = strdup(con); @@ -105,11 +107,10 @@ static int parse_ports(char **dest_ports, const char **jports) static size_t find_buffersize(jack_t *jd, int latency) { - int i; + int i, buffer_frames, min_buffer_frames, jack_latency = 0; + jack_latency_range_t range; int frames = latency * g_settings.audio.out_rate / 1000; - jack_latency_range_t range; - int jack_latency = 0; for (i = 0; i < 2; i++) { jack_port_get_latency_range(jd->ports[i], JackPlaybackLatency, &range); @@ -119,8 +120,9 @@ static size_t find_buffersize(jack_t *jd, int latency) RARCH_LOG("JACK: Jack latency is %d frames.\n", jack_latency); - int buffer_frames = frames - jack_latency; - int min_buffer_frames = jack_get_buffer_size(jd->client) * 2; + buffer_frames = frames - jack_latency; + min_buffer_frames = jack_get_buffer_size(jd->client) * 2; + RARCH_LOG("JACK: Minimum buffer size is %d frames.\n", min_buffer_frames); if (buffer_frames < min_buffer_frames) @@ -132,17 +134,17 @@ static size_t find_buffersize(jack_t *jd, int latency) static void *ja_init(const char *device, unsigned rate, unsigned latency) { int i; + const char **jports = NULL; + char *dest_ports[2]; + size_t bufsize = 0; + int parsed = 0; jack_t *jd = (jack_t*)calloc(1, sizeof(jack_t)); + if (!jd) return NULL; pthread_cond_init(&jd->cond, NULL); pthread_mutex_init(&jd->cond_lock, NULL); - - const char **jports = NULL; - char *dest_ports[2]; - size_t bufsize = 0; - int parsed = 0; jd->client = jack_client_open("RetroArch", JackNullOption, NULL); if (jd->client == NULL) @@ -214,12 +216,12 @@ error: static size_t write_buffer(jack_t *jd, const float *buf, size_t size) { int i; - size_t j; + size_t j, frames, written = 0; jack_default_audio_sample_t out_deinterleaved_buffer[2][AUDIO_CHUNK_SIZE_NONBLOCKING * AUDIO_MAX_RATIO]; - size_t frames = FRAMES(size); + frames = FRAMES(size); - // Avoid buffer overflow if a DSP plugin generated a huge number of frames + /* Avoid buffer overflow if a DSP plugin generated a huge number of frames. */ if (frames > AUDIO_CHUNK_SIZE_NONBLOCKING * AUDIO_MAX_RATIO) frames = AUDIO_CHUNK_SIZE_NONBLOCKING * AUDIO_MAX_RATIO; @@ -227,21 +229,19 @@ static size_t write_buffer(jack_t *jd, const float *buf, size_t size) for (j = 0; j < frames; j++) out_deinterleaved_buffer[i][j] = buf[j * 2 + i]; - size_t written = 0; while (written < frames) { + size_t avail[2], min_avail, write_frames; if (jd->shutdown) return 0; - size_t avail[2] = { - jack_ringbuffer_write_space(jd->buffer[0]), - jack_ringbuffer_write_space(jd->buffer[1]), - }; + avail[0] = jack_ringbuffer_write_space(jd->buffer[0]); + avail[1] = jack_ringbuffer_write_space(jd->buffer[1]); - size_t min_avail = avail[0] < avail[1] ? avail[0] : avail[1]; + min_avail = avail[0] < avail[1] ? avail[0] : avail[1]; min_avail /= sizeof(float); - size_t write_frames = frames - written > min_avail ? min_avail : frames - written; + write_frames = frames - written > min_avail ? min_avail : frames - written; if (write_frames > 0) { @@ -284,15 +284,16 @@ static bool ja_stop(void *data) static bool ja_alive(void *data) { jack_t *jd = (jack_t*)data; - if (jd) - return !jd->is_paused; - return false; + if (!jd) + return false; + return !jd->is_paused; } static void ja_set_nonblock_state(void *data, bool state) { jack_t *jd = (jack_t*)data; - jd->nonblock = state; + if (jd) + jd->nonblock = state; } static bool ja_start(void *data) diff --git a/audio/nullaudio.c b/audio/drivers/nullaudio.c similarity index 97% rename from audio/nullaudio.c rename to audio/drivers/nullaudio.c index 5ead09c472..84a87f4f81 100644 --- a/audio/nullaudio.c +++ b/audio/drivers/nullaudio.c @@ -13,8 +13,8 @@ * If not, see . */ -#include "../general.h" -#include "../driver.h" +#include "../../general.h" +#include "../../driver.h" static void *null_audio_init(const char *device, unsigned rate, unsigned latency) { diff --git a/audio/openal.c b/audio/drivers/openal.c similarity index 91% rename from audio/openal.c rename to audio/drivers/openal.c index dd1ab31837..49bc5399fa 100644 --- a/audio/openal.c +++ b/audio/drivers/openal.c @@ -13,8 +13,8 @@ * If not, see . */ -#include "../driver.h" -#include "../general.h" +#include "../../driver.h" +#include "../../general.h" #ifdef __APPLE__ #include @@ -56,6 +56,7 @@ typedef struct al static void al_free(void *data) { al_t *al = (al_t*)data; + if (!al) return; @@ -78,24 +79,27 @@ static void al_free(void *data) static void *al_init(const char *device, unsigned rate, unsigned latency) { + al_t *al; + (void)device; - al_t *al = (al_t*)calloc(1, sizeof(al_t)); + + al = (al_t*)calloc(1, sizeof(al_t)); if (!al) return NULL; al->handle = alcOpenDevice(NULL); - if (al->handle == NULL) + if (!al->handle) goto error; al->ctx = alcCreateContext(al->handle, NULL); - if (al->ctx == NULL) + if (!al->ctx) goto error; alcMakeContextCurrent(al->ctx); al->rate = rate; - // We already use one buffer for tmpbuf. + /* We already use one buffer for tmpbuf. */ al->num_buffers = (latency * rate * 2 * sizeof(int16_t)) / (1000 * BUFSIZE) - 1; if (al->num_buffers < 2) al->num_buffers = 2; @@ -126,14 +130,12 @@ static bool al_unqueue_buffers(al_t *al) alGetSourcei(al->source, AL_BUFFERS_PROCESSED, &val); - if (val > 0) - { - alSourceUnqueueBuffers(al->source, val, &al->res_buf[al->res_ptr]); - al->res_ptr += val; - return true; - } + if (val <= 0) + return false; - return false; + alSourceUnqueueBuffers(al->source, val, &al->res_buf[al->res_ptr]); + al->res_ptr += val; + return true; } static bool al_get_buffer(al_t *al, ALuint *buffer) @@ -169,11 +171,14 @@ static ssize_t al_write(void *data, const void *buf_, size_t size) { al_t *al = (al_t*)data; const uint8_t *buf = (const uint8_t*)buf_; - size_t written = 0; + while (size) { + ALint val; + ALuint buffer; size_t rc = al_fill_internal_buf(al, buf, size); + written += rc; buf += rc; size -= rc; @@ -181,7 +186,6 @@ static ssize_t al_write(void *data, const void *buf_, size_t size) if (al->tmpbuf_ptr != BUFSIZE) break; - ALuint buffer; if (!al_get_buffer(al, &buffer)) break; @@ -191,7 +195,6 @@ static ssize_t al_write(void *data, const void *buf_, size_t size) if (alGetError() != AL_NO_ERROR) return -1; - ALint val; alGetSourcei(al->source, AL_SOURCE_STATE, &val); if (val != AL_PLAYING) alSourcePlay(al->source); @@ -214,15 +217,16 @@ static bool al_stop(void *data) static bool al_alive(void *data) { al_t *al = (al_t*)data; - if (al) - return !al->is_paused; - return false; + if (!al) + return false; + return !al->is_paused; } static void al_set_nonblock_state(void *data, bool state) { al_t *al = (al_t*)data; - al->nonblock = state; + if (al) + al->nonblock = state; } static bool al_start(void *data) @@ -243,7 +247,7 @@ static size_t al_write_avail(void *data) static size_t al_buffer_size(void *data) { al_t *al = (al_t*)data; - return (al->num_buffers + 1) * BUFSIZE; // Also got tmpbuf. + return (al->num_buffers + 1) * BUFSIZE; /* Also got tmpbuf. */ } static bool al_use_float(void *data) diff --git a/audio/opensl.c b/audio/drivers/opensl.c similarity index 93% rename from audio/opensl.c rename to audio/drivers/opensl.c index b14d2eabf8..76292016f3 100644 --- a/audio/opensl.c +++ b/audio/drivers/opensl.c @@ -14,8 +14,8 @@ * If not, see . */ -#include "../driver.h" -#include "../general.h" +#include "../../driver.h" +#include "../../general.h" #include #include @@ -23,7 +23,7 @@ #include #endif -// Helper macros, COM-style! +/* Helper macros, COM-style. */ #define SLObjectItf_Realize(a, ...) ((*(a))->Realize(a, __VA_ARGS__)) #define SLObjectItf_GetInterface(a, ...) ((*(a))->GetInterface(a, __VA_ARGS__)) #define SLObjectItf_Destroy(a) ((*(a))->Destroy((a))) @@ -100,20 +100,23 @@ static void sl_free(void *data) static void *sl_init(const char *device, unsigned rate, unsigned latency) { unsigned i; - (void)device; - + SLInterfaceID id; + SLboolean req; + SLresult res; + sl_t *sl; SLDataFormat_PCM fmt_pcm = {0}; SLDataSource audio_src = {0}; SLDataSink audio_sink = {0}; - SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {0}; SLDataLocator_OutputMix loc_outmix = {0}; - SLInterfaceID id = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - SLboolean req = SL_BOOLEAN_TRUE; + (void)device; - SLresult res = 0; - sl_t *sl = (sl_t*)calloc(1, sizeof(sl_t)); + id = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; + req = SL_BOOLEAN_TRUE; + + res = 0; + sl = (sl_t*)calloc(1, sizeof(sl_t)); if (!sl) goto error; @@ -154,7 +157,7 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency) fmt_pcm.bitsPerSample = 16; fmt_pcm.containerSize = 16; fmt_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - fmt_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; // Android only. + fmt_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; /* Android only. */ audio_src.pLocator = &loc_bufq; audio_src.pFormat = &fmt_pcm; @@ -180,7 +183,7 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency) (*sl->buffer_queue)->RegisterCallback(sl->buffer_queue, opensl_callback, sl); - // Enqueue a bit to get stuff rolling. + /* Enqueue a bit to get stuff rolling. */ sl->buffered_blocks = sl->buf_count; sl->buffer_index = 0; for (i = 0; i < sl->buf_count; i++) @@ -207,15 +210,16 @@ static bool sl_stop(void *data) static bool sl_alive(void *data) { sl_t *sl = (sl_t*)data; - if (sl) - return !sl->is_paused; - return false; + if (!sl) + return false; + return !sl->is_paused; } static void sl_set_nonblock_state(void *data, bool state) { sl_t *sl = (sl_t*)data; - sl->nonblock = state; + if (sl) + sl->nonblock = state; } static bool sl_start(void *data) @@ -229,12 +233,13 @@ static bool sl_start(void *data) static ssize_t sl_write(void *data, const void *buf_, size_t size) { sl_t *sl = (sl_t*)data; - size_t written = 0; const uint8_t *buf = (const uint8_t*)buf_; while (size) { + size_t avail_write; + if (sl->nonblock) { if (sl->buffered_blocks == sl->buf_count) @@ -248,7 +253,8 @@ static ssize_t sl_write(void *data, const void *buf_, size_t size) slock_unlock(sl->lock); } - size_t avail_write = min(sl->buf_size - sl->buffer_ptr, size); + avail_write = min(sl->buf_size - sl->buffer_ptr, size); + if (avail_write) { memcpy(sl->buffer[sl->buffer_index] + sl->buffer_ptr, buf, avail_write); diff --git a/audio/oss.c b/audio/drivers/oss.c similarity index 93% rename from audio/oss.c rename to audio/drivers/oss.c index 00c5e9e09d..7ba2baaf65 100644 --- a/audio/oss.c +++ b/audio/drivers/oss.c @@ -17,8 +17,8 @@ #include "config.h" #endif -#include "driver.h" -#include "general.h" +#include "../../driver.h" +#include "../../general.h" #include #ifdef HAVE_OSS_BSD @@ -43,7 +43,9 @@ static bool oss_is_paused; static void *oss_init(const char *device, unsigned rate, unsigned latency) { + int frags, frag, channels, format, new_rate; int *fd = (int*)calloc(1, sizeof(int)); + if (fd == NULL) return NULL; @@ -59,15 +61,14 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency) return NULL; } - int frags = (latency * rate * 4) / (1000 * (1 << 10)); - int frag = (frags << 16) | 10; + frags = (latency * rate * 4) / (1000 * (1 << 10)); + frag = (frags << 16) | 10; if (ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0) RARCH_WARN("Cannot set fragment sizes. Latency might not be as expected ...\n"); - int channels = 2; - int format = is_little_endian() ? - AFMT_S16_LE : AFMT_S16_BE; + channels = 2; + format = is_little_endian() ? AFMT_S16_LE : AFMT_S16_BE; if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0) { @@ -85,7 +86,8 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency) return NULL; } - int new_rate = rate; + new_rate = rate; + if (ioctl(*fd, SNDCTL_DSP_SPEED, &new_rate) < 0) { close(*fd); @@ -105,12 +107,12 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency) static ssize_t oss_write(void *data, const void *buf, size_t size) { + ssize_t ret; int *fd = (int*)data; if (size == 0) return 0; - ssize_t ret; if ((ret = write(*fd, buf, size)) < 0) { if (errno == EAGAIN && (fcntl(*fd, F_GETFL) & O_NONBLOCK)) @@ -125,6 +127,7 @@ static ssize_t oss_write(void *data, const void *buf, size_t size) static bool oss_stop(void *data) { int *fd = (int*)data; + ioctl(*fd, SNDCTL_DSP_RESET, 0); oss_is_paused = true; return true; @@ -145,8 +148,9 @@ static bool oss_alive(void *data) static void oss_set_nonblock_state(void *data, bool state) { - int *fd = (int*)data; int rc; + int *fd = (int*)data; + if (state) rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK); else diff --git a/audio/ps3_audio.c b/audio/drivers/ps3_audio.c similarity index 95% rename from audio/ps3_audio.c rename to audio/drivers/ps3_audio.c index 3d12e5be4d..60fe4a1da1 100644 --- a/audio/ps3_audio.c +++ b/audio/drivers/ps3_audio.c @@ -19,7 +19,7 @@ #include #include -#include "../fifo_buffer.h" +#include #include "../ps3/sdk_defines.h" @@ -46,17 +46,16 @@ static void event_loop(void *data) static void event_loop(uint64_t data) #endif { - ps3_audio_t *aud = data; + float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS] + __attribute__((aligned(16))); sys_event_queue_t id; sys_ipc_key_t key; sys_event_t event; + ps3_audio_t *aud = data; cellAudioCreateNotifyEventQueue(&id, &key); cellAudioSetNotifyEventQueue(key); - float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS] - __attribute__((aligned(16))); - while (!aud->quit_thread) { sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); @@ -80,16 +79,19 @@ static void event_loop(uint64_t data) static void *ps3_audio_init(const char *device, unsigned rate, unsigned latency) { + CellAudioPortParam params; + ps3_audio_t *data; + (void)latency; (void)device; (void)rate; - ps3_audio_t *data = calloc(1, sizeof(*data)); + data = calloc(1, sizeof(*data)); if (!data) return NULL; - CellAudioPortParam params; cellAudioInit(); + params.numChannels = AUDIO_CHANNELS; params.numBlocks = AUDIO_BLOCKS; #ifdef HAVE_HEADSET @@ -151,15 +153,14 @@ static ssize_t ps3_audio_write(void *data, const void *buf, size_t size) if (fifo_write_avail(aud->buffer) < size) return 0; } - else - { - while (fifo_write_avail(aud->buffer) < size) - sys_lwcond_wait(&aud->cond, 0); - } + + while (fifo_write_avail(aud->buffer) < size) + sys_lwcond_wait(&aud->cond, 0); sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT); fifo_write(aud->buffer, buf, size); sys_lwmutex_unlock(&aud->lock); + return size; } @@ -188,13 +189,16 @@ static bool ps3_audio_start(void *data) static bool ps3_audio_alive(void *data) { ps3_audio_t *aud = data; + if (!aud) + return false; return aud->started; } static void ps3_audio_set_nonblock_state(void *data, bool toggle) { ps3_audio_t *aud = data; - aud->nonblocking = toggle; + if (aud) + aud->nonblocking = toggle; } static void ps3_audio_free(void *data) diff --git a/audio/psp1_audio.c b/audio/drivers/psp1_audio.c similarity index 95% rename from audio/psp1_audio.c rename to audio/drivers/psp1_audio.c index b009e2a2c2..1edd85bb9f 100644 --- a/audio/psp1_audio.c +++ b/audio/drivers/psp1_audio.c @@ -15,8 +15,8 @@ * If not, see . */ -#include "../general.h" -#include "../driver.h" +#include "../../general.h" +#include "../../driver.h" #include #include @@ -71,10 +71,12 @@ static int audioMainLoop(SceSize args, void* argp) static void *psp_audio_init(const char *device, unsigned rate, unsigned latency) { + psp1_audio_t* psp; + (void)device; (void)latency; - psp1_audio_t* psp = (psp1_audio_t*)calloc(1, sizeof(psp1_audio_t)); + psp = (psp1_audio_t*)calloc(1, sizeof(psp1_audio_t)); if (!psp) return NULL; @@ -103,12 +105,13 @@ static void *psp_audio_init(const char *device, static void psp_audio_free(void *data) { + SceUInt timeout = 100000; psp1_audio_t* psp = (psp1_audio_t*)data; if(!psp) return; - psp->running = false; - SceUInt timeout = 100000; + psp->running = false; + sceKernelWaitThreadEnd(psp->thread, &timeout); sceKernelDeleteThread(psp->thread); @@ -153,14 +156,15 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size) static bool psp_audio_alive(void *data) { psp1_audio_t* psp = (psp1_audio_t*)data; - if (psp) - return psp->running; - return false; + if (!psp) + return false; + return psp->running; } static bool psp_audio_stop(void *data) { SceKernelThreadRunStatus runStatus; + SceUInt timeout = 100000; psp1_audio_t* psp = (psp1_audio_t*)data; runStatus.size = sizeof(SceKernelThreadRunStatus); @@ -172,7 +176,6 @@ static bool psp_audio_stop(void *data) return false; psp->running = false; - SceUInt timeout = 100000; sceKernelWaitThreadEnd(psp->thread, &timeout); return true; @@ -201,7 +204,8 @@ static bool psp_audio_start(void *data) static void psp_audio_set_nonblock_state(void *data, bool toggle) { psp1_audio_t* psp = (psp1_audio_t*)data; - psp->nonblocking = toggle; + if (psp) + psp->nonblocking = toggle; } static bool psp_audio_use_float(void *data) diff --git a/audio/pulse.c b/audio/drivers/pulse.c similarity index 88% rename from audio/pulse.c rename to audio/drivers/pulse.c index 102a298e48..dd7e1e9289 100644 --- a/audio/pulse.c +++ b/audio/drivers/pulse.c @@ -14,8 +14,8 @@ */ -#include "driver.h" -#include "general.h" +#include "../../driver.h" +#include "../../general.h" #include #include #include @@ -35,28 +35,29 @@ typedef struct static void pulse_free(void *data) { pa_t *pa = (pa_t*)data; - if (pa) + + if (!pa) + return; + + if (pa->mainloop) + pa_threaded_mainloop_stop(pa->mainloop); + + if (pa->stream) { - if (pa->mainloop) - pa_threaded_mainloop_stop(pa->mainloop); - - if (pa->stream) - { - pa_stream_disconnect(pa->stream); - pa_stream_unref(pa->stream); - } - - if (pa->context) - { - pa_context_disconnect(pa->context); - pa_context_unref(pa->context); - } - - if (pa->mainloop) - pa_threaded_mainloop_free(pa->mainloop); - - free(pa); + pa_stream_disconnect(pa->stream); + pa_stream_unref(pa->stream); } + + if (pa->context) + { + pa_context_disconnect(pa->context); + pa_context_unref(pa->context); + } + + if (pa->mainloop) + pa_threaded_mainloop_free(pa->mainloop); + + free(pa); } static void stream_success_cb(pa_stream *s, int success, void *data) @@ -70,6 +71,7 @@ static void stream_success_cb(pa_stream *s, int success, void *data) static void context_state_cb(pa_context *c, void *data) { pa_t *pa = (pa_t*)data; + switch (pa_context_get_state(c)) { case PA_CONTEXT_READY: @@ -85,6 +87,7 @@ static void context_state_cb(pa_context *c, void *data) static void stream_state_cb(pa_stream *s, void *data) { pa_t *pa = (pa_t*)data; + switch (pa_stream_get_state(s)) { case PA_STREAM_READY: @@ -99,23 +102,29 @@ static void stream_state_cb(pa_stream *s, void *data) static void stream_request_cb(pa_stream *s, size_t length, void *data) { + pa_t *pa = (pa_t*)data; + (void)length; (void)s; - pa_t *pa = (pa_t*)data; + pa_threaded_mainloop_signal(pa->mainloop, 0); } static void stream_latency_update_cb(pa_stream *s, void *data) { - (void)s; pa_t *pa = (pa_t*)data; + + (void)s; + pa_threaded_mainloop_signal(pa->mainloop, 0); } static void underrun_update_cb(pa_stream *s, void *data) { - (void)s; pa_t *pa = (pa_t*)data; + + (void)s; + RARCH_LOG("[PulseAudio]: Underrun (Buffer: %u, Writable size: %u).\n", (unsigned)pa->buffer_size, (unsigned)pa_stream_writable_size(pa->stream)); @@ -133,11 +142,14 @@ static void buffer_attr_cb(pa_stream *s, void *data) static void *pulse_init(const char *device, unsigned rate, unsigned latency) { - const pa_buffer_attr *server_attr = NULL; pa_sample_spec spec; - memset(&spec, 0, sizeof(spec)); + pa_t *pa; pa_buffer_attr buffer_attr = {0}; - pa_t *pa = (pa_t*)calloc(1, sizeof(*pa)); + const pa_buffer_attr *server_attr = NULL; + + memset(&spec, 0, sizeof(spec)); + + pa = (pa_t*)calloc(1, sizeof(*pa)); if (!pa) goto error; @@ -217,13 +229,13 @@ static ssize_t pulse_write(void *data, const void *buf_, size_t size) { pa_t *pa = (pa_t*)data; const uint8_t *buf = (const uint8_t*)buf_; - size_t written = 0; pa_threaded_mainloop_lock(pa->mainloop); while (size) { size_t writable = pa_stream_writable_size(pa->stream); + writable = min(size, writable); if (writable) @@ -246,13 +258,16 @@ static ssize_t pulse_write(void *data, const void *buf_, size_t size) static bool pulse_stop(void *data) { - RARCH_LOG("[PulseAudio]: Pausing.\n"); + bool ret; pa_t *pa = (pa_t*)data; - pa->success = true; // In case of spurious wakeup. Not critical. + + RARCH_LOG("[PulseAudio]: Pausing.\n"); + + pa->success = true; /* In case of spurious wakeup. Not critical. */ pa_threaded_mainloop_lock(pa->mainloop); pa_stream_cork(pa->stream, true, stream_success_cb, pa); pa_threaded_mainloop_wait(pa->mainloop); - bool ret = pa->success; + ret = pa->success; pa_threaded_mainloop_unlock(pa->mainloop); pa->is_paused = true; return ret; @@ -261,20 +276,24 @@ static bool pulse_stop(void *data) static bool pulse_alive(void *data) { pa_t *pa = (pa_t*)data; - if (pa) - return !pa->is_paused; - return false; + + if (!pa) + return false; + return !pa->is_paused; } static bool pulse_start(void *data) { - RARCH_LOG("[PulseAudio]: Unpausing.\n"); + bool ret; pa_t *pa = (pa_t*)data; - pa->success = true; // In case of spurious wakeup. Not critical. + + RARCH_LOG("[PulseAudio]: Unpausing.\n"); + + pa->success = true; /* In case of spurious wakeup. Not critical. */ pa_threaded_mainloop_lock(pa->mainloop); pa_stream_cork(pa->stream, false, stream_success_cb, pa); pa_threaded_mainloop_wait(pa->mainloop); - bool ret = pa->success; + ret = pa->success; pa_threaded_mainloop_unlock(pa->mainloop); pa->is_paused = false; return ret; @@ -283,7 +302,8 @@ static bool pulse_start(void *data) static void pulse_set_nonblock_state(void *data, bool state) { pa_t *pa = (pa_t*)data; - pa->nonblock = state; + if (pa) + pa->nonblock = state; } static bool pulse_use_float(void *data) @@ -294,10 +314,12 @@ static bool pulse_use_float(void *data) static size_t pulse_write_avail(void *data) { + size_t length; pa_t *pa = (pa_t*)data; + pa_threaded_mainloop_lock(pa->mainloop); - size_t length = pa_stream_writable_size(pa->stream); - g_extern.audio_data.driver_buffer_size = pa->buffer_size; // Can change spuriously. + length = pa_stream_writable_size(pa->stream); + g_extern.audio_data.driver_buffer_size = pa->buffer_size; /* Can change spuriously. */ pa_threaded_mainloop_unlock(pa->mainloop); return length; } diff --git a/audio/roar.c b/audio/drivers/roar.c similarity index 95% rename from audio/roar.c rename to audio/drivers/roar.c index ccbf734589..54d10c7e67 100644 --- a/audio/roar.c +++ b/audio/drivers/roar.c @@ -14,13 +14,13 @@ */ -#include "driver.h" +#include "../../driver.h" #include #include #include #include #include -#include "general.h" +#include "../../general.h" typedef struct { @@ -30,13 +30,15 @@ typedef struct static void *ra_init(const char *device, unsigned rate, unsigned latency) { - (void)latency; int err; + roar_vs_t *vss; roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t)); - if (roar == NULL) + + if (!roar) return NULL; - roar_vs_t *vss; + (void)latency; + if ((vss = roar_vs_new_simple(device, "RetroArch", rate, 2, ROAR_CODEC_PCM_S, 16, ROAR_DIR_PLAY, &err)) == NULL) { RARCH_ERR("RoarAudio: \"%s\"\n", roar_vs_strerr(err)); @@ -52,17 +54,18 @@ static void *ra_init(const char *device, unsigned rate, unsigned latency) static ssize_t ra_write(void *data, const void *buf, size_t size) { - roar_t *roar = (roar_t*)data; + int err; ssize_t rc; + size_t written = 0; + roar_t *roar = (roar_t*)data; if (size == 0) return 0; - int err; - size_t written = 0; while (written < size) { size_t write_amt = size - written; + if ((rc = roar_vs_write(roar->vss, (const char*)buf + written, write_amt, &err)) < (ssize_t)write_amt) { if (roar->nonblocking) @@ -87,9 +90,9 @@ static bool ra_stop(void *data) static bool ra_alive(void *data) { roar_t *roar = (roar_t*)data; - if (roar) - return !roar->is_paused; - return false; + if (!roar) + return false; + return !roar->is_paused; } static void ra_set_nonblock_state(void *data, bool state) diff --git a/audio/rsound.c b/audio/drivers/rsound.c similarity index 98% rename from audio/rsound.c rename to audio/drivers/rsound.c index c05bacefe4..f3fcd4bb86 100644 --- a/audio/rsound.c +++ b/audio/drivers/rsound.c @@ -14,10 +14,10 @@ */ -#include "../driver.h" +#include "../audio_driver.h" #include #include "rsound.h" -#include "../fifo_buffer.h" +#include #include #include diff --git a/audio/rsound.h b/audio/drivers/rsound.h similarity index 99% rename from audio/rsound.h rename to audio/drivers/rsound.h index 70d7827e11..5395c137aa 100644 --- a/audio/rsound.h +++ b/audio/drivers/rsound.h @@ -30,7 +30,7 @@ extern "C" { #include #include -#include "../fifo_buffer.h" +#include #ifdef _WIN32 #define RSD_DEFAULT_HOST "127.0.0.1" // Stupid Windows. diff --git a/audio/rwebaudio.c b/audio/drivers/rwebaudio.c similarity index 93% rename from audio/rwebaudio.c rename to audio/drivers/rwebaudio.c index 824ae76e60..e3b9cef65e 100644 --- a/audio/rwebaudio.c +++ b/audio/drivers/rwebaudio.c @@ -13,10 +13,10 @@ * If not, see . */ -#include "../driver.h" -#include "../general.h" +#include "../../driver.h" +#include "../../general.h" -#include "../emscripten/RWebAudio.h" +#include "../../emscripten/RWebAudio.h" static bool rwebaudio_is_paused; @@ -27,9 +27,11 @@ static void rwebaudio_free(void *data) static void *rwebaudio_init(const char *device, unsigned rate, unsigned latency) { + void *data; (void)device; (void)rate; - void *data = RWebAudioInit(latency); + data = RWebAudioInit(latency); + if (data) g_settings.audio.out_rate = RWebAudioSampleRate(); return data; diff --git a/audio/sdl_audio.c b/audio/drivers/sdl_audio.c similarity index 80% rename from audio/sdl_audio.c rename to audio/drivers/sdl_audio.c index 530dd83c26..ba2cca7cb6 100644 --- a/audio/sdl_audio.c +++ b/audio/drivers/sdl_audio.c @@ -14,7 +14,7 @@ */ -#include "../driver.h" +#include "../../driver.h" #include #include #include @@ -25,8 +25,8 @@ #include "SDL_audio.h" #include -#include "../general.h" -#include "../fifo_buffer.h" +#include "../../general.h" +#include typedef struct sdl_audio { @@ -41,26 +41,36 @@ typedef struct sdl_audio static void sdl_audio_cb(void *data, Uint8 *stream, int len) { sdl_audio_t *sdl = (sdl_audio_t*)data; - size_t avail = fifo_read_avail(sdl->buffer); size_t write_size = len > (int)avail ? avail : len; + fifo_read(sdl->buffer, stream, write_size); scond_signal(sdl->cond); - // If underrun, fill rest with silence. + /* If underrun, fill rest with silence. */ memset(stream + write_size, 0, len - write_size); } static inline int find_num_frames(int rate, int latency) { int frames = (rate * latency) / 1000; - // SDL only likes 2^n sized buffers. + + /* SDL only likes 2^n sized buffers. */ + return next_pow2(frames); } -static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) +static void *sdl_audio_init(const char *device, + unsigned rate, unsigned latency) { + int frames; + size_t bufsize; + void *tmp; + SDL_AudioSpec out; + SDL_AudioSpec spec = {0}; + sdl_audio_t *sdl = NULL; (void)device; + if (SDL_WasInit(0) == 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) @@ -69,14 +79,16 @@ static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) return NULL; - sdl_audio_t *sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl)); + sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl)); if (!sdl) return NULL; - // We have to buffer up some data ourselves, so we let SDL carry approx half of the latency. SDL double buffers audio and we do as well. - int frames = find_num_frames(rate, latency / 4); + /* We have to buffer up some data ourselves, so we let SDL + * carry approximately half of the latency. + * + * SDL double buffers audio and we do as well. */ + frames = find_num_frames(rate, latency / 4); - SDL_AudioSpec spec = {0}; spec.freq = rate; spec.format = AUDIO_S16SYS; spec.channels = 2; @@ -84,8 +96,6 @@ static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) spec.callback = sdl_audio_cb; spec.userdata = sdl; - SDL_AudioSpec out; - if (SDL_OpenAudio(&spec, &out) < 0) { RARCH_ERR("Failed to open SDL audio: %s\n", SDL_GetError()); @@ -97,12 +107,14 @@ static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) sdl->lock = slock_new(); sdl->cond = scond_new(); - RARCH_LOG("SDL audio: Requested %u ms latency, got %d ms\n", latency, (int)(out.samples * 4 * 1000 / g_settings.audio.out_rate)); + RARCH_LOG("SDL audio: Requested %u ms latency, got %d ms\n", + latency, (int)(out.samples * 4 * 1000 / g_settings.audio.out_rate)); - // Create a buffer twice as big as needed and prefill the buffer. - size_t bufsize = out.samples * 4 * sizeof(int16_t); - void *tmp = calloc(1, bufsize); + /* Create a buffer twice as big as needed and prefill the buffer. */ + bufsize = out.samples * 4 * sizeof(int16_t); + tmp = calloc(1, bufsize); sdl->buffer = fifo_new(bufsize); + if (tmp) { fifo_write(sdl->buffer, tmp, bufsize); @@ -115,14 +127,16 @@ static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency) static ssize_t sdl_audio_write(void *data, const void *buf, size_t size) { + ssize_t ret = 0; sdl_audio_t *sdl = (sdl_audio_t*)data; - ssize_t ret = 0; if (sdl->nonblock) { + size_t avail, write_amt; + SDL_LockAudio(); - size_t avail = fifo_write_avail(sdl->buffer); - size_t write_amt = avail > size ? size : avail; + avail = fifo_write_avail(sdl->buffer); + write_amt = avail > size ? size : avail; fifo_write(sdl->buffer, buf, write_amt); SDL_UnlockAudio(); ret = write_amt; @@ -130,10 +144,13 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size) else { size_t written = 0; + while (written < size) { + size_t avail; + SDL_LockAudio(); - size_t avail = fifo_write_avail(sdl->buffer); + avail = fifo_write_avail(sdl->buffer); if (avail == 0) { @@ -167,9 +184,9 @@ static bool sdl_audio_stop(void *data) static bool sdl_audio_alive(void *data) { sdl_audio_t *sdl = (sdl_audio_t*)data; - if (sdl) - return !sdl->is_paused; - return false; + if (!sdl) + return false; + return !sdl->is_paused; } static bool sdl_audio_start(void *data) @@ -184,15 +201,17 @@ static bool sdl_audio_start(void *data) static void sdl_audio_set_nonblock_state(void *data, bool state) { sdl_audio_t *sdl = (sdl_audio_t*)data; - sdl->nonblock = state; + if (sdl) + sdl->nonblock = state; } static void sdl_audio_free(void *data) { + sdl_audio_t *sdl = (sdl_audio_t*)data; + SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); - sdl_audio_t *sdl = (sdl_audio_t*)data; if (sdl) { fifo_free(sdl->buffer); diff --git a/audio/xaudio-c/xaudio-c.cpp b/audio/drivers/xaudio-c.cpp similarity index 97% rename from audio/xaudio-c/xaudio-c.cpp rename to audio/drivers/xaudio-c.cpp index d9f9da5a93..f2169bd4a1 100644 --- a/audio/xaudio-c/xaudio-c.cpp +++ b/audio/drivers/xaudio-c.cpp @@ -67,12 +67,17 @@ struct xaudio2 : public IXAudio2VoiceCallback void xaudio2_enumerate_devices(xaudio2_t *xa) { + UINT32 dev_count = 0; + unsigned i = 0; + (void)xa; + (void)i; + (void)dev_count; #ifndef _XBOX - UINT32 dev_count; xa->pXAudio2->GetDeviceCount(&dev_count); fprintf(stderr, "XAudio2 devices:\n"); - for (unsigned i = 0; i < dev_count; i++) + + for (i = 0; i < dev_count; i++) { XAUDIO2_DEVICE_DETAILS dev_detail; xa->pXAudio2->GetDeviceDetails(i, &dev_detail); @@ -97,13 +102,14 @@ static void xaudio2_set_wavefmt(WAVEFORMATEX *wfx, xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, size_t size, unsigned device) { + xaudio2_t *handle; + WAVEFORMATEX wfx = {0}; + #ifndef _XBOX CoInitializeEx(0, COINIT_MULTITHREADED); #endif - xaudio2_t *handle = new xaudio2; - - WAVEFORMATEX wfx = {0}; + handle = new xaudio2; if (FAILED(XAudio2Create(&handle->pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR))) goto error; @@ -147,9 +153,11 @@ size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes_) { unsigned bytes = bytes_; const uint8_t *buffer = (const uint8_t*)buf; + while (bytes) { unsigned need = min(bytes, handle->bufsize - handle->bufptr); + memcpy(handle->buf + handle->write_buffer * handle->bufsize + handle->bufptr, buffer, need); @@ -159,10 +167,11 @@ size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes_) if (handle->bufptr == handle->bufsize) { + XAUDIO2_BUFFER xa2buffer = {0}; + while (handle->buffers == MAX_BUFFERS - 1) WaitForSingleObject(handle->hEvent, INFINITE); - XAUDIO2_BUFFER xa2buffer = {0}; xa2buffer.AudioBytes = handle->bufsize; xa2buffer.pAudioData = handle->buf + handle->write_buffer * handle->bufsize; diff --git a/audio/xaudio-c/xaudio-c.h b/audio/drivers/xaudio-c.h similarity index 100% rename from audio/xaudio-c/xaudio-c.h rename to audio/drivers/xaudio-c.h diff --git a/audio/xaudio.c b/audio/drivers/xaudio.c similarity index 85% rename from audio/xaudio.c rename to audio/drivers/xaudio.c index 451eca3aef..e255b22abc 100644 --- a/audio/xaudio.c +++ b/audio/drivers/xaudio.c @@ -14,10 +14,10 @@ * If not, see . */ -#include "../driver.h" +#include "../../driver.h" #include -#include "xaudio-c/xaudio-c.h" -#include "../general.h" +#include "xaudio-c.h" +#include "../../general.h" typedef struct { @@ -29,21 +29,24 @@ typedef struct static void *xa_init(const char *device, unsigned rate, unsigned latency) { - if (latency < 8) - latency = 8; // Do not allow shenanigans. + size_t bufsize; + xa_t *xa; + unsigned device_index = 0; - xa_t *xa = (xa_t*)calloc(1, sizeof(*xa)); + if (latency < 8) + latency = 8; /* Do not allow shenanigans. */ + + xa = (xa_t*)calloc(1, sizeof(*xa)); if (!xa) return NULL; - size_t bufsize = latency * rate / 1000; + bufsize = latency * rate / 1000; RARCH_LOG("XAudio2: Requesting %u ms latency, using %d ms latency.\n", latency, (int)bufsize * 1000 / rate); xa->bufsize = bufsize * 2 * sizeof(float); - unsigned device_index = 0; if (device) device_index = strtoul(device, NULL, 0); @@ -63,17 +66,20 @@ static void *xa_init(const char *device, unsigned rate, unsigned latency) static ssize_t xa_write(void *data, const void *buf, size_t size) { + size_t ret; xa_t *xa = (xa_t*)data; + if (xa->nonblock) { size_t avail = xaudio2_write_avail(xa->xa); + if (avail == 0) return 0; if (avail < size) size = avail; } - size_t ret = xaudio2_write(xa->xa, buf, size); + ret = xaudio2_write(xa->xa, buf, size); if (ret == 0 && size > 0) return -1; return ret; @@ -89,15 +95,16 @@ static bool xa_stop(void *data) static bool xa_alive(void *data) { xa_t *xa = (xa_t*)data; - if (xa) - return !xa->is_paused; - return false; + if (!xa) + return false; + return !xa->is_paused; } static void xa_set_nonblock_state(void *data, bool state) { xa_t *xa = (xa_t*)data; - xa->nonblock = state; + if (xa) + xa->nonblock = state; } static bool xa_start(void *data) @@ -116,12 +123,13 @@ static bool xa_use_float(void *data) static void xa_free(void *data) { xa_t *xa = (xa_t*)data; - if (xa) - { - if (xa->xa) - xaudio2_free(xa->xa); - free(xa); - } + + if (!xa) + return; + + if (xa->xa) + xaudio2_free(xa->xa); + free(xa); } static size_t xa_write_avail(void *data) diff --git a/audio/xaudio-c/xaudio.h b/audio/drivers/xaudio.h similarity index 100% rename from audio/xaudio-c/xaudio.h rename to audio/drivers/xaudio.h diff --git a/audio/xenon360_audio.c b/audio/drivers/xenon360_audio.c similarity index 93% rename from audio/xenon360_audio.c rename to audio/drivers/xenon360_audio.c index d66d0b36ab..9e8d4b1336 100644 --- a/audio/xenon360_audio.c +++ b/audio/drivers/xenon360_audio.c @@ -14,10 +14,10 @@ * If not, see . */ -#include "../driver.h" +#include "../../driver.h" #include #include -#include "../general.h" +#include "../../general.h" #include @@ -35,6 +35,7 @@ static void *xenon360_audio_init(const char *device, unsigned rate, unsigned latency) { static bool inited = false; + if (!inited) { xenon_sound_init(); @@ -53,12 +54,11 @@ static inline uint32_t bswap_32(uint32_t val) static ssize_t xenon360_audio_write(void *data, const void *buf, size_t size) { + size_t written = 0, i; + const uint32_t *in_buf = buf; xenon_audio_t *xa = data; - size_t written = 0; - - const uint32_t *in_buf = buf; - for (size_t i = 0; i < (size >> 2); i++) + for (i = 0; i < (size >> 2); i++) xa->buffer[i] = bswap_32(in_buf[i]); if (!xa->nonblock) @@ -95,15 +95,16 @@ static bool xenon360_audio_stop(void *data) static bool xenon360_audio_alive(void *data) { xenon_audio_t *xa = data; - if (xa) - return !xa->is_paused; - return false; + if (!xa) + return false; + return !xa->is_paused; } static void xenon360_audio_set_nonblock_state(void *data, bool state) { xenon_audio_t *xa = data; - xa->nonblock = state; + if (xa) + xa->nonblock = state; } static bool xenon360_audio_start(void *data) diff --git a/audio/resamplers/cc_resampler.c b/audio/drivers_resampler/cc_resampler.c similarity index 99% rename from audio/resamplers/cc_resampler.c rename to audio/drivers_resampler/cc_resampler.c index 65d71f042d..bc1eb991a2 100644 --- a/audio/resamplers/cc_resampler.c +++ b/audio/drivers_resampler/cc_resampler.c @@ -15,10 +15,13 @@ /* Convoluted Cosine Resampler */ -#include "resampler.h" +#include "../audio_resampler_driver.h" #include #include #include +#ifdef __SSE__ +#include +#endif #if !defined(RESAMPLER_TEST) && defined(RARCH_INTERNAL) #include "../../general.h" @@ -212,9 +215,6 @@ static void *resampler_CC_init(const struct resampler_config *config, #if defined(__SSE__) - -#include - #define CC_RESAMPLER_IDENT "SSE" static void resampler_CC_downsample(void *re_, struct resampler_data *data) diff --git a/audio/resamplers/cc_resampler_neon.S b/audio/drivers_resampler/cc_resampler_neon.S similarity index 100% rename from audio/resamplers/cc_resampler_neon.S rename to audio/drivers_resampler/cc_resampler_neon.S diff --git a/audio/resamplers/nearest.c b/audio/drivers_resampler/nearest.c similarity index 98% rename from audio/resamplers/nearest.c rename to audio/drivers_resampler/nearest.c index 8664518302..2166d2374a 100644 --- a/audio/resamplers/nearest.c +++ b/audio/drivers_resampler/nearest.c @@ -13,7 +13,7 @@ * If not, see . */ -#include "resampler.h" +#include "../audio_resampler_driver.h" #include #include #include diff --git a/audio/resamplers/sinc.c b/audio/drivers_resampler/sinc.c similarity index 99% rename from audio/resamplers/sinc.c rename to audio/drivers_resampler/sinc.c index faac11b66e..456478b238 100644 --- a/audio/resamplers/sinc.c +++ b/audio/drivers_resampler/sinc.c @@ -15,7 +15,7 @@ /* Bog-standard windowed SINC implementation. */ -#include "resampler.h" +#include "../audio_resampler_driver.h" #include #include #include diff --git a/audio/resamplers/sinc_neon.S b/audio/drivers_resampler/sinc_neon.S similarity index 100% rename from audio/resamplers/sinc_neon.S rename to audio/drivers_resampler/sinc_neon.S diff --git a/audio/librsound.c b/audio/librsound.c index ba352b7af5..68830fb9a2 100644 --- a/audio/librsound.c +++ b/audio/librsound.c @@ -29,14 +29,14 @@ * If not, see . */ -#include "rsound.h" +#include "drivers/rsound.h" #if defined(__CELLOS_LV2__) #include #include #include -// network headers +/* Network headers */ #include #include #define NETWORK_COMPAT_HEADERS 1 diff --git a/audio/test/main.c b/audio/test/main.c index fe04bebe15..15e5bfc4e3 100644 --- a/audio/test/main.c +++ b/audio/test/main.c @@ -17,7 +17,7 @@ // Used for testing and performance benchmarking. #include "../resamplers/resampler.h" -#include "../utils.h" +#include "../audio_utils.h" #include #include #include diff --git a/audio/test/snr.c b/audio/test/snr.c index 565c417010..01d91b16c3 100644 --- a/audio/test/snr.c +++ b/audio/test/snr.c @@ -14,7 +14,7 @@ */ #include "../resamplers/resampler.h" -#include "../utils.h" +#include "../audio_utils.h" #include #include #include diff --git a/blackberry-qnx/bb10/.cproject b/blackberry-qnx/bb10/.cproject index 3360d1ae04..856fd0f472 100644 --- a/blackberry-qnx/bb10/.cproject +++ b/blackberry-qnx/bb10/.cproject @@ -104,7 +104,7 @@ - + - + - + - + - + - + - + - + - + - + - +