如何解码 MIDI 中的可变长度字段?在 [1] 中找到的描述仅给出了一些示例,而没有提及如果设置了最高有效位会发生什么。这是我当前的代码:
uint32_t MuStudio::MIDI::FileReader::varfieldGet()
{
// Note: always swap bytes on return since the loop reads in LE fashion since it
// it cannot be known a priori how many bytes to read
uint32_t ret=0;
uint8_t byte_in;
uint8_t k=0;
while(!m_source.eof())
{
byte_in=m_source.byteGet();
if(byte_in&0x80)
{
if(k==sizeof(ret))
{break;}
// How to continue here?
}
else
{return __builtin_bswap32(ret|(byte_in<<k));}
}
while(!m_source.eof() && byte_in&0x80)
{byte_in=m_source.byteGet();}
return __builtin_bswap32(ret);
}
[1] http://www.music.mcgill.ca/~ich/classes/mumt306/midiformat.pdf