VirtualBox

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

Last change on this file since 89089 was 89072, checked in by vboxsync, 4 years ago

Audio/ValKit: Moved the AudioTestWaveXXX functions to AudioTest.cpp so those can also be used for injecting input (recording) data later. bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: AudioTest.h 89072 2021-05-17 07:20:36Z 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 /** Prequel (in ms) to play silence. Optional and can be set to 0. */
81 RTMSINTERVAL msPrequel;
82 /** Duration (in ms) to play the test tone. */
83 RTMSINTERVAL msDuration;
84 /** Sequel (in ms) to play silence. Optional and can be set to 0. */
85 RTMSINTERVAL msSequel;
86 /** Volume (in percent, 0-100) to use.
87 * If set to 0, the tone is muted (i.e. silent). */
88 uint8_t uVolumePercent;
89} AUDIOTESTTONEPARMS;
90/** Pointer to audio test tone parameters. */
91typedef AUDIOTESTTONEPARMS *PAUDIOTESTTONEPARMS;
92
93/**
94 * Structure for keeping an audio test audio stream.
95 */
96typedef struct AUDIOTESTSTREAM
97{
98 /** Created flag to avoid double destruction in backends. */
99 bool fCreated;
100 /** Backend-specific stream data. */
101 PDMAUDIOBACKENDSTREAM Backend;
102} AUDIOTESTSTREAM;
103/** Pointer to audio test stream. */
104typedef AUDIOTESTSTREAM *PAUDIOTESTSTREAM;
105
106/**
107 * Enumeration for the test set mode.
108 */
109typedef enum AUDIOTESTSETMODE
110{
111 /** Invalid test set mode. */
112 AUDIOTESTSETMODE_INVALID = 0,
113 /** Test set is being created (testing in progress). */
114 AUDIOTESTSETMODE_TEST,
115 /** Existing test set is being verified. */
116 AUDIOTESTSETMODE_VERIFY,
117 /** The usual 32-bit hack. */
118 AUDIOTESTSETMODE_32BIT_HACK = 0x7fffffff
119} AUDIOTESTSETMODE;
120
121/**
122 * Enumeration to specify an audio test type.
123 */
124typedef enum AUDIOTESTTYPE
125{
126 /** Invalid test type, do not use. */
127 AUDIOTESTTYPE_INVALID = 0,
128 /** Play a test tone. */
129 AUDIOTESTTYPE_TESTTONE,
130 /** The usual 32-bit hack. */
131 AUDIOTESTTYPE_32BIT_HACK = 0x7fffffff
132} AUDIOTESTTYPE;
133
134/**
135 * Audio test request data.
136 */
137typedef struct AUDIOTESTPARMS
138{
139 /** Specifies the current test iteration. */
140 uint32_t idxCurrent;
141 /** How many iterations the test should be executed. */
142 uint32_t cIterations;
143 /** Audio device to use. */
144 PDMAUDIOHOSTDEV Dev;
145 /** How much to delay (wait, in ms) the test being executed. */
146 RTMSINTERVAL msDelay;
147 /** The test direction. */
148 PDMAUDIODIR enmDir;
149 /** The test type. */
150 AUDIOTESTTYPE enmType;
151 /** Union for test type-specific data. */
152 union
153 {
154 AUDIOTESTTONEPARMS TestTone;
155 };
156} AUDIOTESTPARMS;
157/** Pointer to a test parameter structure. */
158typedef AUDIOTESTPARMS *PAUDIOTESTPARMS;
159
160typedef enum AUDIOTESTOBJTYPE
161{
162 AUDIOTESTOBJTYPE_UNKNOWN = 0,
163 AUDIOTESTOBJTYPE_FILE,
164 /** The usual 32-bit hack. */
165 AUDIOTESTOBJTYPE_32BIT_HACK = 0x7fffffff
166} AUDIOTESTOBJTYPE;
167
168typedef struct AUDIOTESTOBJFILE
169{
170 RTFILE hFile;
171} AUDIOTESTOBJFILE;
172
173typedef struct AUDIOTESTOBJ
174{
175 RTLISTNODE Node;
176 char szName[64];
177 AUDIOTESTOBJTYPE enmType;
178 union
179 {
180 AUDIOTESTOBJFILE File;
181 };
182} AUDIOTESTOBJ;
183/** Pointer to an audio test object. */
184typedef AUDIOTESTOBJ *PAUDIOTESTOBJ;
185
186/**
187 * Structure specifying an audio test set.
188 */
189typedef struct AUDIOTESTSET
190{
191 /** The set's tag. */
192 char szTag[AUDIOTEST_TAG_MAX];
193 /** Absolute path where to store the test audio data. */
194 char szPathAbs[RTPATH_MAX];
195 /** Current mode the test set is in. */
196 AUDIOTESTSETMODE enmMode;
197 union
198 {
199 RTFILE hFile;
200 RTINIFILE hIniFile;
201 } f;
202 uint32_t cObj;
203 RTLISTANCHOR lstObj;
204} AUDIOTESTSET;
205/** Pointer to an audio test set. */
206typedef AUDIOTESTSET *PAUDIOTESTSET;
207
208/**
209 * Structure for holding a single audio test error entry.
210 */
211typedef struct AUDIOTESTERRORENTRY
212{
213 /** The entrie's list node. */
214 RTLISTNODE Node;
215 /** Additional rc. */
216 int rc;
217 /** Actual error description. */
218 char szDesc[AUDIOTEST_ERROR_DESC_MAX];
219} AUDIOTESTERRORENTRY;
220/** Pointer to an audio test error description. */
221typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY;
222
223/**
224 * Structure for holding an audio test error description.
225 * This can contain multiple errors (FIFO list).
226 */
227typedef struct AUDIOTESTERRORDESC
228{
229 /** List entries containing the (FIFO-style) errors of type AUDIOTESTERRORENTRY. */
230 RTLISTANCHOR List;
231 /** Number of errors in the list. */
232 uint32_t cErrors;
233} AUDIOTESTERRORDESC;
234/** Pointer to an audio test error description. */
235typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC;
236
237/**
238 * An open wave (.WAV) file.
239 */
240typedef struct AUDIOTESTWAVEFILE
241{
242 /** The file handle. */
243 RTFILE hFile;
244 /** The absolute file offset of the first sample */
245 uint32_t offSamples;
246 /** Number of bytes of samples. */
247 uint32_t cbSamples;
248 /** The current read position relative to @a offSamples. */
249 uint32_t offCur;
250 /** The PCM properties for the file format. */
251 PDMAUDIOPCMPROPS Props;
252} AUDIOTESTWAVEFILE;
253/** Pointer to an open wave file. */
254typedef AUDIOTESTWAVEFILE *PAUDIOTESTWAVEFILE;
255
256
257double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps);
258int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
259
260int AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps);
261
262int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
263int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID);
264
265int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj);
266int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf);
267int AudioTestSetObjClose(PAUDIOTESTOBJ pObj);
268
269int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag);
270int AudioTestSetDestroy(PAUDIOTESTSET pSet);
271int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath);
272void AudioTestSetClose(PAUDIOTESTSET pSet);
273void AudioTestSetWipe(PAUDIOTESTSET pSet);
274int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName);
275int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir);
276int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc);
277
278bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr);
279void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr);
280
281int AudioTestWaveFileOpen(const char *pszFile, PAUDIOTESTWAVEFILE pWaveFile);
282int AudioTestWaveFileRead(PAUDIOTESTWAVEFILE pWaveFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
283void AudioTestWaveFileClose(PAUDIOTESTWAVEFILE pWaveFile);
284
285#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */
286
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