ddiakopoulos / libnyquist

:microphone: Cross platform C++11 library for decoding audio (mp3, wav, ogg, opus, flac, etc)
BSD 2-Clause "Simplified" License
534 stars 64 forks source link

shouldn't rely on file extension #53

Open bart9h opened 2 years ago

bart9h commented 2 years ago

libnyquist decodes "myfile.mp3" just fine.

But if I rename it to "myfile.data", it gives some kind of format error.

Shouldn't the library read the header from the beginning of the file, instead of relying on the file extension?

4321ba commented 2 years ago

if you need to work around it, you can read in the file yourself and pass only the raw encoded audio to libnyquist like this:

        vector<uint8_t> encoded_audio;
...//read in idk how
        shared_ptr<nqr::AudioData> file_data = make_shared<nqr::AudioData>();
        nqr::NyquistIO loader;
        loader.Load(file_data.get(), encoded_audio);

then it should properly recognize the file format, at least I think so

ddiakopoulos commented 2 years ago

@4321ba Unfortunately it does not!

@bart9h You're definitely right here, that's what the library should do :) I started incubating this feature a long time ago on this branch, but never had time to test and merge it. Happy to accept and PRs to get it working properly.

4321ba commented 2 years ago

hmm does it not? it worked for me though and like I don't know the codebase but at https://github.com/ddiakopoulos/libnyquist/blob/master/src/Common.cpp#L64 it really seems like it guesses the file type based on magic numbers, properly this commit: https://github.com/ddiakopoulos/libnyquist/commit/dafe5969aee9be47b96c88903f1d46d5341833b7

ddiakopoulos commented 2 years ago

@4321ba lol, alright my memory was clearly very wrong and I didn't bother to look at the code. Thanks for checking :)