ddiakopoulos / libnyquist

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

Very low sound quality #46

Closed gtreshchev closed 3 years ago

gtreshchev commented 3 years ago

When converting audio files on Windows, no problems are observed, the quality is good. But for some reason, when working with UNIX system (Android), the sound quality becomes much worse. Here is an example of what happens when converting the "TestBeat_Float32.wv" file to the .ogg format on UNIX.

TestBeat_Float32.zip

ddiakopoulos commented 3 years ago

Hi @Respirant thank you for the bug report. The WavPack file you linked plays fine on Windows, but you said the error occurs when it is transcoded to .ogg. Can you upload the file, and can you note which Unix system/distribution you are using?

gtreshchev commented 3 years ago

Hi. I'm sorry, I've uploaded the input file, not the output. Here's the output file with ogg format: PCM_FLT_ConvertedfromWv.zip

gtreshchev commented 3 years ago

I used the following code for transcoding from .wv to .ogg:

NyquistIO loader;
std::shared_ptr<AudioData> fileData = std::make_shared<AudioData>();
auto memory = ReadFile(std::string("TestBeat_Float32.wv"));
loader.Load(fileData.get(), "wv", memory.buffer);

outputBuffer.reserve( fileData->samples.size()*2 );
hermite_resample( fileData->sampleRate / 48000.0f , fileData->samples, outputBuffer, (uint32_t)fileData->samples.size());
fileData->samples = outputBuffer;
int encoderStatus = encode_opus_to_disk({ fileData->channelCount, PCM_FLT, DITHER_NONE }, fileData.get(), "PCM_FLT_ConvertedfromWv.ogg");

I also noticed that the length of the transcoding audio is for some reason twice as long as the original audio. Here's an example of the original audio: vvnBfk

And here's transcoded one: AbvheQ

I tried to speed the audio up and change some code:

outputBuffer.reserve( (fileData->samples.size()*2)*2 );
hermite_resample( (fileData->sampleRate / 48000.0f) * 2, fileData->samples, outputBuffer, (uint32_t)fileData->samples.size()/2);

Afterwards the audio has been sped up, but it still has some kind of ripple background. 2XPCM_FLT_ConvertedfromWv.zip

gtreshchev commented 3 years ago

This problem appears not only on UNIX systems, but also on Windows

gtreshchev commented 3 years ago

Hi, I found that the error has been occured to due the sampling of the audio, which must be done before encoding. Since your library "does not provide comprehensive resampling functionality", it isn't an issue.