1 | /* $Id: AudioMixBuffer.h 55005 2015-03-30 12:07:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox audio: TODO
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2015 Oracle Corporation
|
---|
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 |
|
---|
18 | #ifndef AUDIO_MIXBUF_H
|
---|
19 | #define AUDIO_MIXBUF_H
|
---|
20 |
|
---|
21 | #include <iprt/cdefs.h>
|
---|
22 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
23 |
|
---|
24 | /** Constructs 32 bit value for given frequency, number of channels, bits per sample and signed bit.
|
---|
25 | * Note: This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */
|
---|
26 | #define AUDMIXBUF_AUDIO_FMT_MAKE(freq, c, bps, s) ((((s) & 0x1) << 28) + (((bps) & 0xFF) << 20) + (((c) & 0xF) << 16) + ((freq) & 0xFFFF))
|
---|
27 |
|
---|
28 | /** Decodes frequency (Hz). */
|
---|
29 | #define AUDMIXBUF_FMT_SAMPLE_FREQ(a) ((a) & 0xFFFF)
|
---|
30 | /** Decodes number of channels. */
|
---|
31 | #define AUDMIXBUF_FMT_CHANNELS(a) (((a) >> 16) & 0xF)
|
---|
32 | /** Decodes signed bit. */
|
---|
33 | #define AUDMIXBUF_FMT_SIGNED(a) (((a) >> 28) & 0x1)
|
---|
34 | /** Decodes number of bits per sample. */
|
---|
35 | #define AUDMIXBUF_FMT_BITS_PER_SAMPLE(a) (((a) >> 20) & 0xFF)
|
---|
36 | /** Decodes number of bytes per sample. */
|
---|
37 | #define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8)
|
---|
38 |
|
---|
39 | /** Converts samples to bytes. */
|
---|
40 | #define AUDIOMIXBUF_S2B(pBuf, samples) ((samples) << (pBuf)->cShift)
|
---|
41 | /** Converts samples to bytes, respecting the conversion ratio to
|
---|
42 | * a linked buffer. */
|
---|
43 | #define AUDIOMIXBUF_S2B_RATIO(pBuf, samples) ((((int64_t) samples << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift)
|
---|
44 | /** Converts bytes to samples, *not* taking the conversion ratio
|
---|
45 | * into account. */
|
---|
46 | #define AUDIOMIXBUF_B2S(pBuf, cb) (cb >> (pBuf)->cShift)
|
---|
47 | /** Converts number of samples according to the buffer's ratio. */
|
---|
48 | #define AUDIOMIXBUF_S2S_RATIO(pBuf, samples) (((int64_t) samples << 32) / (pBuf)->iFreqRatio)
|
---|
49 |
|
---|
50 |
|
---|
51 | int audioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);
|
---|
52 | inline uint32_t audioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf);
|
---|
53 | void audioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf);
|
---|
54 | void audioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear);
|
---|
55 | uint32_t audioMixBufFree(PPDMAUDIOMIXBUF pMixBuf);
|
---|
56 | size_t audioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf);
|
---|
57 | int audioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples);
|
---|
58 | bool audioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf);
|
---|
59 | int audioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent);
|
---|
60 | uint32_t audioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf);
|
---|
61 | int audioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);
|
---|
62 | int audioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);
|
---|
63 | uint32_t audioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf);
|
---|
64 | int audioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
|
---|
65 | int audioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
|
---|
66 | int audioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, size_t cbBuf, uint32_t *pcRead);
|
---|
67 | int audioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, size_t cbBuf, uint32_t *pcRead);
|
---|
68 | void audioMixBufReset(PPDMAUDIOMIXBUF pMixBuf);
|
---|
69 | void audioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol);
|
---|
70 | uint32_t audioMixBufSize(PPDMAUDIOMIXBUF pMixBuf);
|
---|
71 | size_t audioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf);
|
---|
72 | void audioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf);
|
---|
73 | int audioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, size_t cbBuf, uint32_t *pcWritten);
|
---|
74 | int audioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, const void *pvBuf, size_t cbBuf, uint32_t *pcWritten);
|
---|
75 | int audioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, size_t cbBuf, uint32_t *pcWritten);
|
---|
76 | int audioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, const void *pvBuf, size_t cbBuf, uint32_t *pcWritten);
|
---|
77 |
|
---|
78 | #endif /* AUDIO_MIXBUF_H */
|
---|
79 |
|
---|