summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/Audio/AudioHlp.h
blob: c592a778176f0601c7264f386c3c14ca9564fc84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* $Id: AudioHlp.h $ */
/** @file
 * Audio helper routines.
 */

/*
 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef VBOX_INCLUDED_SRC_Audio_AudioHlp_h
#define VBOX_INCLUDED_SRC_Audio_AudioHlp_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <limits.h>

#include <iprt/circbuf.h>
#include <iprt/critsect.h>
#include <iprt/file.h>
#include <iprt/path.h>

#include <VBox/vmm/pdmaudioifs.h>

/** @name Audio calculation helper methods.
 * @{ */
uint32_t AudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
/** @} */

/** @name Audio PCM properties helper methods.
 * @{ */
bool     AudioHlpPcmPropsAreValidAndSupported(PCPDMAUDIOPCMPROPS pProps);
/** @}  */

/** @name Audio configuration helper methods.
 * @{ */
bool    AudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg);
/** @}  */


/** @name AUDIOHLPFILE_FLAGS_XXX
 * @{ */
/** No flags defined. */
#define AUDIOHLPFILE_FLAGS_NONE             UINT32_C(0)
/** Keep the audio file even if it contains no audio data. */
#define AUDIOHLPFILE_FLAGS_KEEP_IF_EMPTY    RT_BIT_32(0)
/** Audio file flag validation mask. */
#define AUDIOHLPFILE_FLAGS_VALID_MASK       UINT32_C(0x1)
/** @} */

/** Audio file default open flags. */
#define AUDIOHLPFILE_DEFAULT_OPEN_FLAGS (RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE)

/**
 * Audio file types.
 */
typedef enum AUDIOHLPFILETYPE
{
    /** The customary invalid zero value. */
    AUDIOHLPFILETYPE_INVALID = 0,
    /** Raw (PCM) file. */
    AUDIOHLPFILETYPE_RAW,
    /** Wave (.WAV) file. */
    AUDIOHLPFILETYPE_WAV,
    /** Hack to blow the type up to 32-bit. */
    AUDIOHLPFILETYPE_32BIT_HACK = 0x7fffffff
} AUDIOHLPFILETYPE;

/** @name AUDIOHLPFILENAME_FLAGS_XXX
 * @{ */
/** No flags defined. */
#define AUDIOHLPFILENAME_FLAGS_NONE         UINT32_C(0)
/** Adds an ISO timestamp to the file name. */
#define AUDIOHLPFILENAME_FLAGS_TS           RT_BIT_32(0)
/** Valid flag mask. */
#define AUDIOHLPFILENAME_FLAGS_VALID_MASK   AUDIOHLPFILENAME_FLAGS_TS
/** @} */

/**
 * Audio file handle.
 */
typedef struct AUDIOHLPFILE
{
    /** Type of the audio file. */
    AUDIOHLPFILETYPE    enmType;
    /** Audio file flags, AUDIOHLPFILE_FLAGS_XXX. */
    uint32_t            fFlags;
    /** Amount of wave data written. */
    uint64_t            cbWaveData;
    /** Actual file handle. */
    RTFILE              hFile;
    /** File name and path. */
    RT_FLEXIBLE_ARRAY_EXTENSION
    char                szName[RT_FLEXIBLE_ARRAY];
} AUDIOHLPFILE;
/** Pointer to an audio file handle. */
typedef AUDIOHLPFILE *PAUDIOHLPFILE;

/** @name Audio file methods.
 * @{ */
int     AudioHlpFileCreateAndOpen(PAUDIOHLPFILE *ppFile, const char *pszDir, const char *pszName,
                                  uint32_t iInstance, PCPDMAUDIOPCMPROPS pProps);
int     AudioHlpFileCreateAndOpenEx(PAUDIOHLPFILE *ppFile, AUDIOHLPFILETYPE enmType, const char *pszDir,
                                    uint32_t iInstance, uint32_t fFilename, uint32_t fCreate,
                                    PCPDMAUDIOPCMPROPS pProps, uint64_t fOpen, const char *pszName, ...);
int     AudioHlpFileCreateF(PAUDIOHLPFILE *ppFile, uint32_t fFlags, AUDIOHLPFILETYPE enmType,
                            const char *pszPath, uint32_t fFilename, uint32_t uInstance, const char *pszFileFmt, ...);

void    AudioHlpFileDestroy(PAUDIOHLPFILE pFile);
int     AudioHlpFileOpen(PAUDIOHLPFILE pFile, uint64_t fOpen, PCPDMAUDIOPCMPROPS pProps);
int     AudioHlpFileClose(PAUDIOHLPFILE pFile);
int     AudioHlpFileDelete(PAUDIOHLPFILE pFile);
bool    AudioHlpFileIsOpen(PAUDIOHLPFILE pFile);
int     AudioHlpFileWrite(PAUDIOHLPFILE pFile, const void *pvBuf, size_t cbBuf);
/** @}  */

#endif /* !VBOX_INCLUDED_SRC_Audio_AudioHlp_h */