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()