VirtualBox

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

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

Audio/Validation Kit: A bit more code for the audio data beacons. ​bugref:10008

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