From 404fa9b232c77c2a5e5a806bd82e2963b4c68597 Mon Sep 17 00:00:00 2001 From: Nicolas Allemand Date: Mon, 9 Dec 2024 18:47:35 +0100 Subject: [PATCH] upgrade to SDL3 Co-authored-by: Anonymous Maarten Co-authored-by: Ozkan Sezer --- .github/workflows/main.yml | 47 ++-- .gitignore | 6 +- Android.mk | 6 +- CMakeLists.txt | 171 ++++++------- README.md | 2 +- build-scripts/test-versioning.sh | 142 +++++++++++ cmake/SDL2_soundConfig.cmake.in | 34 --- cmake/SDL3_soundConfig.cmake.in | 34 +++ cmake/{SDL2_sound.pc.in => sdl3-sound.pc.in} | 8 +- cmake/test/CMakeLists.txt | 32 +-- cmake/test/main.c | 7 +- docs/Doxyfile | 2 +- docs/INSTALL.txt | 10 +- examples/playsound.c | 163 +++++------- examples/playsound_simple.c | 40 ++- {src => include/SDL3_sound}/SDL_sound.h | 22 +- src/Makefile.os2 | 139 ---------- src/SDL_sound.c | 251 ++++++------------- src/SDL_sound_aiff.c | 91 +++---- src/SDL_sound_au.c | 52 ++-- src/SDL_sound_coreaudio.c | 59 ++--- src/SDL_sound_flac.c | 15 +- src/SDL_sound_internal.h | 54 ++-- src/SDL_sound_midi.c | 13 +- src/SDL_sound_modplug.c | 42 ++-- src/SDL_sound_mp3.c | 14 +- src/SDL_sound_raw.c | 17 +- src/SDL_sound_shn.c | 72 +++--- src/SDL_sound_skeleton.c | 32 +-- src/SDL_sound_voc.c | 46 ++-- src/SDL_sound_vorbis.c | 13 +- src/SDL_sound_wav.c | 98 ++++---- src/libmodplug/fastmix.c | 2 +- src/libmodplug/libmodplug.h | 8 +- src/libmodplug/snd_fx.c | 4 +- src/stb_vorbis.h | 30 +-- src/timidity/common.c | 10 +- src/timidity/common.h | 2 +- src/timidity/instrum.c | 32 +-- src/timidity/readmidi.c | 76 +++--- src/timidity/timidity.c | 44 ++-- src/timidity/timidity.h | 4 +- src/version.rc | 12 +- update_version.sh | 13 +- 44 files changed, 890 insertions(+), 1081 deletions(-) create mode 100755 build-scripts/test-versioning.sh delete mode 100644 cmake/SDL2_soundConfig.cmake.in create mode 100644 cmake/SDL3_soundConfig.cmake.in rename cmake/{SDL2_sound.pc.in => sdl3-sound.pc.in} (72%) rename {src => include/SDL3_sound}/SDL_sound.h (98%) delete mode 100644 src/Makefile.os2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 33f0f751..8fe13e34 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,22 +18,22 @@ jobs: - { name: MacOS, os: macos-latest, shell: sh } - { name: mingw-w64 (i686), os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686 } - { name: mingw-w64 (x86_64), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64 } - - { name: MSVC (x86), os: windows-latest, shell: pwsh, flags: "-DCMAKE_TOOLCHAIN_FILE=C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake -A Win32", vcpkg: x86-windows } - - { name: MSVC (x64), os: windows-latest, shell: pwsh, flags: "-DCMAKE_TOOLCHAIN_FILE=C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake -A x64", vcpkg: x64-windows } - - { name: MSVC (ARM64), os: windows-latest, shell: pwsh, flags: "-DCMAKE_TOOLCHAIN_FILE=C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake -A ARM64", vcpkg: arm64-windows } - + - { name: MSVC (x86), os: windows-latest, shell: pwsh, msvc: 1, msvc-arch: amd64_x86 } + - { name: MSVC (x64), os: windows-latest, shell: pwsh, msvc: 1, msvc-arch: amd64 } + - { name: MSVC (ARM64), os: windows-latest, shell: pwsh, msvc: 1, msvc-arch: amd64_arm64 } + steps: + - uses: ilammy/msvc-dev-cmd@v1 + if: ${{ matrix.platform.msvc }} + with: + arch: ${{ matrix.platform.msvc-arch }} - name: Setup Linux dependencies if: runner.os == 'Linux' run: | sudo apt-get update - sudo apt-get install cmake ninja-build libsdl2-dev - - name: Setup MacOS dependencies - if: runner.os == 'MacOS' - run: | - brew install sdl2 - - name: Set up MSYS2 dependencies - if: matrix.platform.shell == 'msys2 {0}' + sudo apt-get install cmake ninja-build + - name: Set up MSYS2 + if: ${{ matrix.platform.shell == 'msys2 {0}' }} uses: msys2/setup-msys2@v2 with: msystem: ${{ matrix.platform.msystem }} @@ -41,22 +41,29 @@ jobs: ${{ matrix.platform.msys-env }}-gcc ${{ matrix.platform.msys-env }}-cmake ${{ matrix.platform.msys-env }}-ninja - ${{ matrix.platform.msys-env }}-SDL2 - - name: Setup MSVC dependencies - if: matrix.platform.vcpkg != '' - run: | - vcpkg install --triplet ${{ matrix.platform.vcpkg }} sdl2 - + - name: Set up Ninja + uses: aseprite/get-ninja@main + if: ${{ !contains(matrix.platform.shell, 'msys2') }} + - name: Set up SDL + id: sdl + uses: libsdl-org/setup-sdl@main + with: + cmake-generator: Ninja + version: 3-head + sdl-test: false + shell: ${{ matrix.platform.shell }} - name: Get SDL_sound sources uses: actions/checkout@v3 - name: Configure (CMake) - run: cmake -B build -DSDLSOUND_DECODER_MIDI=ON ${{ matrix.platform.flags }} -DCMAKE_INSTALL_PREFIX=prefix -DCMAKE_BUILD_TYPE=Release + run: | + cmake -B build -DSDLSOUND_DECODER_MIDI=ON -GNinja -DCMAKE_INSTALL_PREFIX=prefix -DCMAKE_BUILD_TYPE=Release - name: Build (CMake) - run: cmake --build build/ --config Release + run: | + cmake --build build/ --config Release - name: Install (CMake) run: | cmake --install build/ --config Release - name: Verify CMake configuration files run: | - cmake -S cmake/test -B build_cmake_test ${{ matrix.platform.flags }} -DCMAKE_PREFIX_PATH="${{ github.workspace }}/prefix" -DCMAKE_BUILD_TYPE=Release + cmake -S cmake/test -B build_cmake_test -GNinja -DCMAKE_PREFIX_PATH="${{ github.workspace }}/prefix" -DCMAKE_BUILD_TYPE=Release cmake --build build_cmake_test --verbose --config Release diff --git a/.gitignore b/.gitignore index d6066133..db4a0e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -SDL2_sound.pc +SDL3_sound.pc *.so *.so.* @@ -35,3 +35,7 @@ RelWithDebInfo playsound playsound_simple + +.DS_Store +build +.vscode diff --git a/Android.mk b/Android.mk index 83de6ac2..2a5a0d38 100644 --- a/Android.mk +++ b/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := SDL2_sound +LOCAL_MODULE := SDL3_sound SUPPORT_MIDI ?= false @@ -10,7 +10,7 @@ SUPPORT_MIDI ?= false SUPPORT_MODPLUG ?= true -LOCAL_C_INCLUDES := $(LOCAL_PATH)/src +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_CFLAGS := LOCAL_SRC_FILES := $(LOCAL_PATH)/src/SDL_sound.c \ @@ -42,7 +42,7 @@ else LOCAL_CFLAGS += -DSOUND_SUPPORTS_MODPLUG=0 endif -LOCAL_SHARED_LIBRARIES := SDL2 +LOCAL_SHARED_LIBRARIES := SDL3 LOCAL_EXPORT_C_INCLUDES += $(LOCAL_C_INCLUDES) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49856b04..5d38e574 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,17 @@ -# NOTE: If you installed SDL2 at an unusual place and find_package() -# fails, define SDL2_DIR environment variable to point to your SDL2 +# NOTE: If you installed SDL3 at an unusual place and find_package() +# fails, define SDL3_DIR environment variable to point to your SDL3 # installation. -set(SDLSOUND_VERSION 2.0.3) +set(MAJOR_VERSION 3) +set(MINOR_VERSION 0) +set(MICRO_VERSION 0) +set(SDLSOUND_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}") # Increment this if/when we break backwards compatibility. -set(SDLSOUND_SOVERSION 2) +set(SDLSOUND_SOVERSION 3) cmake_minimum_required(VERSION 3.0...3.10) +cmake_policy(SET CMP0074 NEW) project(SDL_sound VERSION ${SDLSOUND_VERSION} @@ -28,24 +32,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL "SunPro") add_compile_options(-xldscope=hidden) endif() -find_package(SDL2 REQUIRED) -if(WIN32) - # -lmingw32: gcc adds it automatically. - # -mwindows: doesn't make sense. - # -lSDL2main: the dll doesn't need it, the test apps are console-only - # and specifically define SDL_MAIN_HANDLED. it will be ignored. - string(REGEX REPLACE "-mwindows" "" SDL2_LIBRARIES "${SDL2_LIBRARIES}") - string(REGEX REPLACE "-lmingw32" "" SDL2_LIBRARIES "${SDL2_LIBRARIES}") -# string(REGEX REPLACE "-lSDL2main" "" SDL2_LIBRARIES "${SDL2_LIBRARIES}") - string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES) -endif() - -if(UNIX AND NOT (WIN32 OR APPLE OR HAIKU OR EMSCRIPTEN)) - find_library(LIBM_LIBRARY m) - if(LIBM_LIBRARY) - set(LIBM_LIBRARY m) - endif() -endif() +find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3) # Decoders ... # These are (mostly) on by default now, so these options are only useful for @@ -72,14 +59,6 @@ sdlsound_decoder_option(MP3 "MPEG-1 Layers I-III" ".MP3, .MP2, .MP1" TRUE) # timidity is not public domain code, so default to not building it. sdlsound_decoder_option(MIDI "Midi" ".MID" FALSE) -if(SDLSOUND_DECODER_VORBIS AND LIBM_LIBRARY) -# stb_vorbis uses exp(), SDL_exp() is available as of SDL2-2.0.9 -# Instead of testing SDL_exp() presence, we unconditionally link -# with -lm which is just harmless. - set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${LIBM_LIBRARY}) - set(PC_LIBS ${PC_LIBS} -l${LIBM_LIBRARY}) -endif() - if(APPLE) sdlsound_decoder_option(COREAUDIO "CoreAudio" "various audio formats" TRUE) if(SDLSOUND_DECODER_COREAUDIO) @@ -182,7 +161,7 @@ set(SDLSOUND_SRCS set(SDLSOUND_HDRS src/dr_flac.h src/dr_mp3.h - src/SDL_sound.h + "include/SDL3_sound/SDL_sound.h" src/SDL_sound_internal.h src/stb_vorbis.h ) @@ -198,57 +177,49 @@ set(SDLSOUND_ALL_SRCS ) option(SDLSOUND_BUILD_STATIC "Build static library" TRUE) -if(OS2) # no static library on os/2 - set(SDLSOUND_BUILD_STATIC FALSE) -endif() if(SDLSOUND_BUILD_STATIC) - add_library(SDL2_sound-static STATIC ${SDLSOUND_ALL_SRCS}) - add_library(SDL2_sound::SDL2_sound-static ALIAS SDL2_sound-static) + add_library(SDL3_sound-static STATIC ${SDLSOUND_ALL_SRCS}) + add_library(SDL3_sound::SDL3_sound-static ALIAS SDL3_sound-static) # Don't rename this on Windows, since DLLs will also produce an import - # library named "SDL2_sound.lib" which would conflict; Unix tend to like + # library named "SDL3_sound.lib" which would conflict; Unix tend to like # the same library name with a different extension for static libs, but # Windows can just have a separate name. if(NOT MSVC) - set_target_properties(SDL2_sound-static PROPERTIES OUTPUT_NAME "SDL2_sound") + set_target_properties(SDL3_sound-static PROPERTIES OUTPUT_NAME "SDL3_sound") endif() - target_include_directories(SDL2_sound-static PUBLIC + target_include_directories(SDL3_sound-static PUBLIC $ - $ - $) - target_include_directories(SDL2_sound-static PUBLIC "$") - target_link_libraries(SDL2_sound-static PRIVATE "$" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) - set(SDLSOUND_LIB_TARGET SDL2_sound-static) + $) + target_include_directories(SDL3_sound-static PUBLIC "$") + target_link_libraries(SDL3_sound-static PRIVATE SDL3::SDL3 ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) + set(SDLSOUND_LIB_TARGET SDL3_sound-static) endif() option(SDLSOUND_BUILD_SHARED "Build shared library" TRUE) if(SDLSOUND_BUILD_SHARED) - add_library(SDL2_sound SHARED ${SDLSOUND_ALL_SRCS} ${SDLSOUND_SHARED_SRCS}) - add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound) - set_target_properties(SDL2_sound PROPERTIES MACOSX_RPATH 1) - set_target_properties(SDL2_sound PROPERTIES VERSION ${SDLSOUND_VERSION}) - set_target_properties(SDL2_sound PROPERTIES SOVERSION ${SDLSOUND_SOVERSION}) + add_library(SDL3_sound SHARED ${SDLSOUND_ALL_SRCS} ${SDLSOUND_SHARED_SRCS}) + add_library(SDL3_sound::SDL3_sound ALIAS SDL3_sound) + set_target_properties(SDL3_sound PROPERTIES MACOSX_RPATH 1) + set_target_properties(SDL3_sound PROPERTIES VERSION ${SDLSOUND_VERSION}) + set_target_properties(SDL3_sound PROPERTIES SOVERSION ${SDLSOUND_SOVERSION}) # Use `Compatible Interface Properties` to ensure a shared SDL_sound is linked to a shared SDL library - set_property(TARGET SDL2_sound PROPERTY INTERFACE_SDL2_SHARED ON) - set_property(TARGET SDL2_sound APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED) - if(WIN32 OR OS2) - SET_TARGET_PROPERTIES(SDL2_sound PROPERTIES DEFINE_SYMBOL SDL_SOUND_DLL_EXPORTS) + set_property(TARGET SDL3_sound PROPERTY INTERFACE_SDL3_SHARED ON) + set_property(TARGET SDL3_sound APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL3_SHARED) + if(WIN32) + SET_TARGET_PROPERTIES(SDL3_sound PROPERTIES DEFINE_SYMBOL SDL_SOUND_DLL_EXPORTS) # avoid DLL having "lib" prefix SET(CMAKE_SHARED_LIBRARY_PREFIX "") endif() - if(OS2) # OS/2 does not support a DLL name longer than 8 characters. - SET_TARGET_PROPERTIES(SDL2_sound PROPERTIES OUTPUT_NAME "SDL2snd") - endif() - target_include_directories(SDL2_sound PUBLIC + target_include_directories(SDL3_sound PUBLIC $ - $ - $ + $ ) - target_include_directories(SDL2_sound PUBLIC "$") - target_link_libraries(SDL2_sound PRIVATE "$" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) - set(SDLSOUND_LIB_TARGET SDL2_sound) + # target_include_directories(SDL3_sound PUBLIC "$") + target_link_libraries(SDL3_sound PRIVATE SDL3::SDL3 ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) + set(SDLSOUND_LIB_TARGET SDL3_sound) endif() -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/SDL2_sound.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/SDL2_sound.pc" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl3-sound.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sdl3-sound.pc" @ONLY) if(NOT SDLSOUND_BUILD_SHARED AND NOT SDLSOUND_BUILD_STATIC) message(FATAL "Both shared and static libraries are disabled!") @@ -258,11 +229,12 @@ option(SDLSOUND_BUILD_TEST "Build stdio test program." TRUE) mark_as_advanced(SDLSOUND_BUILD_TEST) if(SDLSOUND_BUILD_TEST) add_executable(playsound examples/playsound.c) - if(TARGET SDL2::SDL2) - target_link_libraries(playsound PRIVATE SDL2::SDL2) + target_link_libraries(playsound PRIVATE SDL3::SDL3) + if(TARGET SDL3::SDL3) + target_link_libraries(playsound PRIVATE SDL3::SDL3) else() - target_include_directories(playsound PRIVATE ${SDL2_INCLUDE_DIRS}) - target_link_libraries(playsound PRIVATE ${SDL2_LIBRARIES}) + target_include_directories(playsound PRIVATE ${SDL3_INCLUDE_DIRS}) + target_link_libraries(playsound PRIVATE ${SDL3_LIBRARIES}) endif() target_link_libraries(playsound PRIVATE ${SDLSOUND_LIB_TARGET} ${OTHER_LDFLAGS}) # assuming assert.h, signal.h and setbuf() being available universally @@ -272,11 +244,12 @@ if(SDLSOUND_BUILD_TEST) list(APPEND SDLSOUND_INSTALL_TARGETS playsound) add_executable(playsound_simple examples/playsound_simple.c) - if(TARGET SDL2::SDL2) - target_link_libraries(playsound_simple PRIVATE SDL2::SDL2) + target_link_libraries(playsound_simple PRIVATE SDL3::SDL3) + if(TARGET SDL3::SDL3) + target_link_libraries(playsound_simple PRIVATE SDL3::SDL3) else() - target_include_directories(playsound_simple PRIVATE ${SDL2_INCLUDE_DIRS}) - target_link_libraries(playsound_simple PRIVATE ${SDL2_LIBRARIES}) + target_include_directories(playsound_simple PRIVATE ${SDL3_INCLUDE_DIRS}) + target_link_libraries(playsound_simple PRIVATE ${SDL3_LIBRARIES}) endif() target_link_libraries(playsound_simple PRIVATE ${SDLSOUND_LIB_TARGET} ${OTHER_LDFLAGS}) #list(APPEND SDLSOUND_INSTALL_TARGETS playsound_simple) @@ -291,8 +264,8 @@ if(SDLSOUND_BUILD_TEST) SET_TARGET_PROPERTIES(playsound_simple PROPERTIES LINK_FLAGS "-mconsole") ENDIF () if(NOT SDLSOUND_BUILD_SHARED) - target_link_libraries(playsound ${SDL2_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) - target_link_libraries(playsound_simple ${SDL2_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) + target_link_libraries(playsound ${SDL3_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) + target_link_libraries(playsound_simple ${SDL3_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) endif() endif() @@ -301,40 +274,40 @@ set(PKGCONFIG_INSTALLDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") if(WIN32 AND NOT MINGW) set(SDLSOUND_INSTALL_CMAKEDIR_DEFAULT "cmake") else() - set(SDLSOUND_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL2_sound") + set(SDLSOUND_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL3_sound") endif() -set(SDLSOUND_INSTALL_CMAKEDIR "${SDLSOUND_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL2_sound.cmake") +set(SDLSOUND_INSTALL_CMAKEDIR "${SDLSOUND_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL3_sound.cmake") -configure_package_config_file(cmake/SDL2_soundConfig.cmake.in SDL2_soundConfig.cmake +configure_package_config_file(cmake/SDL3_soundConfig.cmake.in SDL3_soundConfig.cmake INSTALL_DESTINATION "${SDLSOUND_INSTALL_CMAKEDIR}" ) -write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL2_soundConfigVersion.cmake" +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL3_soundConfigVersion.cmake" VERSION "${SDLSOUND_VERSION}" COMPATIBILITY AnyNewerVersion ) if(SDLSOUND_BUILD_SHARED) - install(TARGETS SDL2_sound + install(TARGETS SDL3_sound EXPORT SDLSoundSharedExports - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT library ) install(EXPORT SDLSoundSharedExports FILE "${SDLSOUND_LIB_TARGET}-shared-targets.cmake" - NAMESPACE SDL2_sound:: + NAMESPACE SDL3_sound:: DESTINATION "${SDLSOUND_INSTALL_CMAKEDIR}" ) endif() if(SDLSOUND_BUILD_STATIC) - install(TARGETS SDL2_sound-static + install(TARGETS SDL3_sound-static EXPORT SDLSoundStaticExports - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT library ) install(EXPORT SDLSoundStaticExports FILE "${SDLSOUND_LIB_TARGET}-static-targets.cmake" - NAMESPACE SDL2_sound:: + NAMESPACE SDL3_sound:: DESTINATION "${SDLSOUND_INSTALL_CMAKEDIR}" ) endif() @@ -344,14 +317,16 @@ install(TARGETS ${SDLSOUND_INSTALL_TARGETS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/SDL2_soundConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/SDL2_soundConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SDL3_soundConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SDL3_soundConfigVersion.cmake" DESTINATION "${SDLSOUND_INSTALL_CMAKEDIR}" ) -install(FILES src/SDL_sound.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SDL2) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SDL2_sound.pc - DESTINATION "${PKGCONFIG_INSTALLDIR}") +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/SDL3_sound/SDL_sound.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SDL3_sound" COMPONENT DEVEL +) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdl3-sound.pc + DESTINATION "${PKGCONFIG_INSTALLDIR}" COMPONENT DEVEL) option(SDLSOUND_BUILD_DOCS "Build documentation" TRUE) mark_as_advanced(SDLSOUND_BUILD_DOCS) @@ -371,7 +346,7 @@ if(SDLSOUND_BUILD_DOCS) file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n") add_custom_target( - SDL2_sound-docs + SDL3_sound-docs ${DOXYGEN_EXECUTABLE} "${SDLSOUND_OUTPUT_DOXYFILE}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Building documentation..." @@ -387,7 +362,7 @@ configure_file( IMMEDIATE @ONLY) add_custom_target( - SDL2_sound-uninstall + SDL3_sound-uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMENT "Uninstall the project..." @@ -419,9 +394,9 @@ message_bool_option("Build shared library" SDLSOUND_BUILD_SHARED) message_bool_option("Build stdio test program" SDLSOUND_BUILD_TEST) message_bool_option("Build documentation" SDLSOUND_BUILD_DOCS) -# Make sure SDL2_sound::SDL2_sound always exists -if(TARGET SDL2_sound::SDL2_sound-static AND NOT TARGET SDL2_sound::SDL2_sound) - add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound-static) +# Make sure SDL3_sound::SDL3_sound always exists +if(TARGET SDL3_sound::SDL3_sound-static AND NOT TARGET SDL3_sound::SDL3_sound) + add_library(SDL3_sound::SDL3_sound ALIAS SDL3_sound-static) endif() # end of CMakeLists.txt diff --git a/README.md b/README.md index 012f9c76..1a9eac85 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Please check the website for the most up-to-date information about SDL_sound: https://icculus.org/SDL_sound/ -SDL_sound _REQUIRES_ Simple Directmedia Layer (SDL) 2.x to function, and cannot +SDL_sound _REQUIRES_ Simple Directmedia Layer (SDL) 3.x to function, and cannot be built without it. You can get SDL from https://www.libsdl.org/ Current versions of SDL_sound do not use any external libraries for decoding diff --git a/build-scripts/test-versioning.sh b/build-scripts/test-versioning.sh new file mode 100755 index 00000000..5a97d646 --- /dev/null +++ b/build-scripts/test-versioning.sh @@ -0,0 +1,142 @@ +#!/bin/sh +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: Zlib + +set -eu + +cd `dirname $0`/.. + +# Needed so sed doesn't report illegal byte sequences on macOS +export LC_CTYPE=C + +header=include/SDL3_sound/SDL_sound.h +ref_major=$(sed -ne 's/^#define SOUND_VER_MAJOR *//p' $header) +ref_minor=$(sed -ne 's/^#define SOUND_VER_MINOR *//p' $header) +ref_micro=$(sed -ne 's/^#define SOUND_VER_PATCH *//p' $header) +ref_version="${ref_major}.${ref_minor}.${ref_micro}" + +tests=0 +failed=0 + +ok () { + tests=$(( tests + 1 )) + echo "ok - $*" +} + +not_ok () { + tests=$(( tests + 1 )) + echo "not ok - $*" + failed=1 +} + +major=$(sed -ne 's/^set(MAJOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt) +minor=$(sed -ne 's/^set(MINOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt) +micro=$(sed -ne 's/^set(MICRO_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt) +ref_sdl_req=$(sed -ne 's/^set(SDL_REQUIRED_VERSION \([0-9.]*\))$/\1/p' CMakeLists.txt) +version="${major}.${minor}.${micro}" + +if [ "$ref_version" = "$version" ]; then + ok "CMakeLists.txt $version" +else + not_ok "CMakeLists.txt $version disagrees with SDL_sound.h $ref_version" +fi + +for rcfile in src/version.rc; do + tuple=$(sed -ne 's/^ *FILEVERSION *//p' "$rcfile" | tr -d '\r') + ref_tuple="${ref_major},${ref_minor},${ref_micro},0" + + if [ "$ref_tuple" = "$tuple" ]; then + ok "$rcfile FILEVERSION $tuple" + else + not_ok "$rcfile FILEVERSION $tuple disagrees with SDL_sound.h $ref_tuple" + fi + + tuple=$(sed -ne 's/^ *PRODUCTVERSION *//p' "$rcfile" | tr -d '\r') + + if [ "$ref_tuple" = "$tuple" ]; then + ok "$rcfile PRODUCTVERSION $tuple" + else + not_ok "$rcfile PRODUCTVERSION $tuple disagrees with SDL_sound.h $ref_tuple" + fi + + tuple=$(sed -Ene 's/^ *VALUE "FileVersion", "([0-9, ]*)\\0"\r?$/\1/p' "$rcfile" | tr -d '\r') + ref_tuple="${ref_major}, ${ref_minor}, ${ref_micro}, 0" + + if [ "$ref_tuple" = "$tuple" ]; then + ok "$rcfile FileVersion $tuple" + else + not_ok "$rcfile FileVersion $tuple disagrees with SDL_sound.h $ref_tuple" + fi + + tuple=$(sed -Ene 's/^ *VALUE "ProductVersion", "([0-9, ]*)\\0"\r?$/\1/p' "$rcfile" | tr -d '\r') + + if [ "$ref_tuple" = "$tuple" ]; then + ok "$rcfile ProductVersion $tuple" + else + not_ok "$rcfile ProductVersion $tuple disagrees with SDL_sound.h $ref_tuple" + fi +done + +# version=$(sed -Ene '/CFBundleShortVersionString/,+1 s/.*(.*)<\/string>.*/\1/p' Xcode/Info-Framework.plist) + +# if [ "$ref_version" = "$version" ]; then +# ok "Info-Framework.plist CFBundleShortVersionString $version" +# else +# not_ok "Info-Framework.plist CFBundleShortVersionString $version disagrees with SDL_sound.h $ref_version" +# fi + +# version=$(sed -Ene '/CFBundleVersion/,+1 s/.*(.*)<\/string>.*/\1/p' Xcode/Info-Framework.plist) + +# if [ "$ref_version" = "$version" ]; then +# ok "Info-Framework.plist CFBundleVersion $version" +# else +# not_ok "Info-Framework.plist CFBundleVersion $version disagrees with SDL_sound.h $ref_version" +# fi + +# For simplicity this assumes we'll never break ABI before SDL 3. +# dylib_compat=$(sed -Ene 's/.*DYLIB_COMPATIBILITY_VERSION = (.*);$/\1/p' Xcode/SDL_sound.xcodeproj/project.pbxproj) + +# case "$ref_minor" in +# (*[02468]) +# major="$(( ref_minor * 100 + 1 ))" +# minor="0" +# ;; +# (*) +# major="$(( ref_minor * 100 + ref_micro + 1 ))" +# minor="0" +# ;; +# esac + +# ref="${major}.${minor}.0 +# ${major}.${minor}.0" + +# if [ "$ref" = "$dylib_compat" ]; then +# ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent" +# else +# not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent, expected $ref, got $dylib_compat" +# fi + +# dylib_cur=$(sed -Ene 's/.*DYLIB_CURRENT_VERSION = (.*);$/\1/p' Xcode/SDL_sound.xcodeproj/project.pbxproj) + +# case "$ref_minor" in +# (*[02468]) +# major="$(( ref_minor * 100 + 1 ))" +# minor="$ref_micro" +# ;; +# (*) +# major="$(( ref_minor * 100 + ref_micro + 1 ))" +# minor="0" +# ;; +# esac + +# ref="${major}.${minor}.0 +# ${major}.${minor}.0" + +# if [ "$ref" = "$dylib_cur" ]; then +# ok "project.pbxproj DYLIB_CURRENT_VERSION is consistent" +# else +# not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref, got $dylib_cur" +# fi + +echo "1..$tests" +exit "$failed" diff --git a/cmake/SDL2_soundConfig.cmake.in b/cmake/SDL2_soundConfig.cmake.in deleted file mode 100644 index c92bdd01..00000000 --- a/cmake/SDL2_soundConfig.cmake.in +++ /dev/null @@ -1,34 +0,0 @@ -# sdl2_sound cmake project-config input - -@PACKAGE_INIT@ - -include(FeatureSummary) -set_package_properties(SDL2_sound PROPERTIES - URL "https://github.com/icculus/SDL_sound/" - DESCRIPTION " An abstract soundfile decoder" -) - -set(SDL2_sound_FOUND ON) - -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_sound-shared-targets.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/SDL2_sound-shared-targets.cmake") - set(SDL2_sound_SDL2_sound_FOUND TRUE) -endif() - -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_sound-static-targets.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/SDL2_sound-static-targets.cmake") - set(SDL2_sound_SDL2_sound-static_FOUND TRUE) -endif() - -check_required_components(SDL2_sound) - -# Create SDL2_sound::SDL2_sound alias for static-only builds -if(TARGET SDL2_sound::SDL2_sound-static AND NOT TARGET SDL2_sound::SDL2_sound) - if(CMAKE_VERSION VERSION_LESS "3.18") - # FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global. - add_library(SDL2_sound::SDL2_sound INTERFACE IMPORTED) - set_target_properties(SDL2_sound::SDL2_sound PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2_sound::SDL2_sound-static") - else() - add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound::SDL2_sound-static) - endif() -endif() diff --git a/cmake/SDL3_soundConfig.cmake.in b/cmake/SDL3_soundConfig.cmake.in new file mode 100644 index 00000000..6ff7c82c --- /dev/null +++ b/cmake/SDL3_soundConfig.cmake.in @@ -0,0 +1,34 @@ +# sdl3_sound cmake project-config input + +@PACKAGE_INIT@ + +include(FeatureSummary) +set_package_properties(SDL3_sound PROPERTIES + URL "https://github.com/icculus/SDL_sound/" + DESCRIPTION " An abstract soundfile decoder" +) + +set(SDL3_sound_FOUND ON) + +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_sound-shared-targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SDL3_sound-shared-targets.cmake") + set(SDL3_sound_SDL3_sound_FOUND TRUE) +endif() + +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_sound-static-targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SDL3_sound-static-targets.cmake") + set(SDL3_sound_SDL3_sound-static_FOUND TRUE) +endif() + +check_required_components(SDL3_sound) + +# Create SDL3_sound::SDL3_sound alias for static-only builds +if(TARGET SDL3_sound::SDL3_sound-static AND NOT TARGET SDL3_sound::SDL3_sound) + if(CMAKE_VERSION VERSION_LESS "3.18") + # FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global. + add_library(SDL3_sound::SDL3_sound INTERFACE IMPORTED) + set_target_properties(SDL3_sound::SDL3_sound PROPERTIES INTERFACE_LINK_LIBRARIES "SDL3_sound::SDL3_sound-static") + else() + add_library(SDL3_sound::SDL3_sound ALIAS SDL3_sound::SDL3_sound-static) + endif() +endif() diff --git a/cmake/SDL2_sound.pc.in b/cmake/sdl3-sound.pc.in similarity index 72% rename from cmake/SDL2_sound.pc.in rename to cmake/sdl3-sound.pc.in index 6f9bcf09..dfa2baf9 100644 --- a/cmake/SDL2_sound.pc.in +++ b/cmake/sdl3-sound.pc.in @@ -3,10 +3,10 @@ exec_prefix=${prefix} libdir=@CMAKE_INSTALL_FULL_LIBDIR@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -Name: SDL2_sound +Name: SDL3_sound Description: Sound library for Simple DirectMedia Layer Version: @SDLSOUND_VERSION@ -Requires: sdl2 -Libs: -L${libdir} -lSDL2_sound -Cflags: -I${includedir}/SDL2 +Requires: sdl3 +Libs: -L${libdir} -lSDL3_sound +Cflags: -I${includedir} Libs.private: @PC_LIBS@ diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt index 9fabf587..e3c0d289 100644 --- a/cmake/test/CMakeLists.txt +++ b/cmake/test/CMakeLists.txt @@ -5,43 +5,29 @@ project(sdl_test LANGUAGES C) cmake_policy(SET CMP0074 NEW) -# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL2_sound outside of sysroot +# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3_sound outside of sysroot set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) include(FeatureSummary) -option(TEST_SHARED "Test linking to shared SDL2_sound library" ON) +option(TEST_SHARED "Test linking to shared SDL3_sound library" ON) add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") -option(TEST_STATIC "Test linking to static SDL2_sound libary" ON) +option(TEST_STATIC "Test linking to static SDL3_sound libary" ON) add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") -macro(my_find_sdl2) - # FIXME: this should unconditionally use CMake config file - find_package(SDL2) - if(NOT TARGET SDL2::SDL2) - find_library(SDL2_LIBRARY NAMES SDL2) - find_path(SDL2_INCLUDE_DIRS FILES SDL.h SUFFIXES SDL2) - if(NOT SDL2_LIBRARY OR NOT SDL2_INCLUDE_DIRS) - message(FATAL_ERROR "Faild to find SDL2 (configure SDL2_LIBRARY and SDL2_INCLUDE_DIRS)") - endif() - add_library(SDL2::SDL2 SHARED IMPORTED) - set_target_properties(SDL2::SDL2 PROPERTIES IMPORTED_LOCATION "${SDL2_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}") - endif() -endmacro() - if(TEST_SHARED) - find_package(SDL2_sound REQUIRED CONFIG) - my_find_sdl2() + find_package(SDL3_sound REQUIRED CONFIG) + find_package(SDL3 REQUIRED CONFIG) add_executable(main_shared main.c) - target_link_libraries(main_shared PRIVATE SDL2_sound::SDL2_sound SDL2::SDL2) + target_link_libraries(main_shared PRIVATE SDL3_sound::SDL3_sound SDL3::SDL3) endif() if(TEST_STATIC) - find_package(SDL2_sound REQUIRED CONFIG) - my_find_sdl2() + find_package(SDL3_sound REQUIRED CONFIG) + find_package(SDL3 REQUIRED CONFIG) add_executable(main_static main.c) - target_link_libraries(main_static PRIVATE SDL2_sound::SDL2_sound-static SDL2::SDL2) + target_link_libraries(main_static PRIVATE SDL3_sound::SDL3_sound-static SDL3::SDL3) endif() feature_summary(WHAT ALL) diff --git a/cmake/test/main.c b/cmake/test/main.c index b4f1287b..7003a56b 100644 --- a/cmake/test/main.c +++ b/cmake/test/main.c @@ -1,11 +1,12 @@ #define SDL_MAIN_HANDLED -#include "SDL.h" -#include "SDL_sound.h" +#include +#include +#include #include int main(int argc, char *argv[]) { SDL_SetMainReady(); - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { fprintf(stderr, "SDL_Init: could not initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/docs/Doxyfile b/docs/Doxyfile index d876ce26..48145f92 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -790,7 +790,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = src/SDL_sound.h +INPUT = include/SDL3_sound/SDL_sound.h # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/docs/INSTALL.txt b/docs/INSTALL.txt index 6afce83a..273eb097 100644 --- a/docs/INSTALL.txt +++ b/docs/INSTALL.txt @@ -1,14 +1,14 @@ -HOW TO BUILD SDL_SOUND 2.x ... +HOW TO BUILD SDL_SOUND 3.x ... The 1.x branch of SDL_sound was pretty complicated to build, needing you to hunt down external libraries and poke through various incompatible project -files. We've simplified this as much as possible for SDL2_sound. Now there are +files. We've simplified this as much as possible for SDL3_sound. Now there are no external libraries (everything is built internally, either with source code we wrote or public domain code included with this project, and CMake manages building. -The only external library SDL2_sound needs is SDL2. We assume you are using -SDL2 already if you've come looking for this library. It can be found at +The only external library SDL3_sound needs is SDL3. We assume you are using +SDL3 already if you've come looking for this library. It can be found at https://www.libsdl.org/ @@ -34,7 +34,7 @@ compile it directly, instead of messing with it as an external library. There are no restrictions on doing this, even if you're writing commercial, closed-source software. -This assumes you are already using SDL2, which SDL_sound relies on. If +This assumes you are already using SDL3, which SDL_sound relies on. If not, you'll need to make sure SDL's header's are available and we can link against the SDL library. diff --git a/examples/playsound.c b/examples/playsound.c index bb635452..b69881f2 100644 --- a/examples/playsound.c +++ b/examples/playsound.c @@ -13,8 +13,9 @@ #ifdef _WIN32 #define SDL_MAIN_HANDLED /* this is a console-only app */ #endif -#include "SDL.h" -#include "SDL_sound.h" +#include +#include +#include #include @@ -38,7 +39,6 @@ static const char *option_list[] = "--decodebuf", "n Buffer n decoded bytes at a time (default 16384).", "--audiobuf", "n Buffer n samples to audio device (default 4096).", "--volume", "n Playback volume multiplier (default 1.0).", - "--stdin", "[ext] Read from stdin (treat data as format [ext])", "--version", " Display version information and exit.", "--decoders", " List supported data formats and exit.", "--predecode", " Decode entire sample before playback.", @@ -54,15 +54,11 @@ static void output_versions(const char *argv0) { Sound_Version compiled; Sound_Version linked; - SDL_version sdl_compiled; - SDL_version sdl_linked_ver; - const SDL_version *sdl_linked = &sdl_linked_ver; + int sdl_compiled = SDL_VERSION; + int sdl_linked = SDL_GetVersion(); SOUND_VERSION(&compiled); Sound_GetLinkedVersion(&linked); - SDL_VERSION(&sdl_compiled); - - SDL_GetVersion(&sdl_linked_ver); fprintf(stdout, "%s version %d.%d.%d\n" @@ -72,12 +68,16 @@ static void output_versions(const char *argv0) " and linked against %d.%d.%d.\n" " Compiled against SDL version %d.%d.%d,\n" " and linked against %d.%d.%d.\n\n", - argv0, - PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH, - compiled.major, compiled.minor, compiled.patch, - linked.major, linked.minor, linked.patch, - sdl_compiled.major, sdl_compiled.minor, sdl_compiled.patch, - sdl_linked->major, sdl_linked->minor, sdl_linked->patch); + argv0, + PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH, + compiled.major, compiled.minor, compiled.patch, + linked.major, linked.minor, linked.patch, + SDL_VERSIONNUM_MAJOR(sdl_compiled), + SDL_VERSIONNUM_MINOR(sdl_compiled), + SDL_VERSIONNUM_MICRO(sdl_compiled), + SDL_VERSIONNUM_MAJOR(sdl_linked), + SDL_VERSIONNUM_MINOR(sdl_linked), + SDL_VERSIONNUM_MICRO(sdl_linked)); } /* output_versions */ @@ -130,8 +130,6 @@ static void output_usage(const char *argv0) " Valid arguments to the --format option are:\n" " U8 Unsigned 8-bit.\n" " S8 Signed 8-bit.\n" - " U16LSB Unsigned 16-bit (least significant byte first).\n" - " U16MSB Unsigned 16-bit (most significant byte first).\n" " S16LSB Signed 16-bit (least significant byte first).\n" " S16MSB Signed 16-bit (most significant byte first).\n" " S32LSB Signed 32-bit (least significant byte first).\n" @@ -337,8 +335,6 @@ static void memcpy_with_volume(Sound_Sample *sample, Uint8 *dst, Uint8 *src, int len) { int i; - Uint16 *u16src = NULL; - Uint16 *u16dst = NULL; Sint16 *s16src = NULL; Sint16 *s16dst = NULL; Sint32 *s32src = NULL; @@ -357,98 +353,78 @@ static void memcpy_with_volume(Sound_Sample *sample, /* !!! FIXME: This would be more efficient with a lookup table. */ switch (sample->desired.format) { - case AUDIO_U8: + case SDL_AUDIO_U8: for (i = 0; i < len; i++, src++, dst++) *dst = (Uint8) (((float) (*src)) * volume); break; - case AUDIO_S8: + case SDL_AUDIO_S8: for (i = 0; i < len; i++, src++, dst++) *dst = (Sint8) (((float) (*src)) * volume); break; - case AUDIO_U16LSB: - u16src = (Uint16 *) src; - u16dst = (Uint16 *) dst; - for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) - { - *u16dst = (Uint16) (((float) (SDL_SwapLE16(*u16src))) * volume); - *u16dst = SDL_SwapLE16(*u16dst); - } /* for */ - break; - - case AUDIO_S16LSB: + case SDL_AUDIO_S16LE: s16src = (Sint16 *) src; s16dst = (Sint16 *) dst; for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) { - *s16dst = (Sint16) (((float) (SDL_SwapLE16(*s16src))) * volume); - *s16dst = SDL_SwapLE16(*s16dst); + *s16dst = (Sint16) (((float) (SDL_Swap16LE(*s16src))) * volume); + *s16dst = SDL_Swap16LE(*s16dst); } /* for */ break; - case AUDIO_U16MSB: - u16src = (Uint16 *) src; - u16dst = (Uint16 *) dst; - for (i = 0; i < len; i += sizeof (Uint16), u16src++, u16dst++) - { - *u16dst = (Uint16) (((float) (SDL_SwapBE16(*u16src))) * volume); - *u16dst = SDL_SwapBE16(*u16dst); - } /* for */ - break; - - case AUDIO_S16MSB: + case SDL_AUDIO_S16BE: s16src = (Sint16 *) src; s16dst = (Sint16 *) dst; for (i = 0; i < len; i += sizeof (Sint16), s16src++, s16dst++) { - *s16dst = (Sint16) (((float) (SDL_SwapBE16(*s16src))) * volume); - *s16dst = SDL_SwapBE16(*s16dst); + *s16dst = (Sint16)(((float) (SDL_Swap16BE(*s16src))) * volume); + *s16dst = SDL_Swap16BE(*s16dst); } /* for */ break; - case AUDIO_S32LSB: + case SDL_AUDIO_S32LE: s32src = (Sint32 *) src; s32dst = (Sint32 *) dst; for (i = 0; i < len; i += sizeof (Sint32), s32src++, s32dst++) { - *s32dst = (Sint32) (((double) (SDL_SwapLE32(*s32src))) * volume); - *s32dst = SDL_SwapLE32(*s32dst); + *s32dst = (Sint32)(((double) (SDL_Swap32LE(*s32src))) * volume); + *s32dst = SDL_Swap32LE(*s32dst); } /* for */ break; - case AUDIO_S32MSB: + case SDL_AUDIO_S32BE: s32src = (Sint32 *) src; s32dst = (Sint32 *) dst; for (i = 0; i < len; i += sizeof (Sint32), s32src++, s32dst++) { - *s32dst = (Sint32) (((double) (SDL_SwapBE32(*s32src))) * volume); - *s32dst = SDL_SwapBE32(*s32dst); + *s32dst = (Sint32)(((double) (SDL_Swap32BE(*s32src))) * volume); + *s32dst = SDL_Swap32BE(*s32dst); } /* for */ break; - case AUDIO_F32LSB: + case SDL_AUDIO_F32LE: f32src = (float *) src; f32dst = (float *) dst; for (i = 0; i < len; i += sizeof (float), f32src++, f32dst++) { floatswapper.f = *f32src; - floatswapper.ui32 = SDL_SwapLE32(floatswapper.ui32); + floatswapper.ui32 = SDL_Swap32LE(floatswapper.ui32); floatswapper.f *= volume; - floatswapper.ui32 = SDL_SwapLE32(floatswapper.ui32); + floatswapper.ui32 = SDL_Swap32LE(floatswapper.ui32); *f32dst = floatswapper.f; } /* for */ break; - case AUDIO_F32MSB: + case SDL_AUDIO_F32BE: f32src = (float *) src; f32dst = (float *) dst; for (i = 0; i < len; i += sizeof (float), f32src++, f32dst++) { floatswapper.f = *f32src; - floatswapper.ui32 = SDL_SwapBE32(floatswapper.ui32); + floatswapper.ui32 = SDL_Swap32BE(floatswapper.ui32); floatswapper.f *= volume; - floatswapper.ui32 = SDL_SwapBE32(floatswapper.ui32); + floatswapper.ui32 = SDL_Swap32BE(floatswapper.ui32); *f32dst = floatswapper.f; } /* for */ break; @@ -494,6 +470,19 @@ static void SDLCALL audio_callback(void *userdata, Uint8 *stream, int len) } /* while */ } /* audio_callback */ +void SDLCALL sdl3_audio_callback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount) +{ + if (additional_amount > 0) + { + Uint8 *data = SDL_stack_alloc(Uint8, additional_amount); + if (data) + { + audio_callback(userdata, data, additional_amount); + SDL_PutAudioStreamData(stream, data, additional_amount); + SDL_stack_free(data); + } + } +} static int count_seek_list(const char *list) { @@ -585,25 +574,21 @@ static void parse_seek_list(const char *_list) static int str_to_fmt(char *str) { if (SDL_strcmp(str, "U8") == 0) - return AUDIO_U8; + return SDL_AUDIO_U8; if (SDL_strcmp(str, "S8") == 0) - return AUDIO_S8; - if (SDL_strcmp(str, "U16LSB") == 0) - return AUDIO_U16LSB; + return SDL_AUDIO_S8; if (SDL_strcmp(str, "S16LSB") == 0) - return AUDIO_S16LSB; - if (SDL_strcmp(str, "U16MSB") == 0) - return AUDIO_U16MSB; + return SDL_AUDIO_S16LE; if (SDL_strcmp(str, "S16MSB") == 0) - return AUDIO_S16MSB; + return SDL_AUDIO_S16BE; if (SDL_strcmp(str, "S32LSB") == 0) - return AUDIO_S32LSB; + return SDL_AUDIO_S32LE; if (SDL_strcmp(str, "S32MSB") == 0) - return AUDIO_S32MSB; + return SDL_AUDIO_S32BE; if (SDL_strcmp(str, "F32LSB") == 0) - return AUDIO_F32LSB; + return SDL_AUDIO_F32LE; if (SDL_strcmp(str, "F32MSB") == 0) - return AUDIO_F32MSB; + return SDL_AUDIO_F32BE; return 0; } /* str_to_fmt */ @@ -734,7 +719,7 @@ int main(int argc, char **argv) } /* else if */ } /* for */ - if (SDL_Init(sdl_init_flags) == -1) + if (!SDL_Init(sdl_init_flags)) { fprintf(stderr, "SDL_Init() failed!\n" " reason: [%s].\n", SDL_GetError()); @@ -763,6 +748,7 @@ int main(int argc, char **argv) for (i = 1; i < argc; i++) { const char *filename = NULL; + SDL_AudioStream *stream; /* set variables back to defaults for next file... */ if (new_sample) @@ -799,7 +785,7 @@ int main(int argc, char **argv) if (sound_desired.format == 0) { fprintf(stderr, "Bad argument to --format! Try one of:\n" - "U8, S8, U16LSB, S16LSB, U16MSB, S16MSB, S32LSB, S32MSB, F32LSB, L32MSB\n"); + "U8, S8, S16LSB, S16MSB, S32LSB, S32MSB, F32LSB, L32MSB\n"); return(42); } /* if */ } /* else if */ @@ -849,20 +835,6 @@ int main(int argc, char **argv) parse_seek_list(argv[++i]); } /* else if */ - else if (SDL_strcmp(argv[i], "--stdin") == 0) - { - SDL_RWops *rw = SDL_RWFromFP(stdin, 1); - filename = "...from stdin..."; - - /* - * The second argument will be NULL if --stdin is the last - * thing on the command line. This is correct behaviour. - */ - sample = Sound_NewSample(rw, argv[++i], - use_specific_audiofmt ? &sound_desired : NULL, - decode_buffersize); - } /* if */ - else if (SDL_strncmp(argv[i], "--", 2) == 0) { /* ignore it, since it was handled at startup. */ @@ -917,14 +889,10 @@ int main(int argc, char **argv) sdl_desired.channels = sample->actual.channels; } /* else */ - sdl_desired.samples = audio_buffersize; - sdl_desired.callback = audio_callback; - sdl_desired.userdata = sample; - /* grr, SDL_CloseAudio() calls SDL_QuitSubSystem internally. */ if (!SDL_WasInit(SDL_INIT_AUDIO)) { - if (SDL_Init(SDL_INIT_AUDIO) == -1) + if (!SDL_Init(SDL_INIT_AUDIO)) { fprintf(stderr, "SDL_Init() failed!\n" " reason: [%s].\n", SDL_GetError()); @@ -936,7 +904,8 @@ int main(int argc, char **argv) report_filename(filename); - if (SDL_OpenAudio(&sdl_desired, NULL) < 0) + stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &sdl_desired, sdl3_audio_callback, sample); + if (stream == NULL) { fprintf(stderr, "Couldn't open audio device!\n" " reason: [%s].\n", SDL_GetError()); @@ -966,7 +935,7 @@ int main(int argc, char **argv) fflush(stdout); } /* if */ - SDL_PauseAudio(0); + SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); done_flag = 0; /* the audio callback will flip this flag. */ while (!done_flag) @@ -980,17 +949,17 @@ int main(int argc, char **argv) SDL_Delay(10); } /* while */ - SDL_PauseAudio(1); + SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream)); /* * Sleep two buffers' worth of audio before closing, in order * to allow the playback to finish. This isn't always enough; * perhaps SDL needs a way to explicitly wait for device drain? */ - delay = 2 * 1000 * sdl_desired.samples / sdl_desired.freq; + delay = 2 * 1000 * audio_buffersize / sdl_desired.freq; SDL_Delay(delay); - SDL_CloseAudio(); /* reopen with next sample's format if possible */ + SDL_CloseAudioDevice(SDL_GetAudioStreamDevice(stream)); /* reopen with next sample's format if possible */ Sound_FreeSample(sample); if (done_flag < 0) diff --git a/examples/playsound_simple.c b/examples/playsound_simple.c index d8d94d54..157e7c3d 100644 --- a/examples/playsound_simple.c +++ b/examples/playsound_simple.c @@ -18,8 +18,9 @@ #ifdef _WIN32 #define SDL_MAIN_HANDLED /* this is a console-only app */ #endif -#include "SDL.h" -#include "SDL_sound.h" +#include +#include +#include /* global decoding state. */ typedef struct @@ -95,10 +96,27 @@ static void SDLCALL audio_callback(void *userdata, Uint8 *stream, int len) } /* while */ } /* audio_callback */ +void SDLCALL sdl3_audio_callback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount) +{ + if (additional_amount > 0) + { + Uint8 *data = SDL_stack_alloc(Uint8, additional_amount); + if (data) + { + audio_callback(userdata, data, additional_amount); + SDL_PutAudioStreamData(stream, data, additional_amount); + SDL_stack_free(data); + } + } +} + static void playOneSoundFile(const char *fname) { + SDL_AudioStream *stream; PlaysoundAudioCallbackData data; + SDL_AudioSpec spec; + int sample_frames; SDL_zero(data); data.sample = Sound_NewSampleFromFile(fname, NULL, 65536); @@ -120,10 +138,9 @@ static void playOneSoundFile(const char *fname) data.devformat.freq = data.sample->actual.rate; data.devformat.format = data.sample->actual.format; data.devformat.channels = data.sample->actual.channels; - data.devformat.samples = 4096; /* I just picked a largish number here. */ - data.devformat.callback = audio_callback; - data.devformat.userdata = &data; - if (SDL_OpenAudio(&data.devformat, NULL) < 0) + + stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &data.devformat, sdl3_audio_callback, &data); + if (stream == NULL) { fprintf(stderr, "Couldn't open audio device: %s.\n", SDL_GetError()); Sound_FreeSample(data.sample); @@ -131,14 +148,14 @@ static void playOneSoundFile(const char *fname) } /* if */ printf("Now playing [%s]...\n", fname); - SDL_PauseAudio(0); /* SDL audio device is "paused" right after opening. */ + SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); /* SDL audio device is "paused" right after opening. */ global_done_flag = 0; /* the audio callback will flip this flag. */ while (!global_done_flag) SDL_Delay(10); /* just wait for the audio callback to finish. */ /* at this point, we've played the entire audio file. */ - SDL_PauseAudio(1); /* so stop the device. */ + SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream)); /* so stop the device. */ /* * Sleep two buffers' worth of audio before closing, in order @@ -149,14 +166,16 @@ static void playOneSoundFile(const char *fname) * As an alternative for this app, you could also change the callback * to write silence for a call or two before flipping global_done_flag. */ - SDL_Delay(2 * 1000 * data.devformat.samples / data.devformat.freq); + sample_frames = 0; + SDL_GetAudioDeviceFormat(SDL_GetAudioStreamDevice(stream), &spec, &sample_frames); + SDL_Delay(sample_frames * 1000 / spec.freq); /* if there was an error, tell the user. */ if (data.sample->flags & SOUND_SAMPLEFLAG_ERROR) fprintf(stderr, "Error decoding file: %s\n", Sound_GetError()); Sound_FreeSample(data.sample); /* clean up SDL_Sound resources... */ - SDL_CloseAudio(); /* will reopen with next file's format. */ + SDL_CloseAudioDevice(SDL_GetAudioStreamDevice(stream)); /* will reopen with next file's format. */ } /* playOneSoundFile */ @@ -181,4 +200,3 @@ int main(int argc, char **argv) } /* main */ /* end of playsound-simple.c ... */ - diff --git a/src/SDL_sound.h b/include/SDL3_sound/SDL_sound.h similarity index 98% rename from src/SDL_sound.h rename to include/SDL3_sound/SDL_sound.h index 72a5cd0d..c468626f 100644 --- a/src/SDL_sound.h +++ b/include/SDL3_sound/SDL_sound.h @@ -47,13 +47,13 @@ * \author many others, please see CREDITS in the source's root directory. */ -#ifndef _INCLUDE_SDL_SOUND_H_ -#define _INCLUDE_SDL_SOUND_H_ +#ifndef SDL_SOUND_H_ +#define SDL_SOUND_H_ -#include "SDL.h" +#include -#if SDL_MAJOR_VERSION < 2 -#error SDL2_sound requires SDL 2.0.0 or later. +#if SDL_MAJOR_VERSION < 3 +#error SDL3_sound requires SDL 3.0.0 or later. #endif #ifdef __cplusplus @@ -62,17 +62,17 @@ extern "C" { #ifndef DOXYGEN_SHOULD_IGNORE_THIS -#if defined(SDL_SOUND_DLL_EXPORTS) && (defined(_WIN32) || defined(__OS2__)) +#if defined(SDL_SOUND_DLL_EXPORTS) && defined(_WIN32) # define SNDDECLSPEC __declspec(dllexport) -#elif ((defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)) && !(defined(_WIN32) || defined(__OS2__)) +#elif ((defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)) && !defined(_WIN32) # define SNDDECLSPEC __attribute__((visibility("default"))) #else # define SNDDECLSPEC #endif -#define SOUND_VER_MAJOR 2 +#define SOUND_VER_MAJOR 3 #define SOUND_VER_MINOR 0 -#define SOUND_VER_PATCH 3 +#define SOUND_VER_PATCH 0 #endif @@ -433,7 +433,7 @@ SNDDECLSPEC void SDLCALL Sound_ClearError(void); * \sa Sound_Rewind * \sa Sound_FreeSample */ -SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSample(SDL_RWops *rw, +SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSample(SDL_IOStream *rw, const char *ext, Sound_AudioInfo *desired, Uint32 bufferSize); @@ -719,7 +719,7 @@ SNDDECLSPEC int SDLCALL Sound_Seek(Sound_Sample *sample, Uint32 ms); } #endif -#endif /* !defined _INCLUDE_SDL_SOUND_H_ */ +#endif /* !defined SDL_SOUND_H_ */ /* end of SDL_sound.h ... */ diff --git a/src/Makefile.os2 b/src/Makefile.os2 deleted file mode 100644 index 45f6fe1c..00000000 --- a/src/Makefile.os2 +++ /dev/null @@ -1,139 +0,0 @@ -# Open Watcom makefile to build SDL_sound for OS/2 -# wmake -f Makefile.os2 -# -# Remember to edit DEPS_INC and DEPS_LIB below to meet -# your own environment!. - -# change DEPS_INC in order to point to the dependency headers. -DEPS_INC=-IC:\SDL2DEV\h\SDL2 -# change DEPS_LIB in order to point to the dependency libraries. -DEPS_LIB=C:\SDL2DEV\lib - -LIBNAME = SDL2snd -VERSION = 2.0.3 - -LIBFILE = $(LIBNAME).lib -DLLFILE = $(LIBNAME).dll -LNKFILE = $(LIBNAME).lnk - -MODPLIB = modplug.lib -TIMILIB = timidity.lib - -TITLENAME = $(LIBNAME) $(VERSION) - -SRCS = SDL_sound_aiff.c SDL_sound_au.c SDL_sound_raw.c SDL_sound_shn.c & - SDL_sound_voc.c SDL_sound_wav.c SDL_sound_flac.c SDL_sound_mp3.c & - SDL_sound_vorbis.c SDL_sound_midi.c SDL_sound_modplug.c SDL_sound.c - -MODPSRCS = modplug.c sndfile.c fastmix.c snd_dsp.c snd_flt.c snd_fx.c sndmix.c & - load_669.c load_amf.c load_ams.c load_dbm.c load_dmf.c load_dsm.c & - load_far.c load_it.c load_mdl.c load_med.c load_mod.c load_mt2.c & - load_mtm.c load_okt.c load_psm.c load_ptm.c load_s3m.c load_stm.c & - load_gdm.c load_ult.c load_umx.c load_xm.c mmcmp.c - -TIMISRCS = common.c instrum.c mix.c output.c playmidi.c readmidi.c resample.c & - tables.c timidity.c - -OBJS = $(SRCS:.c=.obj) -MODPOBJS = $(MODPSRCS:.c=.obj) -TIMIOBJS = $(TIMISRCS:.c=.obj) - -CFLAGS_BASE = -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oeatxh -ei -j -CFLAGS_BASE+= -DNDEBUG -# warnings: -CFLAGS_BASE+= -wx -# newer OpenWatcom versions enable W303 by default -CFLAGS_BASE+= -wcd=303 -# include paths: -CFLAGS_BASE+= -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" -CFLAGS_BASE+= -I. $(DEPS_INC) -CFLAGS = $(CFLAGS_BASE) -# to build a dll: -CFLAGS+= -bd -# for DECLSPEC: -CFLAGS+= -DBUILD_SDL -DSDL_SOUND_DLL_EXPORTS - -# These already default to 1: see in SDL_sound_internal.h. -#CFLAGS+= -DSOUND_SUPPORTS_MP3 & -# -DSOUND_SUPPORTS_MODPLUG & -# -DSOUND_SUPPORTS_MIDI & -# -DSOUND_SUPPORTS_WAV & -# -DSOUND_SUPPORTS_AIFF & -# -DSOUND_SUPPORTS_AU & -# -DSOUND_SUPPORTS_VORBIS & -# -DSOUND_SUPPORTS_VOC & -# -DSOUND_SUPPORTS_SHN & -# -DSOUND_SUPPORTS_RAW & -# -DSOUND_SUPPORTS_FLAC - -LIBSDL = SDL2.lib -LIBS = $(LIBSDL) $(MODPLIB) $(TIMILIB) - -.extensions: -.extensions: .lib .dll .obj .c - -all: $(DLLFILE) playsound.exe playsound_simple.exe - -.c: decoders -.c: examples - -$(LIBFILE): $(DLLFILE) - @echo * Create library: $@... - wlib -b -n -q -c -pa -s -t -zld -ii -io $@ $(DLLFILE) - -$(DLLFILE): $(OBJS) $(MODPLIB) $(TIMILIB) $(LNKFILE) - @echo * Link: $@ - wlink @$(LNKFILE) - -$(LNKFILE): - @%create $@ - @%append $@ SYSTEM os2v2_dll INITINSTANCE TERMINSTANCE - @%append $@ NAME $(LIBNAME) - @for %i in ($(OBJS)) do @%append $@ FILE %i - @%append $@ OPTION QUIET - @%append $@ OPTION DESCRIPTION '@$#icculus org:$(VERSION)$#@Simple DirectMedia Layer, abstract soundfile decoder' - @%append $@ LIBPATH $(DEPS_LIB) - @for %i in ($(LIBS)) do @%append $@ LIB %i - @%append $@ OPTION MAP=$^&.map - @%append $@ OPTION ELIMINATE - @%append $@ OPTION MANYAUTODATA - @%append $@ OPTION STACK=0x40000 - @%append $@ OPTION OSNAME='OS/2 and eComStation' - @%append $@ OPTION SHOWDEAD - -.c.obj: - wcc386 $(CFLAGS) -fo=$^@ $< - -playsound.obj: "../examples/playsound.c" - wcc386 $(CFLAGS_BASE) -DHAVE_SIGNAL_H=1 -DHAVE_SETBUF=1 -DHAVE_ASSERT_H=1 -fo=$^@ $< -playsound_simple.obj: "../examples/playsound_simple.c" - wcc386 $(CFLAGS_BASE) -fo=$^@ $< - -playsound.exe: $(LIBFILE) playsound.obj - @echo * Link: $@ - wlink SYS os2v2 LIBPATH $(DEPS_LIB) LIBR {$(LIBFILE) $(LIBSDL)} op q op el op stack=0x40000 F {playsound.obj} N playsound.exe - -playsound_simple.exe: $(LIBFILE) playsound_simple.obj - @echo * Link: $@ - wlink SYS os2v2 LIBPATH $(DEPS_LIB) LIBR {$(LIBFILE) $(LIBSDL)} op q op el op stack=0x40000 F {playsound_simple.obj} N playsound_simple.exe - -.c: libmodplug; -modplug.lib: $(MODPOBJS) - wlib -b -n -q -c -pa -s -t -zld -ii -io $@ $(MODPOBJS) - -.c: timidity; -timidity.lib: $(TIMIOBJS) - wlib -b -n -q -c -pa -s -t -zld -ii -io $@ $(TIMIOBJS) - -clean: .SYMBOLIC - @echo * Clean: $(TITLENAME) - @if exist *.obj rm *.obj - @if exist *.err rm *.err - @if exist $(MODPLIB) rm $(MODPLIB) - @if exist $(TIMILIB) rm $(TIMILIB) - @if exist $(LNKFILE) rm $(LNKFILE) -distclean: .SYMBOLIC clean - @if exist $(DLLFILE) rm $(DLLFILE) - @if exist $(LIBFILE) rm $(LIBFILE) - @if exist *.map rm *.map - @if exist *.exe rm *.exe diff --git a/src/SDL_sound.c b/src/SDL_sound.c index 78293918..2918cb1d 100644 --- a/src/SDL_sound.c +++ b/src/SDL_sound.c @@ -34,7 +34,7 @@ extern const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio; typedef struct { - SDL_bool available; + bool available; const Sound_DecoderFunctions *funcs; } decoder_element; @@ -84,16 +84,16 @@ static decoder_element decoders[] = /* General SDL_sound state ... */ -static SDL_TLSID tlsid_errmsg = 0; +static SDL_TLSID tlsid_errmsg; typedef struct { - SDL_bool error_available; + bool error_available; char error_string[128]; } ErrMsg; static Sound_Sample *sample_list = NULL; /* this is a linked list. */ -static SDL_mutex *samplelist_mutex = NULL; +static SDL_Mutex *samplelist_mutex = NULL; static const Sound_DecoderInfo **available_decoders = NULL; static int initialized = 0; @@ -127,7 +127,8 @@ int Sound_Init(void) SDL_InitSubSystem(SDL_INIT_AUDIO); - tlsid_errmsg = SDL_TLSCreate(); + tlsid_errmsg.value = 0; + BAIL_IF_MACRO(!SDL_SetTLS(&tlsid_errmsg, NULL, NULL), ERR_OUT_OF_MEMORY, 0); samplelist_mutex = SDL_CreateMutex(); @@ -174,7 +175,7 @@ int Sound_Quit(void) SDL_free((void *) available_decoders); available_decoders = NULL; - tlsid_errmsg = 0; + tlsid_errmsg.value = 0; return 1; } /* Sound_Quit */ @@ -185,10 +186,9 @@ const Sound_DecoderInfo **Sound_AvailableDecoders(void) return available_decoders; /* READ. ONLY. */ } /* Sound_AvailableDecoders */ - static ErrMsg *findErrorForCurrentThread(void) { - return (ErrMsg *) SDL_TLSGet(tlsid_errmsg); + return (ErrMsg *) SDL_GetTLS(&tlsid_errmsg); } @@ -204,7 +204,7 @@ const char *Sound_GetError(void) if ((err != NULL) && (err->error_available)) { retval = err->error_string; - err->error_available = SDL_FALSE; + err->error_available = false; } /* if */ return retval; @@ -239,10 +239,10 @@ void __Sound_SetError(const char *str) if (err == NULL) return; /* uhh...? */ - SDL_TLSSet(tlsid_errmsg, err, SDL_free); + SDL_SetTLS(&tlsid_errmsg, err, SDL_free); } /* if */ - err->error_available = SDL_TRUE; + err->error_available = true; SDL_strlcpy(err->error_string, str, sizeof (err->error_string)); } /* __Sound_SetError */ @@ -261,8 +261,8 @@ Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms) * Allocate a Sound_Sample, and fill in most of its fields. Those that need * to be filled in later, by a decoder, will be initialized to zero. */ -static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, - Uint32 bufferSize) +static Sound_Sample *alloc_sample(SDL_IOStream *rw, Sound_AudioInfo *desired, + Uint32 bufferSize) { /* * !!! FIXME: We're going to need to pool samples, since the mixer @@ -307,25 +307,21 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, static SDL_INLINE const char *fmt_to_str(Uint16 fmt) { switch(fmt) { - case AUDIO_U8: + case SDL_AUDIO_U8: return "U8"; - case AUDIO_S8: + case SDL_AUDIO_S8: return "S8"; - case AUDIO_U16LSB: - return "U16LSB"; - case AUDIO_S16LSB: + case SDL_AUDIO_S16LE: return "S16LSB"; - case AUDIO_S32LSB: + case SDL_AUDIO_S32LE: return "S32LSB"; - case AUDIO_F32LSB: + case SDL_AUDIO_F32LE: return "F32LSB"; - case AUDIO_U16MSB: - return "U16MSB"; - case AUDIO_S16MSB: + case SDL_AUDIO_S16BE: return "S16MSB"; - case AUDIO_S32MSB: + case SDL_AUDIO_S32BE: return "S32MSB"; - case AUDIO_F32MSB: + case SDL_AUDIO_F32BE: return "F32MSB"; } /* switch */ return "Unknown"; @@ -345,14 +341,14 @@ static int init_sample(const Sound_DecoderFunctions *funcs, { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; Sound_AudioInfo desired; - const Sint64 pos = SDL_RWtell(internal->rw); + const Sint64 pos = SDL_TellIO(internal->rw); /* fill in the funcs for this decoder... */ sample->decoder = &funcs->info; internal->funcs = funcs; if (!funcs->open(sample, ext)) { - SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */ + SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); /* set for next try... */ return 0; } /* if */ @@ -373,18 +369,23 @@ static int init_sample(const Sound_DecoderFunctions *funcs, (sample->actual.channels != desired.channels) || (sample->actual.rate != desired.rate) ) { - internal->stream = SDL_NewAudioStream(sample->actual.format, - sample->actual.channels, - sample->actual.rate, - desired.format, - desired.channels, - desired.rate); + SDL_AudioSpec src_spec, dst_spec; + + src_spec.format = sample->actual.format, + src_spec.channels = sample->actual.channels, + src_spec.freq = sample->actual.rate, + dst_spec.format = desired.format, + dst_spec.channels = desired.channels, + dst_spec.freq = desired.rate, + + internal->stream = SDL_CreateAudioStream(&src_spec, + &dst_spec); if (internal->stream == NULL) { __Sound_SetError(SDL_GetError()); funcs->close(sample); - SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */ + SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); /* set for next try... */ return 0; } /* if */ } /* if */ @@ -420,7 +421,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs, } /* init_sample */ -Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, +Sound_Sample *Sound_NewSample(SDL_IOStream *rw, const char *ext, Sound_AudioInfo *desired, Uint32 bSize) { Sound_Sample *retval; @@ -486,13 +487,13 @@ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, /* !!! FIXME: can we just push this through Sound_FreeSample() ? */ if (retval->opaque != NULL) { - SDL_FreeAudioStream(((Sound_SampleInternal *) retval->opaque)->stream); + SDL_DestroyAudioStream(((Sound_SampleInternal *) retval->opaque)->stream); SDL_free(retval->opaque); } /* if */ __Sound_SIMDFree(retval->buffer); SDL_free(retval); - SDL_RWclose(rw); + SDL_CloseIO(rw); __Sound_SetError(ERR_UNSUPPORTED_FORMAT); return NULL; } /* Sound_NewSample */ @@ -503,13 +504,13 @@ Sound_Sample *Sound_NewSampleFromFile(const char *filename, Uint32 bufferSize) { const char *ext; - SDL_RWops *rw; + SDL_IOStream *rw; BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL); ext = SDL_strrchr(filename, '.'); - rw = SDL_RWFromFile(filename, "rb"); + rw = SDL_IOFromFile(filename, "rb"); BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); if (ext != NULL) @@ -525,13 +526,13 @@ Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data, Sound_AudioInfo *desired, Uint32 bufferSize) { - SDL_RWops *rw; + SDL_IOStream *rw; BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); BAIL_IF_MACRO(data == NULL, ERR_INVALID_ARGUMENT, NULL); BAIL_IF_MACRO(size == 0, ERR_INVALID_ARGUMENT, NULL); - rw = SDL_RWFromConstMem(data, size); + rw = SDL_IOFromConstMem(data, size); BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); return Sound_NewSample(rw, ext, desired, bufferSize); @@ -584,9 +585,9 @@ void Sound_FreeSample(Sound_Sample *sample) internal->funcs->close(sample); if (internal->rw != NULL) /* this condition is a "just in case" thing. */ - SDL_RWclose(internal->rw); + SDL_CloseIO(internal->rw); - SDL_FreeAudioStream(internal->stream); + SDL_DestroyAudioStream(internal->stream); SDL_free(internal); __Sound_SIMDFree(sample->buffer); SDL_free(sample); @@ -638,9 +639,9 @@ Uint32 Sound_Decode(Sound_Sample *sample) } /* if */ /* call into the decoder several times until we have enough data. */ - while ((available = SDL_AudioStreamAvailable(internal->stream)) < internal->buffer_size) + while ((available = SDL_GetAudioStreamAvailable(internal->stream)) < internal->buffer_size) { - SDL_bool flush_stream = SDL_FALSE; + bool flush_stream = false; Uint32 br; if (internal->pending_eof || internal->pending_error) @@ -655,18 +656,18 @@ Uint32 Sound_Decode(Sound_Sample *sample) if (sample->flags & SOUND_SAMPLEFLAG_EOF) { sample->flags &= ~SOUND_SAMPLEFLAG_EOF; - internal->pending_eof = SDL_TRUE; - flush_stream = SDL_TRUE; + internal->pending_eof = true; + flush_stream = true; } /* if */ if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { sample->flags &= ~SOUND_SAMPLEFLAG_ERROR; - internal->pending_error = SDL_TRUE; - flush_stream = SDL_TRUE; + internal->pending_error = true; + flush_stream = true; } /* if */ - if ((br > 0) && (SDL_AudioStreamPut(internal->stream, internal->buffer, (int) br) == -1)) + if ((br > 0) && (!SDL_PutAudioStreamData(internal->stream, internal->buffer, (int) br))) { __Sound_SetError(SDL_GetError()); sample->flags |= SOUND_SAMPLEFLAG_ERROR; @@ -674,14 +675,14 @@ Uint32 Sound_Decode(Sound_Sample *sample) } /* if */ if (flush_stream) - SDL_AudioStreamFlush(internal->stream); + SDL_FlushAudioStream(internal->stream); } /* while */ /* if we hit eof or error, drain the stream before reporting that. */ if (available > 0) { const int readlen = SDL_min(available, sample->buffer_size); - const int br = SDL_AudioStreamGet(internal->stream, sample->buffer, readlen); + const int br = SDL_GetAudioStreamData(internal->stream, sample->buffer, readlen); if (br != readlen) { __Sound_SetError(SDL_GetError()); @@ -700,7 +701,7 @@ Uint32 Sound_Decode(Sound_Sample *sample) if (internal->pending_error) sample->flags |= SOUND_SAMPLEFLAG_ERROR; - internal->pending_eof = internal->pending_error = SDL_FALSE; + internal->pending_eof = internal->pending_error = false; return 0; } /* Sound_Decode */ @@ -798,144 +799,49 @@ Sint32 Sound_GetDuration(Sound_Sample *sample) /* Utility functions ... */ -/* The following uses the implementation suggested by - * the standard document, assumes RAND_MAX == 32767 */ -static unsigned long __Sound_seed = 1; -int __Sound_rand(void) -{ - __Sound_seed = __Sound_seed * 1103515245 + 12345; - return (__Sound_seed / 65536) % 32768; -} -void __Sound_srand(unsigned int seed) -{ - __Sound_seed = seed; -} - -#if !defined(HAVE_SDL_STRTOKR) -/* Adapted from _PDCLIB_strtok() of PDClib library at - * https://github.com/DevSolar/pdclib.git - * - * The code was under CC0 license: - * https://creativecommons.org/publicdomain/zero/1.0/legalcode - */ -char *__Sound_strtokr(char *s1, const char *s2, char **ptr) -{ - const char *p = s2; - - if (!s2 || !ptr || (!s1 && !*ptr)) return NULL; - - if (s1 != NULL) { /* new string */ - *ptr = s1; - } else { /* old string continued */ - if (*ptr == NULL) { - /* No old string, no new string, nothing to do */ - return NULL; - } - s1 = *ptr; - } - - /* skip leading s2 characters */ - while (*p && *s1) { - if (*s1 == *p) { - /* found separator; skip and start over */ - ++s1; - p = s2; - continue; - } - ++p; - } - - if (! *s1) { /* no more to parse */ - *ptr = s1; - return NULL; - } - - /* skipping non-s2 characters */ - *ptr = s1; - while (**ptr) { - p = s2; - while (*p) { - if (**ptr == *p++) { - /* found separator; overwrite with '\0', position *ptr, return */ - *((*ptr)++) = '\0'; - return s1; - } - } - ++(*ptr); - } - - /* parsed to end of string */ - return s1; -} -#endif - - -/* This falls back to an included copy/paste of SDL's SIMDAlloc code if you aren't using a new enough SDL. - To keep this simple, the included copy assumes you need to align to 64 bytes, which is a little - wasteful but should work on everything from MMX to AVX-512. The real SDL checks the CPU at runtime - to decide what's available and aligns to smaller numbers if all you have is SSE, Altivec or NEON. - Not to mention this is just a second copy of the code that doesn't get attention...you should really - upgrade your SDL. Ideally this copy goes away at some point. */ - -#define USE_REAL_SDL_SIMDALLOC SDL_VERSION_ATLEAST(2, 0, 14) - void *__Sound_SIMDAlloc(const size_t len) { -#if USE_REAL_SDL_SIMDALLOC - return SDL_SIMDAlloc(len); -#else - const size_t alignment = 64; - const size_t padding = alignment - (len % alignment); - const size_t padded = (padding != alignment) ? (len + padding) : len; - Uint8 *retval = NULL; - Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *)); - if (ptr) { - /* store the actual allocated pointer right before our aligned pointer. */ - retval = ptr + sizeof (void *); - retval += alignment - (((size_t) retval) % alignment); - *(((void **) retval) - 1) = ptr; - } - return retval; -#endif + return SDL_aligned_alloc(SDL_GetSIMDAlignment(), len); } void *__Sound_SIMDRealloc(void *mem, const size_t len) { -#if USE_REAL_SDL_SIMDALLOC - return SDL_SIMDRealloc(mem, len); -#else - const size_t alignment = 64; - const size_t padding = alignment - (len % alignment); - const size_t padded = (padding != alignment) ? (len + padding) : len; - Uint8 *retval = (Uint8*) mem; + const size_t alignment = SDL_GetSIMDAlignment(); + const size_t padding = (alignment - (len % alignment)) % alignment; + Uint8 *retval = (Uint8 *)mem; void *oldmem = mem; size_t memdiff = 0, ptrdiff; Uint8 *ptr; + size_t to_allocate; + + /* alignment + padding + sizeof (void *) is bounded (a few hundred + * bytes max), so no need to check for overflow within that argument */ + if (!SDL_size_add_check_overflow(len, alignment + padding + sizeof(void *), &to_allocate)) { + return NULL; + } if (mem) { - void **realptr = (void **) mem; - realptr--; - mem = *(((void **) mem) - 1); + mem = *(((void **)mem) - 1); /* Check the delta between the real pointer and user pointer */ - memdiff = ((size_t) oldmem) - ((size_t) mem); + memdiff = ((size_t)oldmem) - ((size_t)mem); } - ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *)); + ptr = (Uint8 *) SDL_realloc(mem, to_allocate); if (ptr == NULL) { return NULL; /* Out of memory, bail! */ } /* Store the actual allocated pointer right before our aligned pointer. */ - retval = ptr + sizeof (void *); - retval += alignment - (((size_t) retval) % alignment); + retval = ptr + sizeof(void *); + retval += alignment - (((size_t)retval) % alignment); /* Make sure the delta is the same! */ if (mem) { - ptrdiff = ((size_t) retval) - ((size_t) ptr); + ptrdiff = ((size_t)retval) - ((size_t)ptr); if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */ - oldmem = (void*) (((uintptr_t) ptr) + memdiff); + oldmem = (void *)(((uintptr_t)ptr) + memdiff); /* Even though the data past the old `len` is undefined, this is the * only length value we have, and it guarantees that we copy all the @@ -946,22 +852,13 @@ void *__Sound_SIMDRealloc(void *mem, const size_t len) } /* Actually store the allocated pointer, finally. */ - *(((void **) retval) - 1) = ptr; + *(((void **)retval) - 1) = ptr; return retval; -#endif } void __Sound_SIMDFree(void *ptr) { -#if USE_REAL_SDL_SIMDALLOC - SDL_SIMDFree(ptr); -#else - if (ptr) { - void **realptr = (void **) ptr; - realptr--; - SDL_free(*(((void **) ptr) - 1)); - } -#endif + SDL_aligned_free(ptr); } /* end of SDL_sound.c ... */ diff --git a/src/SDL_sound_aiff.c b/src/SDL_sound_aiff.c index 0e1cc654..58139517 100644 --- a/src/SDL_sound_aiff.c +++ b/src/SDL_sound_aiff.c @@ -162,30 +162,30 @@ static Uint32 SANE_to_Uint32 (Uint8 *sanebuf) * Read in a comm_t from disk. This makes this process safe regardless of * the processor's byte order or how the comm_t structure is packed. */ -static int read_comm_chunk(SDL_RWops *rw, comm_t *comm) +static int read_comm_chunk(SDL_IOStream *rw, comm_t *comm) { Uint8 sampleRate[10]; /* skip reading the chunk ID, since it was already read at this point... */ comm->ckID = commID; - if (SDL_RWread(rw, &comm->ckDataSize, sizeof (comm->ckDataSize), 1) != 1) + if (SDL_ReadIO(rw, &comm->ckDataSize, sizeof (comm->ckDataSize)) != sizeof (comm->ckDataSize)) return 0; - comm->ckDataSize = SDL_SwapBE32(comm->ckDataSize); + comm->ckDataSize = SDL_Swap32BE(comm->ckDataSize); - if (SDL_RWread(rw, &comm->numChannels, sizeof (comm->numChannels), 1) != 1) + if (SDL_ReadIO(rw, &comm->numChannels, sizeof (comm->numChannels)) != sizeof (comm->numChannels)) return 0; - comm->numChannels = SDL_SwapBE16(comm->numChannels); + comm->numChannels = SDL_Swap16BE(comm->numChannels); - if (SDL_RWread(rw, &comm->numSampleFrames, sizeof (comm->numSampleFrames), 1) != 1) + if (SDL_ReadIO(rw, &comm->numSampleFrames, sizeof (comm->numSampleFrames)) != sizeof (comm->numSampleFrames)) return 0; - comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames); + comm->numSampleFrames = SDL_Swap32BE(comm->numSampleFrames); - if (SDL_RWread(rw, &comm->sampleSize, sizeof (comm->sampleSize), 1) != 1) + if (SDL_ReadIO(rw, &comm->sampleSize, sizeof (comm->sampleSize)) != sizeof (comm->sampleSize)) return 0; - comm->sampleSize = SDL_SwapBE16(comm->sampleSize); + comm->sampleSize = SDL_Swap16BE(comm->sampleSize); - if (SDL_RWread(rw, sampleRate, sizeof (sampleRate), 1) != 1) + if (SDL_ReadIO(rw, sampleRate, sizeof (sampleRate)) != sizeof (sampleRate)) return 0; comm->sampleRate = SANE_to_Uint32(sampleRate); @@ -194,10 +194,10 @@ static int read_comm_chunk(SDL_RWops *rw, comm_t *comm) + sizeof(comm->sampleSize) + sizeof(sampleRate)) { - if (SDL_RWread(rw, &comm->compressionType, - sizeof (comm->compressionType), 1) != 1) + if (SDL_ReadIO(rw, &comm->compressionType, + sizeof (comm->compressionType)) != sizeof (comm->compressionType)) return 0; - comm->compressionType = SDL_SwapBE32(comm->compressionType); + comm->compressionType = SDL_Swap32BE(comm->compressionType); } /* if */ else { @@ -226,25 +226,25 @@ typedef struct } ssnd_t; -static int read_ssnd_chunk(SDL_RWops *rw, ssnd_t *ssnd) +static int read_ssnd_chunk(SDL_IOStream *rw, ssnd_t *ssnd) { /* skip reading the chunk ID, since it was already read at this point... */ ssnd->ckID = ssndID; - if (SDL_RWread(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize), 1) != 1) + if (SDL_ReadIO(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize)) != sizeof (ssnd->ckDataSize)) return 0; - ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize); + ssnd->ckDataSize = SDL_Swap32BE(ssnd->ckDataSize); - if (SDL_RWread(rw, &ssnd->offset, sizeof (ssnd->offset), 1) != 1) + if (SDL_ReadIO(rw, &ssnd->offset, sizeof (ssnd->offset)) != sizeof (ssnd->offset)) return 0; - ssnd->offset = SDL_SwapBE32(ssnd->offset); + ssnd->offset = SDL_Swap32BE(ssnd->offset); - if (SDL_RWread(rw, &ssnd->blockSize, sizeof (ssnd->blockSize), 1) != 1) + if (SDL_ReadIO(rw, &ssnd->blockSize, sizeof (ssnd->blockSize)) != sizeof (ssnd->blockSize)) return 0; - ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize); + ssnd->blockSize = SDL_Swap32BE(ssnd->blockSize); - /* Leave the SDL_RWops position indicator at the start of the samples */ - if (SDL_RWseek(rw, ssnd->offset, RW_SEEK_CUR) == -1) + /* Leave the SDL_IOStream position indicator at the start of the samples */ + if (SDL_SeekIO(rw, ssnd->offset, SDL_IO_SEEK_CUR) == -1) return 0; return 1; @@ -269,7 +269,7 @@ static Uint32 read_sample_fmt_normal(Sound_Sample *sample) * We don't actually do any decoding, so we read the AIFF data * directly into the internal buffer... */ - retval = SDL_RWread(internal->rw, internal->buffer, 1, max); + retval = SDL_ReadIO(internal->rw, internal->buffer, max); a->bytesLeft -= retval; @@ -302,7 +302,7 @@ static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms) const fmt_t *fmt = &a->fmt; const Uint32 offset = __Sound_convertMsToBytePos(&sample->actual, ms); const Sint64 pos = (Sint64) (fmt->data_starting_offset + offset); - const Sint64 rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); a->bytesLeft = fmt->total_bytes - offset; return 1; /* success. */ @@ -315,7 +315,7 @@ static void free_fmt_normal(fmt_t *fmt) } /* free_fmt_normal */ -static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) +static int read_fmt_normal(SDL_IOStream *rw, fmt_t *fmt) { /* (don't need to read more from the RWops...) */ fmt->free = free_fmt_normal; @@ -332,9 +332,9 @@ static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) * Everything else... * *****************************************************************************/ -static SDL_bool AIFF_init(void) +static bool AIFF_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* AIFF_init */ @@ -344,28 +344,28 @@ static void AIFF_quit(void) } /* AIFF_quit */ -static int find_chunk(SDL_RWops *rw, Uint32 id) +static int find_chunk(SDL_IOStream *rw, Uint32 id) { Sint32 siz = 0; Uint32 _id = 0; while (1) { - BAIL_IF_MACRO(SDL_RWread(rw, &_id, sizeof (_id), 1) != 1, NULL, 0); - if (SDL_SwapLE32(_id) == id) + BAIL_IF_MACRO(SDL_ReadIO(rw, &_id, sizeof (_id)) != sizeof (_id), NULL, 0); + if (SDL_Swap32LE(_id) == id) return 1; - BAIL_IF_MACRO(SDL_RWread(rw, &siz, sizeof (siz), 1) != 1, NULL, 0); - siz = SDL_SwapBE32(siz); + BAIL_IF_MACRO(SDL_ReadIO(rw, &siz, sizeof (siz)) != sizeof (siz), NULL, 0); + siz = SDL_Swap32BE(siz); SDL_assert(siz > 0); - BAIL_IF_MACRO(SDL_RWseek(rw, siz, RW_SEEK_CUR) == -1, NULL, 0); + BAIL_IF_MACRO(SDL_SeekIO(rw, siz, SDL_IO_SEEK_CUR) == -1, NULL, 0); } /* while */ return 0; /* shouldn't hit this, but just in case... */ } /* find_chunk */ -static int read_fmt(SDL_RWops *rw, comm_t *c, fmt_t *fmt) +static int read_fmt(SDL_IOStream *rw, comm_t *c, fmt_t *fmt) { fmt->type = c->compressionType; @@ -389,7 +389,7 @@ static int read_fmt(SDL_RWops *rw, comm_t *c, fmt_t *fmt) static int AIFF_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; Uint32 chunk_id; Uint32 bytes_per_sample; Sint64 pos; @@ -397,15 +397,17 @@ static int AIFF_open(Sound_Sample *sample, const char *ext) ssnd_t s; aiff_t *a; - BAIL_IF_MACRO(SDL_ReadLE32(rw) != formID, "AIFF: Not a FORM file.", 0); - SDL_ReadBE32(rw); /* throw the length away; we don't need it. */ + Uint32 value = 0; + SDL_ReadU32LE(rw, &value); + BAIL_IF_MACRO(value != formID, "AIFF: Not a FORM file.", 0); + SDL_ReadU32BE(rw, &value); /* throw the length away; we don't need it. */ - chunk_id = SDL_ReadLE32(rw); + SDL_ReadU32LE(rw, &chunk_id); BAIL_IF_MACRO(chunk_id != aiffID && chunk_id != aifcID, "AIFF: Not an AIFF or AIFC file.", 0); /* Chunks may appear in any order, so we establish base camp here. */ - pos = SDL_RWtell(rw); + pos = SDL_TellIO(rw); BAIL_IF_MACRO(!find_chunk(rw, commID), "AIFF: No common chunk.", 0); BAIL_IF_MACRO(!read_comm_chunk(rw, &c), @@ -418,12 +420,12 @@ static int AIFF_open(Sound_Sample *sample, const char *ext) if (c.sampleSize <= 8) { - sample->actual.format = AUDIO_S8; + sample->actual.format = SDL_AUDIO_S8; bytes_per_sample = c.numChannels; } /* if */ else if (c.sampleSize <= 16) { - sample->actual.format = AUDIO_S16MSB; + sample->actual.format = SDL_AUDIO_S16BE; bytes_per_sample = 2 * c.numChannels; } /* if */ else @@ -442,7 +444,7 @@ static int AIFF_open(Sound_Sample *sample, const char *ext) return 0; } /* if */ - SDL_RWseek(rw, pos, RW_SEEK_SET); /* if the seek fails, let it go... */ + SDL_SeekIO(rw, pos, SDL_IO_SEEK_SET); /* if the seek fails, let it go... */ if (!find_chunk(rw, ssndID)) { @@ -465,7 +467,7 @@ static int AIFF_open(Sound_Sample *sample, const char *ext) a->fmt.total_bytes = a->bytesLeft = bytes_per_sample * c.numSampleFrames; - a->fmt.data_starting_offset = SDL_RWtell(rw); + a->fmt.data_starting_offset = SDL_TellIO(rw); internal->decoder_private = (void *) a; sample->flags = SOUND_SAMPLEFLAG_CANSEEK; @@ -491,13 +493,12 @@ static Uint32 AIFF_read(Sound_Sample *sample) return a->fmt.read_sample(sample); } /* AIFF_read */ - static int AIFF_rewind(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; aiff_t *a = (aiff_t *) internal->decoder_private; const fmt_t *fmt = &a->fmt; - const Sint64 rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, fmt->data_starting_offset, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0); a->bytesLeft = fmt->total_bytes; return fmt->rewind_sample(sample); diff --git a/src/SDL_sound_au.c b/src/SDL_sound_au.c index 95785bda..95737f65 100644 --- a/src/SDL_sound_au.c +++ b/src/SDL_sound_au.c @@ -18,9 +18,9 @@ #if SOUND_SUPPORTS_AU /* no init/deinit needed */ -static SDL_bool AU_init(void) +static bool AU_init(void) { - return SDL_TRUE; + return true; } /* AU_init */ static void AU_quit(void) @@ -73,31 +73,31 @@ struct audec * regardless of the processor's byte order or how the au_file_hdr * structure is packed. */ -static int read_au_header(SDL_RWops *rw, struct au_file_hdr *hdr) +static int read_au_header(SDL_IOStream *rw, struct au_file_hdr *hdr) { - if (SDL_RWread(rw, &hdr->magic, sizeof (hdr->magic), 1) != 1) + if (SDL_ReadIO(rw, &hdr->magic, sizeof(hdr->magic)) != sizeof(hdr->magic)) return 0; - hdr->magic = SDL_SwapBE32(hdr->magic); + hdr->magic = SDL_Swap32BE(hdr->magic); - if (SDL_RWread(rw, &hdr->hdr_size, sizeof (hdr->hdr_size), 1) != 1) + if (SDL_ReadIO(rw, &hdr->hdr_size, sizeof(hdr->hdr_size)) != sizeof(hdr->hdr_size)) return 0; - hdr->hdr_size = SDL_SwapBE32(hdr->hdr_size); + hdr->hdr_size = SDL_Swap32BE(hdr->hdr_size); - if (SDL_RWread(rw, &hdr->data_size, sizeof (hdr->data_size), 1) != 1) + if (SDL_ReadIO(rw, &hdr->data_size, sizeof(hdr->data_size)) != sizeof(hdr->data_size)) return 0; - hdr->data_size = SDL_SwapBE32(hdr->data_size); + hdr->data_size = SDL_Swap32BE(hdr->data_size); - if (SDL_RWread(rw, &hdr->encoding, sizeof (hdr->encoding), 1) != 1) + if (SDL_ReadIO(rw, &hdr->encoding, sizeof(hdr->encoding)) != sizeof(hdr->encoding)) return 0; - hdr->encoding = SDL_SwapBE32(hdr->encoding); + hdr->encoding = SDL_Swap32BE(hdr->encoding); - if (SDL_RWread(rw, &hdr->sample_rate, sizeof (hdr->sample_rate), 1) != 1) + if (SDL_ReadIO(rw, &hdr->sample_rate, sizeof(hdr->sample_rate)) != sizeof(hdr->sample_rate)) return 0; - hdr->sample_rate = SDL_SwapBE32(hdr->sample_rate); + hdr->sample_rate = SDL_Swap32BE(hdr->sample_rate); - if (SDL_RWread(rw, &hdr->channels, sizeof (hdr->channels), 1) != 1) + if (SDL_ReadIO(rw, &hdr->channels, sizeof(hdr->channels)) != sizeof(hdr->channels)) return 0; - hdr->channels = SDL_SwapBE32(hdr->channels); + hdr->channels = SDL_Swap32BE(hdr->channels); return 1; } /* read_au_header */ @@ -108,7 +108,7 @@ static int read_au_header(SDL_RWops *rw, struct au_file_hdr *hdr) static int AU_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; int hsize, i, bytes_per_second; struct au_file_hdr hdr; struct audec *dec; @@ -131,15 +131,15 @@ static int AU_open(Sound_Sample *sample, const char *ext) /* Convert 8-bit µ-law to 16-bit linear on the fly. This is slightly wasteful if the audio driver must convert them back, but µ-law only devices are rare (mostly _old_ Suns) */ - sample->actual.format = AUDIO_S16SYS; + sample->actual.format = SDL_AUDIO_S16; break; case AU_ENC_LINEAR_8: - sample->actual.format = AUDIO_S8; + sample->actual.format = SDL_AUDIO_S8; break; case AU_ENC_LINEAR_16: - sample->actual.format = AUDIO_S16MSB; + sample->actual.format = SDL_AUDIO_S16BE; break; default: @@ -155,7 +155,7 @@ static int AU_open(Sound_Sample *sample, const char *ext) /* skip remaining part of header (input may be unseekable) */ for (i = HDR_SIZE; i < hsize; i++) { - if (SDL_RWread(rw, &c, 1, 1) != 1) + if (SDL_ReadIO(rw, &c, 1) != 1) { SDL_free(dec); BAIL_MACRO(ERR_IO_ERROR, 0); @@ -173,10 +173,10 @@ static int AU_open(Sound_Sample *sample, const char *ext) SNDDBG(("AU: Invalid header, assuming raw 8kHz µ-law.\n")); /* if seeking fails, we lose 24 samples. big deal */ - SDL_RWseek(rw, -HDR_SIZE, RW_SEEK_CUR); + SDL_SeekIO(rw, -HDR_SIZE, SDL_IO_SEEK_CUR); dec->encoding = AU_ENC_ULAW_8; dec->remaining = (Uint32)-1; /* no limit */ - sample->actual.format = AUDIO_S16SYS; + sample->actual.format = SDL_AUDIO_S16; sample->actual.rate = 8000; sample->actual.channels = 1; } /* else if */ @@ -196,7 +196,7 @@ static int AU_open(Sound_Sample *sample, const char *ext) sample->flags = SOUND_SAMPLEFLAG_CANSEEK; dec->total = dec->remaining; - dec->start_offset = SDL_RWtell(rw); + dec->start_offset = SDL_TellIO(rw); SNDDBG(("AU: Accepting data stream.\n")); return 1; @@ -268,7 +268,7 @@ static Uint32 AU_read(Sound_Sample *sample) if (maxlen > dec->remaining) maxlen = dec->remaining; - ret = SDL_RWread(internal->rw, buf, 1, maxlen); + ret = SDL_ReadIO(internal->rw, buf, maxlen); if (ret == 0) sample->flags |= SOUND_SAMPLEFLAG_EOF; else if (ret == -1) /** FIXME: this error check is broken **/ @@ -297,7 +297,7 @@ static int AU_rewind(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; struct audec *dec = (struct audec *) internal->decoder_private; - const Sint64 rc = SDL_RWseek(internal->rw, dec->start_offset, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, dec->start_offset, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != dec->start_offset, ERR_IO_ERROR, 0); dec->remaining = dec->total; return 1; @@ -316,7 +316,7 @@ static int AU_seek(Sound_Sample *sample, Uint32 ms) offset >>= 1; /* halve the byte offset for compression. */ pos = (dec->start_offset + offset); - rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET); + rc = SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); dec->remaining = dec->total - offset; return 1; diff --git a/src/SDL_sound_coreaudio.c b/src/SDL_sound_coreaudio.c index d71d25e9..e17ca324 100644 --- a/src/SDL_sound_coreaudio.c +++ b/src/SDL_sound_coreaudio.c @@ -22,9 +22,9 @@ typedef struct CoreAudioFileContainer } CoreAudioFileContainer; -static SDL_bool CoreAudio_init(void) +static bool CoreAudio_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* CoreAudio_init */ @@ -158,7 +158,7 @@ static AudioFileTypeID CoreAudio_GetAudioTypeForExtension(const char* file_exten static const char* CoreAudio_FourCCToString(Sint32 error_code) { static char return_string[16]; - Uint32 big_endian_code = SDL_SwapBE32((Uint32)error_code); + Uint32 big_endian_code = SDL_Swap32BE((Uint32)error_code); char* big_endian_str = (char*)&big_endian_code; // see if it appears to be a 4-char-code if(isprint(big_endian_str[0]) @@ -191,10 +191,10 @@ static const char* CoreAudio_FourCCToString(Sint32 error_code) SInt64 CoreAudio_SizeCallback(void* inClientData) { - SDL_RWops* rw_ops = (SDL_RWops*)inClientData; - const Sint64 current_position = SDL_RWtell(rw_ops); - const Sint64 end_position = SDL_RWseek(rw_ops, 0, RW_SEEK_END); - SDL_RWseek(rw_ops, current_position, RW_SEEK_SET); + SDL_IOStream *rw_ops = (SDL_IOStream *) inClientData; + const Sint64 current_position = SDL_TellIO(rw_ops); + const Sint64 end_position = SDL_SeekIO(rw_ops, 0, SDL_IO_SEEK_END); + SDL_SeekIO(rw_ops, current_position, SDL_IO_SEEK_SET); // fprintf(stderr, "CoreAudio_SizeCallback:%d\n", end_position); return end_position; } @@ -207,10 +207,10 @@ OSStatus CoreAudio_ReadCallback( UInt32* actualCount ) { - SDL_RWops* rw_ops = (SDL_RWops*)inClientData; - SDL_RWseek(rw_ops, inPosition, RW_SEEK_SET); - size_t bytes_actually_read = SDL_RWread(rw_ops, data_buffer, 1, requestCount); - // Not sure how to test for a read error with SDL_RWops + SDL_IOStream* rw_ops = (SDL_IOStream *) inClientData; + SDL_SeekIO(rw_ops, inPosition, SDL_IO_SEEK_SET); + size_t bytes_actually_read = SDL_ReadIO(rw_ops, data_buffer, requestCount); + // Not sure how to test for a read error with SDL_IOStream // fprintf(stderr, "CoreAudio_ReadCallback:%d, %d\n", requestCount, bytes_actually_read); *actualCount = bytes_actually_read; @@ -302,22 +302,22 @@ static int CoreAudio_open(Sound_Sample *sample, const char *ext) { if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) { - sample->actual.format = AUDIO_F32MSB; + sample->actual.format = SDL_AUDIO_F32BE; } else { - sample->actual.format = AUDIO_F32LSB; + sample->actual.format = SDL_AUDIO_F32LE; } } else { - if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) + if (actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) { - sample->actual.format = AUDIO_S32MSB; + sample->actual.format = SDL_AUDIO_S32BE; } else { - sample->actual.format = AUDIO_S32LSB; + sample->actual.format = SDL_AUDIO_S32LE; } } } @@ -327,22 +327,11 @@ static int CoreAudio_open(Sound_Sample *sample, const char *ext) { if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) { - sample->actual.format = AUDIO_S16MSB; + sample->actual.format = SDL_AUDIO_S16BE; } else { - sample->actual.format = AUDIO_S16LSB; - } - } - else - { - if(actual_format.mFormatFlags & kAudioFormatFlagIsBigEndian) - { - sample->actual.format = AUDIO_U16MSB; - } - else - { - sample->actual.format = AUDIO_U16LSB; + sample->actual.format = SDL_AUDIO_S16LE; } } } @@ -350,17 +339,17 @@ static int CoreAudio_open(Sound_Sample *sample, const char *ext) { if(kAudioFormatFlagIsSignedInteger & actual_format.mFormatFlags) { - sample->actual.format = AUDIO_S8; + sample->actual.format = SDL_AUDIO_S8; } else { - sample->actual.format = AUDIO_U8; + sample->actual.format = SDL_AUDIO_U8; } } else // might be 0 for undefined? { // This case seems to come up a lot for me. Maybe for file types like .m4a? - sample->actual.format = AUDIO_S16SYS; + sample->actual.format = SDL_AUDIO_S16; SNDDBG(("Core Audio: Unsupported actual_format.mBitsPerChannel: [%d].\n", actual_format.mBitsPerChannel)); } } @@ -375,12 +364,6 @@ static int CoreAudio_open(Sound_Sample *sample, const char *ext) sample->actual.format = sample->desired.format; } - /* AUDIO_U16LSB and AUDIO_U16MSB don't seem to be supported by CoreAudio. */ - if (sample->actual.format == AUDIO_U16LSB) - sample->actual.format = AUDIO_S16LSB; - if (sample->actual.format == AUDIO_U16MSB) - sample->actual.format = AUDIO_S16MSB; - SNDDBG(("CoreAudio: channels == (%d).\n", sample->actual.channels)); SNDDBG(("CoreAudio: sampling rate == (%d).\n",sample->actual.rate)); SNDDBG(("CoreAudio: total seconds of sample == (%d).\n", internal->total_time)); diff --git a/src/SDL_sound_flac.c b/src/SDL_sound_flac.c index eb14a274..786fe0e6 100644 --- a/src/SDL_sound_flac.c +++ b/src/SDL_sound_flac.c @@ -44,13 +44,13 @@ static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead) Uint8 *ptr = (Uint8 *) pBufferOut; Sound_Sample *sample = (Sound_Sample *) pUserData; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rwops = internal->rw; + SDL_IOStream *rwops = internal->rw; size_t retval = 0; /* !!! FIXME: dr_flac treats returning less than bytesToRead as EOF. So we can't EAGAIN. */ while (bytesToRead) { - const size_t rc = SDL_RWread(rwops, ptr, 1, bytesToRead); + const size_t rc = SDL_ReadIO(rwops, ptr, bytesToRead); if (rc == 0) break; bytesToRead -= rc; retval += rc; @@ -62,16 +62,15 @@ static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead) static drflac_bool32 flac_seek(void* pUserData, int offset, drflac_seek_origin origin) { - const int whence = (origin == drflac_seek_origin_start) ? RW_SEEK_SET : RW_SEEK_CUR; + const int whence = (origin == drflac_seek_origin_start) ? SDL_IO_SEEK_SET : SDL_IO_SEEK_CUR; Sound_Sample *sample = (Sound_Sample *) pUserData; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - return (SDL_RWseek(internal->rw, offset, whence) != -1) ? DRFLAC_TRUE : DRFLAC_FALSE; + return (SDL_SeekIO(internal->rw, offset, whence) != -1) ? DRFLAC_TRUE : DRFLAC_FALSE; } /* flac_seek */ - -static SDL_bool FLAC_init(void) +static bool FLAC_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* FLAC_init */ @@ -97,7 +96,7 @@ static int FLAC_open(Sound_Sample *sample, const char *ext) sample->actual.channels = dr->channels; sample->actual.rate = dr->sampleRate; - sample->actual.format = AUDIO_S32SYS; /* dr_flac only does Sint32. */ + sample->actual.format = SDL_AUDIO_S32; /* dr_flac only does Sint32. */ if (dr->totalPCMFrameCount == 0) internal->total_time = -1; diff --git a/src/SDL_sound_internal.h b/src/SDL_sound_internal.h index 7e4a036a..360a7000 100644 --- a/src/SDL_sound_internal.h +++ b/src/SDL_sound_internal.h @@ -11,21 +11,16 @@ * application. */ -#ifndef _INCLUDE_SDL_SOUND_INTERNAL_H_ -#define _INCLUDE_SDL_SOUND_INTERNAL_H_ +#ifndef SDL_SOUND_INTERNAL_H_ +#define SDL_SOUND_INTERNAL_H_ #ifndef __SDL_SOUND_INTERNAL__ #error Do not include this header from your applications. #endif -#include "SDL_sound.h" +#include -/* SDL_AudioStream, which we use internally, didn't arrive until SDL 2.0.7. */ -#if !SDL_VERSION_ATLEAST(2, 0, 7) -#error SDL_sound requires SDL 2.0.7 or later. Please upgrade. -#endif - -#if ((defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)) && !(defined(_WIN32) || defined(__OS2__)) +#if ((defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)) && !defined(_WIN32) #define SOUND_HAVE_PRAGMA_VISIBILITY 1 #endif @@ -98,7 +93,7 @@ * SDL itself only supports mono and stereo output, but hopefully we can * raise this value someday...there's probably a lot of assumptions in * SDL_sound that rely on it, though. - * !!! FIXME: SDL2 supports more channels. + * !!! FIXME: SDL3 supports more channels. */ #define SOUND_MAX_CHANNELS 2 @@ -113,7 +108,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__ * set up any global state that your decoder needs, such as * initializing an external library, etc. * - * Return SDL_TRUE if initialization is successful, SDL_FALSE if + * Return true if initialization is successful, false if * there's a fatal error. If this method fails, then this decoder * is flagged as unavailable until SDL_sound() is shut down and * reinitialized, in which case this method will be tried again. @@ -122,7 +117,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__ * method fails, so if you can't intialize, you'll have to clean * up the half-initialized state in this method. */ - SDL_bool (*init)(void); + bool (*init)(void); /* * This is called during the Sound_Quit() function. Use this to @@ -154,11 +149,11 @@ typedef struct __SOUND_DECODERFUNCTIONS__ * in Sound_SampleInternal section: * Sound_Sample *next; (offlimits) * Sound_Sample *prev; (offlimits) - * SDL_RWops *rw; (can use, but do NOT close it) + * SDL_IOStream *rw; (can use, but do NOT close it) * const Sound_DecoderFunctions *funcs; (that's this structure) * SDL_AudioStream stream; (offlimits) - * SDL_bool pending_eof; (offlimits) - * SDL_bool pending_error; (offlimits) + * bool pending_eof; (offlimits) + * bool pending_error; (offlimits) * void *buffer; (offlimits until read() method) * Uint32 buffer_size; (offlimits until read() method) * void *decoder_private; (read and write access) @@ -223,7 +218,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__ /* * Reset the decoding to the beginning of the stream. Nonzero on * success, zero on failure. - * + * * The purpose of this method is to allow for higher efficiency than * an application could get by just recreating the sample externally; * not only do they not have to reopen the RWops, reallocate buffers, @@ -233,7 +228,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__ * have a valid audio stream with a given set of characteristics. * * The decoder is responsible for calling seek() on the associated - * SDL_RWops. A failing call to seek() should be the ONLY reason that + * SDL_IOStream. A failing call to seek() should be the ONLY reason that * this method should ever fail! */ int (*rewind)(Sound_Sample *sample); @@ -247,7 +242,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__ * decoding to a given point. * * The decoder is responsible for calling seek() on the associated - * SDL_RWops. + * SDL_IOStream. * * If there is an error, try to recover so that the next read will * continue as if nothing happened. @@ -262,11 +257,11 @@ typedef struct __SOUND_SAMPLEINTERNAL__ { Sound_Sample *next; Sound_Sample *prev; - SDL_RWops *rw; + SDL_IOStream *rw; const Sound_DecoderFunctions *funcs; SDL_AudioStream *stream; - SDL_bool pending_eof; - SDL_bool pending_error; + bool pending_eof; + bool pending_error; void *buffer; Uint32 buffer_size; void *decoder_private; @@ -316,20 +311,7 @@ Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms); #define BAIL_MACRO(e, r) { __Sound_SetError(e); return r; } #define BAIL_IF_MACRO(c, e, r) if (c) { __Sound_SetError(e); return r; } -#if SDL_VERSION_ATLEAST(2,0,12) -#define HAVE_SDL_STRTOKR -#else -#define SDL_strtokr __Sound_strtokr -extern char *SDL_strtokr(char *s1, const char *s2, char **saveptr); -#endif - -/* SDL doesn't provide a rand() replacement */ -#define SDL_rand __Sound_rand -#define SDL_srand __Sound_srand -extern int SDL_rand(void); -extern void SDL_srand(unsigned int seed); - -/* Wrappers around the SDL versions of these in case you're on an older SDL */ +/* Wrappers around SDL versions. SDL3 doesn't provide a SIMDRealloc() */ extern void *__Sound_SIMDAlloc(const size_t len); extern void *__Sound_SIMDRealloc(void *mem, const size_t len); extern void __Sound_SIMDFree(void *ptr); @@ -338,7 +320,7 @@ extern void __Sound_SIMDFree(void *ptr); } #endif -#endif /* defined _INCLUDE_SDL_SOUND_INTERNAL_H_ */ +#endif /* defined SDL_SOUND_INTERNAL_H_ */ /* end of SDL_sound_internal.h ... */ diff --git a/src/SDL_sound_midi.c b/src/SDL_sound_midi.c index d470284b..f5ce7e20 100644 --- a/src/SDL_sound_midi.c +++ b/src/SDL_sound_midi.c @@ -29,7 +29,7 @@ # define TIMIDITY_CFG_FREEPATS "/etc/timidity/freepats.cfg" #endif -static SDL_bool MIDI_init(void) +static bool MIDI_init(void) { const char *cfg; int rc = -1; @@ -51,8 +51,8 @@ static SDL_bool MIDI_init(void) if (rc < 0) rc = Timidity_Init(NULL); /* library's default cfg. */ } - BAIL_IF_MACRO(rc < 0, "MIDI: Could not initialise", SDL_FALSE); - return SDL_TRUE; + BAIL_IF_MACRO(rc < 0, "MIDI: Could not initialise", false); + return true; } /* MIDI_init */ @@ -65,15 +65,14 @@ static void MIDI_quit(void) static int MIDI_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; SDL_AudioSpec spec; MidiSong *song; spec.channels = (sample->desired.channels == 1) ? 1 : 2; - spec.format = (sample->desired.format == 0) ? AUDIO_S16SYS : sample->desired.format; + spec.format = (sample->desired.format == 0) ? SDL_AUDIO_S16 : sample->desired.format; spec.freq = (sample->desired.rate == 0) ? 44100 : sample->desired.rate; - spec.samples = sample->buffer_size / (SDL_AUDIO_BITSIZE(spec.format) / 8) / spec.channels; - + song = Timidity_LoadSong(rw, &spec); BAIL_IF_MACRO(song == NULL, "MIDI: Not a MIDI file.", 0); Timidity_SetVolume(song, 100); diff --git a/src/SDL_sound_modplug.c b/src/SDL_sound_modplug.c index d9ff13ee..32979e3b 100644 --- a/src/SDL_sound_modplug.c +++ b/src/SDL_sound_modplug.c @@ -56,7 +56,7 @@ static const char *extensions_modplug[] = -static SDL_bool MODPLUG_init(void) +static bool MODPLUG_init(void) { return ModPlug_Init(); /* success. */ } /* MODPLUG_init */ @@ -102,41 +102,33 @@ static int MODPLUG_open(Sound_Sample *sample, const char *ext) /* ModPlug needs the entire stream in one big chunk. I don't like it, but I don't think there's any way around it. !!! FIXME: rework modplug? */ - size = SDL_RWsize(internal->rw); + size = SDL_GetIOSize(internal->rw); BAIL_IF_MACRO(size <= 0 || size > (Sint64)0x7fffffff, "MODPLUG: Not a module file.", 0); - if (internal->rw->type == SDL_RWOPS_MEMORY || internal->rw->type == SDL_RWOPS_MEMORY_RO) - { - data = internal->rw->hidden.mem.base; - retval = 0; - } - else - { - data = SDL_malloc((size_t) size); - BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); - retval = SDL_RWread(internal->rw, data, 1, size); - if (retval != (size_t)size) SDL_free(data); - BAIL_IF_MACRO(retval != (size_t)size, ERR_IO_ERROR, 0); - } + data = SDL_malloc((size_t) size); + BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); + retval = SDL_ReadIO(internal->rw, data, size); + if (retval != (size_t)size) SDL_free(data); + BAIL_IF_MACRO(retval != (size_t)size, ERR_IO_ERROR, 0); SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); if (sample->actual.rate == 0) sample->actual.rate = 44100; if (sample->actual.channels != 1) sample->actual.channels = 2; - if (sample->actual.format == 0) sample->actual.format = AUDIO_S16SYS; + if (sample->actual.format == 0) sample->actual.format = SDL_AUDIO_S16; switch (sample->actual.format) { - case AUDIO_U8: - case AUDIO_S8: - sample->actual.format = AUDIO_U8; + case SDL_AUDIO_U8: + case SDL_AUDIO_S8: + sample->actual.format = SDL_AUDIO_U8; break; - case AUDIO_S32MSB: - case AUDIO_S32LSB: - case AUDIO_F32MSB: - case AUDIO_F32LSB: - sample->actual.format = AUDIO_S32SYS; + case SDL_AUDIO_S32BE: + case SDL_AUDIO_S32LE: + case SDL_AUDIO_F32BE: + case SDL_AUDIO_F32LE: + sample->actual.format = SDL_AUDIO_S32; break; default: - sample->actual.format = AUDIO_S16SYS; + sample->actual.format = SDL_AUDIO_S16; break; } diff --git a/src/SDL_sound_mp3.c b/src/SDL_sound_mp3.c index 1302eb94..474044e7 100644 --- a/src/SDL_sound_mp3.c +++ b/src/SDL_sound_mp3.c @@ -37,13 +37,13 @@ static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead) Uint8 *ptr = (Uint8 *) pBufferOut; Sound_Sample *sample = (Sound_Sample *) pUserData; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rwops = internal->rw; + SDL_IOStream *rwops = internal->rw; size_t retval = 0; /* !!! FIXME: dr_mp3 treats returning less than bytesToRead as EOF. So we can't EAGAIN. */ while (bytesToRead) { - const size_t rc = SDL_RWread(rwops, ptr, 1, bytesToRead); + const size_t rc = SDL_ReadIO(rwops, ptr, bytesToRead); if (rc == 0) break; bytesToRead -= rc; retval += rc; @@ -55,16 +55,16 @@ static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead) static drmp3_bool32 mp3_seek(void* pUserData, int offset, drmp3_seek_origin origin) { - const int whence = (origin == drmp3_seek_origin_start) ? RW_SEEK_SET : RW_SEEK_CUR; + const int whence = (origin == drmp3_seek_origin_start) ? SDL_IO_SEEK_SET : SDL_IO_SEEK_CUR; Sound_Sample *sample = (Sound_Sample *) pUserData; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - return (SDL_RWseek(internal->rw, offset, whence) != -1) ? DRMP3_TRUE : DRMP3_FALSE; + return (SDL_SeekIO(internal->rw, offset, whence) != -1) ? DRMP3_TRUE : DRMP3_FALSE; } /* mp3_seek */ -static SDL_bool MP3_init(void) +static bool MP3_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* MP3_init */ @@ -92,7 +92,7 @@ static int MP3_open(Sound_Sample *sample, const char *ext) sample->actual.channels = dr->channels; sample->actual.rate = dr->sampleRate; - sample->actual.format = AUDIO_F32SYS; /* dr_mp3 only does float. */ + sample->actual.format = SDL_AUDIO_F32; /* dr_mp3 only does float. */ frames = drmp3_get_pcm_frame_count(dr); if (frames == 0) /* ever possible ??? */ diff --git a/src/SDL_sound_raw.c b/src/SDL_sound_raw.c index 5a3ee932..6f77faef 100644 --- a/src/SDL_sound_raw.c +++ b/src/SDL_sound_raw.c @@ -28,9 +28,9 @@ #if SOUND_SUPPORTS_RAW -static SDL_bool RAW_init(void) +static bool RAW_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* RAW_init */ @@ -73,10 +73,10 @@ static int RAW_open(Sound_Sample *sample, const char *ext) SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); sample->flags = SOUND_SAMPLEFLAG_CANSEEK; - if ((pos = SDL_RWseek(internal->rw, 0, RW_SEEK_END)) <= 0) { + if ((pos = SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_END)) <= 0) { BAIL_MACRO("RAW: can't seek to the end of the file.", 0); } - if ( SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0) { + if (SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_SET) != 0) { BAIL_MACRO("RAW: can't reset file.", 0); } @@ -103,8 +103,8 @@ static Uint32 RAW_read(Sound_Sample *sample) * We don't actually do any decoding, so we read the raw data * directly into the internal buffer... */ - retval = SDL_RWread(internal->rw, internal->buffer, - 1, internal->buffer_size); + retval = SDL_ReadIO(internal->rw, internal->buffer, + internal->buffer_size); /* Make sure the read went smoothly... */ if (retval == 0) @@ -124,16 +124,15 @@ static Uint32 RAW_read(Sound_Sample *sample) static int RAW_rewind(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0); + BAIL_IF_MACRO(SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_SET) != 0, ERR_IO_ERROR, 0); return 1; } /* RAW_rewind */ - static int RAW_seek(Sound_Sample *sample, Uint32 ms) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; const Sint64 pos = __Sound_convertMsToBytePos(&sample->actual, ms); - const int err = (SDL_RWseek(internal->rw, pos, RW_SEEK_SET) != pos); + const int err = (SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET) != pos); BAIL_IF_MACRO(err, ERR_IO_ERROR, 0); return 1; } /* RAW_seek */ diff --git a/src/SDL_sound_shn.c b/src/SDL_sound_shn.c index e43e2cf2..e705a2b2 100644 --- a/src/SDL_sound_shn.c +++ b/src/SDL_sound_shn.c @@ -175,11 +175,11 @@ static const Uint8 ulaw_outward[13][256] = { #endif -static int word_get(shn_t *shn, SDL_RWops *rw, Uint32 *word) +static int word_get(shn_t *shn, SDL_IOStream *rw, Uint32 *word) { if (shn->nbyteget < 4) { - shn->nbyteget += SDL_RWread(rw, shn->getbuf, 1, SHN_BUFSIZ); + shn->nbyteget += SDL_ReadIO(rw, shn->getbuf, SHN_BUFSIZ); BAIL_IF_MACRO(shn->nbyteget < 4, NULL, 0); shn->getbufp = shn->getbuf; } /* if */ @@ -199,7 +199,7 @@ static int word_get(shn_t *shn, SDL_RWops *rw, Uint32 *word) } /* word_get */ -static int uvar_get(int nbin, shn_t *shn, SDL_RWops *rw, Sint32 *word) +static int uvar_get(int nbin, shn_t *shn, SDL_IOStream *rw, Sint32 *word) { Sint32 result; @@ -245,7 +245,7 @@ static int uvar_get(int nbin, shn_t *shn, SDL_RWops *rw, Sint32 *word) } /* uvar_get */ -static int var_get(int nbin, shn_t *shn, SDL_RWops *rw, Sint32 *word) +static int var_get(int nbin, shn_t *shn, SDL_IOStream *rw, Sint32 *word) { BAIL_IF_MACRO(!uvar_get(nbin + 1, shn, rw, word), NULL, 0); @@ -258,7 +258,7 @@ static int var_get(int nbin, shn_t *shn, SDL_RWops *rw, Sint32 *word) } /* var_get */ -static int ulong_get(shn_t *shn, SDL_RWops *rw, Sint32 *word) +static int ulong_get(shn_t *shn, SDL_IOStream *rw, Sint32 *word) { Sint32 nbit; Sint32 retval; @@ -272,15 +272,15 @@ static int ulong_get(shn_t *shn, SDL_RWops *rw, Sint32 *word) } /* ulong_get */ -static SDL_INLINE int uint_get(int nbit, shn_t *shn, SDL_RWops *rw, Sint32 *w) +static SDL_INLINE int uint_get(int nbit, shn_t *shn, SDL_IOStream *rw, Sint32 *w) { return (shn->version == 0) ? uvar_get(nbit, shn, rw, w) : ulong_get(shn, rw, w); } /* uint_get */ -static SDL_bool SHN_init(void) +static bool SHN_init(void) { - return SDL_TRUE; /* initialization always successful. */ + return true; /* initialization always successful. */ } /* SHN_init */ @@ -296,17 +296,17 @@ static void SHN_quit(void) */ static SDL_INLINE int extended_shn_magic_search(Sound_Sample *sample) { - SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw; + SDL_IOStream *rw = ((Sound_SampleInternal *) sample->opaque)->rw; Uint32 word = 0; Uint8 ch; while (1) { - BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1); + BAIL_IF_MACRO(SDL_ReadIO(rw, &ch, sizeof (ch)) != sizeof (ch), NULL, -1); word = ((word << 8) & 0xFFFFFF00) | ch; - if (SDL_SwapBE32(word) == SHN_MAGIC) + if (SDL_Swap32BE(word) == SHN_MAGIC) { - BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1); + BAIL_IF_MACRO(SDL_ReadIO(rw, &ch, sizeof (ch)) != sizeof (ch), NULL, -1); return (int) ch; } /* if */ } /* while */ @@ -319,7 +319,7 @@ static SDL_INLINE int extended_shn_magic_search(Sound_Sample *sample) static SDL_INLINE int determine_shn_version(Sound_Sample *sample, const char *ext) { - SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw; + SDL_IOStream *rw = ((Sound_SampleInternal *) sample->opaque)->rw; Uint32 magic; Uint8 ch; @@ -334,9 +334,9 @@ static SDL_INLINE int determine_shn_version(Sound_Sample *sample, if (ext != NULL && SDL_strcasecmp(ext, "shn") == 0) return extended_shn_magic_search(sample); - BAIL_IF_MACRO(SDL_RWread(rw, &magic, sizeof (magic), 1) != 1, NULL, -1); - BAIL_IF_MACRO(SDL_SwapLE32(magic) != SHN_MAGIC, "SHN: Not a SHN file", -1); - BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1); + BAIL_IF_MACRO(SDL_ReadIO(rw, &magic, sizeof (magic)) != sizeof (magic), NULL, -1); + BAIL_IF_MACRO(SDL_Swap32LE(magic) != SHN_MAGIC, "SHN: Not a SHN file", -1); + BAIL_IF_MACRO(SDL_ReadIO(rw, &ch, sizeof (ch)) != sizeof (ch), NULL, -1); BAIL_IF_MACRO(ch > 3, "SHN: Unsupported file version", -1); return (int) ch; @@ -386,7 +386,7 @@ static SDL_INLINE Uint16 cvt_shnftype_to_sdlfmt(Sint16 shntype) switch (shntype) { case SHN_TYPE_S8: - return AUDIO_S8; + return SDL_AUDIO_S8; case SHN_TYPE_ALAW: case SHN_TYPE_ULAW: @@ -394,26 +394,26 @@ static SDL_INLINE Uint16 cvt_shnftype_to_sdlfmt(Sint16 shntype) case SHN_TYPE_AU2: case SHN_TYPE_AU3: case SHN_TYPE_U8: - return AUDIO_U8; + return SDL_AUDIO_U8; case SHN_TYPE_S16HL: - return AUDIO_S16MSB; + return SDL_AUDIO_S16BE; case SHN_TYPE_S16LH: - return AUDIO_S16LSB; + return SDL_AUDIO_S16LE; case SHN_TYPE_U16HL: - return AUDIO_U16MSB; + return SDL_AUDIO_S16BE; case SHN_TYPE_U16LH: - return AUDIO_U16LSB; + return SDL_AUDIO_S16LE; } /* switch */ return 0; } /* cvt_shnftype_to_sdlfmt */ -static SDL_INLINE int skip_bits(shn_t *shn, SDL_RWops *rw) +static SDL_INLINE int skip_bits(shn_t *shn, SDL_IOStream *rw) { int i; Sint32 skip; @@ -451,7 +451,7 @@ static Sint32 **shn_long2d(Uint32 n0, Uint32 n1) #define fmtID 0x20746D66 /* "fmt ", in ascii. */ #define dataID 0x61746164 /* "data", in ascii. */ -static int verb_ReadLE32(shn_t *shn, SDL_RWops *rw, Uint32 *word) +static int verb_ReadLE32(shn_t *shn, SDL_IOStream *rw, Uint32 *word) { int i; Uint8 chars[4]; @@ -465,13 +465,13 @@ static int verb_ReadLE32(shn_t *shn, SDL_RWops *rw, Uint32 *word) } /* for */ SDL_memcpy(word, chars, sizeof (*word)); - *word = SDL_SwapLE32(*word); + *word = SDL_Swap32LE(*word); return 1; } /* verb_ReadLE32 */ -static int verb_ReadLE16(shn_t *shn, SDL_RWops *rw, Uint16 *word) +static int verb_ReadLE16(shn_t *shn, SDL_IOStream *rw, Uint16 *word) { int i; Uint8 chars[2]; @@ -485,7 +485,7 @@ static int verb_ReadLE16(shn_t *shn, SDL_RWops *rw, Uint16 *word) } /* for */ SDL_memcpy(word, chars, sizeof (*word)); - *word = SDL_SwapLE16(*word); + *word = SDL_Swap16LE(*word); return 1; } /* verb_ReadLE16 */ @@ -494,7 +494,7 @@ static int verb_ReadLE16(shn_t *shn, SDL_RWops *rw, Uint16 *word) static SDL_INLINE int parse_riff_header(shn_t *shn, Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; Uint16 u16; Uint32 u32; Sint32 cklen; @@ -536,7 +536,7 @@ static SDL_INLINE int parse_riff_header(shn_t *shn, Sound_Sample *sample) static int SHN_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; shn_t _shn; shn_t *shn = &_shn; /* malloc and copy later. */ Sint32 cmd; @@ -613,7 +613,7 @@ static int SHN_open(Sound_Sample *sample, const char *ext) return 0; } /* if */ - shn->start_pos = SDL_RWtell(rw); + shn->start_pos = SDL_TellIO(rw); shn = (shn_t *) SDL_malloc(sizeof (shn_t)); if (shn == NULL) @@ -919,18 +919,18 @@ static Uint32 put_to_buffers(Sound_Sample *sample, Uint32 bw) case SHN_TYPE_U16HL: case SHN_TYPE_U16LH: { - Uint16 *writebufp = (Uint16 *) shn->backBuffer; + Sint16 *writebufp = (Sint16 *) shn->backBuffer; if (shn->nchan == 1) { for (i = 0; i < nitem; i++) - *writebufp++ = CAPMAXUSHORT(data0[i]); + *writebufp++ = CAPMAXUSHORT(data0[i]) ^ 0x8000; } /* if */ else { for (i = 0; i < nitem; i++) { for (chan = 0; chan < shn->nchan; chan++) - *writebufp++ = CAPMAXUSHORT(shn->buffer[chan][i]); + *writebufp++ = CAPMAXUSHORT(shn->buffer[chan][i]) ^ 0x8000; } /* for */ } /* else */ } /* case */ @@ -1017,7 +1017,7 @@ static Uint32 SHN_read(Sound_Sample *sample) Uint32 retval = 0; Sint32 chan = 0; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; shn_t *shn = (shn_t *) internal->decoder_private; Sint32 cmd; @@ -1253,7 +1253,7 @@ static int SHN_rewind(Sound_Sample *sample) #if 0 shn_t *shn = (shn_t *) internal->decoder_private; - Sint64 rc = SDL_RWseek(internal->rw, shn->start_pos, RW_SEEK_SET); + Sint64 rc = SDL_SeekIO(internal->rw, shn->start_pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != shn->start_pos, ERR_IO_ERROR, 0); /* !!! FIXME: set state. */ return 1; @@ -1264,7 +1264,7 @@ static int SHN_rewind(Sound_Sample *sample) * !!! FIXME: to decode. The below kludge adds unneeded overhead and * !!! FIXME: risk of failure. */ - BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0); + BAIL_IF_MACRO(SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_SET) != 0, ERR_IO_ERROR, 0); SHN_close(sample); return SHN_open(sample, "SHN"); #endif diff --git a/src/SDL_sound_skeleton.c b/src/SDL_sound_skeleton.c index 2d82778b..1d5e4c90 100644 --- a/src/SDL_sound_skeleton.c +++ b/src/SDL_sound_skeleton.c @@ -27,11 +27,11 @@ #if SOUND_SUPPORTS_FMT -static SDL_bool FMT_init(void) +static bool FMT_init(void) { /* do any global decoder/library initialization you need here. */ - return SDL_TRUE; /* initialization successful. */ + return true; /* initialization successful. */ } /* FMT_init */ @@ -44,13 +44,13 @@ static void FMT_quit(void) static int FMT_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; - if (can NOT accept the data) - BAIL_MACRO("FMT: expected X, got Y.", 0); + // if (can NOT accept the data) + // BAIL_MACRO("FMT: expected X, got Y.", 0); SNDDBG(("FMT: Accepting data stream.\n")); - set up sample->actual; + // set up sample->actual; sample->flags = SOUND_SAMPLEFLAG_NONE; return 1; /* we'll handle this data. */ } /* FMT_open */ @@ -59,7 +59,7 @@ static int FMT_open(Sound_Sample *sample, const char *ext) static void FMT_close(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - clean up anything you put into internal->decoder_private; + // clean up anything you put into internal->decoder_private; } /* FMT_close */ @@ -72,10 +72,10 @@ static Uint32 FMT_read(Sound_Sample *sample) * We don't actually do any decoding, so we read the fmt data * directly into the internal buffer... */ - retval = SDL_RWread(internal->rw, internal->buffer, - 1, internal->buffer_size); + retval = SDL_ReadIO(internal->rw, internal->buffer, + internal->buffer_size); - (or whatever. Do some decoding here...) + // (or whatever.Do some decoding here...) /* Make sure the read went smoothly... */ if (retval == 0) @@ -84,11 +84,11 @@ static Uint32 FMT_read(Sound_Sample *sample) else if (retval == -1) /** FIXME: this error check is broken **/ sample->flags |= SOUND_SAMPLEFLAG_ERROR; - /* (next call this EAGAIN may turn into an EOF or error.) */ + /* (next call this EAGAIN may turn into an EOF or error.) */ else if (retval < internal->buffer_size) sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; - (or whatever. retval == number of bytes you put in internal->buffer). + // (or whatever. retval == number of bytes you put in internal->buffer). return retval; } /* FMT_read */ @@ -99,9 +99,9 @@ static int FMT_rewind(Sound_Sample *sample) Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; /* seek to the appropriate place... */ - BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0); + BAIL_IF_MACRO(SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_SET) != 0, ERR_IO_ERROR, 0); - (reset state as necessary.) + // (reset state as necessary.) return 1; /* success. */ } /* FMT_rewind */ @@ -112,9 +112,9 @@ static int FMT_seek(Sound_Sample *sample, Uint32 ms) Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; /* seek to the appropriate place... */ - BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0); + BAIL_IF_MACRO(SDL_SeekIO(internal->rw, 0, SDL_IO_SEEK_SET) != 0, ERR_IO_ERROR, 0); - (set state as necessary.) + // (set state as necessary.) return 1; /* success. */ } /* FMT_seek */ diff --git a/src/SDL_sound_voc.c b/src/SDL_sound_voc.c index 003e415a..6f13690b 100644 --- a/src/SDL_sound_voc.c +++ b/src/SDL_sound_voc.c @@ -77,9 +77,9 @@ typedef struct vocstuff { #define VOC_DATA_16 9 -static SDL_bool VOC_init(void) +static bool VOC_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* VOC_init */ @@ -89,9 +89,9 @@ static void VOC_quit(void) } /* VOC_quit */ -static SDL_INLINE int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size) +static SDL_INLINE int voc_readbytes(SDL_IOStream *src, vs_t *v, void *p, int size) { - if (SDL_RWread(src, p, size, 1) != 1) + if (SDL_ReadIO(src, p, size) != size) { v->error = 1; BAIL_MACRO("VOC: i/o error", 0); @@ -101,7 +101,7 @@ static SDL_INLINE int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size) } /* voc_readbytes */ -static SDL_INLINE int voc_check_header(SDL_RWops *src) +static SDL_INLINE int voc_check_header(SDL_IOStream *src) { /* VOC magic header */ Uint8 signature[20]; /* "Creative Voice File\032" */ @@ -120,9 +120,9 @@ static SDL_INLINE int voc_check_header(SDL_RWops *src) if (!voc_readbytes(src, &v, &datablockofs, sizeof (Uint16))) return 0; - datablockofs = SDL_SwapLE16(datablockofs); + datablockofs = SDL_Swap16LE(datablockofs); - if (SDL_RWseek(src, datablockofs, RW_SEEK_SET) != datablockofs) + if (SDL_SeekIO(src, datablockofs, SDL_IO_SEEK_SET) != datablockofs) { BAIL_MACRO("VOC: Failed to seek to data block.", 0); } /* if */ @@ -135,7 +135,7 @@ static SDL_INLINE int voc_check_header(SDL_RWops *src) static int voc_get_block(Sound_Sample *sample, vs_t *v) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *src = internal->rw; + SDL_IOStream *src = internal->rw; Uint8 bits24[3]; Uint8 uc, block; Uint32 sblen; @@ -149,15 +149,15 @@ static int voc_get_block(Sound_Sample *sample, vs_t *v) v->silent = 0; while (v->rest == 0) { - if (SDL_RWread(src, &block, sizeof (block), 1) != 1) + if (SDL_ReadIO(src, &block, sizeof (block)) != sizeof (block)) return 1; /* assume that's the end of the file. */ if (block == VOC_TERM) return 1; - if (SDL_RWread(src, bits24, sizeof (bits24), 1) != 1) + if (SDL_ReadIO(src, bits24, sizeof (bits24)) != sizeof (bits24)) return 1; /* assume that's the end of the file. */ - + /* Size is an 24-bit value. Ugh. */ sblen = ( (bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16) ); @@ -201,7 +201,7 @@ static int voc_get_block(Sound_Sample *sample, vs_t *v) if (!voc_readbytes(src, v, &new_rate_long, sizeof (Uint32))) return 0; - new_rate_long = SDL_SwapLE32(new_rate_long); + new_rate_long = SDL_Swap32LE(new_rate_long); BAIL_IF_MACRO(!new_rate_long, "VOC: Sample rate is zero?", 0); if ((v->rate != -1) && (new_rate_long != v->rate)) @@ -243,7 +243,7 @@ static int voc_get_block(Sound_Sample *sample, vs_t *v) if (!voc_readbytes(src, v, &period, sizeof (period))) return 0; - period = SDL_SwapLE16(period); + period = SDL_Swap16LE(period); if (!voc_readbytes(src, v, &uc, sizeof (uc))) return 0; @@ -284,7 +284,7 @@ static int voc_get_block(Sound_Sample *sample, vs_t *v) if (!voc_readbytes(src, v, &new_rate_short, sizeof (Uint16))) return 0; - new_rate_short = SDL_SwapLE16(new_rate_short); + new_rate_short = SDL_Swap16LE(new_rate_short); BAIL_IF_MACRO(!new_rate_short, "VOC: sample rate is zero", 0); if ((v->rate != -1) && (new_rate_short != v->rate)) @@ -339,7 +339,7 @@ static int voc_get_block(Sound_Sample *sample, vs_t *v) static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *src = internal->rw; + SDL_IOStream *src = internal->rw; vs_t *v = (vs_t *) internal->decoder_private; Sint64 done = 0; Uint8 silence = 0x80; @@ -374,7 +374,7 @@ static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max) { if (fill_buf) { - done = SDL_RWread(src, buf + v->bufpos, 1, max); + done = SDL_ReadIO(src, buf + v->bufpos, max); if (done < ((Sint64) max)) { __Sound_SetError("VOC: i/o error"); @@ -385,10 +385,10 @@ static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max) else { Sint64 cur, rc; - cur = SDL_RWtell(src); + cur = SDL_TellIO(src); if (cur >= 0) { - rc = SDL_RWseek(src, max, RW_SEEK_CUR); + rc = SDL_SeekIO(src, max, SDL_IO_SEEK_CUR); if (rc >= 0) done = rc - cur; else @@ -418,7 +418,7 @@ static int VOC_open(Sound_Sample *sample, const char *ext) v = (vs_t *) SDL_calloc(1, sizeof (vs_t)); BAIL_IF_MACRO(v == NULL, ERR_OUT_OF_MEMORY, 0); - v->start_pos = SDL_RWtell(internal->rw); + v->start_pos = SDL_TellIO(internal->rw); v->rate = -1; if (!voc_get_block(sample, v)) { @@ -433,7 +433,7 @@ static int VOC_open(Sound_Sample *sample, const char *ext) } /* if */ SNDDBG(("VOC: Accepting data stream.\n")); - sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8; + sample->actual.format = (v->size == ST_SIZE_WORD) ? SDL_AUDIO_S16LE : SDL_AUDIO_U8; sample->actual.channels = v->channels; sample->flags = SOUND_SAMPLEFLAG_CANSEEK; internal->decoder_private = v; @@ -482,7 +482,7 @@ static int VOC_rewind(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; vs_t *v = (vs_t *) internal->decoder_private; - const Sint64 rc = SDL_RWseek(internal->rw, v->start_pos, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, v->start_pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != v->start_pos, ERR_IO_ERROR, 0); v->rest = 0; return 1; @@ -504,7 +504,7 @@ static int VOC_seek(Sound_Sample *sample, Uint32 ms) Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; vs_t *v = (vs_t *) internal->decoder_private; Uint32 offset = __Sound_convertMsToBytePos(&sample->actual, ms); - const Sint64 origpos = SDL_RWtell(internal->rw); + const Sint64 origpos = SDL_TellIO(internal->rw); const Uint32 origrest = v->rest; BAIL_IF_MACRO(!VOC_rewind(sample), NULL, 0); @@ -516,7 +516,7 @@ static int VOC_seek(Sound_Sample *sample, Uint32 ms) Uint32 rc = voc_read_waveform(sample, 0, offset); if ( (rc == 0) || (!voc_get_block(sample, v)) ) { - SDL_RWseek(internal->rw, origpos, RW_SEEK_SET); + SDL_SeekIO(internal->rw, origpos, SDL_IO_SEEK_SET); v->rest = origrest; return 0; } /* if */ diff --git a/src/SDL_sound_vorbis.c b/src/SDL_sound_vorbis.c index b427521e..847c3da7 100644 --- a/src/SDL_sound_vorbis.c +++ b/src/SDL_sound_vorbis.c @@ -60,11 +60,8 @@ #define cos(x) SDL_cos(x) #define sin(x) SDL_sin(x) #define log(x) SDL_log(x) -#if SDL_VERSION_ATLEAST(2, 0, 9) -#define exp SDL_exp +#define exp(x) SDL_exp(x) #endif -#endif - #include "stb_vorbis.h" static const char *vorbis_error_string(const int err) @@ -96,9 +93,9 @@ static const char *vorbis_error_string(const int err) return "VORBIS: unknown error"; } /* vorbis_error_string */ -static SDL_bool VORBIS_init(void) +static bool VORBIS_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* VORBIS_init */ static void VORBIS_quit(void) @@ -109,7 +106,7 @@ static void VORBIS_quit(void) static int VORBIS_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; int err = 0; stb_vorbis *stb = stb_vorbis_open_rwops(rw, 0, &err, NULL); unsigned int num_frames; @@ -120,7 +117,7 @@ static int VORBIS_open(Sound_Sample *sample, const char *ext) internal->decoder_private = stb; sample->flags = SOUND_SAMPLEFLAG_CANSEEK; - sample->actual.format = AUDIO_F32SYS; + sample->actual.format = SDL_AUDIO_F32; sample->actual.channels = stb->channels; sample->actual.rate = stb->sample_rate; num_frames = stb_vorbis_stream_length_in_samples(stb); diff --git a/src/SDL_sound_wav.c b/src/SDL_sound_wav.c index 31c338d9..72984c58 100644 --- a/src/SDL_sound_wav.c +++ b/src/SDL_sound_wav.c @@ -19,40 +19,40 @@ #if SOUND_SUPPORTS_WAV /* Better than SDL_ReadLE16, since you can detect i/o errors... */ -static SDL_INLINE int read_le16(SDL_RWops *rw, Uint16 *ui16) +static SDL_INLINE int read_le16(SDL_IOStream *rw, Uint16 *ui16) { - int rc = SDL_RWread(rw, ui16, sizeof (Uint16), 1); - BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0); - *ui16 = SDL_SwapLE16(*ui16); + int rc = SDL_ReadIO(rw, ui16, sizeof(Uint16)); + BAIL_IF_MACRO(rc != sizeof(Uint16), ERR_IO_ERROR, 0); + *ui16 = SDL_Swap16LE(*ui16); return 1; } /* read_le16 */ -/* Better than SDL_ReadLE32, since you can detect i/o errors... */ -static SDL_INLINE int read_le32(SDL_RWops *rw, Uint32 *ui32) +/* Better than SDL_ReadU32LE, since you can detect i/o errors... */ +static SDL_INLINE int read_le32(SDL_IOStream *rw, Uint32 *ui32) { - int rc = SDL_RWread(rw, ui32, sizeof (Uint32), 1); - BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0); - *ui32 = SDL_SwapLE32(*ui32); + int rc = SDL_ReadIO(rw, ui32, sizeof(Uint32)); + BAIL_IF_MACRO(rc != sizeof(Uint32), ERR_IO_ERROR, 0); + *ui32 = SDL_Swap32LE(*ui32); return 1; } /* read_le32 */ -static SDL_INLINE int read_le16s(SDL_RWops *rw, Sint16 *si16) +static SDL_INLINE int read_le16s(SDL_IOStream *rw, Sint16 *si16) { return read_le16(rw, (Uint16 *) si16); } /* read_le16s */ -static SDL_INLINE int read_le32s(SDL_RWops *rw, Sint32 *si32) +static SDL_INLINE int read_le32s(SDL_IOStream *rw, Sint32 *si32) { return read_le32(rw, (Uint32 *) si32); } /* read_le32s */ /* This is just cleaner on the caller's end... */ -static SDL_INLINE int read_uint8(SDL_RWops *rw, Uint8 *ui8) +static SDL_INLINE int read_uint8(SDL_IOStream *rw, Uint8 *ui8) { - int rc = SDL_RWread(rw, ui8, sizeof (Uint8), 1); - BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0); + int rc = SDL_ReadIO(rw, ui8, sizeof (Uint8)); + BAIL_IF_MACRO(rc != sizeof (Uint8), ERR_IO_ERROR, 0); return 1; } /* read_uint8 */ @@ -136,14 +136,14 @@ typedef struct S_WAV_FMT_T * Note that the union "fmt" is not read in here; that is handled as * needed in the read_fmt_* functions. */ -static int read_fmt_chunk(SDL_RWops *rw, fmt_t *fmt) +static int read_fmt_chunk(SDL_IOStream *rw, fmt_t *fmt) { /* skip reading the chunk ID, since it was already read at this point... */ fmt->chunkID = fmtID; BAIL_IF_MACRO(!read_le32s(rw, &fmt->chunkSize), NULL, 0); BAIL_IF_MACRO(fmt->chunkSize < 16, "WAV: Invalid chunk size", 0); - fmt->next_chunk_offset = SDL_RWtell(rw) + fmt->chunkSize; + fmt->next_chunk_offset = SDL_TellIO(rw) + fmt->chunkSize; BAIL_IF_MACRO(!read_le16(rw, &fmt->wFormatTag), NULL, 0); BAIL_IF_MACRO(!read_le16(rw, &fmt->wChannels), NULL, 0); @@ -175,7 +175,7 @@ typedef struct * Read in a data_t from disk. This makes this process safe regardless of * the processor's byte order or how the fmt_t structure is packed. */ -static int read_data_chunk(SDL_RWops *rw, data_t *data) +static int read_data_chunk(SDL_IOStream *rw, data_t *data) { /* skip reading the chunk ID, since it was already read at this point... */ data->chunkID = dataID; @@ -214,7 +214,7 @@ static Uint32 read_sample_fmt_normal(Sound_Sample *sample) Uint32 max = (internal->buffer_size < (Uint32) w->bytesLeft) ? internal->buffer_size : (Uint32) w->bytesLeft; - /* We need to convert 24-bit PCM to an SDL-friendly AUDIO_S32SYS ... */ + /* We need to convert 24-bit PCM to an SDL-friendly SDL_AUDIO_S32 ... */ if (w->fmt->wBitsPerSample == 24) { const Uint32 num_samples = max / 3; @@ -232,7 +232,7 @@ static Uint32 read_sample_fmt_normal(Sound_Sample *sample) * We don't actually do any decoding, so we read the wav data * directly into the internal buffer... */ - retval = SDL_RWread(internal->rw, internal->buffer, 1, max); + retval = SDL_ReadIO(internal->rw, internal->buffer, max); w->bytesLeft -= retval; @@ -271,7 +271,7 @@ static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms) fmt_t *fmt = w->fmt; const Sint64 offset = __Sound_convertMsToBytePos(&sample->actual, ms); const Sint64 pos = (fmt->data_starting_offset + offset); - const Sint64 rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); w->bytesLeft = fmt->total_bytes - offset; return 1; /* success. */ @@ -285,7 +285,7 @@ static int rewind_sample_fmt_normal(Sound_Sample *sample) } /* rewind_sample_fmt_normal */ -static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) +static int read_fmt_normal(SDL_IOStream *rw, fmt_t *fmt) { /* (don't need to read more from the RWops...) */ fmt->free = NULL; @@ -309,7 +309,7 @@ static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) static SDL_INLINE int read_adpcm_block_headers(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; ADPCMBLOCKHEADER *headers = fmt->fmt.adpcm.blockheaders; @@ -386,7 +386,7 @@ static SDL_INLINE int decode_adpcm_sample_frame(Sound_Sample *sample) wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; ADPCMBLOCKHEADER *headers = fmt->fmt.adpcm.blockheaders; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; int i; int max = fmt->wChannels; Uint8 nib = fmt->fmt.adpcm.nibble; @@ -517,12 +517,12 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms) wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; const Uint32 origsampsleft = fmt->fmt.adpcm.samples_left_in_block; - const Sint64 origpos = SDL_RWtell(internal->rw); + const Sint64 origpos = SDL_TellIO(internal->rw); const Sint64 offset = __Sound_convertMsToBytePos(&sample->actual, ms); const Sint64 bpb = (fmt->fmt.adpcm.wSamplesPerBlock * fmt->sample_frame_size); Sint64 skipsize = (offset / bpb) * fmt->wBlockAlign; const Sint64 pos = skipsize + fmt->data_starting_offset; - Sint64 rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET); + Sint64 rc = SDL_SeekIO(internal->rw, pos, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); /* The offset we need is in this block, so we need to decode to there. */ @@ -530,7 +530,7 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms) rc = (offset % bpb); /* bytes into this block we need to decode */ if (!read_adpcm_block_headers(sample)) { - SDL_RWseek(internal->rw, origpos, RW_SEEK_SET); /* try to make sane. */ + SDL_SeekIO(internal->rw, origpos, SDL_IO_SEEK_SET); /* try to make sane. */ return 0; } /* if */ @@ -541,7 +541,7 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms) { if (!decode_adpcm_sample_frame(sample)) { - SDL_RWseek(internal->rw, origpos, RW_SEEK_SET); + SDL_SeekIO(internal->rw, origpos, SDL_IO_SEEK_SET); fmt->fmt.adpcm.samples_left_in_block = origsampsleft; return 0; } /* if */ @@ -560,7 +560,7 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms) * safe regardless of the processor's byte order or how the fmt_t * structure is packed. */ -static int read_fmt_adpcm(SDL_RWops *rw, fmt_t *fmt) +static int read_fmt_adpcm(SDL_IOStream *rw, fmt_t *fmt) { size_t i; @@ -599,9 +599,9 @@ static int read_fmt_adpcm(SDL_RWops *rw, fmt_t *fmt) * Everything else... * *****************************************************************************/ -static SDL_bool WAV_init(void) +static bool WAV_init(void) { - return SDL_TRUE; /* always succeeds. */ + return true; /* always succeeds. */ } /* WAV_init */ @@ -611,7 +611,7 @@ static void WAV_quit(void) } /* WAV_quit */ -static int read_fmt(SDL_RWops *rw, fmt_t *fmt) +static int read_fmt(SDL_IOStream *rw, fmt_t *fmt) { /* if it's in this switch statement, we support the format. */ switch (fmt->wFormatTag) @@ -641,11 +641,11 @@ static int read_fmt(SDL_RWops *rw, fmt_t *fmt) /* * Locate a specific chunk in the WAVE file by ID... */ -static int find_chunk(SDL_RWops *rw, Uint32 id) +static int find_chunk(SDL_IOStream *rw, Uint32 id) { Sint32 siz = 0; Uint32 _id = 0; - Sint64 pos = SDL_RWtell(rw); + Sint64 pos = SDL_TellIO(rw); while (1) { @@ -658,7 +658,7 @@ static int find_chunk(SDL_RWops *rw, Uint32 id) SDL_assert(siz >= 0); pos += (sizeof (Uint32) * 2) + siz; if (siz > 0) - BAIL_IF_MACRO(SDL_RWseek(rw, pos, RW_SEEK_SET) != pos, NULL, 0); + BAIL_IF_MACRO(SDL_SeekIO(rw, pos, SDL_IO_SEEK_SET) != pos, NULL, 0); } /* while */ return 0; /* shouldn't hit this, but just in case... */ @@ -668,13 +668,17 @@ static int find_chunk(SDL_RWops *rw, Uint32 id) static int WAV_open_internal(Sound_Sample *sample, const char *ext, fmt_t *fmt) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; - SDL_RWops *rw = internal->rw; + SDL_IOStream *rw = internal->rw; data_t d; wav_t *w; - BAIL_IF_MACRO(SDL_ReadLE32(rw) != riffID, "WAV: Not a RIFF file.", 0); - SDL_ReadLE32(rw); /* throw the length away; we get this info later. */ - BAIL_IF_MACRO(SDL_ReadLE32(rw) != waveID, "WAV: Not a WAVE file.", 0); + Uint32 value = 0; + SDL_ReadU32LE(rw, &value); + BAIL_IF_MACRO(value != riffID, "WAV: Not a RIFF file.", 0); + SDL_ReadU32LE(rw, &value); /* throw the length away; we get this info later. */ + value = 0; + SDL_ReadU32LE(rw, &value); + BAIL_IF_MACRO(value != waveID, "WAV: Not a WAVE file.", 0); BAIL_IF_MACRO(!find_chunk(rw, fmtID), "WAV: No format chunk.", 0); BAIL_IF_MACRO(!read_fmt_chunk(rw, fmt), "WAV: Can't read format chunk.", 0); @@ -684,17 +688,17 @@ static int WAV_open_internal(Sound_Sample *sample, const char *ext, fmt_t *fmt) if (fmt->wFormatTag == FMT_IEEE_FLOAT) { BAIL_IF_MACRO(fmt->wBitsPerSample != 32, "WAV: Unsupported sample size.", 0); - sample->actual.format = AUDIO_F32LSB; + sample->actual.format = SDL_AUDIO_F32LE; } /* if */ else { switch (fmt->wBitsPerSample) { - case 4: sample->actual.format = AUDIO_S16SYS; break; - case 8: sample->actual.format = AUDIO_U8; break; - case 16: sample->actual.format = AUDIO_S16LSB; break; - case 24: sample->actual.format = AUDIO_S32SYS; break; - case 32: sample->actual.format = AUDIO_S32LSB; break; + case 4: sample->actual.format = SDL_AUDIO_S16; break; + case 8: sample->actual.format = SDL_AUDIO_U8; break; + case 16: sample->actual.format = SDL_AUDIO_S16LE; break; + case 24: sample->actual.format = SDL_AUDIO_S32; break; + case 32: sample->actual.format = SDL_AUDIO_S32LE; break; default: SNDDBG(("WAV: %d bits per sample!?\n", (int) fmt->wBitsPerSample)); BAIL_MACRO("WAV: Unsupported sample size.", 0); @@ -702,7 +706,7 @@ static int WAV_open_internal(Sound_Sample *sample, const char *ext, fmt_t *fmt) } /* else */ BAIL_IF_MACRO(!read_fmt(rw, fmt), NULL, 0); - SDL_RWseek(rw, fmt->next_chunk_offset, RW_SEEK_SET); + SDL_SeekIO(rw, fmt->next_chunk_offset, SDL_IO_SEEK_SET); BAIL_IF_MACRO(!find_chunk(rw, dataID), "WAV: No data chunk.", 0); BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0); @@ -710,7 +714,7 @@ static int WAV_open_internal(Sound_Sample *sample, const char *ext, fmt_t *fmt) BAIL_IF_MACRO(w == NULL, ERR_OUT_OF_MEMORY, 0); w->fmt = fmt; fmt->total_bytes = w->bytesLeft = d.chunkSize; - fmt->data_starting_offset = SDL_RWtell(rw); + fmt->data_starting_offset = SDL_TellIO(rw); fmt->sample_frame_size = ( ((sample->actual.format & 0xFF) / 8) * sample->actual.channels ); internal->decoder_private = (void *) w; @@ -778,7 +782,7 @@ static int WAV_rewind(Sound_Sample *sample) Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; - const Sint64 rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, RW_SEEK_SET); + const Sint64 rc = SDL_SeekIO(internal->rw, fmt->data_starting_offset, SDL_IO_SEEK_SET); BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0); w->bytesLeft = fmt->total_bytes; return fmt->rewind_sample(sample); diff --git a/src/libmodplug/fastmix.c b/src/libmodplug/fastmix.c index dd702adf..1d82adce 100644 --- a/src/libmodplug/fastmix.c +++ b/src/libmodplug/fastmix.c @@ -8,7 +8,7 @@ #include "libmodplug.h" #include -#include "SDL_stdinc.h" +#include #define floor SDL_floor /* diff --git a/src/libmodplug/libmodplug.h b/src/libmodplug/libmodplug.h index 432f2389..22ac264e 100644 --- a/src/libmodplug/libmodplug.h +++ b/src/libmodplug/libmodplug.h @@ -353,10 +353,10 @@ typedef const BYTE * LPCBYTE; int _muldiv(long a, long b, long c); int _muldivr(long a, long b, long c); -#define bswapLE16(X) SDL_SwapLE16((X)) -#define bswapLE32(X) SDL_SwapLE32((X)) -#define bswapBE16(X) SDL_SwapBE16((X)) -#define bswapBE32(X) SDL_SwapBE32((X)) +#define bswapLE16(X) SDL_Swap16LE((X)) +#define bswapLE32(X) SDL_Swap32LE((X)) +#define bswapBE16(X) SDL_Swap16BE((X)) +#define bswapBE32(X) SDL_Swap32BE((X)) // Reverb Types (GM2 Presets) enum { diff --git a/src/libmodplug/snd_fx.c b/src/libmodplug/snd_fx.c index b926f861..3725efbf 100644 --- a/src/libmodplug/snd_fx.c +++ b/src/libmodplug/snd_fx.c @@ -536,13 +536,13 @@ void CSoundFile_NoteChange(CSoundFile *_this, UINT nChn, int note, BOOL bPorta, // Volume Swing if (penv->nVolSwing) { - int d = ((LONG)penv->nVolSwing*(LONG)((SDL_rand() & 0xFF) - 0x7F)) / 128; + int d = ((LONG)penv->nVolSwing*(LONG)((SDL_rand_bits() & 0xFF) - 0x7F)) / 128; pChn->nVolSwing = (signed short)((d * pChn->nVolume + 1)/128); } // Pan Swing if (penv->nPanSwing) { - int d = ((LONG)penv->nPanSwing*(LONG)((SDL_rand() & 0xFF) - 0x7F)) / 128; + int d = ((LONG)penv->nPanSwing*(LONG)((SDL_rand_bits() & 0xFF) - 0x7F)) / 128; pChn->nPanSwing = (signed short)d; } } diff --git a/src/stb_vorbis.h b/src/stb_vorbis.h index 8686bdf8..90b70228 100644 --- a/src/stb_vorbis.h +++ b/src/stb_vorbis.h @@ -306,8 +306,8 @@ extern stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_cl #endif #ifdef STB_VORBIS_SDL -extern stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length); -extern stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc); +extern stb_vorbis * stb_vorbis_open_rwops_section(SDL_IOStream *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length); +extern stb_vorbis * stb_vorbis_open_rwops(SDL_IOStream *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc); #endif extern int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number); @@ -832,7 +832,7 @@ struct stb_vorbis int close_on_free; #endif #ifdef STB_VORBIS_SDL - SDL_RWops *rwops; + SDL_IOStream *rwops; uint32 rwops_start; int close_on_free; #endif @@ -1399,7 +1399,7 @@ static uint8 get8(vorb *z) { #ifdef STB_VORBIS_SDL uint8 c; - if (SDL_RWread(z->rwops, &c, 1, 1) != 1) { z->eof = TRUE; return 0; } + if (SDL_ReadIO(z->rwops, &c, 1) != 1) { z->eof = TRUE; return 0; } return c; #else @@ -1431,7 +1431,7 @@ static uint32 get32(vorb *f) static int getn(vorb *z, uint8 *data, int n) { #ifdef STB_VORBIS_SDL - if (SDL_RWread(z->rwops, data, n, 1) == 1) return 1; + if (SDL_ReadIO(z->rwops, data, n) == n) return 1; z->eof = 1; return 0; @@ -1457,7 +1457,7 @@ static int getn(vorb *z, uint8 *data, int n) static void skip(vorb *z, int n) { #ifdef STB_VORBIS_SDL - SDL_RWseek(z->rwops, n, RW_SEEK_CUR); + SDL_SeekIO(z->rwops, n, SDL_IO_SEEK_CUR); #else if (USE_MEMORY(z)) { @@ -1489,10 +1489,10 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc) } else { loc += f->rwops_start; } - if (SDL_RWseek(f->rwops, loc, RW_SEEK_SET) != -1) + if (SDL_SeekIO(f->rwops, loc, SDL_IO_SEEK_SET) != -1) return 1; f->eof = 1; - SDL_RWseek(f->rwops, f->rwops_start, RW_SEEK_END); + SDL_SeekIO(f->rwops, f->rwops_start, SDL_IO_SEEK_END); return 0; #else @@ -4408,7 +4408,7 @@ static void vorbis_deinit(stb_vorbis *p) setup_temp_free(p, &p->temp_mults, 0); } #ifdef STB_VORBIS_SDL - if (p->close_on_free) SDL_RWclose(p->rwops); + if (p->close_on_free) SDL_CloseIO(p->rwops); #endif #ifndef STB_VORBIS_NO_STDIO if (p->close_on_free) fclose(p->f); @@ -4709,7 +4709,7 @@ unsigned int stb_vorbis_get_file_offset(stb_vorbis *f) if (f->push_mode) return 0; #endif #ifdef STB_VORBIS_SDL - return (unsigned int) (SDL_RWtell(f->rwops) - f->rwops_start); + return (unsigned int) (SDL_TellIO(f->rwops) - f->rwops_start); #else if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start); #endif @@ -5271,12 +5271,12 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const st #endif // STB_VORBIS_NO_STDIO #ifdef STB_VORBIS_SDL -stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length) +stb_vorbis * stb_vorbis_open_rwops_section(SDL_IOStream *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length) { stb_vorbis *f, p; vorbis_init(&p, alloc); p.rwops = rwops; - p.rwops_start = (uint32) SDL_RWtell(rwops); + p.rwops_start = (uint32) SDL_TellIO(rwops); p.stream_len = length; p.close_on_free = close_on_free; if (start_decoder(&p)) { @@ -5292,10 +5292,10 @@ stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, return NULL; } -stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc) +stb_vorbis * stb_vorbis_open_rwops(SDL_IOStream *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc) { - const unsigned int start = (unsigned int) SDL_RWtell(rwops); - const unsigned int len = (unsigned int) (SDL_RWsize(rwops) - start); + const unsigned int start = (unsigned int) SDL_TellIO(rwops); + const unsigned int len = (unsigned int) (SDL_GetIOSize(rwops) - start); return stb_vorbis_open_rwops_section(rwops, close_on_free, error, alloc, len); } #endif diff --git a/src/timidity/common.c b/src/timidity/common.c index e48e50ad..093e2a04 100644 --- a/src/timidity/common.c +++ b/src/timidity/common.c @@ -33,9 +33,9 @@ typedef struct _PathList { static PathList *pathlist = NULL; /* This is meant to find and open files for reading */ -SDL_RWops *timi_openfile(const char *name) +SDL_IOStream *timi_openfile(const char *name) { - SDL_RWops *rw; + SDL_IOStream *rw; if (!name || !(*name)) { SNDDBG(("Attempted to open nameless file.\n")); @@ -45,7 +45,7 @@ SDL_RWops *timi_openfile(const char *name) /* First try the given name */ SNDDBG(("Trying to open %s\n", name)); - if ((rw = SDL_RWFromFile(name, "rb")) != NULL) + if ((rw = SDL_IOFromFile(name, "rb")) != NULL) return rw; if (!is_abspath(name)) @@ -66,11 +66,11 @@ SDL_RWops *timi_openfile(const char *name) if(!is_dirsep(p[-1])) { *p++ = CHAR_DIRSEP; l++; - } } + } SDL_strlcpy(p, name, sizeof(current_filename) - l); SNDDBG(("Trying to open %s\n", current_filename)); - if ((rw = SDL_RWFromFile(current_filename, "rb"))) + if ((rw = SDL_IOFromFile(current_filename, "rb"))) return rw; plp = plp->next; } diff --git a/src/timidity/common.h b/src/timidity/common.h index 2985ad6d..60932b3e 100644 --- a/src/timidity/common.h +++ b/src/timidity/common.h @@ -11,7 +11,7 @@ #ifndef TIMIDITY_COMMON_H #define TIMIDITY_COMMON_H -extern SDL_RWops *timi_openfile(const char *name); +extern SDL_IOStream *timi_openfile(const char *name); /* pathlist funcs only to be used during Timidity_Init/Timidity_Exit */ extern int timi_add_pathlist(const char *s, size_t len); diff --git a/src/timidity/instrum.c b/src/timidity/instrum.c index 2dfaaebb..7c1c781c 100644 --- a/src/timidity/instrum.c +++ b/src/timidity/instrum.c @@ -151,7 +151,7 @@ static void load_instrument(MidiSong *song, const char *name, { Instrument *ip; Sample *sp; - SDL_RWops *rw; + SDL_IOStream *rw; char tmp[1024]; int i,j; static char *patch_ext[] = PATCH_EXT_LIST; @@ -184,7 +184,7 @@ static void load_instrument(MidiSong *song, const char *name, /* Read some headers and do cursory sanity checks. There are loads of magic offsets. This could be rewritten... */ - if ((239 != SDL_RWread(rw, tmp, 1, 239)) || + if ((239 != SDL_ReadIO(rw, tmp, 239)) || (SDL_memcmp(tmp, "GF1PATCH110\0ID#000002", 22) && SDL_memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) /* don't know what the differences are */ @@ -222,18 +222,18 @@ static void load_instrument(MidiSong *song, const char *name, Uint8 tmpchar; #define READ_CHAR(thing) \ - if (1 != SDL_RWread(rw, &tmpchar, 1, 1)) goto badread; \ + if (1 != SDL_ReadIO(rw, &tmpchar, 1)) goto badread; \ thing = tmpchar; #define READ_SHORT(thing) \ - if (1 != SDL_RWread(rw, &tmpshort, 2, 1)) goto badread; \ - thing = SDL_SwapLE16(tmpshort); + if (2 != SDL_ReadIO(rw, &tmpshort, 2)) goto badread; \ + thing = SDL_Swap16LE(tmpshort); #define READ_LONG(thing) \ - if (1 != SDL_RWread(rw, &tmplong, 4, 1)) goto badread; \ - thing = (Sint32)SDL_SwapLE32((Uint32)tmplong); + if (4 != SDL_ReadIO(rw, &tmplong, 4)) goto badread; \ + thing = (Sint32)SDL_Swap32LE((Uint32)tmplong); - SDL_RWseek(rw, 7, RW_SEEK_CUR); /* Skip the wave name */ + SDL_SeekIO(rw, 7, SDL_IO_SEEK_CUR); /* Skip the wave name */ - if (1 != SDL_RWread(rw, &fractions, 1, 1)) + if (1 != SDL_ReadIO(rw, &fractions, 1)) goto badread; sp=&(ip->sample[i]); @@ -245,7 +245,7 @@ static void load_instrument(MidiSong *song, const char *name, READ_LONG(sp->low_freq); READ_LONG(sp->high_freq); READ_LONG(sp->root_freq); - SDL_RWseek(rw, 2, RW_SEEK_CUR); /* Why have a "root frequency" and then + SDL_SeekIO(rw, 2, SDL_IO_SEEK_CUR); /* Why have a "root frequency" and then * "tuning"?? */ READ_CHAR(tmp[0]); @@ -256,7 +256,7 @@ static void load_instrument(MidiSong *song, const char *name, sp->panning=(Uint8)(panning & 0x7F); /* envelope, tremolo, and vibrato */ - if (18 != SDL_RWread(rw, tmp, 1, 18)) + if (18 != SDL_ReadIO(rw, tmp, 18)) goto badread; if (!tmp[13] || !tmp[14]) @@ -294,7 +294,7 @@ static void load_instrument(MidiSong *song, const char *name, READ_CHAR(sp->modes); - SDL_RWseek(rw, 40, RW_SEEK_CUR); /* skip the useless scale frequency, scale + SDL_SeekIO(rw, 40, SDL_IO_SEEK_CUR); /* skip the useless scale frequency, scale factor (what's it mean?), and reserved space */ @@ -368,7 +368,7 @@ static void load_instrument(MidiSong *song, const char *name, sp->data = (sample_t *) SDL_malloc(sp->data_length+4); if (!sp->data) goto nomem; - if (1 != SDL_RWread(rw, sp->data, sp->data_length, 1)) + if (sp->data_length != SDL_ReadIO(rw, sp->data, sp->data_length)) goto badread; if (!(sp->modes & MODES_16BIT)) /* convert to 16-bit data */ @@ -394,7 +394,7 @@ static void load_instrument(MidiSong *song, const char *name, Sint16 *tmp16=(Sint16 *)sp->data,s; while (k--) { - s=SDL_SwapLE16(*tmp16); + s=SDL_Swap16LE(*tmp16); *tmp16++=s; } } @@ -488,7 +488,7 @@ static void load_instrument(MidiSong *song, const char *name, } } - SDL_RWclose(rw); + SDL_CloseIO(rw); return; nomem: @@ -499,7 +499,7 @@ static void load_instrument(MidiSong *song, const char *name, fail: free_instrument (ip); badpat: - SDL_RWclose(rw); + SDL_CloseIO(rw); *out = NULL; } diff --git a/src/timidity/readmidi.c b/src/timidity/readmidi.c index b22469f4..57cdcf17 100644 --- a/src/timidity/readmidi.c +++ b/src/timidity/readmidi.c @@ -31,13 +31,13 @@ static void compute_sample_increment(MidiSong *song, Sint32 tempo, } /* Read variable-length number (7 bits per byte, MSB first) */ -static Sint32 getvl(SDL_RWops *rw) +static Sint32 getvl(SDL_IOStream *rw) { Sint32 l=0; Uint8 c; for (;;) { - if (!SDL_RWread(rw, &c, 1, 1)) return l; + if (!SDL_ReadIO(rw, &c, 1)) return l; l += (c & 0x7f); if (!(c & 0x80)) return l; l<<=7; @@ -47,7 +47,7 @@ static Sint32 getvl(SDL_RWops *rw) #if (defined DEBUG_CHATTER) /* Print a string from the file, followed by a newline. Any non-ASCII or unprintable characters will be converted to periods. */ -static int dumpstring(SDL_RWops *rw, Sint32 len, Uint8 type) +static int dumpstring(SDL_IOStream *rw, Sint32 len, Uint8 type) { static const char *label[] = { "Text event: ", "Text: ", "Copyright: ", "Track name: ", @@ -55,10 +55,10 @@ static int dumpstring(SDL_RWops *rw, Sint32 len, Uint8 type) signed char *s = SDL_malloc(len+1); if (!s) { - SDL_RWseek(rw, len, RW_SEEK_CUR);/* should I ? */ + SDL_SeekIO(rw, len, SDL_IO_SEEK_CUR);/* should I ? */ return -1; } - if (len != (Sint32) SDL_RWread(rw, s, 1, len)) + if (len != (Sint32) SDL_ReadIO(rw, s, len)) { SDL_free(s); return -1; @@ -102,27 +102,27 @@ static MidiEventList *read_midi_event(MidiSong *song) for (;;) { song->at += getvl(song->rw); - if (SDL_RWread(song->rw, &me, 1, 1) != 1) + if (!SDL_ReadIO(song->rw, &me, 1)) { - SNDDBG(("read_midi_event: SDL_RWread() failure\n")); + SNDDBG(("read_midi_event: SDL_ReadIO() failure\n")); return NULL; } if(me==0xF0 || me == 0xF7) /* SysEx event */ { len=getvl(song->rw); - SDL_RWseek(song->rw, len, RW_SEEK_CUR); + SDL_SeekIO(song->rw, len, SDL_IO_SEEK_CUR); } else if(me==0xFF) /* Meta event */ { - SDL_RWread(song->rw, &type, 1, 1); + SDL_ReadIO(song->rw, &type, 1); len=getvl(song->rw); if (type>0 && type<16) { #if (defined DEBUG_CHATTER) dumpstring(song->rw, len, type); #else - SDL_RWseek(song->rw, len, RW_SEEK_CUR); + SDL_SeekIO(song->rw, len, SDL_IO_SEEK_CUR); #endif } else @@ -132,14 +132,14 @@ static MidiEventList *read_midi_event(MidiSong *song) return MAGIC_EOT; case 0x51: /* Tempo */ - SDL_RWread(song->rw, &a, 1, 1); - SDL_RWread(song->rw, &b, 1, 1); - SDL_RWread(song->rw, &c, 1, 1); + SDL_ReadIO(song->rw, &a, 1); + SDL_ReadIO(song->rw, &b, 1); + SDL_ReadIO(song->rw, &c, 1); MIDIEVENT(song->at, ME_TEMPO, c, a, b); default: SNDDBG(("(Meta event type 0x%02x, length %d)\n", type, len)); - SDL_RWseek(song->rw, len, RW_SEEK_CUR); + SDL_SeekIO(song->rw, len, SDL_IO_SEEK_CUR); break; } } @@ -150,28 +150,28 @@ static MidiEventList *read_midi_event(MidiSong *song) { lastchan=a & 0x0F; laststatus=(a>>4) & 0x07; - SDL_RWread(song->rw, &a, 1, 1); + SDL_ReadIO(song->rw, &a, 1); a &= 0x7F; } switch(laststatus) { case 0: /* Note off */ - SDL_RWread(song->rw, &b, 1, 1); + SDL_ReadIO(song->rw, &b, 1); b &= 0x7F; MIDIEVENT(song->at, ME_NOTEOFF, lastchan, a,b); case 1: /* Note on */ - SDL_RWread(song->rw, &b, 1, 1); + SDL_ReadIO(song->rw, &b, 1); b &= 0x7F; MIDIEVENT(song->at, ME_NOTEON, lastchan, a,b); case 2: /* Key Pressure */ - SDL_RWread(song->rw, &b, 1, 1); + SDL_ReadIO(song->rw, &b, 1); b &= 0x7F; MIDIEVENT(song->at, ME_KEYPRESSURE, lastchan, a, b); case 3: /* Control change */ - SDL_RWread(song->rw, &b, 1, 1); + SDL_ReadIO(song->rw, &b, 1); b &= 0x7F; { int control=255; @@ -251,7 +251,7 @@ static MidiEventList *read_midi_event(MidiSong *song) break; case 6: /* Pitch wheel */ - SDL_RWread(song->rw, &b, 1, 1); + SDL_ReadIO(song->rw, &b, 1); b &= 0x7F; MIDIEVENT(song->at, ME_PITCHWHEEL, lastchan, a, b); @@ -290,13 +290,13 @@ static int read_track(MidiSong *song, int append) song->at=0; /* Check the formalities */ - if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1) + if (SDL_ReadIO(song->rw, tmp, 4) != 4 || SDL_ReadIO(song->rw, &len, 4) != 4) { SNDDBG(("Can't read track header.\n")); return -1; } - len=(Sint32)SDL_SwapBE32((Uint32)len); - next_pos = SDL_RWtell(song->rw) + len; + len=(Sint32)SDL_Swap32BE((Uint32)len); + next_pos = SDL_TellIO(song->rw) + len; if (SDL_memcmp(tmp, "MTrk", 4)) { SNDDBG(("Corrupt MIDI file.\n")); @@ -312,9 +312,9 @@ static int read_track(MidiSong *song, int append) { /* If the track ends before the size of the * track data, skip any junk at the end. */ - pos = SDL_RWtell(song->rw); + pos = SDL_TellIO(song->rw); if (pos < next_pos) - SDL_RWseek(song->rw, next_pos - pos, RW_SEEK_CUR); + SDL_SeekIO(song->rw, next_pos - pos, SDL_IO_SEEK_CUR); return 0; } @@ -530,23 +530,23 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp) song->at=0; song->evlist = NULL; - if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1) + if (SDL_ReadIO(song->rw, tmp, 4) != 4 || SDL_ReadIO(song->rw, &len, 4) != 4) { SNDDBG(("Not a MIDI file!\n")); return NULL; } if (SDL_memcmp(tmp, "RIFF", 4) == 0) { /* RMID ?? */ - if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_memcmp(tmp, "RMID", 4) != 0 || - SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_memcmp(tmp, "data", 4) != 0 || - SDL_RWread(song->rw, tmp, 1, 4) != 4 || + if (SDL_ReadIO(song->rw, tmp, 4) != 4 || SDL_memcmp(tmp, "RMID", 4) != 0 || + SDL_ReadIO(song->rw, tmp, 4) != 4 || SDL_memcmp(tmp, "data", 4) != 0 || + SDL_ReadIO(song->rw, tmp, 4) != 4 || /* SMF must begin from here onwards: */ - SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1) + SDL_ReadIO(song->rw, tmp, 4) != 4 || SDL_ReadIO(song->rw, &len, 4) != 4) { SNDDBG(("Not an RMID file!\n")); return NULL; } } - len=(Sint32)SDL_SwapBE32((Uint32)len); + len=(Sint32)SDL_Swap32BE((Uint32)len); if (SDL_memcmp(tmp, "MThd", 4) || len < 6) { SNDDBG(("Not a MIDI file!\n")); @@ -554,12 +554,12 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp) } format=tracks=divisions_tmp = -1; - SDL_RWread(song->rw, &format, 2, 1); - SDL_RWread(song->rw, &tracks, 2, 1); - SDL_RWread(song->rw, &divisions_tmp, 2, 1); - format=SDL_SwapBE16(format); - tracks=SDL_SwapBE16(tracks); - divisions_tmp=SDL_SwapBE16(divisions_tmp); + SDL_ReadIO(song->rw, &format, 2); + SDL_ReadIO(song->rw, &tracks, 2); + SDL_ReadIO(song->rw, &divisions_tmp, 2); + format=SDL_Swap16BE(format); + tracks=SDL_Swap16BE(tracks); + divisions_tmp=SDL_Swap16BE(divisions_tmp); if (divisions_tmp<0) { @@ -572,7 +572,7 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp) if (len > 6) { SNDDBG(("MIDI file header size %u bytes", len)); - SDL_RWseek(song->rw, len-6, RW_SEEK_CUR); /* skip the excess */ + SDL_SeekIO(song->rw, len-6, SDL_IO_SEEK_CUR); /* skip the excess */ } if (format<0 || format >2) { diff --git a/src/timidity/timidity.c b/src/timidity/timidity.c index 0718b9e7..c859dada 100644 --- a/src/timidity/timidity.c +++ b/src/timidity/timidity.c @@ -29,7 +29,7 @@ static char def_instr_name[256] = ""; /* Quick-and-dirty fgets() replacement. */ -static char *RWgets(SDL_RWops *rw, char *s, int size) +static char *RWgets(SDL_IOStream *rw, char *s, int size) { int num_read = 0; char *p = s; @@ -38,7 +38,7 @@ static char *RWgets(SDL_RWops *rw, char *s, int size) for (; num_read < size; ++p) { - if (SDL_RWread(rw, p, 1, 1) != 1) + if (!SDL_ReadIO(rw, p, 1)) break; num_read++; @@ -61,7 +61,7 @@ static char *RWgets(SDL_RWops *rw, char *s, int size) static int read_config_file(const char *name, int rcf_count) { - SDL_RWops *rw; + SDL_IOStream *rw; char tmp[1024]; char *w[MAXWORDS], *cp; char *endp; @@ -84,13 +84,13 @@ static int read_config_file(const char *name, int rcf_count) { line++; words=0; - w[0]=SDL_strtokr(tmp, " \t\240", &endp); + w[0]=SDL_strtok_r(tmp, " \t\240", &endp); if (!w[0]) continue; /* Originally the TiMidity++ extensions were prefixed like this */ if (SDL_strcmp(w[0], "#extension") == 0) { - w[0]=SDL_strtokr(0, " \t\240", &endp); + w[0]=SDL_strtok_r(0, " \t\240", &endp); if (!w[0]) continue; } @@ -423,7 +423,7 @@ static int read_config_file(const char *name, int rcf_count) r = 0; /* we're good. */ fail: - SDL_RWclose(rw); + SDL_CloseIO(rw); return r; } @@ -503,7 +503,7 @@ int Timidity_Init(const char *config_file) return init_with_config(config_file); } -static void do_song_load(SDL_RWops *rw, SDL_AudioSpec *audio, MidiSong **out) +static void do_song_load(SDL_IOStream *rw, SDL_AudioSpec *audio, MidiSong **out) { MidiSong *song; int i; @@ -552,34 +552,28 @@ static void do_song_load(SDL_RWops *rw, SDL_AudioSpec *audio, MidiSong **out) goto fail; } switch (audio->format) { - case AUDIO_S8: + case SDL_AUDIO_S8: song->write = timi_s32tos8; break; - case AUDIO_U8: + case SDL_AUDIO_U8: song->write = timi_s32tou8; break; - case AUDIO_S16LSB: + case SDL_AUDIO_S16LE: song->write = timi_s32tos16l; break; - case AUDIO_S16MSB: + case SDL_AUDIO_S16BE: song->write = timi_s32tos16b; break; - case AUDIO_U16LSB: - song->write = timi_s32tou16l; - break; - case AUDIO_U16MSB: - song->write = timi_s32tou16b; - break; - case AUDIO_S32LSB: + case SDL_AUDIO_S32LE: song->write = timi_s32tos32l; break; - case AUDIO_S32MSB: + case SDL_AUDIO_S32BE: song->write = timi_s32tos32b; break; - case AUDIO_F32LSB: + case SDL_AUDIO_F32LE: song->write = timi_s32tof32l; break; - case AUDIO_F32MSB: + case SDL_AUDIO_F32BE: song->write = timi_s32tof32b; break; default: @@ -587,10 +581,10 @@ static void do_song_load(SDL_RWops *rw, SDL_AudioSpec *audio, MidiSong **out) goto fail; } - song->buffer_size = audio->samples; - song->resample_buffer = SDL_malloc(audio->samples * sizeof(sample_t)); + song->buffer_size = 4096/*audio->samples*/; + song->resample_buffer = SDL_malloc(4096/*audio->samples*/ * sizeof(sample_t)); if (!song->resample_buffer) goto fail; - song->common_buffer = SDL_malloc(audio->samples * 2 * sizeof(Sint32)); + song->common_buffer = SDL_malloc(4096/*audio->samples*/* 2 * sizeof(Sint32)); if (!song->common_buffer) goto fail; song->control_ratio = audio->freq / CONTROLS_PER_SECOND; @@ -624,7 +618,7 @@ fail: Timidity_FreeSong(song); } } -MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio) +MidiSong *Timidity_LoadSong(SDL_IOStream *rw, SDL_AudioSpec *audio) { MidiSong *song; do_song_load(rw, audio, &song); diff --git a/src/timidity/timidity.h b/src/timidity/timidity.h index b3f893a2..1bd38e9c 100644 --- a/src/timidity/timidity.h +++ b/src/timidity/timidity.h @@ -104,7 +104,7 @@ typedef struct _MidiEventList { typedef struct { int oom; /* malloc() failed */ int playing; - SDL_RWops *rw; + SDL_IOStream *rw; Sint32 rate; Sint32 encoding; float master_volume; @@ -147,7 +147,7 @@ extern int Timidity_Init(const char *config_file); extern int Timidity_Init_NoConfig(void); extern void Timidity_SetVolume(MidiSong *song, int volume); extern int Timidity_PlaySome(MidiSong *song, void *stream, Sint32 len); -extern MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio); +extern MidiSong *Timidity_LoadSong(SDL_IOStream *rw, SDL_AudioSpec *audio); extern void Timidity_Start(MidiSong *song); extern void Timidity_Seek(MidiSong *song, Uint32 ms); extern Uint32 Timidity_GetSongLength(MidiSong *song); /* returns millseconds */ diff --git a/src/version.rc b/src/version.rc index bdfe4aa9..4c167d7f 100644 --- a/src/version.rc +++ b/src/version.rc @@ -9,8 +9,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,0,3,0 - PRODUCTVERSION 2,0,3,0 + FILEVERSION 3,0,0,0 + PRODUCTVERSION 3,0,0,0 FILEFLAGSMASK 0x3fL FILEFLAGS 0x0L FILEOS 0x40004L @@ -23,12 +23,12 @@ BEGIN BEGIN VALUE "CompanyName", "\0" VALUE "FileDescription", "SDL_sound\0" - VALUE "FileVersion", "2, 0, 3, 0\0" + VALUE "FileVersion", "3, 0, 0, 0\0" VALUE "InternalName", "SDL_sound\0" - VALUE "LegalCopyright", "Copyright © 2023 Ryan C. Gordon\0" - VALUE "OriginalFilename", "SDL2_sound.dll\0" + VALUE "LegalCopyright", "Copyright (C) 2024 Ryan C. Gordon\0" + VALUE "OriginalFilename", "SDL3_sound.dll\0" VALUE "ProductName", "Simple DirectMedia Layer\0" - VALUE "ProductVersion", "2, 0, 3, 0\0" + VALUE "ProductVersion", "3, 0, 0, 0\0" END END BLOCK "VarFileInfo" diff --git a/update_version.sh b/update_version.sh index 40476054..f154c5a4 100755 --- a/update_version.sh +++ b/update_version.sh @@ -6,17 +6,16 @@ if [ -z $1 ]; then fi NEWVERSION="$1" -echo "Updating version to '2.0.$NEWVERSION' ..." +echo "Updating version to '3.0.$NEWVERSION' ..." # !!! FIXME: update all of these. -perl -w -pi -e 's/(SDLSOUND_VERSION 2\.0\.)\d+/${1}'$NEWVERSION'/;' CMakeLists.txt -perl -w -pi -e 's/(VERSION = 2\.0\.)\d+/${1}'$NEWVERSION'/;' src/Makefile.os2 +perl -w -pi -e 's/(SDLSOUND_VERSION 3\.0\.)\d+/${1}'$NEWVERSION'/;' CMakeLists.txt perl -w -pi -e 's/(\#define SOUND_VER_PATCH )\d+/${1}'$NEWVERSION'/;' src/SDL_sound.h -perl -w -pi -e 's/(FILEVERSION 2,0,)\d+/${1}'$NEWVERSION'/;' src/version.rc -perl -w -pi -e 's/(PRODUCTVERSION 2,0,)\d+/${1}'$NEWVERSION'/;' src/version.rc -perl -w -pi -e 's/(VALUE "FileVersion", "2, 0, )\d+/${1}'$NEWVERSION'/;' src/version.rc -perl -w -pi -e 's/(VALUE "ProductVersion", "2, 0, )\d+/${1}'$NEWVERSION'/;' src/version.rc +perl -w -pi -e 's/(FILEVERSION 3,0,)\d+/${1}'$NEWVERSION'/;' src/version.rc +perl -w -pi -e 's/(PRODUCTVERSION 3,0,)\d+/${1}'$NEWVERSION'/;' src/version.rc +perl -w -pi -e 's/(VALUE "FileVersion", "3, 0, )\d+/${1}'$NEWVERSION'/;' src/version.rc +perl -w -pi -e 's/(VALUE "ProductVersion", "3, 0, )\d+/${1}'$NEWVERSION'/;' src/version.rc echo "All done." echo "Run 'git diff' and make sure this looks correct before 'git commit'."