VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/AudioMixBuffer.h@ 88269

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

Audio: Made sure PDMAUDIOPCMPROPS is initialized using a helper function or the initializer macro, and that vital changes are made using setting helper functions. There are now two derived fields (frame size and shift count) that must be maintained, so this was the sanest way of doing it. Added a raw flag to PDMAUDIOPCMPROPS for VRDE/VRDP, since it wants the raw mixer content and we need a way of expressing this (PDMAUDIOSTREAMLAYOUT isn't the right place). The mixer buffers now uses PDMAUDIOPCMPROPS rather than the weird 32-bit format contraption for picking conversion functions. Simplify the drvAudioStreamPlay code by eliminating the PDMAUDIOSTREAMLAYOUT_RAW special case. bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: AudioMixBuffer.h 88269 2021-03-24 11:45:54Z vboxsync $ */
2/** @file
3 * Audio Mixing bufer convert audio samples to/from different rates / formats.
4 */
5
6/*
7 * Copyright (C) 2014-2020 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 VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h
19#define VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/cdefs.h>
25#include <VBox/vmm/pdmaudioifs.h>
26
27/** Constructs 32 bit value for given frequency, number of channels, bits per sample and signed bit.
28 * @note This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */
29#define AUDMIXBUF_AUDIO_FMT_MAKE(freq, c, bps, s) ((((s) & 0x1) << 28) + (((bps) & 0xFF) << 20) + (((c) & 0xF) << 16) + ((freq) & 0xFFFF))
30
31/** Decodes frequency (Hz). */
32#define AUDMIXBUF_FMT_SAMPLE_FREQ(a) ((a) & 0xFFFF)
33/** Decodes number of channels. */
34#define AUDMIXBUF_FMT_CHANNELS(a) (((a) >> 16) & 0xF)
35/** Decodes signed bit. */
36#define AUDMIXBUF_FMT_SIGNED(a) (((a) >> 28) & 0x1)
37/** Decodes number of bits per sample. */
38#define AUDMIXBUF_FMT_BITS_PER_SAMPLE(a) (((a) >> 20) & 0xFF)
39/** Decodes number of bytes per sample. */
40#define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8)
41
42/** Converts (audio) frames to bytes. */
43#define AUDIOMIXBUF_F2B(a_pMixBuf, a_cFrames) PDMAUDIOPCMPROPS_F2B(&(a_pMixBuf)->Props, a_cFrames)
44/** Converts bytes to (audio) frames.
45 * @note Does *not* take the conversion ratio into account. */
46#define AUDIOMIXBUF_B2F(a_pMixBuf, a_cb) PDMAUDIOPCMPROPS_B2F(&(a_pMixBuf)->Props, a_cb)
47
48/** Converts frames to bytes, respecting the conversion ratio to
49 * a linked buffer. */
50#define AUDIOMIXBUF_F2B_RATIO(a_pMixBuf, a_cFrames) AUDIOMIXBUF_F2B(a_pMixBuf, AUDIOMIXBUF_F2F_RATIO(a_pMixBuf, a_cFrames))
51/** Converts number of frames according to the buffer's ratio.
52 * @todo r=bird: Why the *signed* cast? */
53#define AUDIOMIXBUF_F2F_RATIO(a_pMixBuf, a_cFrames) (((int64_t)(a_cFrames) << 32) / (a_pMixBuf)->iFreqRatio)
54
55
56inline uint32_t AudioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf);
57void AudioMixBufClear(PPDMAUDIOMIXBUF pMixBuf);
58void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf);
59void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToClear);
60uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf);
61uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf);
62int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
63bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf);
64int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent);
65uint32_t AudioMixBufLive(PPDMAUDIOMIXBUF pMixBuf);
66int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed);
67int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed);
68int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME *ppvSamples, uint32_t *pcFramesRead);
69uint32_t AudioMixBufUsed(PPDMAUDIOMIXBUF pMixBuf);
70uint32_t AudioMixBufUsedBytes(PPDMAUDIOMIXBUF pMixBuf);
71int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
72int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps, uint32_t offFrames,
73 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
74int AudioMixBufAcquireReadBlock(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames);
75int AudioMixBufAcquireReadBlockEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pDstProps,
76 void *pvBuf, uint32_t cbBuf, uint32_t *pcAcquiredFrames);
77void AudioMixBufReleaseReadBlock(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames);
78uint32_t AudioMixBufReadPos(PPDMAUDIOMIXBUF pMixBuf);
79void AudioMixBufReset(PPDMAUDIOMIXBUF pMixBuf);
80void AudioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol);
81uint32_t AudioMixBufSize(PPDMAUDIOMIXBUF pMixBuf);
82uint32_t AudioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf);
83void AudioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf);
84int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
85int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps, uint32_t offFrames,
86 const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
87int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);
88int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PCPDMAUDIOPCMPROPS pSrcProps,
89 const void *pvBuf,uint32_t cbBuf, uint32_t *pcWritten);
90uint32_t AudioMixBufWritePos(PPDMAUDIOMIXBUF pMixBuf);
91
92#ifdef DEBUG
93void AudioMixBufDbgPrint(PPDMAUDIOMIXBUF pMixBuf);
94void AudioMixBufDbgPrintChain(PPDMAUDIOMIXBUF pMixBuf);
95#endif
96
97#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h */
98
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette