AntonioDePau / GHDS_ModdingTool

Modding tool for GH and BH on NDS
6 stars 0 forks source link

Unable to import audio file #21

Closed Tannister closed 6 months ago

Tannister commented 1 year ago

image

this happens when putting mono audio files (same thing with wav and ogg)

Tannister commented 1 year ago

same happen with stereo files

AntonioDePau commented 1 year ago

same happen with stereo files

What do you mean? Aren't we able to import stereo files just fine usually? The error message is about needing to have at least two channels (which I can try and have accept mono), so what does it say when feeding it stereo files?

Tannister commented 1 year ago

image Same error message with a stereo file (both with ogg and wav)

AntonioDePau commented 1 year ago

Can you send the stereo file you're getting the error with, please? (can send on Discord in case there might be copyright infringements)

Tannister commented 1 year ago

song.zip Should be good, unmodified audio from ExileLord's Soulless 1

AntonioDePau commented 1 year ago

It works for me! Are you sure that's the audio file you're using? In the CallMeWhenYoureSober folder?

Attached is the successfully created hwas: Main_song.zip

AntonioDePau commented 1 year ago

Are there any other audio files in the folder? Vocals (those would be merged with song)? Crowd?

AntonioDePau commented 1 year ago

Pretty sure your problem is caused by your vocals file: image

Tannister commented 1 year ago

I don't have any vocal file in the directory.

Tannister commented 1 year ago

the song.ogg is the only audio file present. image In this image, audio file is from Too Much, Too Young, Too Fast (GHWT), same error.

ModdingTool recompiled today from the main branch

AntonioDePau commented 1 year ago

I just recompiled from main, and used song.ogg from Too Much, Too Young, Too Fast, and it's working just fine: image

Can you possibly try on Windows 10?

Tannister commented 1 year ago

sadly, no. i don't have any win10 installations here.

Tannister commented 1 year ago

same thing happens when i try to import guitar & rhythm audio file. :/

AntonioDePau commented 1 year ago

But you have no issue when using the last release?

There's been no change in main that affects the conversion of OGG or WAV files since, so I can only assume that it's a problem somehow caused at compilation time on Windows 11, since I have no issues after compiling the tool myself on Windows 10, with the same source code you're using...

same thing happens when i try to import guitar & rhythm audio file. :/

100% exact same error message? The guitar & rhythm audio files should be OGG to begin with and should be decoded and recoded to the correct format, but that's not handled by NAudio.Wave, so that error message should not apply.

AntonioDePau commented 1 year ago

Could you check the temp audio file (oggtool_audio.temp) in the GHDS_ModdingTool_resources folder, and send it over, please?

Tannister commented 1 year ago

100% Identical error message with latest exe found in releases.

100% Identical message for all audio files (song, drums, rhythm and guitar)

Tannister commented 1 year ago

oggtool_audio.zip

That one is with one of the audio files found in embedded_resources from this repo

Tannister commented 1 year ago

oggtool_audio.zip This one with Soulless 1 Song.ogg Audio

AntonioDePau commented 1 year ago

oggtool_audio.zip This one with Soulless 1 Song.ogg Audio

It's properly converted to a stereo WAV file (if you rename it to .WAV or open it with an hex editor), not sure what the issue is here...

AntonioDePau commented 1 year ago

100% Identical message for all audio files (song, drums, rhythm and guitar)

Can you please try the following:

  1. rename your custom_songs folder (to something like custom_songs_backup)
  2. drag & drop your BHDS game onto GHDS_ModdingTool.exe
  3. put guitar.ogg from Soulless 1 into the first folder of the newly created custom_songs folder (All You Need, in the US version, not sure what it is in EU)
  4. drag & drop your BHDS game onto GHDS_ModdingTool.exe
  5. take a screenshot of the error (if any) and upload it here
Tannister commented 1 year ago

image

AntonioDePau commented 1 year ago

Mhhh...

Can you uncomment these lines: https://github.com/AntonioDePau/GHDS_ModdingTool/blob/main/gh/audio/encoding.cs#L92-L94

And copy paste them at line: https://github.com/AntonioDePau/GHDS_ModdingTool/blob/main/gh/audio/encoding.cs#L76

Rebuild, try again, and share the screenshot (or copy paste the output of the 3 uncommented/copied lines).

So, it does happen at NAudio.Wave level because of the volume increase during OGG => OGG conversion (where oggdec converts to WAV first, then volume increase happens, and then it should be converted back to OGG, but you're crashing before that).

With the uncommented Console.WriteLine lines, we should be able to know what WAV format the tool is getting.

Tannister commented 1 year ago

image

All 0 ? does not seem correct

Tannister commented 1 year ago

Added 2 lines to see where we are in the code, we don't hit Encode() image

Tannister commented 1 year ago

image

Tannister commented 1 year ago

image

Length of WAV byte array is 0 ?

AntonioDePau commented 1 year ago

Added 2 lines to see where we are in the code, we don't hit Encode() image

Yeah, OGG to OGG doesn't use Encode, just IncreaseVolume. 0 for channels (and the other 2 values) explains why you're getting the error. As to why you're getting 0...

Try to print the oggFile byte array length here: https://github.com/AntonioDePau/GHDS_ModdingTool/blob/main/gh/audio/OGG/OGG.cs#L79

AntonioDePau commented 1 year ago

Oh, and print the output's length as well: https://github.com/AntonioDePau/GHDS_ModdingTool/blob/main/gh/audio/OGG/OGG.cs#L82

Tannister commented 1 year ago

image That one seems valid

Tannister commented 1 year ago

image Not the output one.

Tannister commented 1 year ago

*side note, i put back the old Command Prompt as the default cmd, as it is still available on win11 through developper settings

Tannister commented 1 year ago

reading the code, shouldnt you read the output file instead of getting the results from StartProcess ?

AntonioDePau commented 1 year ago

Damned... This will be so much easier if/when Evan manages to give us a fully C# solution for decoding and encoding OGGs.

Okay, we may need to have oggdec write the output to a file and read that file rather than expecting oggdec to feed us back a byte array...

Can you try to update the Ogg.Decode method like so:

        public static byte[] Decode(byte[] oggFile){
            string tempFile = Path.Combine(ToolsPath, "oggtool_audio.temp");
            File.WriteAllBytes(tempFile, oggFile);

            string Arguments = $" --quiet --output - \"{tempFile}\"";
            byte[] output = StartProcess(Path.Combine(ToolsPath, "oggdec.exe"), Arguments);

            return output;
        }

Edit: This is to try and see if it works by escaping the temp file's path (\"{tempFile}\"), as I suspect you may have whitespaces in your path to the tool

AntonioDePau commented 1 year ago

reading the code, shouldnt you read the output file instead of getting the results from StartProcess ?

We'll try, but I really hate having to rely on temp files and write/read them when we SHOULD just be able to feed bytes and get bytes in return.

Tannister commented 1 year ago

image Works !

AntonioDePau commented 1 year ago

Spaces then :D ahahah, glad it was an easy fix. I'll make a commit.

Tannister commented 1 year ago

huh image The final file is 0 bytes ..

AntonioDePau commented 1 year ago

Yeah, the oggenc also needs escaping :p:

        public static byte[] Encode(byte[] wavFile, int SampleRate, int BitRate = 18){
            string tempFile = Path.Combine(ToolsPath, "oggtool_audio.temp");
            File.WriteAllBytes(tempFile, wavFile);

            string Arguments = $" --quiet --bitrate {BitRate} --resample {SampleRate} --downmix --min-bitrate {BitRate} --max-bitrate {BitRate} -o - \"{tempFile}\"";

            byte[] output = StartProcess(Path.Combine(ToolsPath, "oggenc.exe"), Arguments);

            return output;
        }
Tannister commented 1 year ago

there might be other places where escaping is required, glad it was only this

AntonioDePau commented 1 year ago

We should be fine. The rest of the paths is handled by Path.Combine and other safer methods. This here was an issue because we're relying on an external tool (oggenc/oggdec) that take path as arguments and I forgot to escape those. But again, hopefully we can have a fully managed C# solution, if Evan can pull it off!

Tannister commented 1 year ago

Now the presence of Guitar_guitar.ogg causes the issue

(at least that one i can go around easily)