Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/framework/mlt_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ void mlt_audio_shrink(mlt_audio self, int samples)
} else if (plane_count == 1 || samples == 0) {
// No need to move any data.
self->samples = samples;
}
if (plane_count > 1) {
} else if (plane_count > 1) {
// Move data to remove gaps between planes.
size_t src_plane_size = mlt_audio_plane_size(self);
self->samples = samples;
Expand Down
37 changes: 36 additions & 1 deletion src/tests/test_audio/test_audio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Meltytech, LLC
* Copyright (C) 2020-2026 Meltytech, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -51,6 +51,41 @@ private Q_SLOTS:
free(data);
a.set_data(nullptr);
}

void ShrinkPlanarAudio_data()
{
QTest::addColumn<int>("format");
QTest::addColumn<int>("samples");
QTest::addColumn<QList<int>>("expected");

const QList<int> unchanged = {11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34};
const QList<int> shrunk = {11, 12, 21, 22, 31, 32};
for (auto format : {mlt_audio_s32, mlt_audio_float}) {
const QString name = mlt_audio_format_name(format);
QTest::newRow(qPrintable(name + "-negative")) << int(format) << -1 << unchanged;
QTest::newRow(qPrintable(name + "-same")) << int(format) << 4 << unchanged;
QTest::newRow(qPrintable(name + "-larger")) << int(format) << 5 << unchanged;
QTest::newRow(qPrintable(name + "-smaller")) << int(format) << 2 << shrunk;
QTest::newRow(qPrintable(name + "-zero")) << int(format) << 0 << QList<int>();
}
}

void ShrinkPlanarAudio()
{
QFETCH(int, format);
QFETCH(int, samples);
QFETCH(QList<int>, expected);

int32_t data[] = {11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34};
struct mlt_audio_s audio = {};
mlt_audio_set_values(&audio, data, 48000, mlt_audio_format(format), 4, 3);

mlt_audio_shrink(&audio, samples);

QCOMPARE(audio.samples, int(expected.size()) / 3);
for (int i = 0; i < expected.size(); i++)
QCOMPARE(data[i], expected[i]);
}
};

QTEST_APPLESS_MAIN(TestAudio)
Expand Down
Loading