about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 00e23de..8c907d0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,6 +8,7 @@ char VersionString[256];
 struct Settings GlobalSettings;
 
 SDL_mutex *AudioQueueBeingModified;
+SDL_mutex *AudioInitializing;
 
 int AudioQueue[20];
 
@@ -24,13 +25,13 @@ int internal_clock() {
 }
 
 int audio() {
+	SDL_TryLockMutex(AudioInitializing);
 	int i;
 	Mix_Init(0);
 	Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024);
 	Mix_AllocateChannels(64);
-	Mix_Volume(-1, 128);
 	Mix_Chunk *Bounce = Mix_LoadWAV("resources/bounce.wav");
-	Mix_Chunk *TitleScreen = Mix_LoadWAV("resources/title.wav");
+	//Mix_Chunk *TitleScreen = Mix_LoadWAV("resources/title.wav");
 	Mix_Chunk *Victory = Mix_LoadWAV("resources/victory.wav");
 	Mix_Chunk *Defeat = Mix_LoadWAV("resources/defeat.wav");
 	Mix_Chunk *PlayerScore = Mix_LoadWAV("resources/score_player.wav");
@@ -39,6 +40,7 @@ int audio() {
 		0, 20000000
 	};
 	struct timespec Remaining;
+	SDL_UnlockMutex(AudioInitializing);
 	while(GameGoing == true) {
 		for(i = 0; i < 20; i++) {
 			if(AudioQueue[i] != -1){
@@ -53,9 +55,9 @@ int audio() {
 					case 2: //Play win
 						Mix_PlayChannel(-1, Victory, 0);
 						break;
-					case 3: //Title Screen
-						Mix_PlayChannel(-1, TitleScreen, 0);
-						break;
+					//case 3: //Title Screen
+					//	Mix_PlayChannel(-1, TitleScreen, 0);
+					//	break;
 					case 4: //Player Score
 						Mix_PlayChannel(-1, PlayerScore, 0);
 						break;
@@ -118,9 +120,10 @@ int main(int argc, char *argv[]) {
 	for(unsigned int i = 0; i < 20; i++) {
 		AudioQueue[i] = -1;
 	}
-	AudioQueueBeingModified = SDL_CreateMutex();
 
-	// Init Threads
+	//Threading
+	AudioQueueBeingModified = SDL_CreateMutex();
+	AudioInitializing = SDL_CreateMutex();
 	SDL_AtomicSet(&Ticks, 0);
 	SDL_Thread *InternalClock = SDL_CreateThread(internal_clock, "Internal Clock", NULL);
 	SDL_Thread *AudioThread = SDL_CreateThread(audio, "Audio", NULL);
@@ -159,6 +162,9 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	// Wait for audio to finish initializing.
+	SDL_LockMutex(AudioInitializing);
+	
 	// Launch Game
 	while (GameGoing == true) {
 		switch(title_screen()) {