1 | /* $Id: AudioTest.h 89265 2021-05-25 11:10:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Audio testing routines.
|
---|
4 | * Common code which is being used by the ValidationKit audio test (VKAT)
|
---|
5 | * and the debug / ValdikationKit audio driver(s).
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2021 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.alldomusa.eu.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef VBOX_INCLUDED_SRC_Audio_AudioTest_h
|
---|
21 | #define VBOX_INCLUDED_SRC_Audio_AudioTest_h
|
---|
22 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
23 | # pragma once
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | /** @todo Some stuff here can be private-only to the implementation. */
|
---|
27 |
|
---|
28 | /** Maximum length in characters an audio test tag can have. */
|
---|
29 | #define AUDIOTEST_TAG_MAX 64
|
---|
30 | /** Maximum length in characters a single audio test error description can have. */
|
---|
31 | #define AUDIOTEST_ERROR_DESC_MAX 128
|
---|
32 | /** Prefix for audio test (set) directories. */
|
---|
33 | #define AUDIOTEST_PATH_PREFIX_STR "vkat"
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Enumeration for an audio test tone (wave) type.
|
---|
37 | */
|
---|
38 | typedef enum AUDIOTESTTONETYPE
|
---|
39 | {
|
---|
40 | /** Invalid type. */
|
---|
41 | AUDIOTESTTONETYPE_INVALID = 0,
|
---|
42 | /** Sine wave. */
|
---|
43 | AUDIOTESTTONETYPE_SINE,
|
---|
44 | /** Square wave. Not implemented yet. */
|
---|
45 | AUDIOTESTTONETYPE_SQUARE,
|
---|
46 | /** Triangluar wave. Not implemented yet. */
|
---|
47 | AUDIOTESTTONETYPE_TRIANGLE,
|
---|
48 | /** Sawtooth wave. Not implemented yet. */
|
---|
49 | AUDIOTESTTONETYPE_SAWTOOTH,
|
---|
50 | /** The usual 32-bit hack. */
|
---|
51 | AUDIOTESTTONETYPE_32BIT_HACK = 0x7fffffff
|
---|
52 | } AUDIOTESTTONETYPE;
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Structure for handling an audio (sine wave) test tone.
|
---|
56 | */
|
---|
57 | typedef struct AUDIOTESTTONE
|
---|
58 | {
|
---|
59 | /** The tone's wave type. */
|
---|
60 | AUDIOTESTTONETYPE enmType;
|
---|
61 | /** The PCM properties. */
|
---|
62 | PDMAUDIOPCMPROPS Props;
|
---|
63 | /** Current sample index for generate the sine wave. */
|
---|
64 | uint64_t uSample;
|
---|
65 | /** The fixed portion of the sin() input. */
|
---|
66 | double rdFixed;
|
---|
67 | /** Frequency (in Hz) of the sine wave to generate. */
|
---|
68 | double rdFreqHz;
|
---|
69 | } AUDIOTESTTONE;
|
---|
70 | /** Pointer to an audio test tone. */
|
---|
71 | typedef AUDIOTESTTONE *PAUDIOTESTTONE;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Structure for handling audio test tone parameters.
|
---|
75 | */
|
---|
76 | typedef struct AUDIOTESTTONEPARMS
|
---|
77 | {
|
---|
78 | /** The PCM properties. */
|
---|
79 | PDMAUDIOPCMPROPS Props;
|
---|
80 | /** Prequel (in ms) to play silence. Optional and can be set to 0. */
|
---|
81 | RTMSINTERVAL msPrequel;
|
---|
82 | /** Duration (in ms) to play the test tone. */
|
---|
83 | RTMSINTERVAL msDuration;
|
---|
84 | /** Sequel (in ms) to play silence. Optional and can be set to 0. */
|
---|
85 | RTMSINTERVAL msSequel;
|
---|
86 | /** Volume (in percent, 0-100) to use.
|
---|
87 | * If set to 0, the tone is muted (i.e. silent). */
|
---|
88 | uint8_t uVolumePercent;
|
---|
89 | } AUDIOTESTTONEPARMS;
|
---|
90 | /** Pointer to audio test tone parameters. */
|
---|
91 | typedef AUDIOTESTTONEPARMS *PAUDIOTESTTONEPARMS;
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Enumeration for the test set mode.
|
---|
95 | */
|
---|
96 | typedef enum AUDIOTESTSETMODE
|
---|
97 | {
|
---|
98 | /** Invalid test set mode. */
|
---|
99 | AUDIOTESTSETMODE_INVALID = 0,
|
---|
100 | /** Test set is being created (testing in progress). */
|
---|
101 | AUDIOTESTSETMODE_TEST,
|
---|
102 | /** Existing test set is being verified. */
|
---|
103 | AUDIOTESTSETMODE_VERIFY,
|
---|
104 | /** The usual 32-bit hack. */
|
---|
105 | AUDIOTESTSETMODE_32BIT_HACK = 0x7fffffff
|
---|
106 | } AUDIOTESTSETMODE;
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Enumeration to specify an audio test type.
|
---|
110 | */
|
---|
111 | typedef enum AUDIOTESTTYPE
|
---|
112 | {
|
---|
113 | /** Invalid test type, do not use. */
|
---|
114 | AUDIOTESTTYPE_INVALID = 0,
|
---|
115 | /** Play a test tone. */
|
---|
116 | AUDIOTESTTYPE_TESTTONE,
|
---|
117 | /** The usual 32-bit hack. */
|
---|
118 | AUDIOTESTTYPE_32BIT_HACK = 0x7fffffff
|
---|
119 | } AUDIOTESTTYPE;
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Audio test request data.
|
---|
123 | */
|
---|
124 | typedef struct AUDIOTESTPARMS
|
---|
125 | {
|
---|
126 | /** Specifies the current test iteration. */
|
---|
127 | uint32_t idxCurrent;
|
---|
128 | /** How many iterations the test should be executed. */
|
---|
129 | uint32_t cIterations;
|
---|
130 | /** Audio device to use. */
|
---|
131 | PDMAUDIOHOSTDEV Dev;
|
---|
132 | /** How much to delay (wait, in ms) the test being executed. */
|
---|
133 | RTMSINTERVAL msDelay;
|
---|
134 | /** The test direction. */
|
---|
135 | PDMAUDIODIR enmDir;
|
---|
136 | /** The test type. */
|
---|
137 | AUDIOTESTTYPE enmType;
|
---|
138 | /** Union for test type-specific data. */
|
---|
139 | union
|
---|
140 | {
|
---|
141 | AUDIOTESTTONEPARMS TestTone;
|
---|
142 | };
|
---|
143 | } AUDIOTESTPARMS;
|
---|
144 | /** Pointer to a test parameter structure. */
|
---|
145 | typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Enumeration for an audio test object type.
|
---|
149 | */
|
---|
150 | typedef enum AUDIOTESTOBJTYPE
|
---|
151 | {
|
---|
152 | /** Unknown / invalid, do not use. */
|
---|
153 | AUDIOTESTOBJTYPE_UNKNOWN = 0,
|
---|
154 | /** The test object is a file. */
|
---|
155 | AUDIOTESTOBJTYPE_FILE,
|
---|
156 | /** The usual 32-bit hack. */
|
---|
157 | AUDIOTESTOBJTYPE_32BIT_HACK = 0x7fffffff
|
---|
158 | } AUDIOTESTOBJTYPE;
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Structure for keeping an audio test object file.
|
---|
162 | */
|
---|
163 | typedef struct AUDIOTESTOBJFILE
|
---|
164 | {
|
---|
165 | RTFILE hFile;
|
---|
166 | } AUDIOTESTOBJFILE;
|
---|
167 | /** Pointer to an audio test object file. */
|
---|
168 | typedef AUDIOTESTOBJFILE *PAUDIOTESTOBJFILE;
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Structure for keeping a single audio test object.
|
---|
172 | *
|
---|
173 | * A test object is data which is needed in order to perform and verify one or
|
---|
174 | * more audio test case(s).
|
---|
175 | */
|
---|
176 | typedef struct AUDIOTESTOBJ
|
---|
177 | {
|
---|
178 | /** List node. */
|
---|
179 | RTLISTNODE Node;
|
---|
180 | /** Name of the test object.
|
---|
181 | * Must not contain a path and has to be able to serialize to disk. */
|
---|
182 | char szName[64];
|
---|
183 | /** The object type. */
|
---|
184 | AUDIOTESTOBJTYPE enmType;
|
---|
185 | /** Union for holding the object type-specific data. */
|
---|
186 | union
|
---|
187 | {
|
---|
188 | AUDIOTESTOBJFILE File;
|
---|
189 | };
|
---|
190 | } AUDIOTESTOBJ;
|
---|
191 | /** Pointer to an audio test object. */
|
---|
192 | typedef AUDIOTESTOBJ *PAUDIOTESTOBJ;
|
---|
193 |
|
---|
194 | struct AUDIOTESTSET;
|
---|
195 |
|
---|
196 | typedef struct AUDIOTESTENTRY
|
---|
197 | {
|
---|
198 | /** List node. */
|
---|
199 | RTLISTNODE Node;
|
---|
200 | AUDIOTESTSET *pParent;
|
---|
201 | char szDesc[64];
|
---|
202 | AUDIOTESTPARMS Parms;
|
---|
203 | int rc;
|
---|
204 | } AUDIOTESTENTRY;
|
---|
205 | /** Pointer to an audio test entry. */
|
---|
206 | typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Structure specifying an audio test set.
|
---|
210 | */
|
---|
211 | typedef struct AUDIOTESTSET
|
---|
212 | {
|
---|
213 | /** The set's tag. */
|
---|
214 | char szTag[AUDIOTEST_TAG_MAX];
|
---|
215 | /** Absolute path where to store the test audio data. */
|
---|
216 | char szPathAbs[RTPATH_MAX];
|
---|
217 | /** Current mode the test set is in. */
|
---|
218 | AUDIOTESTSETMODE enmMode;
|
---|
219 | union
|
---|
220 | {
|
---|
221 | /** @todo r=bird: RTSTREAM not RTFILE. That means you don't have to check
|
---|
222 | * every write status code and it's buffered and thus faster. Also,
|
---|
223 | * you don't have to re-invent fprintf-style RTFileWrite wrappers. */
|
---|
224 | RTFILE hFile;
|
---|
225 | RTINIFILE hIniFile;
|
---|
226 | } f;
|
---|
227 | /** Number of test objects in lstObj. */
|
---|
228 | uint32_t cObj;
|
---|
229 | /** List containing PAUDIOTESTOBJ test object entries. */
|
---|
230 | RTLISTANCHOR lstObj;
|
---|
231 | /** Number of performed tests.
|
---|
232 | * Not necessarily bound to the test object entries above. */
|
---|
233 | uint32_t cTests;
|
---|
234 | /** Absolute offset (in bytes) where to write the "test_count" value later. */
|
---|
235 | uint64_t offTestCount;
|
---|
236 | /** List containing PAUDIOTESTENTRY test entries. */
|
---|
237 | RTLISTANCHOR lstTest;
|
---|
238 | /** Number of tests currently running. */
|
---|
239 | uint32_t cTestsRunning;
|
---|
240 | /** Number of total (test) failures. */
|
---|
241 | uint32_t cTotalFailures;
|
---|
242 | } AUDIOTESTSET;
|
---|
243 | /** Pointer to an audio test set. */
|
---|
244 | typedef AUDIOTESTSET *PAUDIOTESTSET;
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Structure for holding a single audio test error entry.
|
---|
248 | */
|
---|
249 | typedef struct AUDIOTESTERRORENTRY
|
---|
250 | {
|
---|
251 | /** The entrie's list node. */
|
---|
252 | RTLISTNODE Node;
|
---|
253 | /** Additional rc. */
|
---|
254 | int rc;
|
---|
255 | /** Actual error description. */
|
---|
256 | char szDesc[AUDIOTEST_ERROR_DESC_MAX];
|
---|
257 | } AUDIOTESTERRORENTRY;
|
---|
258 | /** Pointer to an audio test error description. */
|
---|
259 | typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Structure for holding an audio test error description.
|
---|
263 | * This can contain multiple errors (FIFO list).
|
---|
264 | */
|
---|
265 | typedef struct AUDIOTESTERRORDESC
|
---|
266 | {
|
---|
267 | /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
|
---|
268 | RTLISTANCHOR List;
|
---|
269 | /** Number of errors in the list. */
|
---|
270 | uint32_t cErrors;
|
---|
271 | } AUDIOTESTERRORDESC;
|
---|
272 | /** Pointer to an audio test error description. */
|
---|
273 | typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * An open wave (.WAV) file.
|
---|
277 | */
|
---|
278 | typedef struct AUDIOTESTWAVEFILE
|
---|
279 | {
|
---|
280 | /** The file handle. */
|
---|
281 | RTFILE hFile;
|
---|
282 | /** The absolute file offset of the first sample */
|
---|
283 | uint32_t offSamples;
|
---|
284 | /** Number of bytes of samples. */
|
---|
285 | uint32_t cbSamples;
|
---|
286 | /** The current read position relative to @a offSamples. */
|
---|
287 | uint32_t offCur;
|
---|
288 | /** The PCM properties for the file format. */
|
---|
289 | PDMAUDIOPCMPROPS Props;
|
---|
290 | } AUDIOTESTWAVEFILE;
|
---|
291 | /** Pointer to an open wave file. */
|
---|
292 | typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
|
---|
293 |
|
---|
294 |
|
---|
295 | double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
|
---|
296 | int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
|
---|
297 |
|
---|
298 | int AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps);
|
---|
299 |
|
---|
300 | int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
|
---|
301 | int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
|
---|
302 |
|
---|
303 | int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj);
|
---|
304 | int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf);
|
---|
305 | int AudioTestSetObjClose(PAUDIOTESTOBJ pObj);
|
---|
306 |
|
---|
307 | int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
|
---|
308 | int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
|
---|
309 | int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
|
---|
310 |
|
---|
311 | int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
|
---|
312 | int AudioTestSetDestroy(PAUDIOTESTSET pSet);
|
---|
313 | int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
|
---|
314 | int AudioTestSetClose(PAUDIOTESTSET pSet);
|
---|
315 | int AudioTestSetWipe(PAUDIOTESTSET pSet);
|
---|
316 | bool AudioTestSetIsPacked(const char *pszPath);
|
---|
317 | int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
|
---|
318 | int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
|
---|
319 | int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc);
|
---|
320 |
|
---|
321 | bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr);
|
---|
322 | void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
|
---|
323 |
|
---|
324 | int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile);
|
---|
325 | int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
|
---|
326 | void AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
|
---|
327 |
|
---|
328 | #endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
|
---|
329 |
|
---|