Skip to content

Commit

Permalink
Vita: fix music crackling when playing videos
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed Oct 25, 2016
1 parent 5e6a104 commit 9107f8f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions avi_player.cpp
Expand Up @@ -346,7 +346,9 @@ void AVI_Player::play(File *f) {
_soundQueuePreloadSize = 0;
if (_demux.open(f)) {
_stub->setYUV(true, _demux._width, _demux._height);
#ifndef BERMUDA_VITA
_mixer->setMusicMix(this, AVI_Player::mixCallback);
#endif
for (int i = 0; i < _demux._frames; ++i) {
uint32_t nextFrameTimeStamp = _stub->getTimeStamp() + 1000 / _demux._frameRate;
_stub->processEvents();
Expand All @@ -358,7 +360,9 @@ void AVI_Player::play(File *f) {
while (_demux.readNextChunk(chunk)) {
switch (chunk.type) {
case kChunkAudioType:
#ifndef BERMUDA_VITA
decodeAudioChunk(chunk);
#endif
break;
case kChunkVideoType:
decodeVideoChunk(chunk);
Expand All @@ -370,7 +374,9 @@ void AVI_Player::play(File *f) {
_stub->sleep(diff);
}
}
#ifndef BERMUDA_VITA
_mixer->setMusicMix(0, 0);
#endif
_stub->setYUV(false, 0, 0);
_demux.close();
}
Expand Down
33 changes: 33 additions & 0 deletions game.cpp
Expand Up @@ -116,8 +116,13 @@ void Game::init() {
_bitmapSequence = 0;
_nextState = kStateBitmapSequence;
} else {
#ifdef BERMUDA_VITA
playVideoVita("DATA/LOGO.AVI", "..\\midi\\logo.mid");
playVideoVita("DATA/INTRO.AVI", "..\\midi\\intro.mid");
#else
playVideo("DATA/LOGO.AVI");
playVideo("DATA/INTRO.AVI");
#endif
_nextState = kStateGame;
}
}
Expand Down Expand Up @@ -506,7 +511,11 @@ void Game::runObjectsScript() {
stopMusic();
clearSceneData(-1);
_varsTable[241] = 2;
#ifdef BERMUDA_VITA
playVideoVita("DATA/FINAL.AVI", "..\\midi\\final.mid");
#else
playVideo("DATA/FINAL.AVI");
#endif
strcpy(_tempTextBuffer, "END.SCN");
_switchScene = true;
}
Expand Down Expand Up @@ -946,6 +955,25 @@ void Game::playVideo(const char *name) {
#endif
}

#ifdef BERMUDA_VITA
void Game::playVideoVita(const char *name, const char *musicName) {
char *filePath = (char *)malloc(strlen(_dataPath) + 1 + strlen(name) + 1);
if (filePath) {
sprintf(filePath, "%s/%s", _dataPath, name);
File f;
if (f.open(filePath)) {
_stub->fillRect(0, 0, kGameScreenWidth, kGameScreenHeight, 0);
_stub->updateScreen();
strcpy(_musicName, musicName);
playMusic(_musicName);
AVI_Player player(_mixer, _stub);
player.play(&f);
}
free(filePath);
}
}
#endif

void Game::drawBitmapSequenceDemo(int num) {
static const char *suffixes[] = { "", "1", "2", "3", 0 };
char filename[32];
Expand Down Expand Up @@ -983,6 +1011,11 @@ void Game::playMusic(const char *name) {
{ "telquad.mid", 10 },
{ "gameover.mid", 11 },
{ "complete.mid", 12 },
#ifdef BERMUDA_VITA
{ "logo.mid", 13 },
{ "intro.mid", 14 },
{ "final.mid", 15 },
#endif
// demo game version
{ "musik.mid", 3 }
};
Expand Down
3 changes: 3 additions & 0 deletions game.h
Expand Up @@ -315,6 +315,9 @@ struct Game {
void redrawObjectBoxes(int previousObject, int currentObject);
void redrawObjects();
void playVideo(const char *name);
#ifdef BERMUDA_VITA
void playVideoVita(const char *name, const char *musicName);
#endif
void drawBitmapSequenceDemo(int num);
void stopMusic();
void playMusic(const char *name);
Expand Down
6 changes: 6 additions & 0 deletions main.cpp
Expand Up @@ -96,6 +96,12 @@ int main(int argc, char *argv[]) {
init(dataPath, savePath, musicPath);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainLoop, kCycleDelay, 0);
#elif BERMUDA_VITA
while (!g_stub->_quit) {
g_game->mainLoop();
g_stub->processEvents();
}
fini();
#else
uint32_t lastFrameTimeStamp = g_stub->getTimeStamp();
while (!g_stub->_quit) {
Expand Down

0 comments on commit 9107f8f

Please sign in to comment.