Skip to content

Commit

Permalink
initial sdl3 migration, audio still missing
Browse files Browse the repository at this point in the history
  • Loading branch information
laamaa committed Feb 24, 2025
1 parent 514e71a commit 02832de
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-macos-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uname -m
- name: 'Install dependencies'
run: brew install cmake pkg-config sdl2 libserialport
run: brew install cmake pkg-config sdl3 libserialport

- name: 'Checkout'
uses: actions/checkout@v4
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/build-macos-intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
build-macos:
runs-on: macos-14
env:
SDL_VERSION: 2.32.0
SDL_SHA256: f5c2b52498785858f3de1e2996eba3c1b805d08fe168a47ea527c7fc339072d0
SDL_VERSION: 3.2.4
SDL_SHA256: 2938328317301dfbe30176d79c251733aa5e7ec5c436c800b99ed4da7adcb0f0

steps:
- name: 'Install dependencies'
Expand Down Expand Up @@ -40,32 +40,32 @@ jobs:
- name: Set current date as env variable
run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: 'Cache SDL2 files'
id: cache-x86_64-sdl2-files
- name: 'Cache SDL3 files'
id: cache-x86_64-sdl3-files
uses: actions/cache@v4
with:
path: 'SDL2-2.30.4'
key: mac-x86_64-sdl2-files
path: 'SDL3-3.2.4'
key: mac-x86_64-sdl3-files

- name: 'Download SDL2 sources'
- name: 'Download SDL3 sources'
if: steps.cache-x86_64-sdl2-files.outputs.cache-hit != 'true'
run: |
(curl https://www.libsdl.org/release/SDL2-$SDL_VERSION.tar.gz || curl -L https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL2-$SDL_VERSION.tar.gz) | tar xvf -
(curl https://www.libsdl.org/release/SDL3-$SDL_VERSION.tar.gz || curl -L https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL3-$SDL_VERSION.tar.gz) | echo $SDL_SHA256 | tar xvf -
- name: 'Build SDL2'
- name: 'Build SDL3'
if: steps.cache-x86_64-sdl2-files.outputs.cache-hit != 'true'
run: |
export MACOSX_DEPLOYMENT_TARGET="10.9"
pushd SDL2-$SDL_VERSION
pushd SDL3-$SDL_VERSION
mkdir build_x86_64
cd build_x86_64
../configure CPPFLAGS="-arch x86_64 -mmacosx-version-min=10.7 -DMAC_OS_X_VERSION_MIN_REQUIRED=1070 -isysroot $HOME/x86_64/SDKs/MacOSX10.7.sdk" CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" LDFLAGS="-arch x86_64 -F$HOME/x86_64/SDKs/MacOSX10.7.sdk/System/Library/Frameworks -L/usr/lib -L/usr/lib/system -Wl,-syslibroot,$HOME/x86_64/SDKs/MacOSX10.7.sdk" --host=x86_64-apple-darwin13 --prefix="$HOME/x86_64prefix"
make
popd
- name: 'Install SDL2'
- name: 'Install SDL3'
run: |
pushd SDL2-$SDL_VERSION/build_x86_64
pushd SDL3-$SDL_VERSION/build_x86_64
make install
popd
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: 'Install dependencies'
run: |
sudo apt-get update
sudo apt-get install --fix-missing build-essential libsdl2-dev libserialport-dev zip
sudo apt-get install --fix-missing build-essential libsdl3-dev libserialport-dev zip
- name: 'Checkout'
uses: actions/checkout@v4

Expand All @@ -27,7 +27,7 @@ jobs:
- name: 'Upload artifact'
uses: actions/upload-artifact@v4
with:
name: m8c-${{ env.NOW }}-linux
name: m8c-${{ env.NOW }}-linux-x86_64
path: |
LICENSE
README.md
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
msystem: ${{ matrix.sys }}
update: true
install: mingw-w64-${{ matrix.env }}-toolchain make mingw-w64-${{ matrix.env }}-SDL2 zip dos2unix autoconf automake-wrapper libtool make unzip
install: mingw-w64-${{ matrix.env }}-toolchain make mingw-w64-${{ matrix.env }}-sdl3 zip dos2unix autoconf automake-wrapper libtool make unzip

- name: 'Build libserialport manually'
run: |
Expand All @@ -58,12 +58,12 @@ jobs:
strip -g m8c.exe
if [ ${{ matrix.win }} == "win32" ]
then
cp /mingw32/bin/SDL2.dll .
cp /mingw32/bin/SDL3.dll .
cp /mingw32/bin/libgcc_s_dw2-1.dll .
cp /mingw32/bin/libserialport-0.dll .
cp /mingw32/bin/libwinpthread-1.dll .
else
cp /mingw64/bin/SDL2.dll .
cp /mingw64/bin/SDL3.dll .
cp /mingw64/bin/libserialport-0.dll .
fi
unix2dos README.md LICENSE AUDIOGUIDE.md
Expand All @@ -74,7 +74,7 @@ jobs:
name: m8c-${{ env.NOW }}-${{ matrix.win }}
path: |
m8c.exe
SDL2.dll
SDL3.dll
libserialport-0.dll
libgcc_s_dw2-1.dll
libwinpthread-1.dll
Expand All @@ -89,7 +89,7 @@ jobs:
name: m8c-${{ env.NOW }}-${{ matrix.win }}
path: |
m8c.exe
SDL2.dll
SDL3.dll
libserialport-0.dll
gamecontrollerdb.txt
LICENSE
Expand Down
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ set(CMAKE_C_FLAGS "-O2 -Wall -Wextra")
set(APP_NAME m8c)

find_package(PkgConfig REQUIRED)
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)

pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL3 REQUIRED sdl3)
if (USE_LIBUSB)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
link_directories(${SDL2_LIBRARY_DIRS} ${LIBUSB_LIBRARY_DIRS})
link_directories(${SDL3_LIBRARY_DIRS} ${LIBUSB_LIBRARY_DIRS})
add_compile_definitions(USE_LIBUSB)
else ()
pkg_check_modules(LIBSERIALPORT REQUIRED libserialport)
link_directories(${SDL2_LIBRARY_DIRS} ${LIBSERIALPORT_LIBRARY_DIRS})
link_directories(${SDL3_LIBRARY_DIRS} ${LIBSERIALPORT_LIBRARY_DIRS})
endif (USE_LIBUSB)

file(GLOB m8c_SRC "src/*.h" "src/*.c")
Expand All @@ -29,13 +30,13 @@ set_source_files_properties(${APP_ICON} PROPERTIES
add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE ${APP_ICON} ${m8c_SRC})

if (USE_LIBUSB)
target_link_libraries(${APP_NAME} ${SDL2_LIBRARIES} ${LIBUSB_LIBRARIES})
target_include_directories(${APP_NAME} PUBLIC ${SDL2_INCLUDE_DIRS} ${LIBUSB_INCLUDE_DIRS})
target_compile_options(${APP_NAME} PUBLIC ${SDL2_CFLAGS_OTHER} ${LIBUSB_CFLAGS_OTHER})
target_link_libraries(${APP_NAME} ${SDL3_LIBRARIES} ${LIBUSB_LIBRARIES})
target_include_directories(${APP_NAME} PUBLIC ${SDL3_INCLUDE_DIRS} ${LIBUSB_INCLUDE_DIRS})
target_compile_options(${APP_NAME} PUBLIC ${SDL3_CFLAGS_OTHER} ${LIBUSB_CFLAGS_OTHER})
else ()
target_link_libraries(${APP_NAME} ${SDL2_LIBRARIES} ${LIBSERIALPORT_LIBRARIES})
target_include_directories(${APP_NAME} PUBLIC ${SDL2_INCLUDE_DIRS} ${LIBSERIALPORT_INCLUDE_DIRS})
target_compile_options(${APP_NAME} PUBLIC ${SDL2_CFLAGS_OTHER} ${LIBSERIALPORT_CFLAGS_OTHER})
target_link_libraries(${APP_NAME} ${SDL3_LIBRARIES} ${LIBSERIALPORT_LIBRARIES})
target_include_directories(${APP_NAME} PUBLIC ${SDL3_INCLUDE_DIRS} ${LIBSERIALPORT_INCLUDE_DIRS})
target_compile_options(${APP_NAME} PUBLIC ${SDL3_CFLAGS_OTHER} ${LIBSERIALPORT_CFLAGS_OTHER})
endif ()

if (APPLE)
Expand All @@ -52,7 +53,7 @@ if (APPLE)
MACOSX_BUNDLE_BUNDLE_VERSION "1"
MACOSX_BUNDLE_COPYRIGHT "Copyright © 2021 laamaa. All rights reserved."
MACOSX_BUNDLE_GUI_IDENTIFIER "fi.laamaa.m8c"
MACOSX_BUNDLE_SHORT_VERSION_STRING "1.7.8"
MACOSX_BUNDLE_SHORT_VERSION_STRING "2.0.0"
MACOSX_BUNDLE_ICON_FILE "m8c.icns")

set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app")
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ OBJ = src/main.o src/serial.o src/slip.o src/command.o src/render.o src/ini.o sr
DEPS = src/serial.h src/slip.h src/command.h src/render.h src/ini.h src/config.h src/input.h src/gamecontrollers.h src/fx_cube.h src/audio.h src/ringbuffer.h src/inline_font.h

#Any special libraries you are using in your project (e.g. -lbcm2835 -lrt `pkg-config --libs gtk+-3.0` ), or leave blank
INCLUDES = $(shell pkg-config --libs sdl2 libserialport | sed 's/-mwindows//')
INCLUDES = $(shell pkg-config --libs sdl3 libserialport | sed 's/-mwindows//')

#Set any compiler flags you want to use (e.g. -I/usr/include/somefolder `pkg-config --cflags gtk+-3.0` ), or leave blank
local_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags sdl2 libserialport) -Wall -Wextra -O2 -pipe -I.
local_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags sdl3 libserialport) -Wall -Wextra -O2 -pipe -I.

#Set the compiler you are using ( gcc for C or g++ for C++ )
CC = gcc
Expand All @@ -27,8 +27,8 @@ SOURCE_DIR = src/
m8c: $(OBJ)
$(CC) -o $@ $^ $(local_CFLAGS) $(INCLUDES)

libusb: INCLUDES = $(shell pkg-config --libs sdl2 libusb-1.0)
libusb: local_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags sdl2 libusb-1.0) -Wall -O2 -pipe -I. -DUSE_LIBUSB=1
libusb: INCLUDES = $(shell pkg-config --libs sdl3 libusb-1.0)
libusb: local_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags sdl3 libusb-1.0) -Wall -O2 -pipe -I. -DUSE_LIBUSB=1
libusb: m8c

#Cleanup
Expand Down
2 changes: 1 addition & 1 deletion src/SDL2_inprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define SDL2_inprint_h

#include "inline_font.h"
#include <SDL.h>
#include <SDL3/SDL.h>

extern void prepare_inline_font(struct inline_font *font);
extern void kill_inline_font(void);
Expand Down
32 changes: 14 additions & 18 deletions src/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Released under the MIT licence, https://opensource.org/licenses/MIT
#ifndef USE_LIBUSB
#include "audio.h"
#include <SDL.h>
#include <SDL3/SDL.h>
#include <stdint.h>

static SDL_AudioDeviceID devid_in = 0;
Expand All @@ -12,23 +12,24 @@ static unsigned int audio_paused = 0;
static unsigned int audio_initialized = 0;

void toggle_audio(const unsigned int audio_buffer_size, const char *output_device_name) {
if (!audio_initialized) {
/*if (!audio_initialized) {
audio_init(audio_buffer_size, output_device_name);
return;
}
audio_paused = !audio_paused;
SDL_PauseAudioDevice(devid_in, audio_paused);
SDL_PauseAudioDevice(devid_out, audio_paused);
SDL_Log(audio_paused ? "Audio paused" : "Audio resumed");
SDL_Log(audio_paused ? "Audio paused" : "Audio resumed");*/
}

void audio_cb_in(void *userdata, uint8_t *stream, int len) {
(void)userdata; // suppress compiler warning
SDL_QueueAudio(devid_out, stream, len);
void SDLCALL audio_cb_in(void *userdata, uint8_t *stream, int len) {
/*(void)userdata; // suppress compiler warning
SDL_QueueAudio(devid_out, stream, len);*/
}

int audio_init(const unsigned int audio_buffer_size, const char *output_device_name) {

/*
int m8_device_id = -1;
// wait for system to initialize possible new audio devices
Expand Down Expand Up @@ -59,9 +60,8 @@ int audio_init(const unsigned int audio_buffer_size, const char *output_device_n
// Open output device first to avoid possible Directsound errors
SDL_zero(want_out);
want_out.freq = 44100;
want_out.format = AUDIO_S16;
want_out.format = SDL_AUDIO_S16LE;
want_out.channels = 2;
want_out.samples = audio_buffer_size;
devid_out =
SDL_OpenAudioDevice(output_device_name, 0, &want_out, &have_out, SDL_AUDIO_ALLOW_ANY_CHANGE);
if (devid_out == 0) {
Expand All @@ -71,10 +71,8 @@ int audio_init(const unsigned int audio_buffer_size, const char *output_device_n
SDL_zero(want_in);
want_in.freq = 44100;
want_in.format = AUDIO_S16;
want_in.format = SDL_AUDIO_S16LE;
want_in.channels = 2;
want_in.samples = audio_buffer_size;
want_in.callback = audio_cb_in;
devid_in = SDL_OpenAudioDevice(SDL_GetAudioDeviceName(m8_device_id, SDL_TRUE), SDL_TRUE, &want_in,
&have_in, SDL_AUDIO_ALLOW_ANY_CHANGE);
if (devid_in == 0) {
Expand All @@ -84,25 +82,23 @@ int audio_init(const unsigned int audio_buffer_size, const char *output_device_n
// Start audio processing
SDL_Log("Opening audio devices");
SDL_PauseAudioDevice(devid_in, 0);
SDL_PauseAudioDevice(devid_out, 0);
audio_paused = 0;
audio_initialized = 1;
return 1;
return 1;*/
}

void audio_destroy() {
if (!audio_initialized)
/*if (!audio_initialized)
return;
SDL_Log("Closing audio devices");
SDL_PauseAudioDevice(devid_in, 1);
SDL_PauseAudioDevice(devid_out, 1);
SDL_PauseAudioDevice(devid_in);
SDL_PauseAudioDevice(devid_out);
SDL_CloseAudioDevice(devid_in);
SDL_CloseAudioDevice(devid_out);
audio_initialized = 0;
audio_initialized = 0;*/
}

#endif
2 changes: 1 addition & 1 deletion src/command.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 Jonne Kokkonen
// Released under the MIT licence, https://opensource.org/licenses/MIT

#include <SDL_log.h>
#include <SDL3/SDL_log.h>

#include "command.h"
#include "render.h"
Expand Down
Loading

0 comments on commit 02832de

Please sign in to comment.