VirtualBox

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

Last change on this file since 89311 was 89308, checked in by vboxsync, 4 years ago

Audio/ValKit: Various small bugfixes for writing the test manifest file. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
Line 
1/* $Id: AudioTest.h 89308 2021-05-27 09:36:18Z 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 /** Name of the test object.
188 * Must not contain a path and has to be able to serialize to disk. */
189 char szName[64];
190 /** The object type. */
191 AUDIOTESTOBJTYPE enmType;
192 /** Union for holding the object type-specific data. */
193 union
194 {
195 AUDIOTESTOBJFILE File;
196 };
197} AUDIOTESTOBJ;
198/** Pointer to an audio test object. */
199typedef AUDIOTESTOBJ *PAUDIOTESTOBJ;
200
201struct AUDIOTESTSET;
202
203typedef struct AUDIOTESTENTRY
204{
205 /** List node. */
206 RTLISTNODE Node;
207 AUDIOTESTSET *pParent;
208 char szDesc[64];
209 AUDIOTESTPARMS Parms;
210 int rc;
211} AUDIOTESTENTRY;
212/** Pointer to an audio test entry. */
213typedef AUDIOTESTENTRY *PAUDIOTESTENTRY;
214
215/**
216 * Structure specifying an audio test set.
217 */
218typedef struct AUDIOTESTSET
219{
220 /** The set's tag. */
221 char szTag[AUDIOTEST_TAG_MAX];
222 /** Absolute path where to store the test audio data. */
223 char szPathAbs[RTPATH_MAX];
224 /** Current mode the test set is in. */
225 AUDIOTESTSETMODE enmMode;
226 union
227 {
228 /** @todo r=bird: RTSTREAM not RTFILE. That means you don't have to check
229 * every write status code and it's buffered and thus faster. Also,
230 * you don't have to re-invent fprintf-style RTFileWrite wrappers. */
231 RTFILE hFile;
232 RTINIFILE hIniFile;
233 } f;
234 /** Number of test objects in lstObj. */
235 uint32_t cObj;
236 /** List containing PAUDIOTESTOBJ test object entries. */
237 RTLISTANCHOR lstObj;
238 /** Number of performed tests.
239 * Not necessarily bound to the test object entries above. */
240 uint32_t cTests;
241 /** Absolute offset (in bytes) where to write the "test_count" value later. */
242 uint64_t offTestCount;
243 /** List containing PAUDIOTESTENTRY test entries. */
244 RTLISTANCHOR lstTest;
245 /** Number of tests currently running. */
246 uint32_t cTestsRunning;
247 /** Number of total (test) failures. */
248 uint32_t cTotalFailures;
249} AUDIOTESTSET;
250/** Pointer to an audio test set. */
251typedef AUDIOTESTSET *PAUDIOTESTSET;
252
253/**
254 * Structure for holding a single audio test error entry.
255 */
256typedef struct AUDIOTESTERRORENTRY
257{
258 /** The entrie's list node. */
259 RTLISTNODE Node;
260 /** Additional rc. */
261 int rc;
262 /** Actual error description. */
263 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
264} AUDIOTESTERRORENTRY;
265/** Pointer to an audio test error description. */
266typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
267
268/**
269 * Structure for holding an audio test error description.
270 * This can contain multiple errors (FIFO list).
271 */
272typedef struct AUDIOTESTERRORDESC
273{
274 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
275 RTLISTANCHOR List;
276 /** Number of errors in the list. */
277 uint32_t cErrors;
278} AUDIOTESTERRORDESC;
279/** Pointer to an audio test error description. */
280typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
281
282/**
283 * An open wave (.WAV) file.
284 */
285typedef struct AUDIOTESTWAVEFILE
286{
287 /** The file handle. */
288 RTFILE hFile;
289 /** The absolute file offset of the first sample */
290 uint32_t offSamples;
291 /** Number of bytes of samples. */
292 uint32_t cbSamples;
293 /** The current read position relative to @a offSamples. */
294 uint32_t offCur;
295 /** The PCM properties for the file format. */
296 PDMAUDIOPCMPROPS Props;
297} AUDIOTESTWAVEFILE;
298/** Pointer to an open wave file. */
299typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
300
301
302double AudioTestToneInit(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps, double dbFreq);
303double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
304int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
305
306int AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps);
307
308int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
309int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
310
311int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj);
312int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf);
313int AudioTestSetObjClose(PAUDIOTESTOBJ pObj);
314
315int AudioTestSetTestBegin(PAUDIOTESTSET pSet, const char *pszDesc, PAUDIOTESTPARMS pParms, PAUDIOTESTENTRY *ppEntry);
316int AudioTestSetTestFailed(PAUDIOTESTENTRY pEntry, int rc, const char *pszErr);
317int AudioTestSetTestDone(PAUDIOTESTENTRY pEntry);
318
319int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
320int AudioTestSetDestroy(PAUDIOTESTSET pSet);
321int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
322int AudioTestSetClose(PAUDIOTESTSET pSet);
323int AudioTestSetWipe(PAUDIOTESTSET pSet);
324bool AudioTestSetIsPacked(const char *pszPath);
325int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
326int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
327int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc);
328
329bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr);
330void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
331
332int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile);
333int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
334void AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
335
336#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
337
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