VirtualBox

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

Last change on this file since 89333 was 89316, checked in by vboxsync, 4 years ago

Audio/ValKit: Implemented handling for meta data of test (set) objects. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: AudioTest.h 89316 2021-05-27 12:31:34Z 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 handling audio test tone parameters.
75 */
76typedef struct AUDIOTESTTONEPARMS
77{
78 /** The PCM properties. */
79 PDMAUDIOPCMPROPS Props;
80 /** Tone frequency (in Hz) to use.
81 * Will be later converted to a double value. */
82 double dbFreqHz;
83 /** Prequel (in ms) to play silence. Optional and can be set to 0. */
84 RTMSINTERVAL msPrequel;
85 /** Duration (in ms) to play the test tone. */
86 RTMSINTERVAL msDuration;
87 /** Sequel (in ms) to play silence. Optional and can be set to 0. */
88 RTMSINTERVAL msSequel;
89 /** Volume (in percent, 0-100) to use.
90 * If set to 0, the tone is muted (i.e. silent). */
91 uint8_t uVolumePercent;
92} AUDIOTESTTONEPARMS;
93/** Pointer to audio test tone parameters. */
94typedef AUDIOTESTTONEPARMS *PAUDIOTESTTONEPARMS;
95
96/**
97 * Enumeration for the test set mode.
98 */
99typedef enum AUDIOTESTSETMODE
100{
101 /** Invalid test set mode. */
102 AUDIOTESTSETMODE_INVALID = 0,
103 /** Test set is being created (testing in progress). */
104 AUDIOTESTSETMODE_TEST,
105 /** Existing test set is being verified. */
106 AUDIOTESTSETMODE_VERIFY,
107 /** The usual 32-bit hack. */
108 AUDIOTESTSETMODE_32BIT_HACK = 0x7fffffff
109} AUDIOTESTSETMODE;
110
111/**
112 * Enumeration to specify an audio test type.
113 */
114typedef enum AUDIOTESTTYPE
115{
116 /** Invalid test type, do not use. */
117 AUDIOTESTTYPE_INVALID = 0,
118 /** Play a test tone. */
119 AUDIOTESTTYPE_TESTTONE_PLAY,
120 /** Record a test tone. */
121 AUDIOTESTTYPE_TESTTONE_RECORD,
122 /** The usual 32-bit hack. */
123 AUDIOTESTTYPE_32BIT_HACK = 0x7fffffff
124} AUDIOTESTTYPE;
125
126/**
127 * Audio test request data.
128 */
129typedef struct AUDIOTESTPARMS
130{
131 /** Specifies the current test iteration. */
132 uint32_t idxCurrent;
133 /** How many iterations the test should be executed. */
134 uint32_t cIterations;
135 /** PCM audio stream properties to use. */
136 PDMAUDIOPCMPROPS Props;
137 /** Audio device to use. */
138 PDMAUDIOHOSTDEV Dev;
139 /** How much to delay (wait, in ms) the test being executed. */
140 RTMSINTERVAL msDelay;
141 /** The test direction. */
142 PDMAUDIODIR enmDir;
143 /** The test type. */
144 AUDIOTESTTYPE enmType;
145 /** Union for test type-specific data. */
146 union
147 {
148 AUDIOTESTTONEPARMS TestTone;
149 };
150} AUDIOTESTPARMS;
151/** Pointer to a test parameter structure. */
152typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
153
154/**
155 * Enumeration for an audio test object type.
156 */
157typedef enum AUDIOTESTOBJTYPE
158{
159 /** Unknown / invalid, do not use. */
160 AUDIOTESTOBJTYPE_UNKNOWN = 0,
161 /** The test object is a file. */
162 AUDIOTESTOBJTYPE_FILE,
163 /** The usual 32-bit hack. */
164 AUDIOTESTOBJTYPE_32BIT_HACK = 0x7fffffff
165} AUDIOTESTOBJTYPE;
166
167/**
168 * Structure for keeping an audio test object file.
169 */
170typedef struct AUDIOTESTOBJFILE
171{
172 RTFILE hFile;
173} AUDIOTESTOBJFILE;
174/** Pointer to an audio test object file. */
175typedef AUDIOTESTOBJFILE *PAUDIOTESTOBJFILE;
176
177/**
178 * Structure for keeping a single audio test object.
179 *
180 * A test object is data which is needed in order to perform and verify one or
181 * more audio test case(s).
182 */
183typedef struct AUDIOTESTOBJ
184{
185 /** List node. */
186 RTLISTNODE Node;
187 RTUUID Uuid;
188 /** Number of references to this test object. */
189 uint32_t cRefs;
190 /** Name of the test object.
191 * Must not contain a path and has to be able to serialize to disk. */
192 char szName[64];
193 /** The object type. */
194 AUDIOTESTOBJTYPE enmType;
195 /** Union for holding the object type-specific data. */
196 union
197 {
198 AUDIOTESTOBJFILE File;
199 };
200} AUDIOTESTOBJ;
201/** Pointer to an audio test object. */
202typedef AUDIOTESTOBJ *PAUDIOTESTOBJ;
203
204struct AUDIOTESTSET;
205
206typedef struct AUDIOTESTENTRY
207{
208 /** List node. */
209 RTLISTNODE Node;
210 AUDIOTESTSET *pParent;
211 char szDesc[64];
212 AUDIOTESTPARMS Parms;
213 /** Number of test objects bound to this test. */
214 uint32_t cObj;
215 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
216 uint64_t offObjCount;
217 int rc;
218} AUDIOTESTENTRY;
219/** Pointer to an audio test entry. */
220typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
221
222/**
223 * Structure specifying an audio test set.
224 */
225typedef struct AUDIOTESTSET
226{
227 /** The set's tag. */
228 char szTag[AUDIOTEST_TAG_MAX];
229 /** Absolute path where to store the test audio data. */
230 char szPathAbs[RTPATH_MAX];
231 /** Current mode the test set is in. */
232 AUDIOTESTSETMODE enmMode;
233 union
234 {
235 /** @todo r=bird: RTSTREAM not RTFILE. That means you don't have to check
236 * every write status code and it's buffered and thus faster. Also,
237 * you don't have to re-invent fprintf-style RTFileWrite wrappers. */
238 RTFILE hFile;
239 RTINIFILE hIniFile;
240 } f;
241 /** Number of test objects in lstObj. */
242 uint32_t cObj;
243 /** Absolute offset (in bytes) where to write the "obj_count" value later. */
244 uint64_t offObjCount;
245 /** List containing PAUDIOTESTOBJ test object entries. */
246 RTLISTANCHOR lstObj;
247 /** Number of performed tests.
248 * Not necessarily bound to the test object entries above. */
249 uint32_t cTests;
250 /** Absolute offset (in bytes) where to write the "test_count" value later. */
251 uint64_t offTestCount;
252 /** List containing PAUDIOTESTENTRY test entries. */
253 RTLISTANCHOR lstTest;
254 /** Current test running. Can be NULL if no test is running. */
255 PAUDIOTESTENTRY pTestCur;
256 /** Number of tests currently running.
257 * Currently we only allow one concurrent test running at a given time. */
258 uint32_t cTestsRunning;
259 /** Number of total (test) failures. */
260 uint32_t cTotalFailures;
261} AUDIOTESTSET;
262/** Pointer to an audio test set. */
263typedef AUDIOTESTSET *PAUDIOTESTSET;
264
265/**
266 * Structure for holding a single audio test error entry.
267 */
268typedef struct AUDIOTESTERRORENTRY
269{
270 /** The entrie's list node. */
271 RTLISTNODE Node;
272 /** Additional rc. */
273 int rc;
274 /** Actual error description. */
275 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
276} AUDIOTESTERRORENTRY;
277/** Pointer to an audio test error description. */
278typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
279
280/**
281 * Structure for holding an audio test error description.
282 * This can contain multiple errors (FIFO list).
283 */
284typedef struct AUDIOTESTERRORDESC
285{
286 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
287 RTLISTANCHOR List;
288 /** Number of errors in the list. */
289 uint32_t cErrors;
290} AUDIOTESTERRORDESC;
291/** Pointer to an audio test error description. */
292typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
293
294/**
295 * An open wave (.WAV) file.
296 */
297typedef struct AUDIOTESTWAVEFILE
298{
299 /** The file handle. */
300 RTFILE hFile;
301 /** The absolute file offset of the first sample */
302 uint32_t offSamples;
303 /** Number of bytes of samples. */
304 uint32_t cbSamples;
305 /** The current read position relative to @a offSamples. */
306 uint32_t offCur;
307 /** The PCM properties for the file format. */
308 PDMAUDIOPCMPROPS Props;
309} AUDIOTESTWAVEFILE;
310/** Pointer to an open wave file. */
311typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
312
313
314double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
315double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
316int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
317
318int AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps);
319
320int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
321int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
322
323int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj);
324int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf);
325int AudioTestSetObjClose(PAUDIOTESTOBJ pObj);
326
327int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
328int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
329int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
330
331int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
332int AudioTestSetDestroy(PAUDIOTESTSET pSet);
333int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
334int AudioTestSetClose(PAUDIOTESTSET pSet);
335int AudioTestSetWipe(PAUDIOTESTSET pSet);
336bool AudioTestSetIsPacked(const char *pszPath);
337int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
338int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
339int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc);
340
341bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr);
342void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
343
344int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile);
345int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
346void AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
347
348#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
349
Note: See TracBrowser for help on using the repository browser.

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