VirtualBox

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

最後變更 在這個檔案從89373是 89373,由 vboxsync 提交於 4 年 前

AudioMixBuffer,tstAudioMixBuffer: Added more conversion tests and fixed a couple of blending bugs. Also fixed AudioMixBufSilence assertion issue and removed unused member AUDIOMIXBUF::cMixed. bugref:9890

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.8 KB
 
1/* $Id: AudioMixBuffer.h 89373 2021-05-29 03:35:17Z 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.alldomusa.eu.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
28/**
29 * Rate processing information of a source & destination audio stream.
30 *
31 * This is needed because both streams can differ regarding their rates and
32 * therefore need to be treated accordingly.
33 */
34typedef struct AUDIOSTREAMRATE
35{
36 /** Current (absolute) offset in the output (destination) stream.
37 * @todo r=bird: Please reveal which unit these members are given in. */
38 uint64_t offDst;
39 /** Increment for moving offDst for the destination stream.
40 * This is needed because the source <-> destination rate might be different. */
41 uint64_t uDstInc;
42 /** Current (absolute) offset in the input stream. */
43 uint32_t offSrc;
44 /** Set if no conversion is necessary. */
45 bool fNoConversionNeeded;
46 bool afPadding[3];
47
48 /** Last processed frame of the input stream.
49 * Needed for interpolation. */
50 union
51 {
52 int64_t ai64Samples[2];
53 PDMAUDIOFRAME Frame;
54 } SrcLast;
55
56 /**
57 * Resampling function.
58 * @returns Number of destination frames written.
59 */
60 DECLR3CALLBACKMEMBER(uint32_t, pfnResample, (int64_t *pi64Dst, uint32_t cDstFrames,
61 int64_t const *pi64Src, uint32_t cSrcFrames, uint32_t *pcSrcFramesRead,
62 struct AUDIOSTREAMRATE *pRate));
63
64} AUDIOSTREAMRATE;
65/** Pointer to rate processing information of a stream. */
66typedef AUDIOSTREAMRATE *PAUDIOSTREAMRATE;
67
68/**
69 * Mixing buffer volume parameters.
70 *
71 * The volume values are in fixed point style and must be converted to/from
72 * before using with e.g. PDMAUDIOVOLUME.
73 */
74typedef struct AUDMIXBUFVOL
75{
76 /** Set to @c true if this stream is muted, @c false if not. */
77 bool fMuted;
78 /** Left volume to apply during conversion.
79 * Pass 0 to convert the original values. May not apply to all conversion functions. */
80 uint32_t uLeft;
81 /** Right volume to apply during conversion.
82 * Pass 0 to convert the original values. May not apply to all conversion functions. */
83 uint32_t uRight;
84} AUDMIXBUFVOL;
85/** Pointer to mixing buffer volument parameters. */
86typedef AUDMIXBUFVOL *PAUDMIXBUFVOL;
87
88
89/** Pointer to audio mixing buffer. */
90typedef struct AUDIOMIXBUF *PAUDIOMIXBUF;
91/** Pointer to a const audio mixing buffer. */
92typedef struct AUDIOMIXBUF const *PCAUDIOMIXBUF;
93
94
95/**
96 * State & config for AudioMixBufPeek created by AudioMixBufInitPeekState.
97 */
98typedef struct AUDIOMIXBUFPEEKSTATE
99{
100 /** Encodes @a cFrames from @a paSrc to @a pvDst. */
101 DECLR3CALLBACKMEMBER(void, pfnEncode,(void *pvDst, int64_t const *paSrc, uint32_t cFrames, struct AUDIOMIXBUFPEEKSTATE *pState));
102 /** Sample rate conversion state (only used when needed). */
103 AUDIOSTREAMRATE Rate;
104 /** Source (mixer) channels. */
105 uint8_t cSrcChannels;
106 /** Destination channels. */
107 uint8_t cDstChannels;
108 /** Destination frame size. */
109 uint8_t cbDstFrame;
110} AUDIOMIXBUFPEEKSTATE;
111/** Pointer to peek state & config. */
112typedef AUDIOMIXBUFPEEKSTATE *PAUDIOMIXBUFPEEKSTATE;
113
114
115/**
116 * State & config for AudioMixBufWrite, AudioMixBufSilence, AudioMixBufBlend and
117 * AudioMixBufBlendGap, created by AudioMixBufInitWriteState.
118 */
119typedef struct AUDIOMIXBUFWRITESTATE
120{
121 /** Encodes @a cFrames from @a pvSrc to @a paDst. */
122 DECLR3CALLBACKMEMBER(void, pfnDecode,(int64_t *paDst, const void *pvSrc, uint32_t cFrames, struct AUDIOMIXBUFWRITESTATE *pState));
123 /** Encodes @a cFrames from @a pvSrc blending into @a paDst. */
124 DECLR3CALLBACKMEMBER(void, pfnDecodeBlend,(int64_t *paDst, const void *pvSrc, uint32_t cFrames, struct AUDIOMIXBUFWRITESTATE *pState));
125 /** Sample rate conversion state (only used when needed). */
126 AUDIOSTREAMRATE Rate;
127 /** Destination (mixer) channels. */
128 uint8_t cDstChannels;
129 /** Source hannels. */
130 uint8_t cSrcChannels;
131 /** Source frame size. */
132 uint8_t cbSrcFrame;
133} AUDIOMIXBUFWRITESTATE;
134/** Pointer to write state & config. */
135typedef AUDIOMIXBUFWRITESTATE *PAUDIOMIXBUFWRITESTATE;
136
137
138/**
139 * Audio mixing buffer.
140 */
141typedef struct AUDIOMIXBUF
142{
143 /** Magic value (AUDIOMIXBUF_MAGIC). */
144 uint32_t uMagic;
145 /** Size of the frame buffer (in audio frames). */
146 uint32_t cFrames;
147 /** Frame buffer. */
148 PPDMAUDIOFRAME pFrames;
149 /** The current read position (in frames). */
150 uint32_t offRead;
151 /** The current write position (in frames). */
152 uint32_t offWrite;
153 /** How much audio frames are currently being used in this buffer.
154 * @note This also is known as the distance in ring buffer terms. */
155 uint32_t cUsed;
156 /** Audio properties for the buffer content - for frequency and channel count.
157 * (This is the guest side PCM properties.) */
158 PDMAUDIOPCMPROPS Props;
159 /** Internal representation of current volume used for mixing. */
160 AUDMIXBUFVOL Volume;
161 /** Name of the buffer. */
162 char *pszName;
163} AUDIOMIXBUF;
164
165/** Magic value for AUDIOMIXBUF (Antonio Lucio Vivaldi). */
166#define AUDIOMIXBUF_MAGIC UINT32_C(0x16780304)
167/** Dead mixer buffer magic. */
168#define AUDIOMIXBUF_MAGIC_DEAD UINT32_C(0x17410728)
169
170/** Converts (audio) frames to bytes. */
171#define AUDIOMIXBUF_F2B(a_pMixBuf, a_cFrames) PDMAUDIOPCMPROPS_F2B(&(a_pMixBuf)->Props, a_cFrames)
172/** Converts bytes to (audio) frames.
173 * @note Does *not* take the conversion ratio into account. */
174#define AUDIOMIXBUF_B2F(a_pMixBuf, a_cb) PDMAUDIOPCMPROPS_B2F(&(a_pMixBuf)->Props, a_cb)
175
176
177int AudioMixBufInit(PAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
178void AudioMixBufTerm(PAUDIOMIXBUF pMixBuf);
179void AudioMixBufDrop(PAUDIOMIXBUF pMixBuf);
180void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol);
181
182/** @name Mixer buffer getters
183 * @{ */
184uint32_t AudioMixBufSize(PCAUDIOMIXBUF pMixBuf);
185uint32_t AudioMixBufSizeBytes(PCAUDIOMIXBUF pMixBuf);
186uint32_t AudioMixBufUsed(PCAUDIOMIXBUF pMixBuf);
187uint32_t AudioMixBufUsedBytes(PCAUDIOMIXBUF pMixBuf);
188uint32_t AudioMixBufFree(PCAUDIOMIXBUF pMixBuf);
189uint32_t AudioMixBufFreeBytes(PCAUDIOMIXBUF pMixBuf);
190bool AudioMixBufIsEmpty(PCAUDIOMIXBUF pMixBuf);
191uint32_t AudioMixBufReadPos(PCAUDIOMIXBUF pMixBuf);
192uint32_t AudioMixBufWritePos(PCAUDIOMIXBUF pMixBuf);
193/** @} */
194
195/** @name Mixer buffer reading
196 * @{ */
197int AudioMixBufInitPeekState(PCAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFPEEKSTATE pState, PCPDMAUDIOPCMPROPS pDstProps);
198void AudioMixBufPeek(PCAUDIOMIXBUF pMixBuf, uint32_t offSrcFrame, uint32_t cMaxSrcFrames, uint32_t *pcSrcFramesPeeked,
199 PAUDIOMIXBUFPEEKSTATE pState, void *pvDst, uint32_t cbDst, uint32_t *pcbDstPeeked);
200void AudioMixBufAdvance(PAUDIOMIXBUF pMixBuf, uint32_t cFrames);
201/** @} */
202
203/** @name Mixer buffer writing
204 * @{ */
205int AudioMixBufInitWriteState(PCAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, PCPDMAUDIOPCMPROPS pSrcProps);
206void AudioMixBufWrite(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
207 uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesWritten);
208void AudioMixBufSilence(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, uint32_t offFrame, uint32_t cFrames);
209void AudioMixBufBlend(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
210 uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesBlended);
211void AudioMixBufBlendGap(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, uint32_t cFrames);
212void AudioMixBufCommit(PAUDIOMIXBUF pMixBuf, uint32_t cFrames);
213/** @} */
214
215#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h */
216
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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