Skip to content

Commit

Permalink
Unify ogg and ogg11
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Mar 14, 2018
1 parent 70a8965 commit 301f06c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 86 deletions.
40 changes: 30 additions & 10 deletions src/sound/ogg11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,46 @@
#include "sound.h" // SAMPLE_RATE
#include "../common/stat.h"
#include "../common/misc.h"
#include "../ResourceManager.h"

static ogg11Song song;
static bool do_loop = false;
static bool looped = false;

char ogg11_load(const std::string& fname_intro, const std::string& fname_loop)
bool ogg11_load(const std::string& fname, const std::string& dir)
{
std::string filename = ResourceManager::getInstance()->getLocalizedPath(dir + fname + "_intro.ogg");
if (!ResourceManager::fileExists(filename))
{
filename = ResourceManager::getInstance()->getLocalizedPath(dir + fname + "_loop.ogg");
if (!ResourceManager::fileExists(filename))
{
filename = ResourceManager::getInstance()->getLocalizedPath(dir + fname + ".ogg");
}
}
song.intro=NULL;
song.intro=Mix_LoadMUS(fname_intro.c_str());
song.intro=Mix_LoadMUS(filename.c_str());
if (!song.intro)
{
staterr("Mix_LoadMUS(): %s\n", Mix_GetError());
return 1;
return false;
}

filename = ResourceManager::getInstance()->getLocalizedPath(dir + fname + "_loop.ogg");
if (!ResourceManager::fileExists(filename))
{
filename = ResourceManager::getInstance()->getLocalizedPath(dir + fname + ".ogg");
}

song.loop=NULL;
song.loop=Mix_LoadMUS(fname_loop.c_str());
song.loop=Mix_LoadMUS(filename.c_str());
if (!song.loop)
{
staterr("Mix_LoadMUS(): %s\n", Mix_GetError());
return 1;
return false;
}
stat("ogg11_load: %s, %s\n", fname_intro.c_str(), fname_loop.c_str());
return 0;
// stat("ogg11_load: %s, %s\n", fname_intro.c_str(), fname_loop.c_str());
return true;
}

void musicFinished11()
Expand All @@ -53,11 +69,15 @@ void musicFinished11()


// start the currently-loaded track playing at beat startbeat.
bool ogg11_start(const std::string& fname_intro, const std::string& fname_loop, int startbeat, bool loop)
bool ogg11_start(const std::string& fname, const std::string& dir, int startbeat, bool loop)
{
ogg11_stop(); // stop any old music

ogg11_load(fname_intro, fname_loop);
if (!ogg11_load(fname, dir))
{
return false;
song.playing = false;
}

song.last_pos = 0;

Expand All @@ -83,7 +103,7 @@ bool ogg11_start(const std::string& fname_intro, const std::string& fname_loop,
Mix_VolumeMusic(song.volume);
Mix_SetMusicPosition(startbeat / 1000);
Mix_HookMusicFinished(musicFinished11);
return 0;
return true;
}


Expand Down
4 changes: 2 additions & 2 deletions src/sound/ogg11.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct ogg11Song
uint32_t last_pos;
};

char ogg11_load(const std::string& name_intro, const std::string& fname_loop);
bool ogg11_start(const std::string& fname_intro, const std::string& fname_loop, int startbeat, bool loop);
bool ogg11_load(const std::string& fname, const std::string& dir);
bool ogg11_start(const std::string& fname, const std::string& dir, int startbeat, bool loop);
void ogg11_stop(void);
bool ogg11_is_playing(void);
void ogg11_fade(void);
Expand Down
81 changes: 15 additions & 66 deletions src/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "../game.h"
#include "pxt.h"
#include "org.h"
#include "ogg.h"
#include "ogg11.h"
#include "sound.h"
#include "../common/stat.h"
Expand Down Expand Up @@ -174,57 +173,14 @@ char fname[MAXPATHLEN];
}
}

static void start_ogg_track(int songno, bool resume)
static void start_ogg11_track(int songno, bool resume, const char* dir)
{
char fname[MAXPATHLEN];

if (songno == 0)
{
ogg_stop();
return;
}

strcpy(fname, ogg_dir);
strcat(fname, org_names[songno]);
strcat(fname, ".ogg");

ogg_start(ResourceManager::getInstance()->getLocalizedPath(fname), resume ? music_lastsongpos() : 0);
}

static void start_ogg11_track(int songno, bool resume)
{
char fname_intro[MAXPATHLEN];
char fname_loop[MAXPATHLEN];

if (songno == 0)
{
ogg11_stop();
return;
}

// There's no intro/loop for lastbtl
if (strstr(org_names[songno], "lastbtl"))
{
strcpy(fname_intro, ogg11_dir);
strcat(fname_intro, org_names[songno]);
strcat(fname_intro, ".ogg");

strcpy(fname_loop, ogg11_dir);
strcat(fname_loop, org_names[songno]);
strcat(fname_loop, ".ogg");
}
else
{
strcpy(fname_intro, ogg11_dir);
strcat(fname_intro, org_names[songno]);
strcat(fname_intro, "_intro.ogg");

strcpy(fname_loop, ogg11_dir);
strcat(fname_loop, org_names[songno]);
strcat(fname_loop, "_loop.ogg");
}

ogg11_start(ResourceManager::getInstance()->getLocalizedPath(fname_intro), ResourceManager::getInstance()->getLocalizedPath(fname_loop), resume ? music_lastsongpos() : 0, resume ? songlooped : false);
if (songno==0)
{
ogg11_stop();
return;
}
ogg11_start(org_names[songno], dir, resume ? music_lastsongpos() : 0, resume ? songlooped : false);
}


Expand All @@ -247,8 +203,6 @@ void music(int songno, bool resume)
org_stop();
break;
case 1:
ogg_stop();
break;
case 2:
ogg11_stop();
break;
Expand All @@ -262,10 +216,10 @@ void music(int songno, bool resume)
start_track(songno,resume);
break;
case 1:
start_ogg_track(songno,resume);
start_ogg11_track(songno,resume, ogg_dir);
break;
case 2:
start_ogg11_track(songno,resume);
start_ogg11_track(songno,resume, ogg11_dir);
break;
}
}
Expand Down Expand Up @@ -316,19 +270,19 @@ void music_set_enabled(int newstate)
}
break;
case 1:
if (play != ogg_is_playing())
if (play != ogg11_is_playing())
{
if (play)
start_ogg_track(cursong,0);
start_ogg11_track(cursong,0, ogg_dir);
else
ogg_stop();
ogg11_stop();
}
break;
case 2:
if (play != ogg11_is_playing())
{
if (play)
start_ogg11_track(cursong,0);
start_ogg11_track(cursong,0, ogg11_dir);
else
ogg11_stop();
}
Expand All @@ -346,7 +300,6 @@ void music_set_newmusic(int newstate)
settings->new_music = newstate;

org_stop();
ogg_stop();
ogg11_stop();

switch (newstate)
Expand All @@ -355,10 +308,10 @@ void music_set_newmusic(int newstate)
start_track(cursong,0);
break;
case 1:
start_ogg_track(cursong,0);
start_ogg11_track(cursong, 0, ogg_dir);
break;
case 2:
start_ogg11_track(cursong,0);
start_ogg11_track(cursong, 0, ogg11_dir);
break;
}
}
Expand All @@ -372,8 +325,6 @@ void music_fade()
org_fade();
break;
case 1:
ogg_fade();
break;
case 2:
ogg11_fade();
break;
Expand All @@ -392,8 +343,6 @@ void music_run_fade()
org_run_fade();
break;
case 1:
ogg_run_fade();
break;
case 2:
ogg11_run_fade();
break;
Expand Down
2 changes: 0 additions & 2 deletions win32/nx/nx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@
<ClCompile Include="..\..\src\siflib\sif.cpp" />
<ClCompile Include="..\..\src\siflib\sifloader.cpp" />
<ClCompile Include="..\..\src\slope.cpp" />
<ClCompile Include="..\..\src\sound\ogg.cpp" />
<ClCompile Include="..\..\src\sound\ogg11.cpp" />
<ClCompile Include="..\..\src\sound\org.cpp" />
<ClCompile Include="..\..\src\sound\pxt.cpp" />
Expand Down Expand Up @@ -430,7 +429,6 @@
<ClInclude Include="..\..\src\siflib\sifloader.h" />
<ClInclude Include="..\..\src\Singleton.h" />
<ClInclude Include="..\..\src\slope.h" />
<ClInclude Include="..\..\src\sound\ogg.h" />
<ClInclude Include="..\..\src\sound\ogg11.h" />
<ClInclude Include="..\..\src\sound\org.h" />
<ClInclude Include="..\..\src\sound\pxt.h" />
Expand Down
6 changes: 0 additions & 6 deletions win32/nx/nx.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@
<ClCompile Include="..\..\src\tsc.cpp">
<Filter>Sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\sound\ogg.cpp">
<Filter>Sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\sound\ogg11.cpp">
<Filter>Sources</Filter>
</ClCompile>
Expand Down Expand Up @@ -821,9 +818,6 @@
<ClInclude Include="..\..\src\version.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\src\sound\ogg.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\src\sound\ogg11.h">
<Filter>Headers</Filter>
</ClInclude>
Expand Down

0 comments on commit 301f06c

Please sign in to comment.