purpl3F0x / MQA_identifier

Master Quality Authenticated codec reverse engineering, Tool to identify MQA encoding and Master's Sample Rate
Apache License 2.0
117 stars 9 forks source link

Problem with the definition of MQA in some files #14

Open Besha1 opened 3 years ago

Besha1 commented 3 years ago

I ran into a problem that MQA_identifier does not define all MQA files as MQA I compared the work of MQA_identifier with the work of is_mqa.py this guy here https://github.com/redsudo/mqaid So MQA_identifier does not find many MQA files where is_mqa.py find

I looked at your implementation and the implementation is_mqa.py.They are similar and I found the problem as it seems to me.

The problem is that you check once if (buffer == 0xbe0498c88) found in buffer |= ((static_cast(s[0]) ^ static_cast(s[1])) >> pos) & 1u; from the value const auto pos = (this->decoder.bps - 16u);

In is_mqa.py the check takes place in the range from 16 to 24 samples = list(iter_data(sound_data)) streams = (Bits((x ^ y) >> p & 1 for x, y in zip(samples[::2], samples[1::2])) for p in range(16, 24))

My tests showed that need to check at least three times Need to check with at least three values from pos

something like this

uint64_t buffer = 0; uint64_t buffer1 = 0; uint64_t buffer2 = 0;

const auto pos = (this->decoder.bps - 16u); // aim for 16th bit

for (const auto &s: this->decoder.samples) { buffer |= ((static_cast(s[0]) ^ static_cast(s[1])) >> pos) & 1u; buffer1 |= ((static_cast(s[0]) ^ static_cast(s[1])) >> pos +1) & 1u; buffer2 |= ((static_cast(s[0]) ^ static_cast(s[1])) >> pos+2) & 1u;

 if (buffer == 0xbe0498c88) {
    this->isMQA_ = true;
    // Get Original Sample Rate
    // Get MQA Studio
    // We are done return true
    return true;
 } else
 if (buffer1 == 0xbe0498c88) {
    this->isMQA_ = true;
    // Get Original Sample Rate
    // Get MQA Studio
    // We are done return true
    return true;
 } else
 if (buffer2 == 0xbe0498c88) {
    this->isMQA_ = true;
    // Get Original Sample Rate
    // Get MQA Studio
    // We are done return true
     return true;
 } else
 buffer = (buffer << 1u) & 0xFFFFFFFFFu;
 buffer1 = (buffer1 << 1u) & 0xFFFFFFFFFu;
 buffer2 = (buffer2 << 1u) & 0xFFFFFFFFFu;

} return false;

With such changes, MQA_identifier works perfectly,

If you are interested, I also added in the MQA_identifier If MQA is found, Vorbis tags are added to the flac file ENCODER = MQAEncode v1.1, 2.3.3+800 (a505918) MQAENCODER = MQAEncode v1.1, 2.3.3+800 (a505918) ORIGINALSAMPLERATE = value from MQA_identifier id.originalSampleRate()

purpl3F0x commented 3 years ago

Yes, that seems correct there might not be on the 16th bit. At the time I assumed it was on the 16th. Some blog posts of B.Stuard mentioned that is not the case, but I didn't fix it - the original sample rate also has some issues. You can make a merge request if you have it working.

purpl3F0x commented 2 years ago

Can pull request be merged?

It's not a pull request