1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
#include <gmock/gmock.h>
#include <QtDebug>
#include "test/mixxxtest.h"
#include "sources/soundsourceproxy.h"
#include "track/trackmetadata.h"
#include "util/samplebuffer.h"
#ifdef __OPUS__
#include "sources/soundsourceopus.h"
#endif // __OPUS__
namespace {
const QDir kTestDir(QDir::current().absoluteFilePath("src/test/id3-test-data"));
} // anonymous namespace
class SoundSourceProxyTest: public MixxxTest {
protected:
static QStringList getFileNameSuffixes() {
QStringList availableFileNameSuffixes;
availableFileNameSuffixes
<< ".aiff"
<< ".flac"
<< ".m4a"
<< "-png.mp3"
<< ".ogg"
<< ".opus"
<< ".wav"
<< ".wv";
QStringList supportedFileNameSuffixes;
for (const auto& fileNameSuffix: availableFileNameSuffixes) {
// We need to check for the whole file name here!
if (SoundSourceProxy::isFileNameSupported(fileNameSuffix)) {
supportedFileNameSuffixes << fileNameSuffix;
}
}
return supportedFileNameSuffixes;
}
static QStringList getFilePaths() {
QStringList filePaths;
for (const auto& fileNameSuffix: getFileNameSuffixes()) {
filePaths.append(kTestDir.absoluteFilePath("cover-test" + fileNameSuffix));
}
return filePaths;
}
static mixxx::AudioSourcePointer openAudioSource(const QString& filePath) {
TrackPointer pTrack(Track::newTemporary(filePath));
return SoundSourceProxy(pTrack).openAudioSource();
}
static void expectDecodedSamplesEqual(
SINT size,
const CSAMPLE* expected,
const CSAMPLE* actual,
const char* errorMessage) {
for (SINT i = 0; i < size; ++i) {
EXPECT_EQ(expected[i], actual[i]) << errorMessage;
}
}
#ifdef __OPUS__
// Known issue: Decoding with libopus is not sample accurate
static void expectDecodedSamplesEqualOpus(
SINT size,
const CSAMPLE* expected,
const CSAMPLE* actual,
const char* errorMessage) {
for (SINT i = 0; i < size; ++i) {
EXPECT_NEAR(expected[i], actual[i],
mixxx::SoundSourceOpus::kMaxDecodingError) << errorMessage;
}
}
#endif // __OPUS__
};
TEST_F(SoundSourceProxyTest, open) {
// This test piggy-backs off of the cover-test files.
for (const auto& filePath: getFilePaths()) {
ASSERT_TRUE(SoundSourceProxy::isFileNameSupported(filePath));
mixxx::AudioSourcePointer pAudioSource(openAudioSource(filePath));
// 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 (!pAudioSource) {
// skip test file
continue;
}
EXPECT_LT(0, pAudioSource->getChannelCount());
EXPECT_LT(0, pAudioSource->getSamplingRate());
EXPECT_LT(0, pAudioSource->getFrameCount());
}
}
TEST_F(SoundSourceProxyTest, readArtist) {
TrackPointer pTrack(Track::newTemporary(
kTestDir.absoluteFilePath("artist.mp3")));
SoundSourceProxy proxy(pTrack);
mixxx::TrackMetadata trackMetadata;
EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata));
EXPECT_EQ("Test Artist", trackMetadata.getArtist());
}
TEST_F(SoundSourceProxyTest, TOAL_TPE2) {
TrackPointer pTrack(Track::newTemporary(
kTestDir.absoluteFilePath("TOAL_TPE2.mp3")));
SoundSourceProxy proxy(pTrack);
mixxx::TrackMetadata trackMetadata;
EXPECT_EQ(OK, proxy.parseTrackMetadata(&trackMetadata));
EXPECT_EQ("TITLE2", trackMetadata.getArtist());
EXPECT_EQ("ARTIST", trackMetadata.getAlbum());
EXPECT_EQ("TITLE", trackMetadata.getAlbumArtist());
}
TEST_F(SoundSourceProxyTest, seekForwardBackward) {
const SINT kReadFrameCount = 10000;
for (const auto& filePath: getFilePaths()) {
ASSERT_TRUE(SoundSourceProxy::isFileNameSupported(filePath));
qDebug() << "Seek forward/backward test:" << filePath;
mixxx::AudioSourcePointer pContReadSource(openAudioSource(filePath));
// 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;
}
SampleBuffer contReadData(
pContReadSource->frames2samples(kReadFrameCount));
SampleBuffer seekReadData(
pContReadSource->frames2samples(kReadFrameCount));
for (SINT contFrameIndex = 0;
pContReadSource->isValidFrameIndex(contFrameIndex);
contFrameIndex += kReadFrameCount) {
qDebug() << "Decoding from:" << contFrameIndex;
// Read next chunk of frames for Cont source without seek
const SINT contReadFrameCount =
pContReadSource->readSampleFrames(kReadFrameCount, &contReadData[0]);
mixxx::AudioSourcePointer pSeekReadSource(openAudioSource(filePath));
ASSERT_FALSE(!pSeekReadSource);
ASSERT_EQ(pContReadSource->getChannelCount(), pSeekReadSource->getChannelCount());
ASSERT_EQ(pContReadSource->getFrameCount(), pSeekReadSource->getFrameCount());
// Seek source to next chunk and read it
SINT seekFrameIndex =
pSeekReadSource->seekSampleFrame(contFrameIndex);
ASSERT_EQ(contFrameIndex, seekFrameIndex);
SINT seekReadFrameCount =
pSeekReadSource->readSampleFrames(kReadFrameCount, &seekReadData[0]);
// Both buffers should be equal
ASSERT_EQ(contReadFrameCount, seekReadFrameCount);
#ifdef __OPUS__
if (filePath.endsWith(".opus")) {
expectDecodedSamplesEqualOpus(
pContReadSource->frames2samples(contReadFrameCount),
&contReadData[0],
&seekReadData[0],
"Decoding mismatch after seeking forward");
} else {
#endif // __OPUS__
expectDecodedSamplesEqual(
pContReadSource->frames2samples(contReadFrameCount),
&contReadData[0],
&seekReadData[0],
"Decoding mismatch after seeking forward");
#ifdef __OPUS__
}
#endif // __OPUS__
// Seek backwards to beginning of chunk and read again
seekFrameIndex =
pSeekReadSource->seekSampleFrame(contFrameIndex);
ASSERT_EQ(contFrameIndex, seekFrameIndex);
seekReadFrameCount =
pSeekReadSource->readSampleFrames(kReadFrameCount, &seekReadData[0]);
// Both buffers should again be equal
ASSERT_EQ(contReadFrameCount, seekReadFrameCount);
#ifdef __OPUS__
if (filePath.endsWith(".opus")) {
expectDecodedSamplesEqualOpus(
pContReadSource->frames2samples(contReadFrameCount),
&contReadData[0],
&seekReadData[0],
"Decoding mismatch after seeking backward");
} else {
#endif // __OPUS__
expectDecodedSamplesEqual(
pContReadSource->frames2samples(contReadFrameCount),
&contReadData[0],
&seekReadData[0],
"Decoding mismatch after seeking backward");
#ifdef __OPUS__
}
#endif // __OPUS__
}
}
}
TEST_F(SoundSourceProxyTest, skipAndRead) {
const SINT kReadFrameCount = 1000;
for (const auto& filePath: getFilePaths()) {
ASSERT_TRUE(SoundSourceProxy::isFileNameSupported(filePath));
qDebug() << "Skip and read test:" << filePath;
mixxx::AudioSourcePointer pContReadSource(openAudioSource(filePath));
// 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::AudioSourcePointer pSkipReadSource(openAudioSource(filePath));
ASSERT_FALSE(!pSkipReadSource);
ASSERT_EQ(pContReadSource->getChannelCount(), pSkipReadSource->getChannelCount());
ASSERT_EQ(pContReadSource->getFrameCount(), pSkipReadSource->getFrameCount());
const SINT readSampleCount = pContReadSource->frames2samples(kReadFrameCount);
SampleBuffer contReadData(readSampleCount);
SampleBuffer skipReadData(readSampleCount);
SINT frameIndex = mixxx::AudioSource::getMinFrameIndex();
SINT contFrameIndex = mixxx::AudioSource::getMinFrameIndex();
SINT skipFrameIndex = mixxx::AudioSource::getMinFrameIndex();
SINT skipCount = 1;
while (pContReadSource->isValidFrameIndex(frameIndex += skipCount)) {
skipCount = frameIndex / 4 + 1;
qDebug() << "Skipping to:" << frameIndex;
// Read (and discard samples) until reaching the frame index
// and read next chunk
ASSERT_LE(contFrameIndex, frameIndex);
while (contFrameIndex < frameIndex) {
SINT readCount = std::min(frameIndex - contFrameIndex, kReadFrameCount);
contFrameIndex += pContReadSource->readSampleFrames(readCount,
|