libretro / vitaquake2

Quake II port for Libretro.
GNU General Public License v2.0
4 stars 16 forks source link

Add music support #34

Closed jdgleaver closed 3 years ago

jdgleaver commented 3 years ago

This PR adds support for playback of CD audio tracks. Music must be in OGG format, placed inside the <PAK_directory>/music folder - i.e.:

.
├── baseq2
│   └── music
│       ├── 02.ogg
│       ├── 03.ogg
│       ├── 04.ogg
│       ├── 05.ogg
│       ├── 06.ogg
│       ├── 07.ogg
│       ├── 08.ogg
│       ├── 09.ogg
│       ├── 10.ogg
│       └── 11.ogg
├── rogue
│   └── music
│       ├── 02.ogg
│       ├── 03.ogg
│       ├── 04.ogg
│       ├── 05.ogg
│       ├── 06.ogg
│       ├── 07.ogg
│       ├── 08.ogg
│       ├── 09.ogg
│       ├── 10.ogg
│       └── 11.ogg
└── xatrix
    └── music
        ├── 02.ogg
        ├── 03.ogg
        ├── 04.ogg
        ├── 05.ogg
        ├── 06.ogg
        ├── 07.ogg
        ├── 08.ogg
        ├── 09.ogg
        ├── 10.ogg
        └── 11.ogg

Music files can be named either XX.ogg or trackXX.ogg.

A new Play Music core option allows this functionality to be switched on or off, while a new Music Volume core option allows the music volume to be set independently of sound effects.

Note that music support is disabled for the Vita builds, because I could not get it to compile... (multiple definition errors caused by stb_vorbis.h)

DrUm78 commented 1 year ago

@jdgleaver As I cannot tag you on the official VitaQuake2 repo (and "Issues" is not enabled on yours), I do it here: For some odd reasons, musics do not work on some platforms like armv7 or the Nintendo Switch (they do on GCW0/RG350/Linux x86_64 though), whatever I tried. I built many OS for the FunKey S handheld (armv7 32-bit) with many packages added (STB, FluidLite with STB support, FluidSynth, libFlac, libogg, libVorbis etc) but in vain, the music do not play whereas they do fine in .ogg format with TyrQuake and its deps on those platforms. I even implemented dr_flac and dr_mp3 in my fork but no luck (even if it compiles fine): https://github.com/DrUm78/vitaquake2/commit/0b733b40fc6c8c359f72285804b8277e3cef9a3e

For those platforms (armv7, Switch...), wouldn't it be a good idea to implement the music support the same way as TyrQuake?

jdgleaver commented 1 year ago

@DrUm78 Adding dr_flac and dr_mp3 to your fork isn't going to help with ogg playback...

The mixer code used here is standard libretro stuff, working on all official platforms - I have no idea why it wouldn't work on the FunKey. It almost seems like stb_vorbis itself isn't working there - I guess you could test this by trying flac or mp3 files with your fork, updating the code here accordingly:

https://github.com/libretro/vitaquake2/blob/59053244a03ed0f0976956365e60ca584fa6f162/libretro/libretro_cdaudio.c#L83-L104

i.e. ogg -> mp3

If mp3/flac work, then you'll at least know that the mixing code is okay...

Otherwise, you'll have to put some printf debugging in there, to see what the code is actually doing (although I don't know if that sort of debugging is possible on the FunKey).

For those platforms (armv7, Switch...), wouldn't it be a good idea to implement the music support the same way as TyrQuake?

The two cores are not directly comparable - you'd need a whole new implementation for vitaQuake2. That's not to say the same deps couldn't be used - just someone would have to do all the legwork.

(and note that I am no longer involved with the libretro project, so it's not something I would work on...)

DrUm78 commented 1 year ago

@DrUm78 Adding dr_flac and dr_mp3 to your fork isn't going to help with ogg playback...

Yeah I know, I wanted to test .mp3 support actually but indeed, I forgot to replace .ogg by .mp3 in this file... That works now, thanks!

Not sure why STB Vorbis does not work though (will test .flac later), but not very important now tbh. Thanks a lot for taking time to answer. 👍