diff options
Diffstat (limited to 'apps/plugins/sdl/progs/quake/snd_mem.c')
-rw-r--r-- | apps/plugins/sdl/progs/quake/snd_mem.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/plugins/sdl/progs/quake/snd_mem.c b/apps/plugins/sdl/progs/quake/snd_mem.c index 71e32aa056..8b0a5ca9f7 100644 --- a/apps/plugins/sdl/progs/quake/snd_mem.c +++ b/apps/plugins/sdl/progs/quake/snd_mem.c | |||
@@ -89,6 +89,10 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data) | |||
89 | 89 | ||
90 | //============================================================================= | 90 | //============================================================================= |
91 | 91 | ||
92 | // used to synchronize with Mod_LoadModel, which causes crashes if not done. | ||
93 | struct mutex snd_mutex; | ||
94 | int snd_mutex_init = 0; | ||
95 | |||
92 | /* | 96 | /* |
93 | ============== | 97 | ============== |
94 | S_LoadSound | 98 | S_LoadSound |
@@ -96,6 +100,7 @@ S_LoadSound | |||
96 | */ | 100 | */ |
97 | sfxcache_t *S_LoadSound (sfx_t *s) | 101 | sfxcache_t *S_LoadSound (sfx_t *s) |
98 | { | 102 | { |
103 | //return NULL; | ||
99 | char namebuffer[256]; | 104 | char namebuffer[256]; |
100 | byte *data; | 105 | byte *data; |
101 | wavinfo_t info; | 106 | wavinfo_t info; |
@@ -104,11 +109,21 @@ sfxcache_t *S_LoadSound (sfx_t *s) | |||
104 | sfxcache_t *sc; | 109 | sfxcache_t *sc; |
105 | byte stackbuf[1*1024]; // avoid dirtying the cache heap | 110 | byte stackbuf[1*1024]; // avoid dirtying the cache heap |
106 | 111 | ||
107 | // see if still in memory | 112 | // see if still in memory (no mutex) |
108 | sc = Cache_Check (&s->cache); | 113 | sc = Cache_Check (&s->cache); |
109 | if (sc) | 114 | if (sc) |
115 | { | ||
110 | return sc; | 116 | return sc; |
117 | } | ||
118 | |||
119 | if(!snd_mutex_init) | ||
120 | { | ||
121 | rb->mutex_init(&snd_mutex); | ||
122 | snd_mutex_init = 1; | ||
123 | } | ||
111 | 124 | ||
125 | rb->mutex_lock(&snd_mutex); | ||
126 | |||
112 | //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf); | 127 | //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf); |
113 | // load it in | 128 | // load it in |
114 | Q_strcpy(namebuffer, "sound/"); | 129 | Q_strcpy(namebuffer, "sound/"); |
@@ -120,6 +135,7 @@ sfxcache_t *S_LoadSound (sfx_t *s) | |||
120 | 135 | ||
121 | if (!data) | 136 | if (!data) |
122 | { | 137 | { |
138 | rb->mutex_unlock(&snd_mutex); | ||
123 | Con_Printf ("Couldn't load %s\n", namebuffer); | 139 | Con_Printf ("Couldn't load %s\n", namebuffer); |
124 | return NULL; | 140 | return NULL; |
125 | } | 141 | } |
@@ -127,6 +143,7 @@ sfxcache_t *S_LoadSound (sfx_t *s) | |||
127 | info = GetWavinfo (s->name, data, com_filesize); | 143 | info = GetWavinfo (s->name, data, com_filesize); |
128 | if (info.channels != 1) | 144 | if (info.channels != 1) |
129 | { | 145 | { |
146 | rb->mutex_unlock(&snd_mutex); | ||
130 | Con_Printf ("%s is a stereo sample\n",s->name); | 147 | Con_Printf ("%s is a stereo sample\n",s->name); |
131 | return NULL; | 148 | return NULL; |
132 | } | 149 | } |
@@ -138,7 +155,10 @@ sfxcache_t *S_LoadSound (sfx_t *s) | |||
138 | 155 | ||
139 | sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); | 156 | sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); |
140 | if (!sc) | 157 | if (!sc) |
158 | { | ||
159 | rb->mutex_unlock(&snd_mutex); | ||
141 | return NULL; | 160 | return NULL; |
161 | } | ||
142 | 162 | ||
143 | sc->length = info.samples; | 163 | sc->length = info.samples; |
144 | sc->loopstart = info.loopstart; | 164 | sc->loopstart = info.loopstart; |
@@ -148,6 +168,7 @@ sfxcache_t *S_LoadSound (sfx_t *s) | |||
148 | 168 | ||
149 | ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); | 169 | ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); |
150 | 170 | ||
171 | rb->mutex_unlock(&snd_mutex); | ||
151 | return sc; | 172 | return sc; |
152 | } | 173 | } |
153 | 174 | ||