Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expand unit tests for clipping
Would have prevented #11714
  • Loading branch information
jyavenard committed Aug 8, 2013
1 parent 3465127 commit 8b25703
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 3 deletions.
143 changes: 141 additions & 2 deletions mythtv/libs/libmyth/test/test_audioconvert/test_audioconvert.h
Expand Up @@ -161,8 +161,8 @@ class TestAudioConvert: public QObject
{
QCOMPARE(arrays1[i], arrays2[i]);
// Check we are indeed getting a 24 bits int
QVERIFY(arrays24[i] >= -(2<<23 + 1));
QVERIFY(arrays24[i] <= (2<<23));
QVERIFY(arrays24[i] >= -(1<<23));
QVERIFY(arrays24[i] <= ((1<<23)-1));
}

av_free(arrays1);
Expand Down Expand Up @@ -384,4 +384,143 @@ class TestAudioConvert: public QObject
av_free(arrays2);
av_free(arrays32);
}

void S32ClipTest(void)
{
int SIZEARRAY = 256;
// +1 will never be 16-bytes aligned, forcing C-code
int offsetint32_t = 0;
int offsetfloat1 = 1;
int offsetfloat2 = 0;

int32_t *arrays1 = (int32_t*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(int32_t));
// has to be 16 int32_t for 16 bytes boundary * 2
int32_t *arrays2 = (int32_t*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(int32_t));
float *arrayf1 = (float*)av_malloc((SIZEARRAY+offsetfloat1+4) * ISIZEOF(float));
float *arrayf2 = (float*)av_malloc((SIZEARRAY+offsetfloat2+4) * ISIZEOF(float));

arrayf1[0+offsetfloat1] = -1.2;
arrayf1[1+offsetfloat1] = -1.1;
arrayf1[2+offsetfloat1] = -1.0;
arrayf1[3+offsetfloat1] = -0.5;
arrayf1[4+offsetfloat1] = 0.5;
arrayf1[5+offsetfloat1] = 1.0;
arrayf1[6+offsetfloat1] = 1.1;
arrayf1[7+offsetfloat1] = 1.2;
arrayf2[0+offsetfloat2] = -1.0;
arrayf2[1+offsetfloat2] = -1.0;
arrayf2[2+offsetfloat2] = -1.0;
arrayf2[3+offsetfloat2] = -0.5;
arrayf2[4+offsetfloat2] = 0.5;
arrayf2[5+offsetfloat2] = 1.0;
arrayf2[6+offsetfloat2] = 1.0;
arrayf2[7+offsetfloat2] = 1.0;
// arrays1 is produced by C-code
// arrays2 is produced by SSE
AudioConvert::fromFloat(FORMAT_S32, arrays1, arrayf1+offsetfloat1, SIZEARRAY * ISIZEOF(float));
AudioConvert::fromFloat(FORMAT_S32, arrays2, arrayf2+offsetfloat2, SIZEARRAY * ISIZEOF(float));
for (int i = 0; i < 8; i++)
{
QCOMPARE(arrays2[i], arrays1[i]);
}

av_free(arrays1);
av_free(arrays2);
av_free(arrayf1);
av_free(arrayf2);
}

void FloatS32ClipTest3_data(void)
{
QTest::addColumn<int>("OFFSET");
QTest::newRow("Use SSE accelerated code") << 0;
QTest::newRow("Use C code") << 1;
}

void FloatS32ClipTest3(void)
{
int SIZEARRAY = 256;
QFETCH(int, OFFSET);
// +1 will never be 16-bytes aligned, forcing C-code
int offsetint32_t = 0;
int offsetfloat1 = OFFSET;

int32_t *arrays1 = (int32_t*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(int32_t));
// has to be 16 int32_t for 16 bytes boundary * 2
int32_t *arrays2 = (int32_t*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(int32_t));
float *arrayf1 = (float*)av_malloc((SIZEARRAY+offsetfloat1+4) * ISIZEOF(float));

arrayf1[0+offsetfloat1] = -1.2;
arrayf1[1+offsetfloat1] = -1.1;
arrayf1[2+offsetfloat1] = -1.0;
arrayf1[3+offsetfloat1] = -1.3;
arrayf1[4+offsetfloat1] = 1.3;
arrayf1[5+offsetfloat1] = 1.0;
arrayf1[6+offsetfloat1] = 1.1;
arrayf1[7+offsetfloat1] = 1.2;
arrays2[0] = -2147483648;
arrays2[1] = -2147483648;
arrays2[2] = -2147483648;
arrays2[3] = -2147483648;
arrays2[4] = 2147483647;
arrays2[5] = 2147483647;
arrays2[6] = 2147483647;
arrays2[7] = 2147483647;
AudioConvert::fromFloat(FORMAT_S32, arrays1, arrayf1+offsetfloat1, SIZEARRAY * ISIZEOF(float));
for (int i = 0; i < 8; i++)
{
QCOMPARE(arrays2[i], arrays1[i]);
}

av_free(arrays1);
av_free(arrays2);
av_free(arrayf1);
}

void FloatS16ClipTest3_data(void)
{
QTest::addColumn<int>("OFFSET");
QTest::newRow("Use SSE accelerated code") << 0;
QTest::newRow("Use C code") << 1;
}

void FloatS16ClipTest3(void)
{
int SIZEARRAY = 256;
QFETCH(int, OFFSET);
// +1 will never be 16-bytes aligned, forcing C-code
int offsetint32_t = 0;
int offsetfloat1 = OFFSET;

short *arrays1 = (short*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(short));
// has to be 16 int32_t for 16 bytes boundary * 2
short *arrays2 = (short*)av_malloc((SIZEARRAY+offsetint32_t+4) * ISIZEOF(short));
float *arrayf1 = (float*)av_malloc((SIZEARRAY+offsetfloat1+4) * ISIZEOF(float));

arrayf1[0+offsetfloat1] = -1.2;
arrayf1[1+offsetfloat1] = -1.1;
arrayf1[2+offsetfloat1] = -1.0;
arrayf1[3+offsetfloat1] = -1.3;
arrayf1[4+offsetfloat1] = 1.3;
arrayf1[5+offsetfloat1] = 1.0;
arrayf1[6+offsetfloat1] = 1.1;
arrayf1[7+offsetfloat1] = 1.2;
arrays2[0] = -32768;
arrays2[1] = -32768;
arrays2[2] = -32768;
arrays2[3] = -32768;
arrays2[4] = 32767;
arrays2[5] = 32767;
arrays2[6] = 32767;
arrays2[7] = 32767;
AudioConvert::fromFloat(FORMAT_S16, arrays1, arrayf1+offsetfloat1, SIZEARRAY * ISIZEOF(float));
for (int i = 0; i < 8; i++)
{
QCOMPARE(arrays2[i], arrays1[i]);
}

av_free(arrays1);
av_free(arrays2);
av_free(arrayf1);
}
};
61 changes: 60 additions & 1 deletion mythtv/libs/libmyth/test/test_audioutils/test_audioutils.h
Expand Up @@ -797,9 +797,68 @@ class TestAudioUtils: public QObject
// sanity check
QCOMPARE(arrayf1[i+offsetfloat1], arrayf2[i+offsetfloat2]);

QCOMPARE(arrays1[i], arrays2[i]);
QCOMPARE(arrays2[i], arrays1[i]);
}

av_free(arrays1);
av_free(arrays2);
av_free(arrayf1);
av_free(arrayf2);
}

void FloatToS32CvsSSESpeed_data(void)
{
QTest::addColumn<bool>("useSSE");
QTest::newRow("Use SSE accelerated code") << true;
QTest::newRow("Use C code") << false;
}

void FloatToS32CvsSSESpeed(void)
{
int SIZEARRAY = (INT16_MAX - INT16_MIN);
// +1 will never be 16-bytes aligned, forcing C-code
int offsetshort = 1;
int offsetfloat = 0;

int32_t *arrays1 = (int32_t*)av_malloc((SIZEARRAY+offsetshort+4) * ISIZEOF(int32_t));
// has to be 16 short for 16 bytes boundary * 2
int32_t *arrays2 = (int32_t*)av_malloc((SIZEARRAY+offsetshort+4) * ISIZEOF(int32_t));
float *arrayf1 = (float*)av_malloc((SIZEARRAY+offsetfloat+4) * ISIZEOF(float));
float *arrayf2 = (float*)av_malloc((SIZEARRAY+offsetfloat+4) * ISIZEOF(float));

short j = INT16_MIN;
for (int i = 0; i < SIZEARRAY; i++, j++)
{
arrays1[i+offsetshort] = j;
arrays2[i] = j;
}

QFETCH(bool, useSSE);

if (useSSE)
{
QBENCHMARK
{
for (int i = 0; i < 128; i++)
{
// Done by SSE
AudioOutputUtil::toFloat(FORMAT_S32, arrayf2, arrays2, SIZEARRAY * ISIZEOF(int32_t));
AudioOutputUtil::fromFloat(FORMAT_S32, arrays2, arrayf2, SIZEARRAY * ISIZEOF(float));
}
}
}
else
{
QBENCHMARK
{
for (int i = 0; i < 128; i++)
{
// Done by C
AudioOutputUtil::toFloat(FORMAT_S32, arrayf1+offsetfloat, arrays1+offsetshort, SIZEARRAY * ISIZEOF(int32_t));
AudioOutputUtil::fromFloat(FORMAT_S32, arrays1+offsetshort, arrayf1+offsetfloat, SIZEARRAY * ISIZEOF(int32_t));
}
}
}
av_free(arrays1);
av_free(arrays2);
av_free(arrayf1);
Expand Down

0 comments on commit 8b25703

Please sign in to comment.