diff options
author | Takamichi Horikawa <takamichiho@gmail.com> | 2017-01-26 20:32:26 +0900 |
---|---|---|
committer | Takamichi Horikawa <takamichiho@gmail.com> | 2017-01-26 20:32:26 +0900 |
commit | fc1ea6ee5b5135e70e1a0e9b2737f6189b740691 (patch) | |
tree | 53f206e2f77e3450f8c0def24c488ef19ac3a72d /win32/soundout.c | |
parent | 49ecf760ec6e8b145850be6f3b13020502e10eb4 (diff) |
refactor win32 sound output and improve stability under load
Diffstat (limited to 'win32/soundout.c')
-rw-r--r-- | win32/soundout.c | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/win32/soundout.c b/win32/soundout.c index bb57bc1..7f04e16 100644 --- a/win32/soundout.c +++ b/win32/soundout.c @@ -2,43 +2,16 @@ #include "dsoundout.h" #include "waveout.h" -static void soundout_dsound_pause(struct sound_state *state, int pause) { - dsound_pause((struct dsound_state *)state->driver_state, pause); -} - -static void soundout_dsound_delete(struct sound_state *state) { - dsound_delete((struct dsound_state *)state->driver_state); - HeapFree(GetProcessHeap(), 0, state); -} - -static void soundout_waveout_pause(struct sound_state *state, int pause) { - waveout_pause((struct waveout_state *)state->driver_state, pause); -} - -static void soundout_waveout_delete(struct sound_state *state) { - waveout_delete((struct waveout_state *)state->driver_state); - HeapFree(GetProcessHeap(), 0, state); -} - struct sound_state *sound_init(HWND hwnd, unsigned srate, unsigned sectlen, sound_callback cbfunc, void *userptr) { - HANDLE heap = GetProcessHeap(); - struct sound_state *sound = HeapAlloc(heap, 0, sizeof(struct sound_state)); - if (!sound) return 0; - struct dsound_state *dsound = dsound_init(hwnd, srate, sectlen, cbfunc, userptr); - if (dsound) { - sound->driver_state = dsound; - sound->pause = soundout_dsound_pause; - sound->delete = soundout_dsound_delete; - return sound; + struct sound_state *state; + state = dsound_init(hwnd, srate, sectlen, cbfunc, userptr); + if (state) { + return state; } - struct waveout_state *waveout = waveout_init(hwnd, srate, sectlen, cbfunc, userptr); - if (waveout) { - sound->driver_state = waveout; - sound->pause = soundout_waveout_pause; - sound->delete = soundout_waveout_delete; - return sound; + state = waveout_init(hwnd, srate, sectlen, cbfunc, userptr); + if (state) { + return state; } - HeapFree(heap, 0, sound); return 0; } |