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

Problem with the definition of MQA in some files #14

Open
Besha1 opened this issue Sep 12, 2021 · 4 comments
Open

Problem with the definition of MQA in some files #14

Besha1 opened this issue Sep 12, 2021 · 4 comments

Comments

@Besha1
Copy link
Contributor

Besha1 commented Sep 12, 2021

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<uint32_t>(s[0]) ^ static_cast<uint32_t>(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<uint32_t>(s[0]) ^ static_cast<uint32_t>(s[1])) >> pos) & 1u;
buffer1 |= ((static_cast<uint32_t>(s[0]) ^ static_cast<uint32_t>(s[1])) >> pos +1) & 1u;
buffer2 |= ((static_cast<uint32_t>(s[0]) ^ static_cast<uint32_t>(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
Copy link
Owner

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
Copy link
Owner

Can pull request be merged?

It's not a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Besha1 @purpl3F0x and others