For those of you that insert or replace OGG files in PSO, you may have noticed that certain songs or areas (mainly CCA, both Crater areas, and desert) do not like having their music replaced where the music doesnt play for whatever reason. I have figured out a workaround for any song that does this and an explanation for whats happening here. Credit to esc, Eidolon, Ender and a few other(s) for helping me figure out what was going on.
Table of Contents:
The game uses OGG files to play back samples/music which are container formats for audio. You may see music files in general (mp3s, etc) to be files "representing" a single song or tune in its entirety, but for OGG this isnt really the case. In truth, PSOs ogg files are more like a book with several "chapters" each with portions of the song called streams. In order to provide a seamless music experience, the game strings along these streams in a certain order (not necessarily in the literal ascending order) based on track definitions. Because PSO needs to switch between the "combat" and "peaceful" version(s) of each respective area, the definitions keep track of when each transition point of the song is and when it can switch over if it needs to. For our purposes, we only need to remember the song(s) are divided up into these "stream" chunks, and they each have an ID number, indexed by 0. (so like, ID 0, ID 1, ID 2, etc)
When you export a song to OGG (we will use Audacity for this example as its commonly used), in most cases it will only export it as a single Stream OGG which contains the entire song. This means its single stream will be ID 0.
For the most part, most areas happen to have a track definition that says to start the song off with Stream ID 0; the area(s) that don't are, you guessed it, CCA, Crater, and Desert. This is why replacing those area(s) works as-is without any extra steps; when the game attempts to play the OGG file for those areas, it looks for a stream ID which doesnt exist in your modded OGG, so you just get silence.
Tools used for Workaround:
In your WSL install, make sure to do "sudo apt-get install ogmtools" to install the tool we will be using.
Steps Taken:
Hope this helps.
Table of Contents:
- Explanation
- Tools used for Workaround
- Steps Taken
The game uses OGG files to play back samples/music which are container formats for audio. You may see music files in general (mp3s, etc) to be files "representing" a single song or tune in its entirety, but for OGG this isnt really the case. In truth, PSOs ogg files are more like a book with several "chapters" each with portions of the song called streams. In order to provide a seamless music experience, the game strings along these streams in a certain order (not necessarily in the literal ascending order) based on track definitions. Because PSO needs to switch between the "combat" and "peaceful" version(s) of each respective area, the definitions keep track of when each transition point of the song is and when it can switch over if it needs to. For our purposes, we only need to remember the song(s) are divided up into these "stream" chunks, and they each have an ID number, indexed by 0. (so like, ID 0, ID 1, ID 2, etc)
When you export a song to OGG (we will use Audacity for this example as its commonly used), in most cases it will only export it as a single Stream OGG which contains the entire song. This means its single stream will be ID 0.
For the most part, most areas happen to have a track definition that says to start the song off with Stream ID 0; the area(s) that don't are, you guessed it, CCA, Crater, and Desert. This is why replacing those area(s) works as-is without any extra steps; when the game attempts to play the OGG file for those areas, it looks for a stream ID which doesnt exist in your modded OGG, so you just get silence.
Tools used for Workaround:
- We will be basing our explanation using a Windows install. Sorry to any of you Linux and Mac users, I dont have a version of this tutorial for those OS versions.
- Audacity
- WSL (Windows Subsystem for Linux)
- ogmtools (WSL package)
In your WSL install, make sure to do "sudo apt-get install ogmtools" to install the tool we will be using.
Steps Taken:
- Have your intended song/track ready that you intend to replace the area with and export it in Audacity as a 44.1khz OGG. If you are looping the track, ensure your "LOOP_START" comment in the metadata is correct. For this tutorial example export it as "song.ogg".
- In a new file in Audacity, go to Generate > Silence and generate 1 second of silence. Other shorter durations might work, but we are using 1 second for this. Export this as a 44.1khz ogg file named "silence.ogg".
- Open up https://github.com/jtuu/pso-slbgm/blob/089479c94f35a47faac47599de29364f261fe5df/js/slbgm.js#L163 in a browser and keep this page open. This page contains the track definition(s) for each area OGG file; we will need a specific number depending on the area you are replacing. To find this number, look after the "from_file_contents" (for the respective OGG being worked on) words for where the numbers begin. The 2nd number in that list (in CCA's, for example, its 7) is the stream ID we will need to keep in mind. Once you have this number then proceed with the next step.
- In WSL, use the "cd" command to navigate to the folder with both your song.ogg and silence.ogg exports. (for example: "cd /mnt/c/Users/(your user)/Documents/Oggs" or whatever). Once you are in the same folder as your exported OGGs, run the following command (w/ modifications): "ogmmerge -o merged.ogg silence.ogg (...) silence.ogg" where silence.ogg is repeated N times, N being that number we got earlier. So for example, in CCA's case: "ogmmerge -o merged.ogg silence.ogg silence.ogg silence.ogg silence.ogg silence.ogg silence.ogg silence.ogg" as its repeated 7 times. Be very careful to get the correct number of repetitions or it wont work.
- Now we add on the actual song. run this command (for CCA for example): "cat merged.ogg song.ogg > slbgm_jungle.ogg"
- The newly produced file in that folder should be correct and you can now replace the actual file with it. To verify the song, you can run "ogminfo slbgm_jungle.ogg" and the terminal will print all the channel info for each stream. A correct looking CCA replacement should have at least 7 lines, since the actual song is on the 7th one.
Hope this helps.