[55057] | 1 | /* $Id: AudioHlp.h 90012 2021-07-04 21:08:37Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[88235] | 3 | * Audio helper routines.
|
---|
[55057] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[82968] | 7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
[55057] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | */
|
---|
| 17 |
|
---|
[88234] | 18 | #ifndef VBOX_INCLUDED_SRC_Audio_AudioHlp_h
|
---|
| 19 | #define VBOX_INCLUDED_SRC_Audio_AudioHlp_h
|
---|
[76520] | 20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 21 | # pragma once
|
---|
| 22 | #endif
|
---|
[55057] | 23 |
|
---|
| 24 | #include <limits.h>
|
---|
| 25 |
|
---|
| 26 | #include <iprt/circbuf.h>
|
---|
[59420] | 27 | #include <iprt/critsect.h>
|
---|
[62580] | 28 | #include <iprt/file.h>
|
---|
| 29 | #include <iprt/path.h>
|
---|
[55057] | 30 |
|
---|
| 31 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
| 32 |
|
---|
[73220] | 33 | /** @name Audio calculation helper methods.
|
---|
| 34 | * @{ */
|
---|
[88234] | 35 | uint32_t AudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
|
---|
[88007] | 36 | /** @} */
|
---|
| 37 |
|
---|
| 38 | /** @name Audio PCM properties helper methods.
|
---|
| 39 | * @{ */
|
---|
[88234] | 40 | bool AudioHlpPcmPropsAreValid(PCPDMAUDIOPCMPROPS pProps);
|
---|
[73220] | 41 | /** @} */
|
---|
| 42 |
|
---|
[76857] | 43 | /** @name Audio configuration helper methods.
|
---|
[73220] | 44 | * @{ */
|
---|
[88234] | 45 | bool AudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg);
|
---|
[76857] | 46 | /** @} */
|
---|
| 47 |
|
---|
[88357] | 48 |
|
---|
| 49 | /** @name AUDIOHLPFILE_FLAGS_XXX
|
---|
| 50 | * @{ */
|
---|
| 51 | /** No flags defined. */
|
---|
| 52 | #define AUDIOHLPFILE_FLAGS_NONE UINT32_C(0)
|
---|
| 53 | /** Keep the audio file even if it contains no audio data. */
|
---|
| 54 | #define AUDIOHLPFILE_FLAGS_KEEP_IF_EMPTY RT_BIT_32(0)
|
---|
| 55 | /** Audio file flag validation mask. */
|
---|
| 56 | #define AUDIOHLPFILE_FLAGS_VALID_MASK UINT32_C(0x1)
|
---|
| 57 | /** @} */
|
---|
| 58 |
|
---|
| 59 | /** Audio file default open flags. */
|
---|
| 60 | #define AUDIOHLPFILE_DEFAULT_OPEN_FLAGS (RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE)
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Audio file types.
|
---|
| 64 | */
|
---|
| 65 | typedef enum AUDIOHLPFILETYPE
|
---|
| 66 | {
|
---|
| 67 | /** The customary invalid zero value. */
|
---|
| 68 | AUDIOHLPFILETYPE_INVALID = 0,
|
---|
| 69 | /** Raw (PCM) file. */
|
---|
| 70 | AUDIOHLPFILETYPE_RAW,
|
---|
| 71 | /** Wave (.WAV) file. */
|
---|
| 72 | AUDIOHLPFILETYPE_WAV,
|
---|
| 73 | /** Hack to blow the type up to 32-bit. */
|
---|
| 74 | AUDIOHLPFILETYPE_32BIT_HACK = 0x7fffffff
|
---|
| 75 | } AUDIOHLPFILETYPE;
|
---|
| 76 |
|
---|
| 77 | /** @name AUDIOHLPFILENAME_FLAGS_XXX
|
---|
[73220] | 78 | * @{ */
|
---|
[88357] | 79 | /** No flags defined. */
|
---|
| 80 | #define AUDIOHLPFILENAME_FLAGS_NONE UINT32_C(0)
|
---|
| 81 | /** Adds an ISO timestamp to the file name. */
|
---|
[90010] | 82 | #define AUDIOHLPFILENAME_FLAGS_TS RT_BIT_32(0)
|
---|
| 83 | /** Valid flag mask. */
|
---|
| 84 | #define AUDIOHLPFILENAME_FLAGS_VALID_MASK AUDIOHLPFILENAME_FLAGS_TS
|
---|
[88357] | 85 | /** @} */
|
---|
[63711] | 86 |
|
---|
[88357] | 87 | /**
|
---|
| 88 | * Audio file handle.
|
---|
| 89 | */
|
---|
| 90 | typedef struct AUDIOHLPFILE
|
---|
| 91 | {
|
---|
| 92 | /** Type of the audio file. */
|
---|
| 93 | AUDIOHLPFILETYPE enmType;
|
---|
| 94 | /** Audio file flags, AUDIOHLPFILE_FLAGS_XXX. */
|
---|
| 95 | uint32_t fFlags;
|
---|
[90012] | 96 | /** Amount of wave data written. */
|
---|
| 97 | uint64_t cbWaveData;
|
---|
[88357] | 98 | /** Actual file handle. */
|
---|
| 99 | RTFILE hFile;
|
---|
| 100 | /** File name and path. */
|
---|
[90011] | 101 | RT_FLEXIBLE_ARRAY_EXTENSION
|
---|
| 102 | char szName[RT_FLEXIBLE_ARRAY];
|
---|
[88357] | 103 | } AUDIOHLPFILE;
|
---|
| 104 | /** Pointer to an audio file handle. */
|
---|
| 105 | typedef AUDIOHLPFILE *PAUDIOHLPFILE;
|
---|
| 106 |
|
---|
[73220] | 107 | /** @name Audio file methods.
|
---|
| 108 | * @{ */
|
---|
[88357] | 109 | int AudioHlpFileCreateAndOpen(PAUDIOHLPFILE *ppFile, const char *pszDir, const char *pszName,
|
---|
[88292] | 110 | uint32_t iInstance, PCPDMAUDIOPCMPROPS pProps);
|
---|
[90011] | 111 | int AudioHlpFileCreateAndOpenEx(PAUDIOHLPFILE *ppFile, AUDIOHLPFILETYPE enmType, const char *pszDir,
|
---|
[88292] | 112 | uint32_t iInstance, uint32_t fFilename, uint32_t fCreate,
|
---|
[90011] | 113 | PCPDMAUDIOPCMPROPS pProps, uint64_t fOpen, const char *pszName, ...);
|
---|
| 114 | int AudioHlpFileCreateF(PAUDIOHLPFILE *ppFile, uint32_t fFlags, AUDIOHLPFILETYPE enmType,
|
---|
| 115 | const char *pszPath, uint32_t fFilename, uint32_t uInstance, const char *pszFileFmt, ...);
|
---|
| 116 |
|
---|
[88357] | 117 | void AudioHlpFileDestroy(PAUDIOHLPFILE pFile);
|
---|
[90012] | 118 | int AudioHlpFileOpen(PAUDIOHLPFILE pFile, uint64_t fOpen, PCPDMAUDIOPCMPROPS pProps);
|
---|
[88357] | 119 | int AudioHlpFileClose(PAUDIOHLPFILE pFile);
|
---|
| 120 | int AudioHlpFileDelete(PAUDIOHLPFILE pFile);
|
---|
| 121 | bool AudioHlpFileIsOpen(PAUDIOHLPFILE pFile);
|
---|
[90012] | 122 | int AudioHlpFileWrite(PAUDIOHLPFILE pFile, const void *pvBuf, size_t cbBuf);
|
---|
[73220] | 123 | /** @} */
|
---|
[62580] | 124 |
|
---|
[88234] | 125 | #endif /* !VBOX_INCLUDED_SRC_Audio_AudioHlp_h */
|
---|
[55057] | 126 |
|
---|