Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First sound test #11887

Merged
merged 18 commits into from
Sep 5, 2023
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
1 change: 1 addition & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sord
doubleClick
sur
jus
caf
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ if(APPLE)

target_sources(mixxx-lib PRIVATE
src/util/darkappearance.mm
src/util/macosversion.mm
)

option(MACOS_ITUNES_LIBRARY "Native macOS iTunes/Music.app library integration" ON)
Expand Down Expand Up @@ -3028,6 +3029,7 @@ if(MEDIAFOUNDATION)
)
target_link_libraries(mixxx-lib PRIVATE
${MediaFoundation_LIBRARIES}
Version.lib
)
endif()

Expand Down
9 changes: 7 additions & 2 deletions src/sources/soundsourcecoreaudio.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "sources/soundsourcecoreaudio.h"
#include "sources/mp3decoding.h"

#include "engine/engine.h"
#include "sources/mp3decoding.h"
#include "util/logger.h"
#include "util/macosversion.h"
#include "util/math.h"

namespace mixxx {
Expand All @@ -27,7 +28,7 @@ constexpr SINT kMp3MaxSeekPrefetchFrames =
} // namespace

//static
const QString SoundSourceProviderCoreAudio::kDisplayName = QStringLiteral("Apple Core Audio");
const QString SoundSourceProviderCoreAudio::kDisplayName = QStringLiteral("Apple CoreAudio");

//static
const QStringList SoundSourceProviderCoreAudio::kSupportedFileTypes = {
Expand All @@ -48,6 +49,10 @@ SoundSourceProviderPriority SoundSourceProviderCoreAudio::getPriorityHint(
return SoundSourceProviderPriority::Higher;
}

QString SoundSourceProviderCoreAudio::getVersionString() const {
return getMacOsVersion();
}

SoundSourceCoreAudio::SoundSourceCoreAudio(QUrl url)
: SoundSource(url),
LegacyAudioSourceAdapter(this, this),
Expand Down
4 changes: 3 additions & 1 deletion src/sources/soundsourcecoreaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SoundSourceProviderCoreAudio : public SoundSourceProvider {
static const QStringList kSupportedFileTypes;

QString getDisplayName() const override {
return kDisplayName;
return kDisplayName + QChar(' ') + getVersionString();
}

QStringList getSupportedFileTypes() const override {
Expand All @@ -71,6 +71,8 @@ class SoundSourceProviderCoreAudio : public SoundSourceProvider {
SoundSourcePointer newSoundSource(const QUrl& url) override {
return newSoundSourceFromUrl<SoundSourceCoreAudio>(url);
}

QString getVersionString() const;
};

} // namespace mixxx
4 changes: 4 additions & 0 deletions src/sources/soundsourceffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ SoundSourceProviderPriority SoundSourceProviderFFmpeg::getPriorityHint(
return SoundSourceProviderPriority::Lowest;
}

QString SoundSourceProviderFFmpeg::getVersionString() const {
return QString::fromUtf8(av_version_info());
}

SoundSourceFFmpeg::SoundSourceFFmpeg(const QUrl& url)
: SoundSource(url),
m_pavStream(nullptr),
Expand Down
4 changes: 3 additions & 1 deletion src/sources/soundsourceffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class SoundSourceProviderFFmpeg : public SoundSourceProvider {
~SoundSourceProviderFFmpeg() override = default;

QString getDisplayName() const override {
return kDisplayName;
return kDisplayName + QChar(' ') + getVersionString();
}

QStringList getSupportedFileTypes() const override;
Expand All @@ -212,6 +212,8 @@ class SoundSourceProviderFFmpeg : public SoundSourceProvider {
SoundSourcePointer newSoundSource(const QUrl& url) override {
return newSoundSourceFromUrl<SoundSourceFFmpeg>(url);
}

QString getVersionString() const;
};

} // namespace mixxx
33 changes: 33 additions & 0 deletions src/sources/soundsourcemediafoundation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ SoundSourcePointer SoundSourceProviderMediaFoundation::newSoundSource(const QUrl
return newSoundSourceFromUrl<SoundSourceMediaFoundation>(url);
}

QString SoundSourceProviderMediaFoundation::getVersionString() const {
HMODULE mfModule = GetModuleHandle(L"mfplat.dll");
VERIFY_OR_DEBUG_ASSERT(mfModule) {
return QString();
}
wchar_t dllPath[MAX_PATH];
DWORD pathLength = GetModuleFileName(mfModule, dllPath, MAX_PATH);
DWORD versionInfoSize = GetFileVersionInfoSize(dllPath, nullptr);
VERIFY_OR_DEBUG_ASSERT(versionInfoSize > 0) {
qWarning() << "failed to read" << dllPath << "error:" << GetLastError();
return QString();
daschuer marked this conversation as resolved.
Show resolved Hide resolved
}
QVarLengthArray<BYTE> info(static_cast<int>(versionInfoSize));
if (GetFileVersionInfo(dllPath, 0, versionInfoSize, info.data())) {
UINT size = 0;
VS_FIXEDFILEINFO* pVerInfo = nullptr;
if (VerQueryValue(info.data(), L"\\", reinterpret_cast<LPVOID*>(&pVerInfo), &size) &&
pVerInfo != nullptr &&
size >= sizeof(VS_FIXEDFILEINFO)) {
return QStringLiteral("%1.%2.%3.%4")
.arg(QString::number(HIWORD(pVerInfo->dwProductVersionMS)),
QString::number(
LOWORD(pVerInfo->dwProductVersionMS)),
QString::number(
HIWORD(pVerInfo->dwProductVersionLS)),
QString::number(
LOWORD(pVerInfo->dwProductVersionLS)));
}
}
qWarning() << "failed to read version from" << dllPath << "error:" << GetLastError();
return QString();
}

SoundSourceMediaFoundation::SoundSourceMediaFoundation(const QUrl& url)
: SoundSource(url),
m_hrCoInitialize(E_FAIL),
Expand Down
4 changes: 3 additions & 1 deletion src/sources/soundsourcemediafoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SoundSourceProviderMediaFoundation : public SoundSourceProvider {
static const QStringList kSupportedFileTypes;

QString getDisplayName() const override {
return kDisplayName;
return kDisplayName + QChar(' ') + getVersionString();
}

QStringList getSupportedFileTypes() const override {
Expand All @@ -105,6 +105,8 @@ class SoundSourceProviderMediaFoundation : public SoundSourceProvider {
const QString& supportedFileType) const override;

SoundSourcePointer newSoundSource(const QUrl& url) override;

QString getVersionString() const;
};

} // namespace mixxx
17 changes: 15 additions & 2 deletions src/sources/soundsourcemp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ bool decodeFrameHeader(
} // anonymous namespace

//static
const QString SoundSourceProviderMp3::kDisplayName = QStringLiteral("MAD: MPEG Audio Decoder");
const QString SoundSourceProviderMp3::kDisplayName = QStringLiteral("MAD");

//static
const QStringList SoundSourceProviderMp3::kSupportedFileTypes = {
QStringLiteral("mp3"),
};

QString SoundSourceProviderMp3::getVersionString() const {
return QString(QString(mad_version) + QChar(' ') + QString(mad_build)).trimmed();
}

SoundSourceMp3::SoundSourceMp3(const QUrl& url)
: SoundSource(url),
m_file(getLocalFileName()),
Expand Down Expand Up @@ -487,7 +491,8 @@ void SoundSourceMp3::close() {
void SoundSourceMp3::restartDecoding(
const SeekFrameType& seekFrame) {
if (kLogger.debugEnabled()) {
kLogger.debug() << "restartDecoding @" << seekFrame.frameIndex;
kLogger.info() << "restartDecoding for frame" << seekFrame.frameIndex << "@"
<< (seekFrame.pInputData - m_pFileData);
}

// Discard decoded output
Expand Down Expand Up @@ -680,6 +685,14 @@ ReadableSampleFrames SoundSourceMp3::readSampleFramesClamped(
<< "Recoverable MP3 frame decoding error:"
<< mad_stream_errorstr(&m_madStream);
}
} else if (m_madStream.error == MAD_ERROR_BADDATAPTR &&
m_curFrameIndex == firstFrameIndex) {
// This is expected after starting decoding with an offset
Comment on lines +688 to +690
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected by us, but is it by MAD? Are we using MAD wrong here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have debugged into that and there is is nothing wrong. That why I have silenced the message.
You find this in other adoptions as well. Here for instance:
https://github.com/Sneeds-Feed-and-Seed/sneedacity/blob/5fba67545ca29d009b51d355687979a3996d252c/src/import/ImportMP3.cpp#L1093

if (kLogger.debugEnabled()) {
kLogger.debug()
<< "Recoverable MP3 frame decoding error:"
<< mad_stream_errorstr(&m_madStream);
}
} else {
kLogger.info() << "Recoverable MP3 frame decoding error:"
<< mad_stream_errorstr(&m_madStream);
Expand Down
4 changes: 3 additions & 1 deletion src/sources/soundsourcemp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SoundSourceProviderMp3 : public SoundSourceProvider {
static const QStringList kSupportedFileTypes;

QString getDisplayName() const override {
return kDisplayName;
return kDisplayName + QStringLiteral(": ") + getVersionString();
}

QStringList getSupportedFileTypes() const override {
Expand All @@ -92,6 +92,8 @@ class SoundSourceProviderMp3 : public SoundSourceProvider {
SoundSourcePointer newSoundSource(const QUrl& url) override {
return newSoundSourceFromUrl<SoundSourceMp3>(url);
}

QString getVersionString() const;
};

} // namespace mixxx
9 changes: 3 additions & 6 deletions src/test/mixxxtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ class MixxxTest : public testing::Test {
};
friend class ApplicationScope;

static const QDir& getOrInitTestDir(const QString& resourcePath = QString()) {
static const QDir& getOrInitTestDir() {
if (s_TestDir.path() == ".") {
s_TestDir.setPath(
(resourcePath.isEmpty() ? ConfigObject<ConfigValue>::
computeResourcePath()
: resourcePath) +
QChar('/') + kTestPath);
QDir::cleanPath(ConfigObject<ConfigValue>::computeResourcePath() + kTestPath));
}
return s_TestDir;
}
Expand All @@ -63,7 +60,7 @@ class MixxxTest : public testing::Test {
}

const QDir& getTestDir() const {
return getOrInitTestDir(m_pConfig->getResourcePath());
return getOrInitTestDir();
}

private:
Expand Down
127 changes: 125 additions & 2 deletions src/test/soundproxy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <QTemporaryFile>
#include <QtDebug>

#include "analyzer/analyzersilence.h"
#include "sources/audiosourcestereoproxy.h"
#include "sources/soundsourceproxy.h"
#include "test/mixxxtest.h"
Expand Down Expand Up @@ -119,8 +120,8 @@ class SoundSourceProxyTest : public MixxxTest, SoundSourceProviderRegistration {
const CSAMPLE* actual,
const char* errorMessage) {
for (SINT i = 0; i < size; ++i) {
EXPECT_NEAR(expected[i], actual[i],
kMaxDecodingError) << errorMessage;
EXPECT_NEAR(expected[i], actual[i], kMaxDecodingError)
<< "i=" << i << " " << errorMessage;
}
}

Expand Down Expand Up @@ -747,6 +748,128 @@ TEST_F(SoundSourceProxyTest, regressionTestCachingReaderChunkJumpForward) {
}
}

TEST_F(SoundSourceProxyTest, firstSoundTest) {
constexpr SINT kReadFrameCount = 2000;

struct RefFirstSound {
QString path;
SINT firstSoundSample;
};

RefFirstSound refs[] = {{QStringLiteral("cover-test.aiff"), 1166},
{QStringLiteral("cover-test-alac.caf"), 1166},
{QStringLiteral("cover-test.flac"), 1166},
{QStringLiteral("cover-test-itunes-12.3.0-aac.m4a"),
#if defined(__WINDOWS__)
1390}, // Media Foundation 10.0.17763.2989
// Media Foundation 10.0.20348.1
#else
1166}, // FFmpeg 4.2.7-0ubuntu0.1
// FFmpeg 4.4.2-0ubuntu0.22.04.1
// FFmpeg 5.1.2 windows
// CoreAudio Version 11.7.8 (Build 20G1351)
// CoreAusio Version 12.6.7 (Build 21G651)
#endif
// 1168 FFmpeg 4.2.7-0ubuntu0.1

{QStringLiteral("cover-test-ffmpeg-aac.m4a"),
#if defined(__WINDOWS__)
3160}, // Media Foundation 10.0.17763.2989
// Media Foundation 10.0.20348.1
#else
1112}, // FFmpeg 4.2.7-0ubuntu0.1
// FFmpeg 4.4.2-0ubuntu0.22.04.1
// FFmpeg 5.1.2 windows
// CoreAudio Version 11.7.8 (Build 20G1351)
// CoreAusio Version 12.6.7 (Build 21G651)
#endif

{QStringLiteral("cover-test-itunes-12.7.0-alac.m4a"), 1166},
{QStringLiteral("cover-test-png.mp3"),
#if defined(__LINUX__)
1752}, // MAD: MPEG Audio Decoder 0.15.1 (beta) NDEBUG FPM_64BIT
#elif defined(__WINDOWS__)
1752}, // MAD: MPEG Audio Decoder 0.15.1 (beta) NDEBUG FPM_DEFAULT
#else
0}, // CoreAudio Version 11.7.8 (Build 20G1351)
#endif

{QStringLiteral("cover-test-vbr.mp3"),
#if defined(__LINUX__) || defined(__WINDOWS__)
3376}, // MAD: MPEG Audio Decoder 0.15.1 (beta) NDEBUG FPM_64BIT
#else
2318}, // CoreAudio Version 11.7.8 (Build 20G1351)
#endif
// 3326 MAD: MPEG Audio Decoder 0.15.1 (beta) NDEBUG FPM_DEFAULT
// No offset compared to FPM_64BIT builds but rounding differences
// https://github.com/mixxxdj/mixxx/issues/11888
// 1166 FFmpeg

{QStringLiteral("cover-test.ogg"), 1166},
{QStringLiteral("cover-test.opus"), 1268},
{QStringLiteral("cover-test.wav"), 1166},
{QStringLiteral("cover-test.wav"), 1166},
{QStringLiteral("cover-test.wv"), 1166}};

for (const auto& ref : refs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered writing a parametrized test? That would have the advantage that the test would not abort after the first failure and each first sound ref would be tested independently.

https://github.com/google/googletest/blob/main/docs/advanced.md#how-to-write-value-parameterized-tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test already continues when one test is failing. I am fine with the current implementation.

QString filePath = getTestDir().filePath(
QStringLiteral("id3-test-data/") +
ref.path);
ASSERT_TRUE(SoundSourceProxy::isFileNameSupported(filePath));
const auto fileUrl = QUrl::fromLocalFile(filePath);
const auto providerRegistrations =
SoundSourceProxy::allProviderRegistrationsForUrl(fileUrl);
for (const auto& providerRegistration : providerRegistrations) {
mixxx::AudioSourcePointer pContReadSource = openAudioSource(
filePath,
providerRegistration.getProvider());

// Obtaining an AudioSource may fail for unsupported file formats,
// even if the corresponding file extension is supported, e.g.
// AAC vs. ALAC in .m4a files
if (!pContReadSource) {
// skip test file
continue;
}
mixxx::SampleBuffer contReadData(
pContReadSource->getSignalInfo().frames2samples(kReadFrameCount));

SINT contFrameIndex = pContReadSource->frameIndexMin();
while (pContReadSource->frameIndexRange().containsIndex(contFrameIndex)) {
const auto readFrameIndexRange =
mixxx::IndexRange::forward(contFrameIndex, kReadFrameCount);
// Read next chunk of frames for Cont source without seeking
const auto contSampleFrames =
pContReadSource->readSampleFrames(
mixxx::WritableSampleFrames(
readFrameIndexRange,
mixxx::SampleBuffer::WritableSlice(contReadData)));
ASSERT_FALSE(contSampleFrames.frameIndexRange().empty());
ASSERT_TRUE(contSampleFrames.frameIndexRange().isSubrangeOf(readFrameIndexRange));
ASSERT_EQ(contSampleFrames.frameIndexRange().start(), readFrameIndexRange.start());
contFrameIndex += contSampleFrames.frameLength();

const SINT sampleCount =
pContReadSource->getSignalInfo().frames2samples(
contSampleFrames.frameLength());

auto samples = std::span<const CSAMPLE>(&contReadData[0], sampleCount);

const SINT firstSoundSample = AnalyzerSilence::findFirstSoundInChunk(samples);
if (firstSoundSample < static_cast<SINT>(samples.size())) {
EXPECT_EQ(firstSoundSample, ref.firstSoundSample)
<< filePath.toStdString() << " "
<< providerRegistration.getProvider()
->getDisplayName()
.toStdString();
break;
}
}
break;
}
}
}

TEST_F(SoundSourceProxyTest, getTypeFromFile) {
QTemporaryDir tempDir;
ASSERT_TRUE(tempDir.isValid());
Expand Down
5 changes: 5 additions & 0 deletions src/util/macosversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <QString>

QString getMacOsVersion();
Loading