[Tux4kids-commits] r1529 - tuxtype/trunk/src
Matthew Trey
treymd-guest at alioth.debian.org
Sat Sep 12 00:11:20 UTC 2009
Author: treymd-guest
Date: 2009-09-12 00:11:20 +0000 (Sat, 12 Sep 2009)
New Revision: 1529
Modified:
tuxtype/trunk/src/audio.c
tuxtype/trunk/src/funcs.h
tuxtype/trunk/src/scripting.c
Log:
scripting.c cleanup, routing audio calls through audio.c
Modified: tuxtype/trunk/src/audio.c
===================================================================
--- tuxtype/trunk/src/audio.c 2009-09-12 00:03:04 UTC (rev 1528)
+++ tuxtype/trunk/src/audio.c 2009-09-12 00:11:20 UTC (rev 1529)
@@ -21,15 +21,29 @@
static Mix_Music* defaultMusic = NULL; // holds music for audioMusicLoad/unload
-
+// play sound once
void PlaySound(Mix_Chunk* snd)
{
- if(!snd) return;
- if (!settings.sys_sound) return;
+ PlaySoundLoop(snd, 0);
+}
- Mix_PlayChannel(-1, snd, 0);
+// play sound with optional repeats, or -1 for infinite
+void PlaySoundLoop(Mix_Chunk* snd, int loops)
+{
+ if(!snd)
+ return;
+ if (!settings.sys_sound)
+ return;
+
+ Mix_PlayChannel(-1, snd, loops);
}
+// halt a channel or -1 for all
+void audioHaltChannel(int channel)
+{
+ Mix_HaltChannel(channel);
+}
+
/* MusicLoad attempts to load and play the music file
* Note: loops == -1 means forever
*/
Modified: tuxtype/trunk/src/funcs.h
===================================================================
--- tuxtype/trunk/src/funcs.h 2009-09-12 00:03:04 UTC (rev 1528)
+++ tuxtype/trunk/src/funcs.h 2009-09-12 00:11:20 UTC (rev 1529)
@@ -54,6 +54,8 @@
/* In audio.c: */
void PlaySound(Mix_Chunk* snd);
+void PlaySoundLoop(Mix_Chunk* snd, int loops);
+void audioHaltChannel(int channel);
void MusicLoad(const char* musicFilename, int repeatQty);
void MusicUnload(void);
void MusicPlay(Mix_Music* musicData, int repeatQty);
Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c 2009-09-12 00:03:04 UTC (rev 1528)
+++ tuxtype/trunk/src/scripting.c 2009-09-12 00:11:20 UTC (rev 1529)
@@ -24,7 +24,6 @@
/* Local function prototypes: */
static void clear_items(itemType* i);
static void clear_pages(pageType* p);
-static void clear_sounds(void);
static void close_script(void);
static SDL_Color* get_color(const char* in);
static int get_int(const char* in);
@@ -1240,7 +1239,11 @@
{
// HACK, we need to make sure no more than 8 sounds or so..
sounds[numWavs] = LoadSound( curItem->data );
- Mix_PlayChannel( numWavs, sounds[numWavs], -curItem->loop );
+
+ // let audio.c handle calls to SDL_mixer
+ //Mix_PlayChannel( numWavs, sounds[numWavs], -curItem->loop );
+
+ PlaySoundLoop( sounds[numWavs], -curItem->loop );
numWavs++;
break;
}
@@ -1268,7 +1271,9 @@
for (j=0; j<numClicks; j++)
{
if (inRect(clickRects[j], event.button.x, event.button.y))
- Mix_PlayChannel(numWavs + j, clickWavs[j], 0);
+ PlaySound( clickWavs[j] );
+ // let audio.c handle calls to SDL_mixer
+ //Mix_PlayChannel(numWavs + j, clickWavs[j], 0);
}
break;
}
@@ -1404,15 +1409,22 @@
if (settings.sys_sound)
{
+ // halt all the channels before we try to free the sounds
+ audioHaltChannel(-1);
+
for (i=0; i<numWavs; i++)
{
- Mix_HaltChannel(i);
+ // let audio.c handle calls to SDL_mixer
+ //Mix_HaltChannel(i);
+
Mix_FreeChunk(sounds[i]);
}
for (i = 0; i < numClicks; i++)
{
- Mix_HaltChannel(i + numWavs);
+ // let audio.c handle calls to SDL_mixer
+ //Mix_HaltChannel(i + numWavs);
+
Mix_FreeChunk(clickWavs[i]);
}
}
More information about the Tux4kids-commits
mailing list