VirtualBox

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

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

AudioMixBuffer: Changed the internal sample type from int64_t to int32_t and made the internal buffer handling capable of an arbitrary channel number (well 1 thru 12 (PDMAUDIO_MAX_CHANNELS)). That said, we don't have decoders, encoders or resamplers for channel counts other than 1 and 2 yet. bugref:9890

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.9 KB
 
1/* $Id: AudioMixBuffer.h 89378 2021-05-30 02:14:34Z 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 int32_t ai32Samples[PDMAUDIO_MAX_CHANNELS];
53 } SrcLast;
54
55 /**
56 * Resampling function.
57 * @returns Number of destination frames written.
58 */
59 DECLR3CALLBACKMEMBER(uint32_t, pfnResample, (int32_t *pi32Dst, uint32_t cDstFrames,
60 int32_t const *pi32Src, uint32_t cSrcFrames, uint32_t *pcSrcFramesRead,
61 struct AUDIOSTREAMRATE *pRate));
62
63} AUDIOSTREAMRATE;
64/** Pointer to rate processing information of a stream. */
65typedef AUDIOSTREAMRATE *PAUDIOSTREAMRATE;
66
67/**
68 * Mixing buffer volume parameters.
69 *
70 * The volume values are in fixed point style and must be converted to/from
71 * before using with e.g. PDMAUDIOVOLUME.
72 */
73typedef struct AUDMIXBUFVOL
74{
75 /** Set to @c true if this stream is muted, @c false if not. */
76 bool fMuted;
77 /** Set if all (relevant) channels are at max. */
78 bool fAllMax;
79 /** The per-channels values. */
80 uint32_t auChannels[PDMAUDIO_MAX_CHANNELS];
81} AUDMIXBUFVOL;
82/** Pointer to mixing buffer volument parameters. */
83typedef AUDMIXBUFVOL *PAUDMIXBUFVOL;
84
85
86/** Pointer to audio mixing buffer. */
87typedef struct AUDIOMIXBUF *PAUDIOMIXBUF;
88/** Pointer to a const audio mixing buffer. */
89typedef struct AUDIOMIXBUF const *PCAUDIOMIXBUF;
90
91
92/**
93 * State & config for AudioMixBufPeek created by AudioMixBufInitPeekState.
94 */
95typedef struct AUDIOMIXBUFPEEKSTATE
96{
97 /** Encodes @a cFrames from @a paSrc to @a pvDst. */
98 DECLR3CALLBACKMEMBER(void, pfnEncode,(void *pvDst, int32_t const *paSrc, uint32_t cFrames, struct AUDIOMIXBUFPEEKSTATE *pState));
99 /** Sample rate conversion state (only used when needed). */
100 AUDIOSTREAMRATE Rate;
101 /** Source (mixer) channels. */
102 uint8_t cSrcChannels;
103 /** Destination channels. */
104 uint8_t cDstChannels;
105 /** Destination frame size. */
106 uint8_t cbDstFrame;
107} AUDIOMIXBUFPEEKSTATE;
108/** Pointer to peek state & config. */
109typedef AUDIOMIXBUFPEEKSTATE *PAUDIOMIXBUFPEEKSTATE;
110
111
112/**
113 * State & config for AudioMixBufWrite, AudioMixBufSilence, AudioMixBufBlend and
114 * AudioMixBufBlendGap, created by AudioMixBufInitWriteState.
115 */
116typedef struct AUDIOMIXBUFWRITESTATE
117{
118 /** Encodes @a cFrames from @a pvSrc to @a paDst. */
119 DECLR3CALLBACKMEMBER(void, pfnDecode,(int32_t *paDst, const void *pvSrc, uint32_t cFrames, struct AUDIOMIXBUFWRITESTATE *pState));
120 /** Encodes @a cFrames from @a pvSrc blending into @a paDst. */
121 DECLR3CALLBACKMEMBER(void, pfnDecodeBlend,(int32_t *paDst, const void *pvSrc, uint32_t cFrames, struct AUDIOMIXBUFWRITESTATE *pState));
122 /** Sample rate conversion state (only used when needed). */
123 AUDIOSTREAMRATE Rate;
124 /** Destination (mixer) channels. */
125 uint8_t cDstChannels;
126 /** Source hannels. */
127 uint8_t cSrcChannels;
128 /** Source frame size. */
129 uint8_t cbSrcFrame;
130} AUDIOMIXBUFWRITESTATE;
131/** Pointer to write state & config. */
132typedef AUDIOMIXBUFWRITESTATE *PAUDIOMIXBUFWRITESTATE;
133
134
135/**
136 * Audio mixing buffer.
137 */
138typedef struct AUDIOMIXBUF
139{
140 /** Magic value (AUDIOMIXBUF_MAGIC). */
141 uint32_t uMagic;
142 /** Size of the frame buffer (in audio frames). */
143 uint32_t cFrames;
144 /** The frame buffer.
145 * This is a two dimensional array consisting of cFrames rows and
146 * cChannels columns. */
147 int32_t *pi32Samples;
148 /** The number of channels. */
149 uint8_t cChannels;
150 /** The frame size (row size if you like). */
151 uint8_t cbFrame;
152 uint8_t abPadding[2];
153 /** The current read position (in frames). */
154 uint32_t offRead;
155 /** The current write position (in frames). */
156 uint32_t offWrite;
157 /** How much audio frames are currently being used in this buffer.
158 * @note This also is known as the distance in ring buffer terms. */
159 uint32_t cUsed;
160 /** Audio properties for the buffer content - for frequency and channel count.
161 * (This is the guest side PCM properties.) */
162 PDMAUDIOPCMPROPS Props;
163 /** Internal representation of current volume used for mixing. */
164 AUDMIXBUFVOL Volume;
165 /** Name of the buffer. */
166 char *pszName;
167} AUDIOMIXBUF;
168
169/** Magic value for AUDIOMIXBUF (Antonio Lucio Vivaldi). */
170#define AUDIOMIXBUF_MAGIC UINT32_C(0x16780304)
171/** Dead mixer buffer magic. */
172#define AUDIOMIXBUF_MAGIC_DEAD UINT32_C(0x17410728)
173
174/** Converts (audio) frames to bytes. */
175#define AUDIOMIXBUF_F2B(a_pMixBuf, a_cFrames) PDMAUDIOPCMPROPS_F2B(&(a_pMixBuf)->Props, a_cFrames)
176/** Converts bytes to (audio) frames.
177 * @note Does *not* take the conversion ratio into account. */
178#define AUDIOMIXBUF_B2F(a_pMixBuf, a_cb) PDMAUDIOPCMPROPS_B2F(&(a_pMixBuf)->Props, a_cb)
179
180
181int AudioMixBufInit(PAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
182void AudioMixBufTerm(PAUDIOMIXBUF pMixBuf);
183void AudioMixBufDrop(PAUDIOMIXBUF pMixBuf);
184void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol);
185
186/** @name Mixer buffer getters
187 * @{ */
188uint32_t AudioMixBufSize(PCAUDIOMIXBUF pMixBuf);
189uint32_t AudioMixBufSizeBytes(PCAUDIOMIXBUF pMixBuf);
190uint32_t AudioMixBufUsed(PCAUDIOMIXBUF pMixBuf);
191uint32_t AudioMixBufUsedBytes(PCAUDIOMIXBUF pMixBuf);
192uint32_t AudioMixBufFree(PCAUDIOMIXBUF pMixBuf);
193uint32_t AudioMixBufFreeBytes(PCAUDIOMIXBUF pMixBuf);
194bool AudioMixBufIsEmpty(PCAUDIOMIXBUF pMixBuf);
195uint32_t AudioMixBufReadPos(PCAUDIOMIXBUF pMixBuf);
196uint32_t AudioMixBufWritePos(PCAUDIOMIXBUF pMixBuf);
197/** @} */
198
199/** @name Mixer buffer reading
200 * @{ */
201int AudioMixBufInitPeekState(PCAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFPEEKSTATE pState, PCPDMAUDIOPCMPROPS pDstProps);
202void AudioMixBufPeek(PCAUDIOMIXBUF pMixBuf, uint32_t offSrcFrame, uint32_t cMaxSrcFrames, uint32_t *pcSrcFramesPeeked,
203 PAUDIOMIXBUFPEEKSTATE pState, void *pvDst, uint32_t cbDst, uint32_t *pcbDstPeeked);
204void AudioMixBufAdvance(PAUDIOMIXBUF pMixBuf, uint32_t cFrames);
205/** @} */
206
207/** @name Mixer buffer writing
208 * @{ */
209int AudioMixBufInitWriteState(PCAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, PCPDMAUDIOPCMPROPS pSrcProps);
210void AudioMixBufWrite(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
211 uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesWritten);
212void AudioMixBufSilence(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, uint32_t offFrame, uint32_t cFrames);
213void AudioMixBufBlend(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
214 uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesBlended);
215void AudioMixBufBlendGap(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, uint32_t cFrames);
216void AudioMixBufCommit(PAUDIOMIXBUF pMixBuf, uint32_t cFrames);
217/** @} */
218
219#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h */
220
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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