Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINTERMUTE: Correctly find .ogg version of .wav files #728

Merged
merged 1 commit into from
Apr 23, 2016

Conversation

tobiatesan
Copy link
Contributor

As it was, it didn't work because it turned
"some\windows\path.wav" into "some/system/pathogg" (not ".ogg"), so any file called by the scripts with its ".wav" extension but actually present in compressed .ogg form on the .dcp archive could not be found.

base_disk_file.cpp (apparently) takes care of preprocessing the path to make it system-agnostic already for those files which reside on the disk.

This one should fix https://sourceforge.net/p/scummvm/bugs/7088/

The corresponding bit in the original engine is:

    // try to switch WAV to OGG file (if available)
    _splitpath(Filename, drive, dir, fname, ext);
    if(_stricmp(ext, ".WAV")==0){
        _makepath(NewFile, drive, dir, fname, ".OGG");
        CBFile* file = Game->m_FileManager->OpenFile(NewFile);
        if(file){
            Filename = NewFile;
            Game->m_FileManager->CloseFile(file);
        }
    }

This way it should work reliably on all platforms like this, but just to be sure I would love it if somebody who runs Windows would check it before merging (I won't probably be able to do it before tomorrow).

@fuzzie
Copy link
Contributor

fuzzie commented Mar 30, 2016

So the changes here are (a) adding the dot before the extension, and then (b) removing the call to combine? I'm curious about (b) since your commit message says "probably don't want".. why probably? Also, you say "should fix #7088" - you don't have the game to test it?

@salty-horse
Copy link
Member

I tested the fix with the game (which is freely available online), and it works.

It's correct that the simplest fix is adding the "." to the path. However, PathUtil::combine seems to do the "wrong" thing since the "wav" string looks like:
interface\speech\sounds\knight_sing.wav
and the combined string looks like:
interface/speech/sounds/knight_singogg

I'd rather keep the current path separator instead of reconstructing the entire path. Maybe the code could be simplified to look at the last 3 chars and replace them (in a new copy of the string) without reconstructing the path + name parts.

Specifically: lower-case useFilename, check hasSuffix("wav"), replace with ogg.

(BTW, the game crashes during the intro while playing actors\dragon\dragon_roar_distant.ogg if you're using an old version of libvorbis - it's unrelated to this bug)

@tobiatesan
Copy link
Contributor Author

@fuzzie:

(a) adding the dot before the extension, and then

True

(b) removing the call to combine

True

you say "should fix #7088" - you don't have the game to test it?

I have it and it works for me. I have rephrased the commit, thanks.
I have a tendency to err on the side of conditional tense which probabl^N^N^N actually doesn't belong to commit messages.

why probably?

Because I wouldn't want you to take my word for it until either @somaen (who originally wrote this bit) or @wjp have seen it.

(BTW, the game crashes during the intro while playing actors\dragon\dragon_roar_distant.ogg if you're using an old version of libvorbis - it's unrelated to this bug)

Yes, it's #7089

@tobiatesan
Copy link
Contributor Author

@salty-horse:

Maybe the code could be simplified to look at the last 3 chars and replace them (in a new copy of the string) without reconstructing the path + name parts.

I like this better as well. See updated commit.

Common::String oggFilename = useFilename;
oggFilename.erase(oggFilename.size() - 3);
assert(oggFilename.lastChar() == '.');
oggFilename = oggFilename + "ogg";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there an append function? I think s = s + suffix creates a new string.

Instead of erasing, maybe just set the last 3 chars manually:

size = s.size()
s[size - 3] = 'o';
s[size - 2] = 'g';
s[size - 1] = 'g';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wouldn't worry about that compared to the cost of opening a file. But see also #688.

As it was, it didn't reliably work across platforms because it turned
some\\windows\\path.wav
into
some/system/pathogg

Note no "." before "ogg"; also since we use the new filename
to search for the file inside DCPs, which use Windows naming,
we don't want system-specific path format.

Fixes #7088
AnsiString newFile = PathUtil::combine(path, name + "ogg");
if (BaseFileManager::getEngineInstance()->hasFile(newFile)) {
useFilename = newFile;
if (useFilename.hasSuffix(".wav")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this case sensitive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it does do a toLowercase on useFilename above, so it shouldn't be an issue (for this check).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you prefer getExtension? I'm rather agnostic on the issue (however you polish I think... well, it's still a hack) I was mostly taking @salty-horse's advice.

@somaen somaen merged commit 7af4a1a into scummvm:master Apr 23, 2016
@tobiatesan tobiatesan deleted the fix_ogg branch June 17, 2017 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants