summaryrefslogtreecommitdiff
path: root/src/sound.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-02-01 22:59:06 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-02-01 22:59:06 +0000
commit6d4e1eae16b84918009625a866104ec26a234277 (patch)
treea340a8a547a60c9f63c8dfafe8909242f9c9bbd8 /src/sound.c
nahranie tarballu tuxanci-ng na SVN server
Dusan Durech ( Oroborus ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@1 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/sound.c')
-rw-r--r--src/sound.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/sound.c b/src/sound.c
new file mode 100644
index 0000000..45cb225
--- /dev/null
+++ b/src/sound.c
@@ -0,0 +1,106 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "interface.h"
+#include "list.h"
+#include "path.h"
+#include "string_length.h"
+#include "audio.h"
+#include "sound.h"
+
+static list_t *listSound;
+
+static bool_t isSoundInit = FALSE;
+
+bool_t isSoundInicialized()
+{
+ return isSoundInit;
+}
+
+void initSound()
+{
+ assert( isAudioInicialized() );
+
+ listSound = newList();
+ isSoundInit = TRUE;
+
+ printf("init sound..\n");
+}
+
+static Mix_Chunk* loadMixSound(char *file)
+{
+ Mix_Chunk *new;
+ char str[STR_PATH_SIZE];
+
+ sprintf(str, PATH_SOUND "%s", file);
+ new = Mix_LoadWAV(str);
+
+ if( new == NULL )
+ {
+ fprintf(stderr, "Nelze nahrat zvuk %s : %s\n", str, Mix_GetError());
+ return NULL;
+ }
+
+ return new;
+}
+
+static sound_t *newSound(char *file, char *name, int group)
+{
+ sound_t *new;
+
+ new = malloc( sizeof(sound_t) );
+ new->name = strdup(name);
+ new->group = group;
+ new->sound = loadMixSound(file);
+
+ return new;
+}
+
+static void playMixSound(sound_t *p)
+{
+ if( Mix_PlayChannel(-1, p->sound, 0) == -1 )
+ {
+ fprintf(stderr, "Nelze prehrat zvuk : %s\n", Mix_GetError());
+ return;
+ }
+}
+
+static void destroySound(sound_t *p)
+{
+ free(p->name);
+ Mix_FreeChunk(p->sound);
+ free(p);
+}
+
+void addSound(char *file, char *name, int group)
+{
+ addList( listSound, newSound(file, name, group) );
+}
+
+void playSound(char *name, int group)
+{
+ int i;
+ sound_t *this;
+
+ for( i = 0 ; i < listSound->count ; i++ )
+ {
+ this = (sound_t *)listSound->list[i];
+
+ if( this->group == group && strcmp(this->name, name) == 0 )
+ {
+ playMixSound(this);
+ return;
+ }
+ }
+}
+
+void quitSound()
+{
+ destroyListItem(listSound, destroySound);
+ isSoundInit = FALSE;
+ printf("quit sound..\n");
+}
+