VirtualBox

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

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

Audio/Validation Kit: Initial implementation of two-pass audio data normalization, which is done before working on the data. Also, a search window has been added when treating / classifying audio data. ​bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1/* $Id: AudioTest.h 91505 2021-10-01 10:15:58Z 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
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 /** Whether to perform audio normalization or not. */
256 bool fNormalize;
257 /** Threshold of file differences (number of chunks) at when we consider audio files
258 * as not matching. 0 means an exact match. */
259 uint32_t cMaxDiff;
260 /** Threshold of file differences (difference in percent) at when we consider audio files
261 * as not matching. 0 means an exact match. */
262 uint8_t uMaxDiffPercent;
263 /** Threshold of file size (+/-, in percent) at when we consider audio files
264 * as not matching. 0 means an exact match.*/
265 uint8_t uMaxSizePercent;
266 /** Search window (in ms) to use for treating / classifying audio data. */
267 uint32_t msSearchWindow;
268} AUDIOTESTVERIFYOPTS;
269/** Pointer to audio test verification options. */
270typedef AUDIOTESTVERIFYOPTS *PAUDIOTESTVERIFYOPTS;
271
272/**
273 * Structure for holding a single audio test error entry.
274 */
275typedef struct AUDIOTESTERRORENTRY
276{
277 /** The entrie's list node. */
278 RTLISTNODE Node;
279 /** Additional rc. */
280 int rc;
281 /** Actual error description. */
282 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
283} AUDIOTESTERRORENTRY;
284/** Pointer to an audio test error description. */
285typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
286
287/**
288 * Structure for holding an audio test error description.
289 * This can contain multiple errors (FIFO list).
290 */
291typedef struct AUDIOTESTERRORDESC
292{
293 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
294 RTLISTANCHOR List;
295 /** Number of errors in the list. */
296 uint32_t cErrors;
297} AUDIOTESTERRORDESC;
298/** Pointer to an audio test error description. */
299typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
300/** Const pointer to an audio test error description. */
301typedef AUDIOTESTERRORDESC const *PCAUDIOTESTERRORDESC;
302
303double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
304double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
305double AudioTestToneGetRandomFreq(void);
306int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
307
308int AudioTestGenTag(char *pszTag, size_t cbTag);
309
310int AudioTestPathGetTemp(char *pszPath, size_t cbPath);
311int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
312int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
313
314int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ pObj);
315
316int AudioTestObjWrite(AUDIOTESTOBJ Obj, const void *pvBuf, size_t cbBuf);
317int AudioTestObjAddMetadataStr(AUDIOTESTOBJ Obj, const char *pszFormat, ...);
318int AudioTestObjClose(AUDIOTESTOBJ Obj);
319
320int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
321int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
322int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
323bool AudioTestSetTestIsRunning(PAUDIOTESTENTRY pEntry);
324
325int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
326int AudioTestSetDestroy(PAUDIOTESTSET pSet);
327int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
328int AudioTestSetClose(PAUDIOTESTSET pSet);
329int AudioTestSetWipe(PAUDIOTESTSET pSet);
330const char *AudioTestSetGetTag(PAUDIOTESTSET pSet);
331uint32_t AudioTestSetGetTestsTotal(PAUDIOTESTSET pSet);
332uint32_t AudioTestSetGetTestsRunning(PAUDIOTESTSET pSet);
333uint32_t AudioTestSetGetTotalFailures(PAUDIOTESTSET pSet);
334bool AudioTestSetIsPacked(const char *pszPath);
335bool AudioTestSetIsRunning(PAUDIOTESTSET pSet);
336int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
337int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
338
339void AudioTestSetVerifyOptsInitStrict(PAUDIOTESTVERIFYOPTS pOpts);
340void AudioTestSetVerifyOptsInit(PAUDIOTESTVERIFYOPTS pOpts);
341bool AudioTestSetVerifyOptsAreEqual(PAUDIOTESTVERIFYOPTS pOptsA, PAUDIOTESTVERIFYOPTS pOptsB);
342
343int AudioTestSetVerify(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTERRORDESC pErrDesc);
344int AudioTestSetVerifyEx(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTVERIFYOPTS pOpts, PAUDIOTESTERRORDESC pErrDesc);
345
346uint32_t AudioTestErrorDescCount(PCAUDIOTESTERRORDESC pErr);
347bool AudioTestErrorDescFailed(PCAUDIOTESTERRORDESC pErr);
348
349void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
350
351/** @name Wave File Accessors
352 * @{ */
353/**
354 * An open wave (.WAV) file.
355 */
356typedef struct AUDIOTESTWAVEFILE
357{
358 /** Magic value (AUDIOTESTWAVEFILE_MAGIC). */
359 uint32_t u32Magic;
360 /** Set if we're in read-mode, clear if in write mode. */
361 bool fReadMode;
362 /** The file handle. */
363 RTFILE hFile;
364 /** The absolute file offset of the first sample */
365 uint32_t offSamples;
366 /** Number of bytes of samples. */
367 uint32_t cbSamples;
368 /** The current read position relative to @a offSamples. */
369 uint32_t offCur;
370 /** The PCM properties for the file format. */
371 PDMAUDIOPCMPROPS Props;
372} AUDIOTESTWAVEFILE;
373/** Pointer to an open wave file. */
374typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
375
376/** Magic value for AUDIOTESTWAVEFILE::u32Magic (Miles Dewey Davis III). */
377#define AUDIOTESTWAVEFILE_MAGIC UINT32_C(0x19260526)
378/** Magic value for AUDIOTESTWAVEFILE::u32Magic after closing. */
379#define AUDIOTESTWAVEFILE_MAGIC_DEAD UINT32_C(0x19910928)
380
381int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
382int AudioTestWaveFileCreate(const char *pszFile, PCPDMAUDIOPCMPROPS pProps, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
383int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
384int AudioTestWaveFileWrite(PAUDIOTESTWAVEFILE pWaveFile, const void *pvBuf, size_t cbBuf);
385int AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
386
387/** @} */
388
389#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
390
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