FNA-Template icon indicating copy to clipboard operation
FNA-Template copied to clipboard

mp3/ogg source files compile to WMA via MGCB

Open danielcrenna opened this issue 7 years ago • 10 comments

If this demo included a bxfr sound sample, that would be helpful.

Basically, any source audio pushed through Content.mgcb is output as a Windows WMA file, presumably because MonoGamePlatform is set to Windows. This causes a ContentLoadException without fail, because FNA doesn't support WMA.

Now it may be that the answer is to set mgcb Build Action to "Copy". but then this requires code changes and explicit loading (i.e. cannot use ContentManager). I don't know if there is am FNA-specific ogg importer for mgcb that knows not to generate a WMA file. /cc @flibitijibibo

I'm currently working with existing code, and don't want to change the sources.

danielcrenna avatar Jun 22 '18 02:06 danielcrenna

This is basically the fix, and it looks like FNA-Template would have to ship with a custom pipeline(s) for audio files. https://github.com/FNA-XNA/FNA/issues/126#issuecomment-385774973

danielcrenna avatar Jun 22 '18 03:06 danielcrenna

I also attempted creating a new Audio.mgcb, setting the outputDir/intermediateDir/platform on that specific file to DesktopGL, thinking I'd make a custom msbuild step to relocate that output and remove any .WMA files (klugey). But, the only way I can get that file to build proper xnb/ogg pairs is if I run it using the MGCB GUI. The targets file blows past any non-Windows content, likely keyed off MonoGamePlatform in the .csproj file.

Perhaps @LennardF1989 has code to donate for this, but I don't think FNA-Template wants to reference any MonoGame libraries directly.

danielcrenna avatar Jun 22 '18 04:06 danielcrenna

ContentManager should be able to read ogg files without any XNB - the XNB just has a Duration value that gets picked up by MediaPlayer anyway. Same idea as FXB, ogv, and common image formats!

flibitijibibo avatar Jun 22 '18 04:06 flibitijibibo

In my experience, if I take an OGG file and set it to passthrough / copy in mgcb, the ContentTypeReader guesses it's a .wav file (as that's the only available entry in SoundEffectReader.supportedExtensions, so .ogg is never guessed.

Normally not a problem unless you don't want to change the source code, which is using ContentManager's extensionless convention, like Content.Load<SoundEffect>("bloop")

danielcrenna avatar Jun 22 '18 04:06 danielcrenna

Weird, it really forces a conversion and doesn’t let you copy? Guess that’d have to go in the csproj instead then... if you can reference content files outside the root tree. (Is that easy with msbuild? Would like to have that for Xbone builds)

flibitijibibo avatar Jun 22 '18 04:06 flibitijibibo

It copies, but fails at runtime when referencing by assetName without an extension.

danielcrenna avatar Jun 22 '18 04:06 danielcrenna

It does...? It shouldn’t:

https://github.com/FNA-XNA/FNA/blob/master/src/Content/ContentManager.cs#L308

flibitijibibo avatar Jun 22 '18 04:06 flibitijibibo

I think I made a mistake in that specific case where I’m trying to load an .ogg file as a SoundEffect (vs a Song) via Load<T> which can only be a .wav.

FNA-Template works with wav files, it’s indeed the Song mp3/ogg files that are forced to WMA if passed through the mgcb. I guess I need to convert sound effects to wav, songs to ogg, and set them all to pass through.

On Jun 22, 2018, at 12:53 AM, Ethan Lee [email protected] wrote:

It does...? It shouldn’t:

https://github.com/FNA-XNA/FNA/blob/master/src/Content/ContentManager.cs#L308

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

danielcrenna avatar Jun 22 '18 05:06 danielcrenna

Hello @danielcrenna - In order to force MGCB to always spit out OGG files, regardless of platforms, you need to do some hackery. More specifically, you have to force DesktopGL in the instance of Songs. For the greater good, I'm more than willing to donate this piece of code:

https://gist.github.com/LennardF1989/a5d7d54c89cb6cd0e6bc9551b6fa6a48

Register the DLL containing this class in your Content-project, and set all songs to "Ogg Song - MonoGame". That's it!

As the TODO mentions, there is currently a slight problem: Ogg-files do not seem to be deterministic. Given the exact same input, different outputs are produced every time. The idea here is to persist the content of SongContent to the file-system along with the SHA1-hash of the incoming song. It's on my road-map to sort this out as it just inflates patches if you forget about it.

LennardF1989 avatar Jun 22 '18 11:06 LennardF1989

I believe the reason encodes aren't always the same is because the Ogg stream serial isn't always the same. When using oggenc you have to use -s to set a specific serial and then it should be consistent; MGCB uses ffmpeg so I'm not sure what the flag is to set the stream serial number.

flibitijibibo avatar Jun 22 '18 18:06 flibitijibibo