aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/qmmp/audioconverter.cpp101
-rw-r--r--src/qmmp/audioconverter.h2
2 files changed, 45 insertions, 58 deletions
diff --git a/src/qmmp/audioconverter.cpp b/src/qmmp/audioconverter.cpp
index 49485f951..eeeebb9f7 100644
--- a/src/qmmp/audioconverter.cpp
+++ b/src/qmmp/audioconverter.cpp
@@ -21,70 +21,35 @@
#include <math.h>
#include <string.h>
#include <QtGlobal>
+#include <QtEndian>
#include "audioconverter.h"
-#define INT_TO_FLOAT(TYPE,in,out,samples,offset,max) \
+#define INT_TO_FLOAT(TYPE,SWAP,in,out,samples,offset,max) \
{ \
TYPE *in_ref = (TYPE *) (in); \
for(size_t i = 0; i < samples; ++i) \
- out[i] = (float) (in_ref[i] - offset) / max; \
+ out[i] = (float) (SWAP(in_ref[i]) - offset) / max; \
}
-#define FLOAT_TO_INT(TYPE,in,out,samples,offset,min,max) \
+#define FLOAT_TO_INT(TYPE,SWAP,in,out,samples,offset,min,max) \
{ \
TYPE *out_ref = (TYPE *) (out); \
float tmp; \
for(size_t i = 0; i < samples; ++i) \
{ \
tmp = in[i] * max; \
- out_ref[i] = offset + (TYPE) lrintf(qBound(-(float)min, tmp, (float)max)); \
+ out_ref[i] = SWAP(offset + (TYPE) lrintf(qBound(-(float)min, tmp, (float)max))); \
} \
}
AudioConverter::AudioConverter()
{
m_format = Qmmp::PCM_UNKNOWM;
- m_swap = false;
}
void AudioConverter::configure(Qmmp::AudioFormat f)
{
m_format = f;
-
- switch (f)
- {
- case Qmmp::PCM_UNKNOWM:
- case Qmmp::PCM_S8:
- case Qmmp::PCM_U8:
- case Qmmp::PCM_FLOAT:
- m_swap = false;
- break;
- case Qmmp::PCM_S16LE:
- case Qmmp::PCM_U16LE:
- case Qmmp::PCM_S24LE:
- case Qmmp::PCM_U24LE:
- case Qmmp::PCM_S32LE:
- case Qmmp::PCM_U32LE:
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- m_swap = true;
-#else
- m_swap = false;
-#endif
- break;
- case Qmmp::PCM_S16BE:
- case Qmmp::PCM_U16BE:
- case Qmmp::PCM_S24BE:
- case Qmmp::PCM_U24BE:
- case Qmmp::PCM_S32BE:
- case Qmmp::PCM_U32BE:
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- m_swap = false;
-#else
- m_swap = true;
-#endif
- break;
-
- }
}
void AudioConverter::toFloat(const unsigned char *in, float *out, size_t samples)
@@ -92,34 +57,46 @@ void AudioConverter::toFloat(const unsigned char *in, float *out, size_t samples
switch (m_format)
{
case Qmmp::PCM_S8:
- INT_TO_FLOAT(qint8, in, out, samples, 0, 0x80);
+ INT_TO_FLOAT(qint8,,in, out, samples, 0, 0x80);
break;
case Qmmp::PCM_U8:
- INT_TO_FLOAT(quint8, in, out, samples, 0x80, 0x80);
+ INT_TO_FLOAT(quint8,,in, out, samples, 0x80, 0x80);
break;
case Qmmp::PCM_S16LE:
+ INT_TO_FLOAT(qint16, qFromLittleEndian, in, out, samples, 0, 0x8000);
+ break;
case Qmmp::PCM_S16BE:
- INT_TO_FLOAT(qint16, in, out, samples, 0, 0x8000);
+ INT_TO_FLOAT(qint16, qFromBigEndian, in, out, samples, 0, 0x8000);
break;
case Qmmp::PCM_U16LE:
+ INT_TO_FLOAT(quint16, qFromLittleEndian, in, out, samples, 0x8000, 0x8000);
+ break;
case Qmmp::PCM_U16BE:
- INT_TO_FLOAT(quint16, in, out, samples, 0x8000, 0x8000);
+ INT_TO_FLOAT(quint16, qFromBigEndian, in, out, samples, 0x8000, 0x8000);
break;
case Qmmp::PCM_S24LE:
+ INT_TO_FLOAT(qint32, qFromLittleEndian, in, out, samples, 0, 0x800000);
+ break;
case Qmmp::PCM_S24BE:
- INT_TO_FLOAT(qint32, in, out, samples, 0, 0x800000);
+ INT_TO_FLOAT(qint32, qFromBigEndian, in, out, samples, 0, 0x800000);
break;
case Qmmp::PCM_U24LE:
+ INT_TO_FLOAT(quint32, qFromLittleEndian, in, out, samples, 0x800000, 0x800000);
+ break;
case Qmmp::PCM_U24BE:
- INT_TO_FLOAT(quint32, in, out, samples, 0x800000, 0x800000);
+ INT_TO_FLOAT(quint32, qFromBigEndian, in, out, samples, 0x800000, 0x800000);
break;
case Qmmp::PCM_S32LE:
+ INT_TO_FLOAT(qint32, qFromLittleEndian, in, out, samples, 0, 0x80000000);
+ break;
case Qmmp::PCM_S32BE:
- INT_TO_FLOAT(qint32, in, out, samples, 0, 0x80000000);
+ INT_TO_FLOAT(qint32, qFromBigEndian, in, out, samples, 0, 0x80000000);
break;
case Qmmp::PCM_U32LE:
+ INT_TO_FLOAT(quint32, qFromLittleEndian, in, out, samples, 0x80000000, 0x80000000);
+ break;
case Qmmp::PCM_U32BE:
- INT_TO_FLOAT(quint32, in, out, samples, 0x80000000, 0x80000000);
+ INT_TO_FLOAT(quint32, qFromBigEndian, in, out, samples, 0x80000000, 0x80000000);
break;
case Qmmp::PCM_FLOAT:
case Qmmp::PCM_UNKNOWM:
@@ -132,34 +109,46 @@ void AudioConverter::fromFloat(const float *in, const unsigned char *out, size_t
switch (m_format)
{
case Qmmp::PCM_S8:
- FLOAT_TO_INT(qint8, in, out, samples, 0, 0x80, 0x7F);
+ FLOAT_TO_INT(qint8,, in, out, samples, 0, 0x80, 0x7F);
break;
case Qmmp::PCM_U8:
- FLOAT_TO_INT(qint8, in, out, samples, 0x80, 0x80, 0x7F);
+ FLOAT_TO_INT(qint8,, in, out, samples, 0x80, 0x80, 0x7F);
break;
case Qmmp::PCM_S16LE:
+ FLOAT_TO_INT(qint16, qToLittleEndian, in, out, samples, 0, 0x8000, 0x7FFF);
+ break;
case Qmmp::PCM_S16BE:
- FLOAT_TO_INT(qint16, in, out, samples, 0, 0x8000, 0x7FFF);
+ FLOAT_TO_INT(qint16, qToBigEndian, in, out, samples, 0, 0x8000, 0x7FFF);
break;
case Qmmp::PCM_U16LE:
+ FLOAT_TO_INT(quint16, qToLittleEndian, in, out, samples, 0x8000, 0x8000, 0x7FFF);
+ break;
case Qmmp::PCM_U16BE:
- FLOAT_TO_INT(quint16, in, out, samples, 0x8000, 0x8000, 0x7FFF);
+ FLOAT_TO_INT(quint16, qToBigEndian, in, out, samples, 0x8000, 0x8000, 0x7FFF);
break;
case Qmmp::PCM_S24LE:
+ FLOAT_TO_INT(qint32, qToLittleEndian, in, out, samples, 0, 0x800000, 0x7FFFFF);
+ break;
case Qmmp::PCM_S24BE:
- FLOAT_TO_INT(qint32, in, out, samples, 0, 0x800000, 0x7FFFFF);
+ FLOAT_TO_INT(qint32, qToBigEndian, in, out, samples, 0, 0x800000, 0x7FFFFF);
break;
case Qmmp::PCM_U24LE:
+ FLOAT_TO_INT(quint32, qToLittleEndian, in, out, samples, 0x800000, 0x800000, 0x7FFFFF);
+ break;
case Qmmp::PCM_U24BE:
- FLOAT_TO_INT(quint32, in, out, samples, 0x800000, 0x800000, 0x7FFFFF);
+ FLOAT_TO_INT(quint32, qToBigEndian, in, out, samples, 0x800000, 0x800000, 0x7FFFFF);
break;
case Qmmp::PCM_S32LE:
+ FLOAT_TO_INT(qint32, qToLittleEndian, in, out, samples, 0, 0x80000000, 0x7FFFFF80);
+ break;
case Qmmp::PCM_S32BE:
- FLOAT_TO_INT(qint32, in, out, samples, 0, 0x80000000, 0x7FFFFF80);
+ FLOAT_TO_INT(qint32, qToBigEndian, in, out, samples, 0, 0x80000000, 0x7FFFFF80);
break;
case Qmmp::PCM_U32LE:
+ FLOAT_TO_INT(quint32, qToLittleEndian, in, out, samples, 0x80000000, 0x80000000, 0x7FFFFF80);
+ break;
case Qmmp::PCM_U32BE:
- FLOAT_TO_INT(quint32, in, out, samples, 0x80000000, 0x80000000, 0x7FFFFF80);
+ FLOAT_TO_INT(quint32, qToBigEndian, in, out, samples, 0x80000000, 0x80000000, 0x7FFFFF80);
break;
case Qmmp::PCM_FLOAT:
case Qmmp::PCM_UNKNOWM:
diff --git a/src/qmmp/audioconverter.h b/src/qmmp/audioconverter.h
index 02ad08297..b15b4cced 100644
--- a/src/qmmp/audioconverter.h
+++ b/src/qmmp/audioconverter.h
@@ -39,8 +39,6 @@ public:
private:
Qmmp::AudioFormat m_format;
- bool m_swap;
-
};
#endif // AUDIOCONVERTER_H