1 | /* $Id: AudioMixBuffer.h 61089 2016-05-20 10:05:27Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox audio: Mixing buffer to convert audio samples to/from different
|
---|
4 | * rates / formats.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2014-2016 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef AUDIO_MIXBUF_H
|
---|
20 | #define AUDIO_MIXBUF_H
|
---|
21 |
|
---|
22 | #include <iprt/cdefs.h>
|
---|
23 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
24 |
|
---|
25 | /** Constructs 32 bit value for given frequency, number of channels, bits per sample and signed bit.
|
---|
26 | * Note: This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */
|
---|
27 | #define AUDMIXBUF_AUDIO_FMT_MAKE(freq, c, bps, s) ((((s) & 0x1) << 28) + (((bps) & 0xFF) << 20) + (((c) & 0xF) << 16) + ((freq) & 0xFFFF))
|
---|
28 |
|
---|
29 | /** Decodes frequency (Hz). */
|
---|
30 | #define AUDMIXBUF_FMT_SAMPLE_FREQ(a) ((a) & 0xFFFF)
|
---|
31 | /** Decodes number of channels. */
|
---|
32 | #define AUDMIXBUF_FMT_CHANNELS(a) (((a) >> 16) & 0xF)
|
---|
33 | /** Decodes signed bit. */
|
---|
34 | #define AUDMIXBUF_FMT_SIGNED(a) (((a) >> 28) & 0x1)
|
---|
35 | /** Decodes number of bits per sample. */
|
---|
36 | #define AUDMIXBUF_FMT_BITS_PER_SAMPLE(a) (((a) >> 20) & 0xFF)
|
---|
37 | /** Decodes number of bytes per sample. */
|
---|
38 | #define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8)
|
---|
39 |
|
---|
40 | /** Converts samples to bytes. */
|
---|
41 | #define AUDIOMIXBUF_S2B(pBuf, samples) ((samples) << (pBuf)->cShift)
|
---|
42 | /** Converts samples to bytes, respecting the conversion ratio to
|
---|
43 | * a linked buffer. */
|
---|
44 | #define AUDIOMIXBUF_S2B_RATIO(pBuf, samples) ((((int64_t) samples << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift)
|
---|
45 | /** Converts bytes to samples, *not* taking the conversion ratio
|
---|
46 | * into account. */
|
---|
47 | #define AUDIOMIXBUF_B2S(pBuf, cb) (cb >> (pBuf)->cShift)
|
---|
48 | /** Converts number of samples according to the buffer's ratio. */
|
---|
49 | #define AUDIOMIXBUF_S2S_RATIO(pBuf, samples) (((int64_t) samples << 32) / (pBuf)->iFreqRatio)
|
---|
50 |
|
---|
51 |
|
---|
52 | int AudioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);
|
---|
53 | uint32_t AudioMixBufAvail(PPDMAUDIOMIXBUF pMixBuf);
|
---|
54 | inline uint32_t AudioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf);
|
---|
55 | void AudioMixBufClear(PPDMAUDIOMIXBUF pMixBuf);
|
---|
56 | void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf);
|
---|
57 | void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear);
|
---|
58 | uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf);
|
---|
59 | uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf);
|
---|
60 | int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples);
|
---|
61 | bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf);
|
---|
62 | int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent);
|
---|
63 | uint32_t AudioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf);
|
---|
64 | int AudioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);
|
---|
65 | int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);
|
---|
66 | uint32_t AudioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf);
|
---|
67 | int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
|
---|
68 | int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
|
---|
69 | int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead);
|
---|
70 | int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead);
|
---|
71 | void AudioMixBufReset(PPDMAUDIOMIXBUF pMixBuf);
|
---|
72 | void AudioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol);
|
---|
73 | uint32_t AudioMixBufSize(PPDMAUDIOMIXBUF pMixBuf);
|
---|
74 | uint32_t AudioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf);
|
---|
75 | void AudioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf);
|
---|
76 | int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
|
---|
77 | int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
|
---|
78 | int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
|
---|
79 | int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
|
---|
80 |
|
---|
81 | #ifdef DEBUG
|
---|
82 | void AudioMixBufDbgPrint(PPDMAUDIOMIXBUF pMixBuf);
|
---|
83 | void AudioMixBufDbgPrintChain(PPDMAUDIOMIXBUF pMixBuf);
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | #endif /* AUDIO_MIXBUF_H */
|
---|
87 |
|
---|