VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/AudioTest.h@ 91194

Last change on this file since 91194 was 91194, checked in by vboxsync, 3 years ago

Audio/Validation Kit: Also send the test index and test creation time (caller UTC) when starting tests. ​bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.1 KB
Line 
1/* $Id: AudioTest.h 91194 2021-09-10 10:11:03Z 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.virtualbox.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 */
38typedef 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 */
57typedef 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. */
71typedef AUDIOTESTTONE *PAUDIOTESTTONE;
72
73/**
74 * Structure for a common test parameters header.
75 */
76typedef struct AUDIOTESTPARMSHDR
77{
78 /** Index in some defined sequence this test has. Can be freely used / assigned
79 * and depends on the actual implementation.
80 * Set to UINT32_MAX if not being used. */
81 uint32_t idxSeq;
82 /** Time of the caller when this test was being created. */
83 RTTIME tsCreated;
84} AUDIOTESTPARMSHDR;
85/** Pointer to an audio test tone. */
86typedef AUDIOTESTPARMSHDR *PAUDIOTESTPARMSHDR;
87
88/**
89 * Structure for handling audio test tone parameters.
90 */
91typedef struct AUDIOTESTTONEPARMS
92{
93 /** Common test header. */
94 AUDIOTESTPARMSHDR Hdr;
95 /** The PCM properties. */
96 PDMAUDIOPCMPROPS Props;
97 /** Tone frequency (in Hz) to use.
98 * Will be later converted to a double value. */
99 double dbFreqHz;
100 /** Prequel (in ms) to play silence. Optional and can be set to 0. */
101 RTMSINTERVAL msPrequel;
102 /** Duration (in ms) to play the test tone. */
103 RTMSINTERVAL msDuration;
104 /** Sequel (in ms) to play silence. Optional and can be set to 0. */
105 RTMSINTERVAL msSequel;
106 /** Volume (in percent, 0-100) to use.
107 * If set to 0, the tone is muted (i.e. silent). */
108 uint8_t uVolumePercent;
109} AUDIOTESTTONEPARMS;
110/** Pointer to audio test tone parameters. */
111typedef AUDIOTESTTONEPARMS *PAUDIOTESTTONEPARMS;
112
113/**
114 * Enumeration for the test set mode.
115 */
116typedef enum AUDIOTESTSETMODE
117{
118 /** Invalid test set mode. */
119 AUDIOTESTSETMODE_INVALID = 0,
120 /** Test set is being created (testing in progress). */
121 AUDIOTESTSETMODE_TEST,
122 /** Existing test set is being verified. */
123 AUDIOTESTSETMODE_VERIFY,
124 /** The usual 32-bit hack. */
125 AUDIOTESTSETMODE_32BIT_HACK = 0x7fffffff
126} AUDIOTESTSETMODE;
127
128/**
129 * Enumeration to specify an audio test type.
130 */
131typedef enum AUDIOTESTTYPE
132{
133 /** Invalid test type, do not use. */
134 AUDIOTESTTYPE_INVALID = 0,
135 /** Play a test tone. */
136 AUDIOTESTTYPE_TESTTONE_PLAY,
137 /** Record a test tone. */
138 AUDIOTESTTYPE_TESTTONE_RECORD,
139 /** The usual 32-bit hack. */
140 AUDIOTESTTYPE_32BIT_HACK = 0x7fffffff
141} AUDIOTESTTYPE;
142
143/**
144 * Audio test request data.
145 */
146typedef struct AUDIOTESTPARMS
147{
148 /** Specifies the current test iteration. */
149 uint32_t idxCurrent;
150 /** How many iterations the test should be executed. */
151 uint32_t cIterations;
152 /** PCM audio stream properties to use. */
153 PDMAUDIOPCMPROPS Props;
154 /** Audio device to use. */
155 PDMAUDIOHOSTDEV Dev;
156 /** How much to delay (wait, in ms) the test being executed. */
157 RTMSINTERVAL msDelay;
158 /** The test direction. */
159 PDMAUDIODIR enmDir;
160 /** The test type. */
161 AUDIOTESTTYPE enmType;
162 /** Union for test type-specific data. */
163 union
164 {
165 AUDIOTESTTONEPARMS TestTone;
166 };
167} AUDIOTESTPARMS;
168/** Pointer to a test parameter structure. */
169typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
170
171/** Test object handle. */
172typedef R3R0PTRTYPE(struct AUDIOTESTOBJINT RT_FAR *) AUDIOTESTOBJ;
173/** Pointer to test object handle. */
174typedef AUDIOTESTOBJ RT_FAR *PAUDIOTESTOBJ;
175/** Nil test object handle. */
176#define NIL_AUDIOTESTOBJ ((AUDIOTESTOBJ)~(RTHCINTPTR)0)
177
178struct AUDIOTESTSET;
179
180/**
181 * Structure specifying a single audio test entry of a test set.
182 *
183 * A test set can contain zero or more test entry (tests).
184 */
185typedef struct AUDIOTESTENTRY
186{
187 /** List node. */
188 RTLISTNODE Node;
189 /** Pointer to test set parent. */
190 AUDIOTESTSET *pParent;
191 /** Friendly description of the test. */
192 char szDesc[64];
193 /** Audio test parameters this test needs to perform the actual test. */
194 AUDIOTESTPARMS Parms;
195 /** Number of test objects bound to this test. */
196 uint32_t cObj;
197 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
198 uint64_t offObjCount;
199 /** Overall test result. */
200 int rc;
201} AUDIOTESTENTRY;
202/** Pointer to an audio test entry. */
203typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
204
205/**
206 * Structure specifying an audio test set.
207 */
208typedef struct AUDIOTESTSET
209{
210 /** The set's tag. */
211 char szTag[AUDIOTEST_TAG_MAX];
212 /** Absolute path where to store the test audio data. */
213 char szPathAbs[RTPATH_MAX];
214 /** Current mode the test set is in. */
215 AUDIOTESTSETMODE enmMode;
216 union
217 {
218 /** @todo r=bird: RTSTREAM not RTFILE. That means you don't have to check
219 * every write status code and it's buffered and thus faster. Also,
220 * you don't have to re-invent fprintf-style RTFileWrite wrappers. */
221 RTFILE hFile;
222 RTINIFILE hIniFile;
223 } f;
224 /** Number of test objects in lstObj. */
225 uint32_t cObj;
226 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
227 uint64_t offObjCount;
228 /** List containing PAUDIOTESTOBJ test object entries. */
229 RTLISTANCHOR lstObj;
230 /** Number of performed tests.
231 * Not necessarily bound to the test object entries above. */
232 uint32_t cTests;
233 /** Absolute offset (in bytes) where to write the "test_count" value later. */
234 uint64_t offTestCount;
235 /** List containing PAUDIOTESTENTRY test entries. */
236 RTLISTANCHOR lstTest;
237 /** Current test running. Can be NULL if no test is running. */
238 PAUDIOTESTENTRY pTestCur;
239 /** Number of tests currently running.
240 * Currently we only allow one concurrent test running at a given time. */
241 uint32_t cTestsRunning;
242 /** Number of total (test) failures. */
243 uint32_t cTotalFailures;
244} AUDIOTESTSET;
245/** Pointer to an audio test set. */
246typedef AUDIOTESTSET *PAUDIOTESTSET;
247
248/**
249 * Audio test verification options.
250 */
251typedef struct AUDIOTESTVERIFYOPTS
252{
253 /** Flag indicating whether to keep going after an error has occurred. */
254 bool fKeepGoing;
255 /** Threshold of file differences (number of chunks) at when we consider audio files
256 * as not matching. 0 means an exact match. */
257 uint32_t cMaxDiff;
258 /** Threshold of file differences (difference in percent) at when we consider audio files
259 * as not matching. 0 means an exact match. */
260 uint8_t uMaxDiffPercent;
261 /** Threshold of file size (+/-, in percent) at when we consider audio files
262 * as not matching. 0 means an exact match.*/
263 uint8_t uMaxSizePercent;
264} AUDIOTESTVERIFYOPTS;
265/** Pointer to audio test verification options. */
266typedef AUDIOTESTVERIFYOPTS *PAUDIOTESTVERIFYOPTS;
267
268/**
269 * Structure for holding a single audio test error entry.
270 */
271typedef struct AUDIOTESTERRORENTRY
272{
273 /** The entrie's list node. */
274 RTLISTNODE Node;
275 /** Additional rc. */
276 int rc;
277 /** Actual error description. */
278 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
279} AUDIOTESTERRORENTRY;
280/** Pointer to an audio test error description. */
281typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
282
283/**
284 * Structure for holding an audio test error description.
285 * This can contain multiple errors (FIFO list).
286 */
287typedef struct AUDIOTESTERRORDESC
288{
289 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
290 RTLISTANCHOR List;
291 /** Number of errors in the list. */
292 uint32_t cErrors;
293} AUDIOTESTERRORDESC;
294/** Pointer to an audio test error description. */
295typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
296/** Const pointer to an audio test error description. */
297typedef AUDIOTESTERRORDESC const *PCAUDIOTESTERRORDESC;
298
299double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
300double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
301double AudioTestToneGetRandomFreq(void);
302int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
303
304int AudioTestGenTag(char *pszTag, size_t cbTag);
305
306int AudioTestPathGetTemp(char *pszPath, size_t cbPath);
307int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
308int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
309
310int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ pObj);
311
312int AudioTestObjWrite(AUDIOTESTOBJ Obj, const void *pvBuf, size_t cbBuf);
313int AudioTestObjAddMetadataStr(AUDIOTESTOBJ Obj, const char *pszFormat, ...);
314int AudioTestObjClose(AUDIOTESTOBJ Obj);
315
316int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
317int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
318int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
319bool AudioTestSetTestIsRunning(PAUDIOTESTENTRY pEntry);
320
321int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
322int AudioTestSetDestroy(PAUDIOTESTSET pSet);
323int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
324int AudioTestSetClose(PAUDIOTESTSET pSet);
325int AudioTestSetWipe(PAUDIOTESTSET pSet);
326const char *AudioTestSetGetTag(PAUDIOTESTSET pSet);
327uint32_t AudioTestSetGetTestsTotal(PAUDIOTESTSET pSet);
328uint32_t AudioTestSetGetTestsRunning(PAUDIOTESTSET pSet);
329uint32_t AudioTestSetGetTotalFailures(PAUDIOTESTSET pSet);
330bool AudioTestSetIsPacked(const char *pszPath);
331bool AudioTestSetIsRunning(PAUDIOTESTSET pSet);
332int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
333int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
334
335void AudioTestSetVerifyOptsInitStrict(PAUDIOTESTVERIFYOPTS pOpts);
336void AudioTestSetVerifyOptsInit(PAUDIOTESTVERIFYOPTS pOpts);
337bool AudioTestSetVerifyOptsAreEqual(PAUDIOTESTVERIFYOPTS pOptsA, PAUDIOTESTVERIFYOPTS pOptsB);
338
339int AudioTestSetVerify(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTERRORDESC pErrDesc);
340int AudioTestSetVerifyEx(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTVERIFYOPTS pOpts, PAUDIOTESTERRORDESC pErrDesc);
341
342uint32_t AudioTestErrorDescCount(PCAUDIOTESTERRORDESC pErr);
343bool AudioTestErrorDescFailed(PCAUDIOTESTERRORDESC pErr);
344
345void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
346
347/** @name Wave File Accessors
348 * @{ */
349/**
350 * An open wave (.WAV) file.
351 */
352typedef struct AUDIOTESTWAVEFILE
353{
354 /** Magic value (AUDIOTESTWAVEFILE_MAGIC). */
355 uint32_t u32Magic;
356 /** Set if we're in read-mode, clear if in write mode. */
357 bool fReadMode;
358 /** The file handle. */
359 RTFILE hFile;
360 /** The absolute file offset of the first sample */
361 uint32_t offSamples;
362 /** Number of bytes of samples. */
363 uint32_t cbSamples;
364 /** The current read position relative to @a offSamples. */
365 uint32_t offCur;
366 /** The PCM properties for the file format. */
367 PDMAUDIOPCMPROPS Props;
368} AUDIOTESTWAVEFILE;
369/** Pointer to an open wave file. */
370typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
371
372/** Magic value for AUDIOTESTWAVEFILE::u32Magic (Miles Dewey Davis III). */
373#define AUDIOTESTWAVEFILE_MAGIC UINT32_C(0x19260526)
374/** Magic value for AUDIOTESTWAVEFILE::u32Magic after closing. */
375#define AUDIOTESTWAVEFILE_MAGIC_DEAD UINT32_C(0x19910928)
376
377int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
378int AudioTestWaveFileCreate(const char *pszFile, PCPDMAUDIOPCMPROPS pProps, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
379int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
380int AudioTestWaveFileWrite(PAUDIOTESTWAVEFILE pWaveFile, const void *pvBuf, size_t cbBuf);
381int AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
382
383/** @} */
384
385#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
386
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette