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
Updated SDL Sound code #336
Conversation
garglk/sndsdl.c
Outdated
if (chan == NULL) | ||
gli_strict_warning("MOD player called with an invalid channel!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since chan
is dereferenced below, I presume the function should return here instead of continuing.
garglk/sndsdl.c
Outdated
if (chan->timer) | ||
SDL_RemoveTimer((SDL_TimerID)chan->timer); | ||
|
||
chan->timer = (int)SDL_AddTimer((Uint32)(duration / FADE_GRANULARITY), volume_timer_callback, (void *)chan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indented with a tab instead of 4 spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, chan->timer
is an int
and SDL_AddTimer
returns a pointer. On many 64-bit systems this could result in the truncation of the pointer. timer
should probably just be made an SDL_TimerID
instead of int
. I think you'd have to add a macro, e.g. -DGARGLK_USESDL
when building with SDL, so you can conditionally include SDL/SDL_timer.h
in garglk/garglk.h
and conditionally define timer
. In fact, you could probably conditionally include most/all of struct glk_schannel_struct
so the members don't exist unless SDL is being used for sound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I actually think SDL_TimerID changes from a pointer to an int between SDL versions, which is why the code ended up this way, but not really an excuse. I'll see if I can work out how to fix it properly.
garglk/sndsdl.c
Outdated
{ | ||
gli_strict_warning("sound callback failed"); | ||
|
||
if (!sound_channel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indented too far.
garglk/sndsdl.c
Outdated
|
||
if (!sound_channel) | ||
{ | ||
fprintf(stderr, "sound_completion_callback called with invalid sound_channel %d\n", chan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ought to be done with gli_strict_warning
, building up a message first with snprintf
. Ideally gli_strict_warning
would take a format string and variable number of arguments. I've added #355 to do this.
garglk/sndsdl.c
Outdated
if (result && paused) | ||
{ | ||
if (paused) | ||
fprintf(stderr, "glk_schannel_play_ext: pausing channel again\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this message necessary? If so, presumably it should be done via gli_strict_warning
.
0676261
to
91604ef
Compare
Right, I think I've done all the requested changes, and it seems to build fine on my Mac at least. Someone should test if it still works with FMOD sound. |
90dd81a
to
8ca9730
Compare
A weird thing is that if I try to make the other SDL-specific members of glk_schannel_struct (sdl_rwops, sdl_memory and sdl_channel) also conditional on SDL sound, most games will break and only show a blank screen. |
f9435a2
to
144a5fa
Compare
Squashed all commits into one. Hopefully this makes the changes more readable. |
garglk/garglk.h
Outdated
@@ -32,6 +32,10 @@ | |||
|
|||
#include "gi_dispa.h" | |||
|
|||
#ifdef GARGLK_USESDL | |||
#include "SDL/SDL_timer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing here: I just tried a Windows build, and it fails because the include path points directly to the SDL directory, meaning that SDL_timer.h
has to be included directly, not using the SDL/
prefix. This seems to be the proper way to do it on Unix systems too, as pkg-config sdl --cflags
spits out -I/usr/include/SDL
.
I'd also request using angle brackets instead of quotes since SDL is nominally a system library, even though on Windows it's being included directly, e.g.:
#include <SDL_timer.h>
The test program looked good, so with this one change, I'll merge it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and squashed again.
d851d41
to
fcd52cf
Compare
This implements the extended GLK sound functions: glk_schannel_create_ext() glk_schannel_play_multi() glk_schannel_set_volume_ext() glk_schannel_pause() glk_schannel_unpause() Sound and volume notifications are still not working properly. See bug report garglk#204 and pull request garglk#337. These changes only touch the SDL sound backend. I've made a test program here: https://github.com/angstsmurf/soundtest/releases
fcd52cf
to
b6f71d5
Compare
Rewrote the PR description and commit message. |
Thanks for implementing this! |
This implements the extended GLK sound functions:
glk_schannel_create_ext()
glk_schannel_play_multi()
glk_schannel_set_volume_ext()
glk_schannel_pause()
glk_schannel_unpause()
What is still missing is working sound and volume notifications. They won't fire until some other event, such as the player pressing a key or moving the mouse, comes along, as reported in #204. This is implemented in #337, if only for Windows and macOS at present.
These changes only touch the SDL sound backend, and I have not been able to test whether FMOD sound still works.
I've made a test program here.