(Standalone) Custom Music Player for the Soundtrack packs

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

havarc
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Feb 11, 2018 2:28 am
Contact:

(Standalone) Custom Music Player for the Soundtrack packs

Post by havarc »

Some of these tracks (absolute kudos to Petr!) make good background music for concentrating on specific tasks, not unlike actually laying out a factory. Yet if there was, say, a custom audio application, that mixes music like in the game does, but doesn't actually need to run the game, it would be very appreciated!
Koub
Global Moderator
Global Moderator
Posts: 7764
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: (Standalone) Custom Music Player for the Soundtrack packs

Post by Koub »

The Space Age soundtrack has been made available on Steam, you can buy and download it, and then listen to the music with whatever software you want.
Koub - Please consider English is not my native language.
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: (Standalone) Custom Music Player for the Soundtrack packs

Post by Donion »

There is no special logic in which tracks play, it's randomized (with some weights), you can just play the .ogg audio files in /data, so I'm gonna assume you're referring to the variable music tracks which are put together from several layers in-game.
Currently there are no specific plans to create a standalone music player (although one person told be it would be neat, so never say never).
rollc_at
Inserter
Inserter
Posts: 27
Joined: Fri Sep 01, 2023 3:11 pm
Contact:

Re: (Standalone) Custom Music Player for the Soundtrack packs

Post by rollc_at »

This is extremely relevant to my interests ^^

TL;DR: The simplest hack (assuming you have a PC around you running) is to keep Factorio open in the background, and just allow the music to play, while your infinite researches keep going. If you don't want to deal with random alerts (biters/pentapods/asteroids eating your stuff), keep the game open on the research screen - the simulation is paused, but the music keeps playing.

The randomised tracks are just folders with .ogg & .lua files, the latter are scripts that describe the random weights with which the listed .ogg samples are picked for playback. The player would have to embed a Lua interpreter, and provide an implementation of the sound_variations function.

If you want a simple and dirty hack/script just to play this specific soundtrack, you can probably stitch something together in C/C++. I would look into GStreamer for an audio engine (it will save you a lot of low-level work); also Lua is trivial to embed in C programs. Point the hypothetical script at the game's assets folder and let it do its magic.

Personally I would be hesitant to embed a Lua interpreter into a "real" music player - this is a security nightmare, you're asking to allow executing arbitrary code coming from potentially untrusted sources. A far saner approach would be to convert the weights to some non-executable data interchange format, like JSON, YAML, XML, etc. Each file is mostly static/constant data, the only function being called is sound_variations, and all of its parameters are constants (string, integer, float) - this conversion could be done manually, or (as the code is nicely formatted) very crudely with regexes ;P

But this is all quite a bit of work, AND assuming you're already intimately familiar with the internals of an existing (open-source) player - it would require changes on every layer, from data model (redefine what a "track" on a playlist is, perhaps remodel it after a shoutcast/HLS stream?), thru UX (expect edge cases), to the audio engine itself (e.g. disable crossfading between samples if enabled for other kinds of tracks).

Of course there is the ethical/legal side of it as well. Technically you purchased a license to the game itself as a whole. You obviously can't redistribute the assets, and whether you are legally allowed to slice them apart for personal use may depend on your jurisdiction (IANAL but it may fall under fair use).

In a much more generalised context, this kind of a "custom randomised player" would be an amazing avenue of exploration for soundtracks, soundscapes, ambient, etc for artists. I've done some experiments (using Pure Data) in creating "random" music, e.g. soundscape generator that responds to ambient noise picked up on the microphone. If anyone is interested in exploring these avenues, HMU.
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: (Standalone) Custom Music Player for the Soundtrack packs

Post by Donion »

rollc_at wrote: Thu Nov 07, 2024 12:45 pm TL;DR: The simplest hack (assuming you have a PC around you running) is to keep Factorio open in the background, and just allow the music to play, while your infinite researches keep going. If you don't want to deal with random alerts (biters/pentapods/asteroids eating your stuff), keep the game open on the research screen - the simulation is paused, but the music keeps playing.
Even simpler would be to just start a new empty game and set the music mode to randomize all (it's a hidden setting).
rollc_at wrote: Thu Nov 07, 2024 12:45 pm The randomised tracks are just folders with .ogg & .lua files, the latter are scripts that describe the random weights with which the listed .ogg samples are picked for playback. The player would have to embed a Lua interpreter, and provide an implementation of the sound_variations function.
This is not accurate at all. The variable track system has way more logic to it than just some weights: states and transitioning between them, interconnectedness of layers and so on.
rollc_at wrote: Thu Nov 07, 2024 12:45 pm If you want a simple and dirty hack/script just to play this specific soundtrack, you can probably stitch something together in C/C++. I would look into GStreamer for an audio engine (it will save you a lot of low-level work); also Lua is trivial to embed in C programs. Point the hypothetical script at the game's assets folder and let it do its magic.
You could probably hack something together for the simplest tracks (interludes), but it wouldn't work well at all for the more complex ones.

For the reasons I stated and other points you've mentioned (dealing with lua, lot of effort) I wouldn't hold my breath waiting for a standalone Factorio music player.
rollc_at
Inserter
Inserter
Posts: 27
Joined: Fri Sep 01, 2023 3:11 pm
Contact:

Re: (Standalone) Custom Music Player for the Soundtrack packs

Post by rollc_at »

This is not accurate at all. The variable track system has way more logic to it than just some weights: states and transitioning between them, interconnectedness of layers and so on.
The main observation here was that the only function being called is sound_variations, and that all of the parameters in each call site are static, which (after having a second look) appears to be correct - so a JSON file could be made functionally equivalent to the Lua code in question.

But fair enough! I'm (obviously) not familiar with the music engine internals, which is precisely why this is a topic of interest to me. Games have been doing dynamic music for decades, so bringing generative compositions to standalone players (and allowing musicians/composers easier access to such feature as a form of artistic expression) would be awesome.

I slept on this and I think the quickest way to a POC would be to split the problem in two - any existing player with support for streaming HLS or Shoutcast, plus another standalone application that does the actual automated composing/DJ'ing, and exposes the "assembled" tracks as streams over the loopback interface. It would be crude but workable, and allow people with different OS's / music player preferences to collaborate on such a project.

There's also the question of how such generative tracks could be authored. Musicians/producers may be familiar with Logic, Ableton, Reaper, etc but not Lua. In the past I've worked to bridge the gap between audio and computer engineering worlds, and it's always been full of... improvisation xD

I would love a deep dive on this as a topic for a future FFF!
Post Reply

Return to “Ideas and Suggestions”