VirtualBox

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

最後變更 在這個檔案從91632是 91632,由 vboxsync 提交於 3 年 前

Audio/Validation Kit: Factored out general I/O options into AUDIOTESTIOOPTS to also support setting the master volume besides the test tone volume, as function parameter lists already were too big. Also uniformed the command line volume arguments a little ("--vol vs. --volume" everywhere). ​bugref:10008

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 14.3 KB
 
1/* $Id: AudioTest.h 91632 2021-10-08 06:59:29Z 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 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 /** Audio device to use. */
153 PDMAUDIOHOSTDEV Dev;
154 /** How much to delay (wait, in ms) the test being executed. */
155 RTMSINTERVAL msDelay;
156 /** The test direction. */
157 PDMAUDIODIR enmDir;
158 /** The test type. */
159 AUDIOTESTTYPE enmType;
160 /** Union for test type-specific data. */
161 union
162 {
163 AUDIOTESTTONEPARMS TestTone;
164 };
165} AUDIOTESTPARMS;
166/** Pointer to a test parameter structure. */
167typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
168
169/** Test object handle. */
170typedef R3R0PTRTYPE(struct AUDIOTESTOBJINT RT_FAR *) AUDIOTESTOBJ;
171/** Pointer to test object handle. */
172typedef AUDIOTESTOBJ RT_FAR *PAUDIOTESTOBJ;
173/** Nil test object handle. */
174#define NIL_AUDIOTESTOBJ ((AUDIOTESTOBJ)~(RTHCINTPTR)0)
175
176struct AUDIOTESTSET;
177
178/**
179 * Structure specifying a single audio test entry of a test set.
180 *
181 * A test set can contain zero or more test entry (tests).
182 */
183typedef struct AUDIOTESTENTRY
184{
185 /** List node. */
186 RTLISTNODE Node;
187 /** Pointer to test set parent. */
188 AUDIOTESTSET *pParent;
189 /** Friendly description of the test. */
190 char szDesc[64];
191 /** Audio test parameters this test needs to perform the actual test. */
192 AUDIOTESTPARMS Parms;
193 /** Number of test objects bound to this test. */
194 uint32_t cObj;
195 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
196 uint64_t offObjCount;
197 /** Overall test result. */
198 int rc;
199} AUDIOTESTENTRY;
200/** Pointer to an audio test entry. */
201typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
202
203/**
204 * Structure specifying an audio test set.
205 */
206typedef struct AUDIOTESTSET
207{
208 /** The set's tag. */
209 char szTag[AUDIOTEST_TAG_MAX];
210 /** Absolute path where to store the test audio data. */
211 char szPathAbs[RTPATH_MAX];
212 /** Current mode the test set is in. */
213 AUDIOTESTSETMODE enmMode;
214 union
215 {
216 /** @todo r=bird: RTSTREAM not RTFILE. That means you don't have to check
217 * every write status code and it's buffered and thus faster. Also,
218 * you don't have to re-invent fprintf-style RTFileWrite wrappers. */
219 RTFILE hFile;
220 RTINIFILE hIniFile;
221 } f;
222 /** Number of test objects in lstObj. */
223 uint32_t cObj;
224 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
225 uint64_t offObjCount;
226 /** List containing PAUDIOTESTOBJ test object entries. */
227 RTLISTANCHOR lstObj;
228 /** Number of performed tests.
229 * Not necessarily bound to the test object entries above. */
230 uint32_t cTests;
231 /** Absolute offset (in bytes) where to write the "test_count" value later. */
232 uint64_t offTestCount;
233 /** List containing PAUDIOTESTENTRY test entries. */
234 RTLISTANCHOR lstTest;
235 /** Current test running. Can be NULL if no test is running. */
236 PAUDIOTESTENTRY pTestCur;
237 /** Number of tests currently running.
238 * Currently we only allow one concurrent test running at a given time. */
239 uint32_t cTestsRunning;
240 /** Number of total (test) failures. */
241 uint32_t cTotalFailures;
242} AUDIOTESTSET;
243/** Pointer to an audio test set. */
244typedef AUDIOTESTSET *PAUDIOTESTSET;
245
246/**
247 * Audio test verification options.
248 */
249typedef struct AUDIOTESTVERIFYOPTS
250{
251 /** Flag indicating whether to keep going after an error has occurred. */
252 bool fKeepGoing;
253 /** Whether to perform audio normalization or not. */
254 bool fNormalize;
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 /** Search window (in ms) to use for treating / classifying audio data. */
265 uint32_t msSearchWindow;
266} AUDIOTESTVERIFYOPTS;
267/** Pointer to audio test verification options. */
268typedef AUDIOTESTVERIFYOPTS *PAUDIOTESTVERIFYOPTS;
269
270/**
271 * Structure for holding a single audio test error entry.
272 */
273typedef struct AUDIOTESTERRORENTRY
274{
275 /** The entrie's list node. */
276 RTLISTNODE Node;
277 /** Additional rc. */
278 int rc;
279 /** Actual error description. */
280 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
281} AUDIOTESTERRORENTRY;
282/** Pointer to an audio test error description. */
283typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
284
285/**
286 * Structure for holding an audio test error description.
287 * This can contain multiple errors (FIFO list).
288 */
289typedef struct AUDIOTESTERRORDESC
290{
291 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
292 RTLISTANCHOR List;
293 /** Number of errors in the list. */
294 uint32_t cErrors;
295} AUDIOTESTERRORDESC;
296/** Pointer to an audio test error description. */
297typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
298/** Const pointer to an audio test error description. */
299typedef AUDIOTESTERRORDESC const *PCAUDIOTESTERRORDESC;
300
301double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
302double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
303double AudioTestToneGetRandomFreq(void);
304int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
305
306int AudioTestGenTag(char *pszTag, size_t cbTag);
307
308int AudioTestPathGetTemp(char *pszPath, size_t cbPath);
309int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
310int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
311
312int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ pObj);
313
314int AudioTestObjWrite(AUDIOTESTOBJ Obj, const void *pvBuf, size_t cbBuf);
315int AudioTestObjAddMetadataStr(AUDIOTESTOBJ Obj, const char *pszFormat, ...);
316int AudioTestObjClose(AUDIOTESTOBJ Obj);
317
318int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
319int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
320int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
321bool AudioTestSetTestIsRunning(PAUDIOTESTENTRY pEntry);
322
323int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
324int AudioTestSetDestroy(PAUDIOTESTSET pSet);
325int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
326int AudioTestSetClose(PAUDIOTESTSET pSet);
327int AudioTestSetWipe(PAUDIOTESTSET pSet);
328const char *AudioTestSetGetTag(PAUDIOTESTSET pSet);
329uint32_t AudioTestSetGetTestsTotal(PAUDIOTESTSET pSet);
330uint32_t AudioTestSetGetTestsRunning(PAUDIOTESTSET pSet);
331uint32_t AudioTestSetGetTotalFailures(PAUDIOTESTSET pSet);
332bool AudioTestSetIsPacked(const char *pszPath);
333bool AudioTestSetIsRunning(PAUDIOTESTSET pSet);
334int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
335int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
336
337void AudioTestSetVerifyOptsInitStrict(PAUDIOTESTVERIFYOPTS pOpts);
338void AudioTestSetVerifyOptsInit(PAUDIOTESTVERIFYOPTS pOpts);
339bool AudioTestSetVerifyOptsAreEqual(PAUDIOTESTVERIFYOPTS pOptsA, PAUDIOTESTVERIFYOPTS pOptsB);
340
341int AudioTestSetVerify(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTERRORDESC pErrDesc);
342int AudioTestSetVerifyEx(PAUDIOTESTSET pSetA, PAUDIOTESTSET pSetB, PAUDIOTESTVERIFYOPTS pOpts, PAUDIOTESTERRORDESC pErrDesc);
343
344uint32_t AudioTestErrorDescCount(PCAUDIOTESTERRORDESC pErr);
345bool AudioTestErrorDescFailed(PCAUDIOTESTERRORDESC pErr);
346
347void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
348
349/** @name Wave File Accessors
350 * @{ */
351/**
352 * An open wave (.WAV) file.
353 */
354typedef struct AUDIOTESTWAVEFILE
355{
356 /** Magic value (AUDIOTESTWAVEFILE_MAGIC). */
357 uint32_t u32Magic;
358 /** Set if we're in read-mode, clear if in write mode. */
359 bool fReadMode;
360 /** The file handle. */
361 RTFILE hFile;
362 /** The absolute file offset of the first sample */
363 uint32_t offSamples;
364 /** Number of bytes of samples. */
365 uint32_t cbSamples;
366 /** The current read position relative to @a offSamples. */
367 uint32_t offCur;
368 /** The PCM properties for the file format. */
369 PDMAUDIOPCMPROPS Props;
370} AUDIOTESTWAVEFILE;
371/** Pointer to an open wave file. */
372typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
373
374/** Magic value for AUDIOTESTWAVEFILE::u32Magic (Miles Dewey Davis III). */
375#define AUDIOTESTWAVEFILE_MAGIC UINT32_C(0x19260526)
376/** Magic value for AUDIOTESTWAVEFILE::u32Magic after closing. */
377#define AUDIOTESTWAVEFILE_MAGIC_DEAD UINT32_C(0x19910928)
378
379int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
380int AudioTestWaveFileCreate(const char *pszFile, PCPDMAUDIOPCMPROPS pProps, PAUDIOTESTWAVEFILE pWaveFile, PRTERRINFO pErrInfo);
381int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
382int AudioTestWaveFileWrite(PAUDIOTESTWAVEFILE pWaveFile, const void *pvBuf, size_t cbBuf);
383int AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
384
385/** @} */
386
387#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
388
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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