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
|
#include <cppunit/extensions/HelperMacros.h>
#include <audiofile.h>
#include <audiocache.h>
#include <unistd.h>
#define FRAMESIZE 64
class AudioCacheTest
: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(AudioCacheTest);
CPPUNIT_TEST(singleChannelNonThreaded);
CPPUNIT_TEST(singleChannelThreaded);
CPPUNIT_TEST(multiChannelNonThreaded);
CPPUNIT_TEST(multiChannelThreaded);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testHelper(const char* filename, int channel, bool threaded,
int framesize)
{
AudioFile audio_file_ref(filename, channel);
printf("audio_file_ref.load\n");
audio_file_ref.load(ALL_SAMPLES);
AudioFile audio_file(filename, channel);
printf("audio_file.load\n");
audio_file.load(4096);
AudioCache audio_cache;
printf("audio_cache.init\n");
audio_cache.init(100);
audio_cache.setAsyncMode(threaded);
audio_cache.setFrameSize(framesize);
cacheid_t id;
for(size_t initial_samples_needed = 0;
initial_samples_needed < (size_t)(framesize + 1);
++initial_samples_needed)
{
printf("open: initial_samples_needed: %d\n", (int)initial_samples_needed);
sample_t *samples =
audio_cache.open(audio_file, initial_samples_needed, channel, id);
size_t size = initial_samples_needed;
size_t offset = 0;
for(size_t i = 0; i < size; ++i)
{
CPPUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]);
++offset;
}
while(offset < audio_file_ref.size)
{
if(threaded)
{
int timeout = 1000;
while(!audio_cache.isReady(id))
{
usleep(1000);
if(--timeout == 0)
{
CPPUNIT_ASSERT(false);
}
}
}
samples = audio_cache.next(id, size);
CPPUNIT_ASSERT_EQUAL(0, (int)audio_cache.getNumberOfUnderruns());
for(size_t i = 0; (i < size) && (offset < audio_file_ref.size); ++i)
{
if(audio_file_ref.data[offset] != samples[i])
{
printf("-----> offset: %d, size: %d, diff: %d,"
" i: %d, size: %d, block-diff: %d\n",
(int)offset, (int)audio_file_ref.size,
(int)(audio_file_ref.size - offset),
(int)i, (int)size, (int)(size - i));
}
CPPUNIT_ASSERT_EQUAL(audio_file_ref.data[offset], samples[i]);
++offset;
}
}
audio_cache.close(id);
}
printf("done\n");
}
void singleChannelNonThreaded()
{
printf("\nsinglechannel_nonthreaded()\n");
const char filename[] = "kit/ride-single-channel.wav";
int channel = 0;
bool threaded = false;
testHelper(filename, channel, threaded, FRAMESIZE);
}
void singleChannelThreaded()
{
printf("\nsinglechannel_threaded()\n");
const char filename[] = "kit/ride-single-channel.wav";
int channel = 0;
bool threaded = true;
testHelper(filename, channel, threaded, FRAMESIZE);
}
void multiChannelNonThreaded()
{
printf("\nmultichannel_nonthreaded()\n");
const char filename[] = "kit/ride-multi-channel.wav";
int channel = 0;
bool threaded = false;
testHelper(filename, channel, threaded, FRAMESIZE);
++channel;
testHelper(filename, channel, threaded, FRAMESIZE);
}
void multiChannelThreaded()
{
printf("\nmultichannel_threaded()\n");
const char filename[] = "kit/ride-multi-channel.wav";
int channel = 0;
bool threaded = true;
testHelper(filename, channel, threaded, FRAMESIZE);
++channel;
testHelper(filename, channel, threaded, FRAMESIZE);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheTest);
|