Просмотр исходного кода

Audio installation divided in substeps. Fixes in the audio manager

Iñigo Valentin 3 лет назад
Родитель
Сommit
53fc66a072

+ 5 - 0
V-Gears-Installer/include/DataInstaller.h

@@ -185,6 +185,11 @@ class DataInstaller{
              */
             MEDIA_IMAGES,
 
+            /**
+             * Prepares the installer for sound extraction.
+             */
+            MEDIA_SOUNDS_INIT,
+
             /**
              * Extract game sounds.
              */

+ 25 - 2
V-Gears-Installer/include/MediaDataInstaller.h

@@ -55,10 +55,18 @@ class MediaDataInstaller{
         void InstallSprites();
 
         /**
-         * Extracts all sound files contained in the audio.dat file and installs them.
+         * Prepares the installer for the sounds extraction.
          *
+         * @return The total number of sounds to process.
          */
-        void InstallSounds();
+        int InstallSoundsInit();
+
+        /**
+         * Extracts the next sound file contained in the audio.dat file and installs it.
+         *
+         * @return True if there are no more sounds to extract, false otherwise.
+         */
+        bool InstallSounds();
 
         /**
          * Writes the XML file with all audio entries.
@@ -140,6 +148,21 @@ class MediaDataInstaller{
          */
         BinGZipFile window_;
 
+        /**
+         * The sounds .fmt file.
+         */
+        File fmt_;
+
+        /**
+         * The sounds .dat file.
+         */
+        File dat_;
+
+        /**
+         * Number of sounds already processed.
+         */
+        int processed_sounds_;
+
         /**
          * Map for sound files with descriptive names.
          */

+ 18 - 6
V-Gears-Installer/src/DataInstaller.cpp

@@ -136,12 +136,19 @@ int DataInstaller::Progress(){
         case MEDIA_IMAGES:
             write_output_line_("Extracting game images...", 2, true);
             media_installer_->InstallSprites();
+            installation_state_ = MEDIA_SOUNDS_INIT;
+            return CalcProgress();
+        case MEDIA_SOUNDS_INIT:
+            write_output_line_("Extracting sounds...", 2, true);
+            substeps_ = media_installer_->InstallSoundsInit();
             installation_state_ = MEDIA_SOUNDS;
+            cur_substep_ = 0;
             return CalcProgress();
         case MEDIA_SOUNDS:
-            write_output_line_("Extracting sounds...", 2, true);
-            media_installer_->InstallSounds();
-            installation_state_ = MEDIA_SOUNDS_INDEX;
+            write_output_line_("Extracting sound " + std::to_string(cur_substep_), 2, true);
+            if (media_installer_->InstallSounds() == true)
+                installation_state_ = MEDIA_SOUNDS_INDEX;
+            else cur_substep_ ++;
             return CalcProgress();
         case MEDIA_SOUNDS_INDEX:
             write_output_line_("Building sound index...", 2, true);
@@ -216,9 +223,14 @@ int DataInstaller::Progress(){
 }
 
 const int DataInstaller::CalcProgress(){
-    // TODO: Make more accurate with iterator_counter_ and
-    // progress_step_num_elements_.
     float curr_step = installation_state_ / static_cast<float>(STATE_COUNT);
+    if (substeps_ > 0 && cur_substep_ < substeps_){
+        curr_step
+          += (
+            (static_cast<float>(cur_substep_) / static_cast<float>(substeps_))
+            / static_cast<float>(STATE_COUNT)
+          );
+    }
     curr_step = curr_step * 100.0f;
     int progress = static_cast<int>(curr_step);
     if (progress >= 100) progress = 99;
@@ -235,7 +247,7 @@ void DataInstaller::CreateDirectories(){
     CreateDir("images/reels");
     CreateDir("images/window");
     CreateDir("models/fields/entities");
-    CreateDir("audio/fx");
+    CreateDir("audio/sound");
     CreateDir("audio/music");
     application_.ResMgr()->addResourceLocation("data/temp/char/", "FileSystem", "FFVII", true, true);
     application_.ResMgr()->addResourceLocation("data/models/", "FileSystem", "FFVII", true, true);

+ 61 - 46
V-Gears-Installer/src/MediaDataInstaller.cpp

@@ -39,7 +39,8 @@ u8 MediaDataInstaller::WAV_HEADER[] = {
 
 MediaDataInstaller::MediaDataInstaller(const std::string input_dir, const std::string output_dir):
   input_dir_(input_dir), output_dir_(output_dir),
-  menu_(input_dir + "data/menu/menu_us.lgp", "LGP"), window_(input_dir + "data/kernel/WINDOW.BIN")
+  menu_(input_dir + "data/menu/menu_us.lgp", "LGP"), window_(input_dir + "data/kernel/WINDOW.BIN"),
+  fmt_(input_dir_ + "data/sound/audio.fmt"), dat_(input_dir_ + "data/sound/audio.dat")
 {PopulateMaps();}
 
 void MediaDataInstaller::PopulateMaps(){
@@ -297,61 +298,75 @@ void MediaDataInstaller::InstallSprites(){
     }
 }
 
-void MediaDataInstaller::InstallSounds(){
-    File fmt(input_dir_ + "data/sound/audio.fmt");
-    File dat(input_dir_ + "data/sound/audio.dat");
+int MediaDataInstaller::InstallSoundsInit(){
+    fmt_.SetOffset(0);
+    dat_.SetOffset(0);
+    processed_sounds_ = 0;
+    return TOTAL_SOUNDS;
+}
 
-    for (int i = 0; i < TOTAL_SOUNDS; i ++){
-        FmtFile header;
+bool MediaDataInstaller::InstallSounds(){
 
-        header.size = fmt.readU32LE();
-        // If size is 0, this is a bad header. There are 112 bytes of bad data, and after that,
-        // the next header.
-        if (header.size == 0){
-            for (int b = 0; b < 112; b += 4) fmt.readU32LE();
-            continue;
-        }
+    FmtFile header;
+    header.size = fmt_.readU32LE();
+    // If size is 0, this is a bad header. There are 112 bytes of bad data, and after that,
+    // the next header.
+    if (header.size == 0){
+        for (int b = 0; b < 112; b += 4) fmt_.readU32LE();
+        processed_sounds_ ++;
+        if (processed_sounds_ >= TOTAL_SOUNDS) return true;
+        else return false;
+    }
 
-        header.offset = fmt.readU32LE();
-        // If the offset is less than the previous one, also bad header. 34 bytes of bad data, and
-        // after that, the next header.
-        if (header.offset < dat.GetCurrentOffset()){
-            for (int b = 0; b < 34; b += 2) fmt.readU16LE();
-            continue;
-        }
+    header.offset = fmt_.readU32LE();
+    // If the offset is less than the previous one, also bad header. 34 bytes of bad data, and
+    // after that, the next header.
+    if (header.offset < dat_.GetCurrentOffset()){
+        for (int b = 0; b < 34; b += 2) fmt_.readU16LE();
+        processed_sounds_ ++;
+        if (processed_sounds_ >= TOTAL_SOUNDS) return true;
+        else return false;
+    }
 
-        // This should never happen, but just in case, never read outside the file
-        if (header.offset + header.size > dat.GetFileSize()) continue;
+    // This should never happen, but just in case, never read outside the file
+    if (header.offset + header.size > dat_.GetFileSize()){
+        processed_sounds_ ++;
+        if (processed_sounds_ >= TOTAL_SOUNDS) return true;
+        else return false;
+    }
 
-        for (int l = 0; l < 16; l ++) header.loop_metadata[l] = fmt.readU8();
-        for (int l = 0; l < 18; l ++) header.wav_header[l] = fmt.readU8();
-        header.samples_per_block = fmt.readU16LE();
-        header.adpcm = fmt.readU16LE();
-        for (int l = 0; l < 28; l ++) header.adpcm_sets[l] = fmt.readU8();
+    for (int l = 0; l < 16; l ++) header.loop_metadata[l] = fmt_.readU8();
+    for (int l = 0; l < 18; l ++) header.wav_header[l] = fmt_.readU8();
+    header.samples_per_block = fmt_.readU16LE();
+    header.adpcm = fmt_.readU16LE();
+    for (int l = 0; l < 28; l ++) header.adpcm_sets[l] = fmt_.readU8();
 
-        dat.SetOffset(header.offset);
-        std::ofstream out(
-          output_dir_ + "audio/sound/" + std::to_string(i) + ".wav", std::ios::out | std::ios::binary
-        );
+    dat_.SetOffset(header.offset);
+    std::ofstream out(
+      output_dir_ + "audio/sound/" + std::to_string(processed_sounds_) + ".wav",
+      std::ios::out | std::ios::binary
+    );
 
 
-        // Write the standard wav header.
-        for (int b = 0; b < 78; b ++) out.put(WAV_HEADER[b]);
-        // Write the data from the dat file.
-        for (int b = 0; b < header.size; b ++) out.put(dat.readU8());
-        out.close();
+    // Write the standard wav header.
+    for (int b = 0; b < 78; b ++) out.put(WAV_HEADER[b]);
+    // Write the data from the dat file.
+    for (int b = 0; b < header.size; b ++) out.put(dat_.readU8());
+    out.close();
 
-        // Convert to OGG.
-        // TODO: Don't use system calls! Integrate libav or something that can do the conversion
-        // natively
-        std::string command = (boost::format(
-          "ffmpeg -hide_banner -loglevel panic -y -i %1%audio/sound/%2%.wav %1%audio/sound/%2%.ogg;"
-          "rm %1%audio/sound/%2%.wav"
-        ) % output_dir_ % i).str();
-        std::system(command.c_str());
+    // Convert to OGG.
+    // TODO: Don't use system calls! Integrate libav or something that can do the conversion
+    // natively
+    std::string command = (boost::format(
+      "ffmpeg -hide_banner -loglevel panic -y -i %1%audio/sound/%2%.wav %1%audio/sound/%2%.ogg;"
+      "rm %1%audio/sound/%2%.wav"
+    ) % output_dir_ % processed_sounds_).str();
+    std::system(command.c_str());
 
-        sounds_.push_back("audio/sound/" + std::to_string(i) + ".ogg");
-    }
+    sounds_.push_back("audio/sound/" + std::to_string(processed_sounds_) + ".ogg");
+    processed_sounds_ ++;
+    if (processed_sounds_ >= TOTAL_SOUNDS) return true;
+    else return false;
 }
 
 void MediaDataInstaller::WriteSoundIndex(){

+ 1 - 1
V-Gears/include/core/AudioManager.h

@@ -109,7 +109,7 @@ class AudioManager : public Ogre::Singleton<AudioManager>{
          * @param[in] name3 Name of the third sound to play.
          * @param[in] name4 Name of the fourth sound to play.
          */
-        void AudioManager::ScriptPlaySounds(
+        void ScriptPlaySounds(
           const char* name1, const char* name2, const char* name3, const char* name4
         );
 

+ 1 - 1
V-Gears/src/core/AudioManager.cpp

@@ -141,7 +141,7 @@ void AudioManager::ScriptPlaySound(const char* name){
     SoundPlay(name_str);
 }
 
-void ScriptPlaySound(const char* name, const int channel){ScriptPlaySound(name1);}
+void AudioManager::ScriptPlaySound(const char* name, const int channel){ScriptPlaySound(name);}
 
 void AudioManager::ScriptPlaySounds(
   const char* name1, const char* name2, const char* name3, const char* name4