JustAudio/io/int.cpp

59 lines
1013 B
C++
Raw Normal View History

#include "int.h"
quint64 rdInt(const QByteArray &data)
{
quint64 out = 0;
quint64 outBit = 1;
for (int i = data.size() - 1; i >= 0; --i)
{
int byte = data[i];
for (int inBit = 1; inBit <= 128; inBit *= 2, outBit *= 2)
{
if ((byte & inBit) != 0) out |= outBit;
}
}
return out;
}
float rdFloat(const QByteArray &data)
{
return data.toFloat();
}
QByteArray wrInt(quint64 value, int intSize)
{
QByteArray out;
quint64 inBit = 1;
while (value != 0)
{
int byte = 0;
for (int outBit = 1; outBit <= 128; outBit *= 2, inBit *= 2)
{
if (value & inBit)
{
byte |= outBit;
value ^= inBit;
}
}
out.insert(0, byte);
}
return out.rightJustified(intSize, 0);
}
QByteArray wrInt(quint64 value)
{
return wrInt(value, INT_SIZE);
}
QByteArray wrFloat(float value)
{
return QByteArray().setNum(value);
}