-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[ports] SDL3_mixer 3.2.0 #26571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ports] SDL3_mixer 3.2.0 #26571
Changes from 9 commits
59372d4
33906c8
3bae82e
317a13c
e467103
bd28c37
17affb5
f787d0c
320a752
4c549ea
3835624
2fcdbc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright 2025 The Emscripten Authors. All rights reserved. | ||
| * Emscripten is available under two separate licenses, the MIT license and the | ||
| * University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| * found in the LICENSE file. | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <SDL3/SDL.h> | ||
| #include <SDL3/SDL_main.h> | ||
| #include <SDL3_mixer/SDL_mixer.h> | ||
| #include <emscripten.h> | ||
|
|
||
| SDL_Window *window = NULL; | ||
| SDL_Renderer *renderer = NULL; | ||
| MIX_Audio *audio = NULL; | ||
| MIX_Track *track = NULL; | ||
| MIX_Mixer *mixer = NULL; | ||
|
|
||
| #define WIDTH 640 | ||
| #define HEIGHT 480 | ||
|
|
||
| #ifndef SOUND_PATH | ||
| #error "must define SOUND_PATH" | ||
| #endif | ||
|
|
||
| void sound_loop_then_quit() { | ||
| if (MIX_TrackPlaying(track)) | ||
| return; | ||
|
|
||
| MIX_DestroyAudio(audio); | ||
| MIX_DestroyTrack(track); | ||
| MIX_DestroyMixer(mixer); | ||
|
|
||
| emscripten_cancel_main_loop(); | ||
| printf("Shutting down\n"); | ||
| exit(0); | ||
| } | ||
|
|
||
| int main(int argc, char *argv[]) { | ||
| SDL_Init(SDL_INIT_VIDEO); | ||
|
|
||
| if (!MIX_Init()) { | ||
| printf("MIX_Init failed: %s\n", SDL_GetError()); | ||
| return 1; | ||
| } | ||
|
|
||
| if (!SDL_CreateWindowAndRenderer("SDL3 MIXER", WIDTH, HEIGHT, 0, &window, &renderer)) { | ||
| printf("SDL_CreateWindowAndRenderer: %s\n", SDL_GetError()); | ||
| return 1; | ||
| } | ||
|
|
||
| mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL); | ||
| if (!mixer) { | ||
| printf("Couldn't create mixer on default device: %s", SDL_GetError()); | ||
| return 1; | ||
| } | ||
|
|
||
| audio = MIX_LoadAudio(mixer, SOUND_PATH, false); | ||
| if (!audio) { | ||
| printf("MIX_LoadAudio: %s\n", SDL_GetError()); | ||
| return 1; | ||
| } | ||
|
|
||
| track = MIX_CreateTrack(mixer); | ||
| if (!track) { | ||
| printf("MIX_CreateTrack: %s\n", SDL_GetError()); | ||
| return 1; | ||
| } | ||
|
|
||
| MIX_SetTrackAudio(track, audio); | ||
| SDL_PropertiesID props = SDL_CreateProperties(); | ||
| SDL_SetNumberProperty(props, MIX_PROP_PLAY_LOOPS_NUMBER, 0); | ||
|
|
||
| printf("Starting sound play loop\n"); | ||
| MIX_PlayTrack(track, props); | ||
|
|
||
| emscripten_set_main_loop(sound_loop_then_quit, 0, 1); | ||
|
|
||
| return 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use 2-space indentation. Maybe run this through
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, fixed. I've copied the style from another c file. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # Copyright 2025 The Emscripten Authors. All rights reserved. | ||
| # Emscripten is available under two separate licenses, the MIT license and the | ||
| # University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| # found in the LICENSE file. | ||
|
|
||
| import os | ||
|
|
||
| from typing import Dict, Set | ||
|
onesixromcom marked this conversation as resolved.
Outdated
|
||
|
|
||
| VERSION = '3.2.0' | ||
| TAG = f'release-{VERSION}' | ||
| HASH = '96f374b3ca96202973fca84228e7775db3d6e38888888573d0ba0d045bc1d3cc6f876984e50dcce1b65875c80f8e263b5ff687570f4b4c720f48ca3cfaff0648' | ||
| SUBDIR = f'SDL3_mixer-{TAG}' | ||
|
|
||
| deps = ['sdl3'] | ||
|
|
||
| variants = { | ||
| 'sdl3_mixer-ogg': {'SDL3_MIXER_FORMATS': ['ogg']}, | ||
| 'sdl3_mixer-none': {'SDL3_MIXER_FORMATS': []}, | ||
| 'sdl3_mixer-ogg-mt': {'SDL3_MIXER_FORMATS': ['ogg'], 'PTHREADS': 1}, | ||
| 'sdl3_mixer-none-mt': {'SDL3_MIXER_FORMATS': [], 'PTHREADS': 1}, | ||
| } | ||
|
|
||
| OPTIONS = { | ||
| 'formats': 'A comma separated list of formats (ex: --use-port=sdl3_mixer:formats=ogg,mp3)', | ||
| } | ||
|
|
||
| SUPPORTED_FORMATS = {'ogg', 'mp3'} | ||
|
|
||
| # user options (from --use-port) | ||
| opts: dict[str, set] = { | ||
| 'formats': set(), | ||
| } | ||
|
|
||
|
|
||
| def needed(settings): | ||
| return settings.USE_SDL_MIXER == 3 | ||
|
|
||
|
|
||
| def get_formats(settings): | ||
| return opts['formats'].union(settings.SDL3_MIXER_FORMATS) | ||
|
|
||
|
|
||
| def get_lib_name(settings): | ||
| formats = '-'.join(sorted(get_formats(settings))) | ||
|
|
||
| libname = 'libSDL3_mixer' | ||
| if formats != '': | ||
| libname += '-' + formats | ||
| if settings.PTHREADS: | ||
| libname += '-mt' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this library actually use threading (or atomics)?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've copied this part from sdl2_mixer.py
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think maybe because SDL3 itself has a threaded variant its required that all the sub-libraries do it.. but I can't remember the exact rationale. Maybe leave it as is. |
||
| libname += '.a' | ||
|
|
||
| return libname | ||
|
|
||
|
|
||
| def get(ports, settings, shared): | ||
| ports.fetch_project('sdl3_mixer', f'https://github.com/libsdl-org/SDL_mixer/archive/{TAG}.zip', sha512hash=HASH) | ||
| libname = get_lib_name(settings) | ||
|
|
||
| def create(final): | ||
| src_root = ports.get_dir('sdl3_mixer', 'SDL_mixer-' + TAG) | ||
| ports.install_header_dir(os.path.join(src_root, 'include'), target='.') | ||
| srcs = [ | ||
| "src/SDL_mixer.c", | ||
| "src/SDL_mixer_metadata_tags.c", | ||
| "src/SDL_mixer_spatialization.c", | ||
| "src/decoder_raw.c", | ||
| "src/decoder_sinewave.c", | ||
| "src/decoder_wav.c", | ||
| ] | ||
|
|
||
| flags = ['-sUSE_SDL=3', '-DDECODER_WAV','-Wno-format-security', '-Wno-experimental'] | ||
|
|
||
| if settings.PTHREADS: | ||
| flags += ['-pthread'] | ||
|
|
||
| formats = get_formats(settings) | ||
|
|
||
| if "ogg" in formats: | ||
|
onesixromcom marked this conversation as resolved.
Outdated
|
||
| flags += [ | ||
| '-sUSE_VORBIS', | ||
| '-DDECODER_OGGVORBIS_VORBISFILE', | ||
| ] | ||
| srcs += ["src/decoder_vorbis.c",] | ||
|
|
||
| if "mp3" in formats: | ||
| flags += [ | ||
| '-sUSE_MPG123', | ||
| '-DDECODER_MP3_MPG123', | ||
| ] | ||
| srcs += ["src/decoder_mpg123.c",] | ||
|
|
||
| ports.build_port(src_root, final, 'sdl3_mixer', flags=flags, srcs=srcs) | ||
| return [shared.cache.get_lib(libname, create, what='port')] | ||
|
|
||
|
|
||
| def clear(ports, settings, shared): | ||
| shared.cache.erase_lib(get_lib_name(settings)) | ||
|
|
||
|
|
||
| def process_dependencies(settings): | ||
| settings.USE_SDL = 3 | ||
| formats = get_formats(settings) | ||
| if "ogg" in formats: | ||
| deps.append('vorbis') | ||
| settings.USE_VORBIS = 1 | ||
| if "mp3" in formats: | ||
| deps.append('mpg123') | ||
| settings.USE_MPG123 = 1 | ||
|
|
||
|
|
||
| def handle_options(options, error_handler): | ||
| formats = options['formats'].split(',') | ||
| for format in formats: | ||
| format = format.lower().strip() | ||
| if format not in SUPPORTED_FORMATS: | ||
| error_handler(f'{format} is not a supported format') | ||
| else: | ||
| opts['formats'].add(format) | ||
|
|
||
|
|
||
| def show(): | ||
| return 'sdl3_mixer (-sUSE_SDL_MIXER=3 or --use-port=sdl3_mixer; zlib license)' | ||
|
onesixromcom marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ | |
| 'USE_FREETYPE', | ||
| 'SDL2_MIXER_FORMATS', | ||
| 'SDL2_IMAGE_FORMATS', | ||
| 'SDL3_MIXER_FORMATS', | ||
| 'USE_SQLITE3', | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.