blupi-games / planetblupi

Planet Blupi source code
https://www.blupi.org
Other
88 stars 22 forks source link

Convert mid files to ogg #47

Closed Skywalker13 closed 6 years ago

Skywalker13 commented 6 years ago

The problem with mid files is that the music changes according to the operating system and it's not complete with just only the timidity support without new instruments. Instead of adding instruments with the Linux build and using the software midi device on Windows and macOS, we should prefer a OGG for each music.

To convert the mid files to ogg, a good idea is to use vlc with the fluidsynth plugin and ffmpeg for writing the ogg file in vbr.

OdyX commented 6 years ago

I this this was released as part of the 1.12.1 version.

In my opinion, we had a loss: considering the .mid files the source, the .ogg files are binary artifacts. Also, they are already compressed, removing the possiblity for recompression in a better (hypothetical) format in the future.

Could we eventually keep the .mid files and have a .mid-to-.ogg conversion during the build process ?

OdyX commented 6 years ago

My concern is that the GPLv3 has

The "source code" for a work means the preferred form of the work

.ogg files are clearly not the preferred form of that work anymore. Iff you start working on lossless versions primarily, a compromise could be to have .flacs in the source code, and convert these to .ogg at build time; that's what was done in Colobot.

Skywalker13 commented 6 years ago

Midi files are in the planetblupi-data repository (with the command line for converting).. nothing is lost

I don't want to have mid file in the planetblupi repository because it will be difficult to convert for exactly the same ogg files with the builds for each operating system. You can't just think for Linux.

Skywalker13 commented 6 years ago

Note that flac files are too big (more than 100 MB) because some mid files have a length of 30 minutes.

Skywalker13 commented 6 years ago

https://github.com/blupi-games/planetblupi-data/tree/master/musics

Skywalker13 commented 6 years ago

And on Windows, it's very difficult to build fluisynth and I don't want to have a strong dep on a glib MSYS2 binary package for building planetblupi. Maybe the flac way is the better one. It needs a step to download the flac files somewhere. And I don't want to use git-lfs or git-annexe in order to not have too much build tools deps.

Skywalker13 commented 6 years ago

@OdyX note that it's the same problem with all PNG files. It's very difficult to generate all renders (with RayDream) with each build. The original vectorial 3D images and animations are in the planetblupi-data repository. Why it should be different for the music?

Skywalker13 commented 6 years ago

I close because v1.12.1 is released

Skywalker13 commented 6 years ago

Because of midi fanboys, the next release will include ogg and midi files. If both files exist, then ogg files are prefered and it fallbacks on midi files. Or with a command line option, it will be possible to force the use of the midi files instead.

OdyX commented 6 years ago

Hi there @Skywalker13,

thanks for re-adding the .mid files back in. Let me just comment on the further developments. Frankly, I don't see the point of shipping .mid files in the final binary packages. I doubt that a game player would really care about how the music is played.

Actually, my ideal setup would be: .mid files in the source repository, .ogg files in the binary artifacts (packages, etc), conversion during the build.

I have tried this on Debian main, with timidity and timgm6mb-soundfont:

timidity -c /etc/timidity/timgm6mb.cfg -Ov resources/music/music*.mid

Besides that it's just awfully long, it seems to produce the .ogg one needs to have music in the game. My concern then is that I didn't find a way to disable the option in the settings (which would not make sense anymore as the .ogg is available for the music).

Would "add a build-time build option to hide the ogg/midi setting" be something you would consider? Does the above approach make sense for you?

Skywalker13 commented 6 years ago

Hi @OdyX

I doubt that a game player would really care about how the music is played.

Me too, before the release ... but ... I was wrong

Actually, my ideal setup would be: .mid files in the source repository, .ogg files in the binary artifacts (packages, etc), conversion during the build.

I can add a build time option for disabling the entry in the settings. But IMHO, music is like 3D rendering. If music output (ogg) must be generated at build time, images (and movies) must be too. Both are binaries artifacts but both are slow to render and for the images it's very difficult because some images are modified by hand and the renderer only works on Windows with compatibility mode (and badly with wine + it's not free)..

OdyX commented 6 years ago

Hi there @Skywalker13, have a happy new year!

Here's what I have done for the Debian packaging for version 1.12.1-22-g13a7e27-2

https://anonscm.debian.org/cgit/pkg-games/planetblupi.git/tree/debian/rules?h=debian/master&id=48aa2bb0f4bbd1d7b5c4fbb59ac6fe33d6cc8e97

midfiles := $(wildcard resources/music/music*.mid)
oggfiles := $(midfiles:.mid=.ogg)

override_dh_clean-indep:
    dh_clean -i
    # These are shipped in the source archive, let's rebuild them
    rm -f $(oggfiles)

override_dh_auto_build-indep: $(oggfiles)
    dh_auto_build -i

resources/music/music%.ogg: resources/music/music%.mid
    # Encode to ogg with "Quality=0" ~ 64 kB
    timidity -c /etc/timidity/timgm6mb.cfg -Ow $< -o - | sox -t wav - -C0 $@

I have tried with (c)vlc but it's much slower. Also, converting to Vorbis with timidity's -Ov option works fine, but doesn't allow selecting the Vorbis' bit-rate or quality. sox seemed like the option with fewer dependencies.

Then, the files are shipped in different packages: planetblupi-music-ogg and planetblupi-music-midi, with the -ogg version installed by default.

The only missing piece there is for the planetblupi executable to detect if the midi/ogg files are present, only offer the available options, and fallback to the one present if both are not available. I could eventually try to get a patch working for that, but you're likely to be faster!

Skywalker13 commented 6 years ago

The only missing piece there is for the planetblupi executable to detect if the midi/ogg files are present, only offer the available options, and fallback to the one present if both are not available. I could eventually try to get a patch working for that, but you're likely to be faster!

Uh? I'm sure to have done that.

Skywalker13 commented 6 years ago

Mmmh. maybe I've done only for user and game dir fallback https://github.com/blupi-games/planetblupi/commit/67ea4d0c2ef566a615600c77ed32dcd621319261

Skywalker13 commented 6 years ago

@OdyX should be fine with fbfadb1

It needs some testing...

OdyX commented 6 years ago

@Skywalker13 I took some time now to cherry-pick two of your patches https://github.com/blupi-games/planetblupi/commit/daa3dbf22bfb64d14e199b1eb70c158d9266a1fa & https://github.com/blupi-games/planetblupi/commit/fbfadb1eef41dfe95f66e6741f9b3c1aaf98d8ed and uploaded 1.12.1-22-g13a7e27-3 to unstable. It worked as I expected it to when I tested (it correctly plays the only available music without configuration, doesn't allow changing the configuration when one is absent). Thanks!

Skywalker13 commented 6 years ago

Thanks for the tests and the packaging, I will release v1.12.2 soon but I must still check something under macOS first.