If you've played a Grand Theft Auto game before, you likely know that one of the most notable features of them are the in-game radio stations that the player hears when they get into a car. This project is born out of the desire to listen to these radio stations without necessarily playing the game.
Q: One can listen to this music on Youtube or Spotify. After all, the music featured in these games are licensed from real-life musicians and artists. What sets this website apart from that?
It is correct that most of the songs featured on GTA radio channels are licensed music from real-life artists, but what sets this format apart, is that in GTA universe everything is a satire. Radio hosts are these fictional characters that have their own quirks and say a lot of out of pocket, humorous things. It is a really entertaining listening experience.
In ye olden times (during the era of GTA III and Vice City), the radio station implementation in the games was really simple. Rockstar included an hour long audio file, for each station, which would play over and over as long as the player was tuned into the station. In GTA San Andreas, they abandoned that system in favor of a more procedural approach. The radio stations are split up in the individual tracks of different categories. The game runtime contains some sort of logic, to decide what it wants to play next. This way, the listening experience does not become repetitive.
Feel free to check out the demo below. Pick a radio station, then a category. A random audio clip will be played based on your selection.
Each of these tracks are extracted from the game binary files, courtesy of San Andreas Audio Toolkit. As you can see, each audio track is its own unit that can be played independently, along with others, to create a life-like radio simulation. We have no knowledge of how the game treats these files, but we can act strategically and reverse engineer a radio-like behavior. Any kind of music player can be used for this as long as they can be interfaced with programatically, but this project uses MusicPlayerDaemon, also known as MPD.
The biggest limitation with this endeavor is the fact that each radio station features about 15 songs on average, as well as about 15 secondary tracks of each category. This corresponds to about 1 hour of playback until the songs have to repeat.
The simplest solution to satisfy rule 1, is to play through a shuffled list of tracks. When the tracks run out, shuffle them again and repeat. This also satisfies the 3rd rule and seems like a reasonable solution, but it violates the 2nd rule. There is a chance that the last element of the first shuffle and the first element of the second shuffle are the same, resulting in same song being played twice in a row.
In this way, Rule 2 and 3 are slightly contradictory. Consider an example where you have tracks [a, b, c, d]. The track a can be played furthest apart from itself, only if b, c, and d are also played. The same goes for all of the other tracks. This fact will keep the order a, b, c, d indefinitely. Therefore, maxing out the 2nd rule will result in ignoring the 3rd rule.
There is a solution that compromises between these two. Let's take the following list again [a, b, c, d]. The player could simply pick at random from the top 2 entries in the list, in this case a and b. The player consumes whichever is drawn and then appends it at the end of the list. The two possibilities after this process is [b, c, d, a] and [a, c, d, b], depending on which one was picked. Either way it is guaranteed that the track that just played will not be picked again until the bottom of the list is reached. Just for reference I'm calling this a Randomized Dual-Head Queue, since it depends on the FIFO principle of the queue, but there is a random element that over-time mutates the list so much that the order may become unrecognizeable from the initial state. I tried researching online if this concept has a name, and closest I came up with is a Sliding Window Sampling algorithm, which still doesn't fully match this specific implementation.