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 | |
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')
-rw-r--r-- | apps/plugins/sdl/progs/quake/cd_rockbox.c | 123 | ||||
-rw-r--r-- | apps/plugins/sdl/progs/quake/snd_sdl.c | 56 |
2 files changed, 147 insertions, 32 deletions
diff --git a/apps/plugins/sdl/progs/quake/cd_rockbox.c b/apps/plugins/sdl/progs/quake/cd_rockbox.c new file mode 100644 index 0000000000..76a955943e --- /dev/null +++ b/apps/plugins/sdl/progs/quake/cd_rockbox.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | Copyright (C) 1996-1997 Id Software, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU General Public License | ||
6 | as published by the Free Software Foundation; either version 2 | ||
7 | of the License, or (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | |||
13 | See the GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | */ | ||
20 | |||
21 | /* Background music for Rockbox. Uses SDL_mixer and plays from | ||
22 | * /.rockbox/quake/%02d.wav */ | ||
23 | |||
24 | #include "quakedef.h" | ||
25 | #include "SDL_mixer.h" | ||
26 | |||
27 | #define MUSIC_DIR ROCKBOX_DIR "/quake" | ||
28 | |||
29 | #if 1 | ||
30 | static Mix_Music *mus = NULL; | ||
31 | #else | ||
32 | static int musfile = -1; | ||
33 | static int musfile_len, musfile_pos; | ||
34 | |||
35 | #define MP3_CHUNK 1024*512 | ||
36 | |||
37 | static char mp3buf[MP3_CHUNK]; | ||
38 | |||
39 | static void get_mp3(const void **start, size_t *size) | ||
40 | { | ||
41 | if(musfile >= 0) | ||
42 | { | ||
43 | int len = MIN(musfile_len - musfile_pos, MP3_CHUNK); | ||
44 | |||
45 | Sys_FileRead(musfile, mp3buf, len); | ||
46 | *start = mp3buf; | ||
47 | *size = len; | ||
48 | |||
49 | musfile_pos += len; | ||
50 | } | ||
51 | } | ||
52 | #endif | ||
53 | |||
54 | void CDAudio_Play(byte track, qboolean looping) | ||
55 | { | ||
56 | char path[MAX_PATH]; | ||
57 | snprintf(path, sizeof(path), "%s/%02d.wav", MUSIC_DIR, track - 1); | ||
58 | |||
59 | rb->splashf(HZ, "playing %s", path); | ||
60 | |||
61 | #if 1 | ||
62 | mus = Mix_LoadMUS(path); | ||
63 | |||
64 | if(!mus) | ||
65 | { | ||
66 | rb->splashf(HZ, "Failed: %s", Mix_GetError()); | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | Mix_PlayMusic(mus, looping ? -1 : 0); | ||
71 | #else | ||
72 | |||
73 | musfile_len = Sys_FileOpenRead(path, &musfile); | ||
74 | musfile_pos = 0; | ||
75 | |||
76 | rb->mp3_play_data(NULL, 0, get_mp3); | ||
77 | #endif | ||
78 | } | ||
79 | |||
80 | |||
81 | void CDAudio_Stop(void) | ||
82 | { | ||
83 | if ( (Mix_PlayingMusic()) || (Mix_PausedMusic()) ) | ||
84 | Mix_HaltMusic(); | ||
85 | } | ||
86 | |||
87 | |||
88 | void CDAudio_Pause(void) | ||
89 | { | ||
90 | Mix_PauseMusic(); | ||
91 | } | ||
92 | |||
93 | |||
94 | void CDAudio_Resume(void) | ||
95 | { | ||
96 | Mix_ResumeMusic(); | ||
97 | } | ||
98 | |||
99 | |||
100 | void CDAudio_Update(void) | ||
101 | { | ||
102 | //Mix_VolumeMusic(bgmvolume.value * SDL_MIX_MAXVOLUME); | ||
103 | } | ||
104 | |||
105 | |||
106 | int CDAudio_Init(void) | ||
107 | { | ||
108 | rb->splashf(HZ, "CD Init"); | ||
109 | |||
110 | if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024)==-1) { | ||
111 | rb->splashf(HZ, "Mix_OpenAudio: %s\n", Mix_GetError()); | ||
112 | return -1; | ||
113 | } | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | |||
118 | void CDAudio_Shutdown(void) | ||
119 | { | ||
120 | if(mus) | ||
121 | Mix_FreeMusic(mus); | ||
122 | CDAudio_Stop(); | ||
123 | } | ||
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; |