diff options
author | Franklin Wei <franklin@rockbox.org> | 2019-08-04 14:58:37 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-10-27 10:23:57 -0400 |
commit | 54b3b6f7978b6ffe4fbba8ad8fec73480ca45a4d (patch) | |
tree | bbcc5f66f136757e582424e5d98d5e554bbba383 /apps/plugins/sdl/progs/quake/snd_sdl.c | |
parent | f5d31fc1c4e31d7da00c87204ae58df9af44bcd1 (diff) | |
download | rockbox-54b3b6f7978b6ffe4fbba8ad8fec73480ca45a4d.tar.gz rockbox-54b3b6f7978b6ffe4fbba8ad8fec73480ca45a4d.zip |
quake: migrate to SDL_mixer and add background music
Kind of skippy and only supports WAV. MP3 would be nice, especially if
using Rockbox's codec.
Change-Id: I0bba195603da32da1e4d1dcf2ee821fa5696824a
Diffstat (limited to 'apps/plugins/sdl/progs/quake/snd_sdl.c')
-rw-r--r-- | apps/plugins/sdl/progs/quake/snd_sdl.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/apps/plugins/sdl/progs/quake/snd_sdl.c b/apps/plugins/sdl/progs/quake/snd_sdl.c index 644d4e1acf..5ebf081241 100644 --- a/apps/plugins/sdl/progs/quake/snd_sdl.c +++ b/apps/plugins/sdl/progs/quake/snd_sdl.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include "SDL_audio.h" | 3 | #include "SDL_audio.h" |
4 | #include "SDL_byteorder.h" | 4 | #include "SDL_byteorder.h" |
5 | #include "SDL_mixer.h" | ||
5 | #include "quakedef.h" | 6 | #include "quakedef.h" |
6 | 7 | ||
7 | static dma_t the_shm; | 8 | static dma_t the_shm; |
@@ -11,7 +12,7 @@ extern int desired_speed; | |||
11 | extern int desired_bits; | 12 | extern int desired_bits; |
12 | 13 | ||
13 | // SDL hereby demands `len' samples in stream, *NOW*! | 14 | // SDL hereby demands `len' samples in stream, *NOW*! |
14 | static void paint_audio(void *unused, Uint8 *stream, int len) | 15 | static void paint_audio(int chan, Uint8 *stream, int len, void *unused) |
15 | { | 16 | { |
16 | if ( shm ) { | 17 | if ( shm ) { |
17 | shm->buffer = stream; | 18 | shm->buffer = stream; |
@@ -46,49 +47,40 @@ qboolean SNDDMA_Init(void) | |||
46 | } | 47 | } |
47 | desired.channels = 2; | 48 | desired.channels = 2; |
48 | desired.samples = 1024; | 49 | desired.samples = 1024; |
49 | desired.callback = paint_audio; | 50 | //desired.callback = paint_audio; |
50 | 51 | ||
52 | if( Mix_OpenAudio(desired_speed, desired.format, desired.channels, desired.samples) < 0 ) | ||
53 | { | ||
54 | Con_Printf("Couldn't open SDL audio: %s\n", Mix_GetError()); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | Mix_RegisterEffect(0, paint_audio, NULL, NULL); | ||
59 | |||
60 | #if 0 | ||
51 | /* Open the audio device */ | 61 | /* Open the audio device */ |
52 | if ( SDL_OpenAudio(&desired, &obtained) < 0 ) { | 62 | if ( SDL_OpenAudio(&desired, &obtained) < 0 ) { |
53 | Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError()); | 63 | Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError()); |
54 | return 0; | 64 | return 0; |
55 | } | 65 | } |
66 | #endif | ||
67 | |||
68 | void *blank_buf = (Uint8 *)malloc(4096); | ||
69 | memset(blank_buf, 0, 4096); | ||
70 | |||
71 | Mix_Chunk *blank = Mix_QuickLoad_RAW(blank_buf, 4096); | ||
72 | |||
73 | Mix_PlayChannel(0, blank, -1); | ||
56 | 74 | ||
57 | /* Make sure we can support the audio format */ | ||
58 | switch (obtained.format) { | ||
59 | case AUDIO_U8: | ||
60 | /* Supported */ | ||
61 | break; | ||
62 | case AUDIO_S16LSB: | ||
63 | case AUDIO_S16MSB: | ||
64 | if ( ((obtained.format == AUDIO_S16LSB) && | ||
65 | (SDL_BYTEORDER == SDL_LIL_ENDIAN)) || | ||
66 | ((obtained.format == AUDIO_S16MSB) && | ||
67 | (SDL_BYTEORDER == SDL_BIG_ENDIAN)) ) { | ||
68 | /* Supported */ | ||
69 | break; | ||
70 | } | ||
71 | /* Unsupported, fall through */; | ||
72 | default: | ||
73 | /* Not supported -- force SDL to do our bidding */ | ||
74 | SDL_CloseAudio(); | ||
75 | if ( SDL_OpenAudio(&desired, NULL) < 0 ) { | ||
76 | Con_Printf("Couldn't open SDL audio: %s\n", | ||
77 | SDL_GetError()); | ||
78 | return 0; | ||
79 | } | ||
80 | memcpy(&obtained, &desired, sizeof(desired)); | ||
81 | break; | ||
82 | } | ||
83 | SDL_PauseAudio(0); | 75 | SDL_PauseAudio(0); |
84 | 76 | ||
85 | /* Fill the audio DMA information block */ | 77 | /* Fill the audio DMA information block */ |
86 | shm = &the_shm; | 78 | shm = &the_shm; |
87 | shm->splitbuffer = 0; | 79 | shm->splitbuffer = 0; |
88 | shm->samplebits = (obtained.format & 0xFF); | 80 | shm->samplebits = (desired.format & 0xFF); |
89 | shm->speed = obtained.freq; | 81 | shm->speed = desired.freq; |
90 | shm->channels = obtained.channels; | 82 | shm->channels = desired.channels; |
91 | shm->samples = obtained.samples*shm->channels; | 83 | shm->samples = desired.samples*shm->channels; |
92 | shm->samplepos = 0; | 84 | shm->samplepos = 0; |
93 | shm->submission_chunk = 1; | 85 | shm->submission_chunk = 1; |
94 | shm->buffer = NULL; | 86 | shm->buffer = NULL; |