/*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
music = NULL;
quickSound = NULL;
- strcpy(levelMusicName, "");
+ levelMusicName[0] = 0;
+ songtitle[0] = 0;
+ songalbum[0] = 0;
+ songartist[0] = 0;
+ songlicense = -1;
}
void Audio::setSoundVolume(int soundVolume)
{
char tempPath[PATH_MAX];
- sprintf(tempPath, "%smusic.mod", engine->userHomeDirectory);
+ snprintf(tempPath, sizeof tempPath, "%smusic.mod", engine->userHomeDirectory);
if (!engine->useAudio)
{
remove(tempPath);
- SDL_Delay(250); // wait a bit, just to be sure!
-
if (music != NULL)
{
Mix_HaltMusic();
music = Mix_LoadMUS(filename);
#endif
+ songtitle[0] = 0;
+ songalbum[0] = 0;
+ songartist[0] = 0;
+ songlicense = -1;
+
if (!music)
{
debug(("WARNING - Failed to load %s\n", filename));
return false;
}
-
- strcpy(levelMusicName, filename);
+
+ #if USEPAK
+ snprintf(tempPath, sizeof tempPath, "%smusic.tags", engine->userHomeDirectory);
+ remove(tempPath);
+ char tagfilename[PATH_MAX];
+ snprintf(tagfilename, sizeof tagfilename, "%s.tags", filename);
+ engine->unpack(tagfilename, PAK_TAGS);
+ #else
+ snprintf(tempPath, sizeof tempPath, "%s.tags", filename);
+ #endif
+ FILE *fp = fopen(tempPath, "r");
+ char line[1024];
+
+ while(fp && fgets(line, sizeof line, fp))
+ {
+ int l = strlen(line);
+ if(line[l - 1] == '\n')
+ line[l - 1] = 0;
+
+ if(!strncasecmp(line, "title=", 6))
+ strlcpy(songtitle, line + 6, sizeof songtitle);
+ else if(!strncasecmp(line, "album=", 6))
+ strlcpy(songalbum, line + 6, sizeof songalbum);
+ else if(!strncasecmp(line, "artist=", 7))
+ strlcpy(songartist, line + 7, sizeof songartist);
+ else if(!strncasecmp(line, "license=", 8))
+ {
+ if(!strncasecmp(line + 8, "CC-BY ", 6))
+ songlicense = 0;
+ else if(!strncasecmp(line + 8, "CC-BY-SA ", 9))
+ songlicense = 1;
+ }
+ }
+
+ if(fp)
+ fclose(fp);
+
+ strlcpy(levelMusicName, filename, sizeof levelMusicName);
return true;
}
-void Audio::playSound(int snd, int channel)
+void Audio::playSoundRelative(int snd, int channel, float x)
{
if ((!engine->useAudio) || (soundVolume == 0))
return;
return;
}
- Mix_Volume(channel, soundVolume);
+ int angle = atanf(x / 480) * 180 / M_PI;
+ int attenuation = fabsf(x) / 40;
+
+ if (angle < 0)
+ angle += 360;
+ if (attenuation > 255)
+ attenuation = 255;
+
+ Mix_Volume(channel, soundVolume);
Mix_PlayChannel(channel, sound[snd], 0);
+ Mix_SetPosition(channel, angle, attenuation);
+}
+
+void Audio::playSound(int snd, int channel, float x)
+{
+ x -= (engine->playerPosX + 320);
+ playSoundRelative(snd, channel, x);
+}
+
+void Audio::playSound(int snd, int channel)
+{
+ playSoundRelative(snd, channel, 0);
}
void Audio::playMusic()
{
char tempPath[PATH_MAX];
- sprintf(tempPath, "%smusic.mod", engine->userHomeDirectory);
+ snprintf(tempPath, sizeof tempPath, "%smusic.mod", engine->userHomeDirectory);
if (!engine->useAudio)
{
}
#if USEPAK
- engine->unpack("music/friendDied.mod", PAK_MUSIC);
+ engine->unpack("music/gameover", PAK_MUSIC);
music = Mix_LoadMUS(tempPath);
#else
- music = Mix_LoadMUS("music/friendDied.mod");
+ music = Mix_LoadMUS("music/gameover");
#endif
if (!music)