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/cd_rockbox.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/cd_rockbox.c')
-rw-r--r-- | apps/plugins/sdl/progs/quake/cd_rockbox.c | 123 |
1 files changed, 123 insertions, 0 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 | } | ||