Javanaise/mrboom-libretro

Libretro: playing music doesn't work [Emscripten + Nintendo switch]

frranck opened this issue ยท 57 comments

I tried to load .MOD and .XM in that branch https://github.com/Javanaise/mrboom-libretro/tree/adding_music using ibxm but I'm getting some "audio_mixer_play_mod cannot retrieve duration !" errors.

If I change https://github.com/Javanaise/mrboom-libretro/blob/adding_music/libretro-common/audio/audio_mixer.c#L599
to replay = new_replay( module, 48000, 1 ); // ( module, s_rate, 1);
I don't get the error message but still don't get the module played...

PS: If you compile the game by default you'll use the data from retro_data.h
If you compile the game with:
make LOAD_FROM_FILES=1
You will get the data decrunched and read from files inside a temporary directory

The reason audio doesnt currently play with the mixer is because the functions for getting the audio and chunk size are not implemented. You will need to use the mixer functions in audio_mixer.c iirc to set up a mixing loop for all music.

Hi @mudlord
What do you mean ? linking with https://github.com/libretro/libretro-common/blob/master/audio/audio_mixer.c, doesn't change anything.

You are using the functions from audio_mix.c it seems. Those functions are incomplete.

@mudlord Sorry I have no idea how to do that. Could you please submit a PR for this ? There's a bounty.

@twinaphex this has been done here:
#41
@DevilFrost can claim this bounty...

OK, sure thing.

Seems it's breaking on ios:
http://p.0bl.net/64615

Please test the branch ios.

still fails:

cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -miphoneos-version-min=5.0 -DIOS -O3 -DMRBOOM -DHAVE_IBXM -D_FORTIFY_SOURCE=0 -DPLATFORM="Darwin" -DGIT_VERSION="" fdffce4"" -D__LIBRETRO__ -I./libretro-common/include -I./libretro-common -I./ai -I. -Wall -pedantic -fPIC -std=gnu99 -fPIC -c -o libretro-common/audio/conversion/float_to_s16_neon.o libretro-common/audio/conversion/float_to_s16_neon.c
cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -miphoneos-version-min=5.0 -DIOS -O3 -DMRBOOM -DHAVE_IBXM -D_FORTIFY_SOURCE=0 -DPLATFORM="Darwin" -DGIT_VERSION="" fdffce4"" -D__LIBRETRO__ -I./libretro-common/include -I./libretro-common -I./ai -I. -Wall -pedantic -fPIC -std=gnu99 -fPIC -c -o libretro-common/ibxm/ibxm.o libretro-common/ibxm/ibxm.c
:5:3: error: unknown directive
.type convert_s16_float_asm, %function
^
:11:3: error: unknown directive
.type _convert_s16_float_asm, %function
^
libretro-common/audio/conversion/float_to_s16_neon.c:30:1: warning: extension used [-Wlanguage-extension-token]
asm(
^
:5:3: error: unknown directive
.type convert_float_s16_asm, %function
^
:11:3: error: unknown directive
.type _convert_float_s16_asm, %function
^
1 warning and 2 errors generated.
1 warning and 2 errors generated.
make: *** [libretro-common/audio/conversion/float_to_s16_neon.o] Error 1
make: *** Waiting for unfinished jobs....

Update. Please test.

1 file changed, 3 insertions(+), 3 deletions(-)
franck-mac-book-air:mrboom-libretro franck$ make -f Makefile platform=ios -j6
2018-11-24 13:13:23.833 xcodebuild[30831:507120] [MT] PluginLoading: Required plug-in compatibility UUID 426A087B-D3AA-431A-AFDF-F135EC00DE1C for plug-in at path '/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XCActionBar.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-11-24 13:13:23.835 xcodebuild[30831:507120] [MT] PluginLoading: Required plug-in compatibility UUID 426A087B-D3AA-431A-AFDF-F135EC00DE1C for plug-in at path '
/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -c -o libretro-common/audio/resampler/drivers/sinc_resampler_neon.o libretro-common/audio/resampler/drivers/sinc_resampler_neon.S
cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -miphoneos-version-min=5.0 -DIOS -O3 -DMRBOOM -DHAVE_IBXM -D_FORTIFY_SOURCE=0 -DPLATFORM="Darwin" -DGIT_VERSION="" 0384120"" -D__LIBRETRO__ -I./libretro-common/include -I./libretro-common -I./ai -I. -Wall -pedantic -fPIC -std=gnu99 -fPIC -c -o libretro-common/audio/conversion/s16_to_float_neon.o libretro-common/audio/conversion/s16_to_float_neon.c
cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -miphoneos-version-min=5.0 -DIOS -O3 -DMRBOOM -DHAVE_IBXM -D_FORTIFY_SOURCE=0 -DPLATFORM="Darwin" -DGIT_VERSION="" 0384120"" -D__LIBRETRO__ -I./libretro-common/include -I./libretro-common -I./ai -I. -Wall -pedantic -fPIC -std=gnu99 -fPIC -c -o libretro-common/audio/conversion/float_to_s16_neon.o libretro-common/audio/conversion/float_to_s16_neon.c
libretro-common/audio/conversion/s16_to_float_neon.c:30:libretro-common/audio/conversion/float_to_s16_neon.c1::30 :1: warning: warning: extension extensionused used[-Wlanguage-extension-token] [-Wlanguage-extension-token]

asm(
^
asm(
^
::55::33:: errorerror: : unknownunknown directivedirective

.type convert_float_s16_asm, %function .type convert_s16_float_asm, %function

^ ^

:11:3: error: unknown directive:
11:3: error: unknown directive
.type _convert_float_s16_asm, %function
^
.type _convert_s16_float_asm, %function
^
11 warning and 2 errors generated.
warning and 2 errors generated.
make: *** [libretro-common/audio/conversion/float_to_s16_neon.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [libretro-common/audio/conversion/s16_to_float_neon.o] Error 1

There should be no s16_to_float_neon.c and float_to_s16_neon.c

make clean?

yes I did a make clean

^
cc -arch armv7 -isysroot /Volumes/T2/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -miphoneos-version-min=5.0 -miphoneos-version-min=5.0 -DIOS -O3 -DMRBOOM -DHAVE_IBXM -D_FORTIFY_SOURCE=0 -DPLATFORM="Darwin" -DGIT_VERSION="" 0384120"" -D__LIBRETRO__ -I./libretro-common/include -I./libretro-common -I./ai -I. -Wall -pedantic -fPIC -std=gnu99 -fPIC -c -o libretro-common/audio/conversion/float_to_s16_neon.o libretro-common/audio/conversion/float_to_s16_neon.c
libretro-common/audio/conversion/float_to_s16_neon.c:30:1: warning: extension used [-Wlanguage-extension-token]
asm(
^
:5:3: error: unknown directive
.type convert_s16_float_asm, %function
^
:5:3: error: unknown directive
.type convert_float_s16_asm, %function
^
:11:3: error: unknown directive
.type _convert_float_s16_asm, %function
^
:11:3: error: unknown directive
.type _convert_s16_float_asm, %function
^
1 warning and 2 errors generated.
1 warning and 2 errors generated.
make: *** [libretro-common/audio/conversion/float_to_s16_neon.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [libretro-common/audio/conversion/s16_to_float_neon.o] Error 1
^Cmake: *** [mrboom.o] Interrupt: 2

franck-mac-book-air:mrboom-libretro franck$ git pull

Already up to date.

$ cat Makefile.common | grep -i neon

SOURCES_ASM := $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler_neon.S
$(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float_neon.S
$(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16_neon.S

$ git status
On branch ios
Your branch is up to date with 'origin/ios'.

nothing to commit, working tree clean

$ git log
commit 0384120 (HEAD -> ios, origin/ios)
Author: Frost 44336975+DevilFrost@users.noreply.github.com
Date: Sat Nov 24 09:01:39 2018 +0000

Update Makefile.common

It seems strange that the old version is used when compiling.
I updated the file Makefile.common. Please test.

just tried with 6fd524a its the same. I also double checked the clean was deleting all .o

you expect SOURCES_ASM not to be compiled?

I think I understand what the problem is.

The compiler compiles .c files instead of .S files.

Please test the branch ios-dont.

@DevilFrost yes ios-dont worked

btw would be cool to have a "no music" option...

btw the SDL2 seems broken in ios-dont

make mrboom LIBSDL2=1

Undefined symbols for architecture x86_64:
"_convert_float_to_s16", referenced from:
_audio_mix_load_wav_file in audio_mix.o
"_convert_s16_to_float", referenced from:
_audio_mix_load_wav_file in audio_mix.o
"_retro_resampler_realloc", referenced from:
_audio_mixer_load_wav in audio_mixer.o
_audio_mix_load_wav_file in audio_mix.o
"_rwav_free", referenced from:
_audio_mixer_load_wav in audio_mixer.o
_audio_mix_free_chunk in audio_mix.o
"_rwav_load", referenced from:
_audio_mixer_load_wav in audio_mixer.o
_audio_mix_load_wav_file in audio_mix.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mrboom] Error 1

It is very strange that it breaks the x86_64.
I updated the Makefile.

there's two x86_64 versions, a libretro and a SDL2, It's getting a bit confusing (the sdl2 version is currently broken in master too, will fix it), can you please make a PR that fixes the ios version ?

Something strange with the PR. Try to create and see.

There was an issue with the make clean, let me check

Current master still fails, can you make a PR with your latest changes?

I can not.

Why not ?

I can not merge any branch.

Ok I added DONT_WANT_ARM_OPTIMIZATIONS and it compiled on iOS.
I noticed one weird thing though: on android there's no music only FX.

It is really strange.

On OS X it's weird also, sometime I run it an there's no music only FX. Sometimes there is both.

Something else: you're not using musics_volume? https://github.com/Javanaise/mrboom-libretro/blob/master/common.cpp#L103
Doesn't every song has a different volume?

musics_volume used with the SDL2. The libretro is not used.
Volume is set here: voice = audio_mixer_play(musics[index], true, 1, NULL);

make mrboom LIBSDL2=1

Works with a gcc for x86_64.

@DevilFrost yes I fixed it

@DevilFrost do you have the random bug where the music is not on? which platform are you using?

@frranck there is no such bug. Debian.

OK I fixed the android issue. There still no music on Nintendo switch though.

Made an interesting discovery. Gamecube music sounds really fast, like 2x Windows builds. And it turns out Windows builds are 2x faster than several standalone MOD players. Which explains why some riffs sound so rushed. Changed libretro rate to 22050 and music tempo now feels more relaxed everywhere. So there's a problem in the ibxm player. :shocked:

edit: Or it's the libretro mixer.

Worth pointing out that the XM player got a small update (2017 -> 2019)
https://github.com/martincameron/micromod/tree/master/ibxm-ac

And it correctly puts out wave files that sound okay. So now we analyze what libretro is doing that speeds it up.

https://github.com/libretro/libretro-common/blob/828be1d3db59d21a50af7133bfad61506f651ba5/audio/audio_mixer.c#L997

That should be int16_t. I'll patch upstream libretro-common and update 2019 mod player. I thought that would work being 16-bit stereo but not. I'll keep looking at this.

Finally found the music issue. It was skipping samples.
https://github.com/libretro/libretro-common/blob/a810c57f8c4e51659ae776beb25d7bd4a7b86251/audio/audio_mixer.c#L999

It should refill when
if (voice->types.mod.samples == 0)

Will test later if gamecube music is fixed.

Submitted a PR to libretro-common. Windows is fixed. Gamecube sounds better but still has stereo separation + very fast tempo, so might be some ibxm endian problem. I don't know if Emscripten or Switch is changed, but I'll PR over here too after common is merged.

Emscripten is not playing music because frontend Makefile.emscripten needs HAVE_IBXM=1. I'll PR that too. Is Switch ctr platform?

@SimpleTease what do you mean ctr platform?

@SimpleTease what do you mean ctr platform?

I was mistaking Switch (libnx, libtransistor) with 3DS (ctr)
https://github.com/Javanaise/mrboom-libretro/blob/master/Makefile#L237
https://github.com/Javanaise/mrboom-libretro/blob/master/Makefile#L215
https://github.com/Javanaise/mrboom-libretro/blob/master/Makefile#L230

seems Switch is erasing the CFLAGS https://github.com/Javanaise/mrboom-libretro/blob/master/Makefile#L221

Maybe it's intentional. Other libretro forks do same thing. No idea why.
https://github.com/libretro/libretro-handy/blob/dba810a87ebae87392259c68dcab7a35f6000aac/Makefile#L240

Emscripten is not playing music because frontend Makefile.emscripten needs HAVE_IBXM=1

Both Switch dev kits have same problem.
https://github.com/libretro/RetroArch/blob/175205c1e6e6904ffacb1fb0b48c2bcd1369a603/Makefile.libnx
https://github.com/libretro/RetroArch/blob/47e22d69bf2d803a3e47b75e2c8ef6a3a7cf1b4d/Makefile.switch

Because Griffin = 0, we have to manually add HAVE_IBXM=1 switch also. I'll take this care of this.

I'll keep you updated after the PRs go through. ;)

Emscripten and Switch should have music now, although I can't test either.

Emscripten can be tested online https://web.libretro.com/ when it's merged and we can ask someone for Switch.

I tried the web player with several browsers but it always hangs on me when trying to start the core.

For the gamecube music problem, ibxm - replay_get_audio is returning $280 (Gamecube) vs $3C0 (Normal). And I'm also getting AI bots (Gamecube) that sometimes freeze when dropping bombs. Reliably when it's this pattern (A -> B). Happens with builds 2 months ago also.

xxB
x
A

Trying to figure out both problems.

Because static linking, frontend is sharing audio mixer with core. Frontend is setting rate to 32000 which is creating our tempo problems.

retroarch.c

#ifdef HAVE_AUDIOMIXER
   audio_mixer_init(settings->uints.audio_out_rate);
#endif

I think we can move the mixer init around in common.cpp but I'll need to do some checking first, to make sure Retroarch can re-init the mixer when switching cores or internal music player.

Libretro web player ""should"" have working music, but I still can't get player to run any cores.

Just adding a note here that Wii U also has no music.