VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/AudioMixer.h@ 61888

Last change on this file since 61888 was 61887, checked in by vboxsync, 9 years ago

Audio: Implemented support for master volume controls.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: AudioMixer.h 61887 2016-06-27 08:26:56Z vboxsync $ */
2/** @file
3 * VBox audio: Mixing routines, mainly used by the various audio device
4 * emulations to achieve proper multiplexing from/to attached
5 * devices LUNs.
6 */
7
8/*
9 * Copyright (C) 2014-2016 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef AUDIO_MIXER_H
21#define AUDIO_MIXER_H
22
23#include <iprt/cdefs.h>
24#include <VBox/vmm/pdmaudioifs.h>
25
26/**
27 * Structure for maintaining an audio mixer instance.
28 */
29typedef struct AUDIOMIXER
30{
31 /** Mixer name. */
32 char *pszName;
33 /** Format the mixer should convert/output
34 * data to so that the underlying device emulation
35 * can work with it. */
36 PDMAUDIOSTREAMCFG devFmt;
37 /** The master volume of this mixer. */
38 PDMAUDIOVOLUME VolMaster;
39 /* List of audio mixer sinks. */
40 RTLISTANCHOR lstSinks;
41 /** Number of used audio sinks. */
42 uint8_t cSinks;
43} AUDIOMIXER, *PAUDIOMIXER;
44
45/** No flags specified. */
46#define AUDMIXSTREAM_FLAG_NONE 0
47
48/** Prototype needed for AUDMIXSTREAM struct definition. */
49typedef struct AUDMIXSINK *PAUDMIXSINK;
50
51/**
52 * Structure for maintaining an audio mixer stream.
53 */
54typedef struct AUDMIXSTREAM
55{
56 /** List node. */
57 RTLISTNODE Node;
58 /** Name of this stream. */
59 char *pszName;
60 /** Sink this stream is attached to. */
61 PAUDMIXSINK pSink;
62 /** Stream flags of type AUDMIXSTREAM_FLAG_. */
63 uint32_t fFlags;
64 /** Pointer to audio connector being used. */
65 PPDMIAUDIOCONNECTOR pConn;
66 /** Pointer to PDM audio stream this mixer stream handles. */
67 PPDMAUDIOSTREAM pStream;
68} AUDMIXSTREAM, *PAUDMIXSTREAM;
69
70/** Defines an audio sink's current status. */
71#define AUDMIXSINKSTS uint32_t
72
73/** No status specified. */
74#define AUDMIXSINK_STS_NONE 0
75/** The sink is active and running. */
76#define AUDMIXSINK_STS_RUNNING RT_BIT(0)
77/** The sink is in a pending disable state. */
78#define AUDMIXSINK_STS_PENDING_DISABLE RT_BIT(1)
79/** Dirty flag.
80 * For output sinks this means that there is data in the
81 * sink which has not been played yet.
82 * For input sinks this means that there is data in the
83 * sink which has been recorded but not transferred to the
84 * destination yet. */
85#define AUDMIXSINK_STS_DIRTY RT_BIT(2)
86
87/**
88 * Audio mixer sink direction.
89 */
90typedef enum AUDMIXSINKDIR
91{
92 AUDMIXSINKDIR_UNKNOWN = 0,
93 AUDMIXSINKDIR_INPUT,
94 AUDMIXSINKDIR_OUTPUT,
95 /** The usual 32-bit hack. */
96 AUDMIXSINKDIR_32BIT_HACK = 0x7fffffff
97} AUDMIXSINKDIR;
98
99/**
100 * Audio mixer sink command.
101 */
102typedef enum AUDMIXSINKCMD
103{
104 /** Unknown command, do not use. */
105 AUDMIXSINKCMD_UNKNOWN = 0,
106 /** Enables the sink. */
107 AUDMIXSINKCMD_ENABLE,
108 /** Disables the sink. */
109 AUDMIXSINKCMD_DISABLE,
110 /** Pauses the sink. */
111 AUDMIXSINKCMD_PAUSE,
112 /** Resumes the sink. */
113 AUDMIXSINKCMD_RESUME,
114 /** Hack to blow the type up to 32-bit. */
115 AUDMIXSINKCMD_32BIT_HACK = 0x7fffffff
116} AUDMIXSINKCMD;
117
118/**
119 * Structure for keeping audio input sink specifics.
120 * Do not use directly. Instead, use AUDMIXSINK.
121 */
122typedef struct AUDMIXSINKIN
123{
124#ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
125 /** This sink's mixing buffer, acting as
126 * a parent buffer for all streams this sink owns. */
127 PDMAUDIOMIXBUF MixBuf;
128#else
129 /** Number of bytes available to read from the sink. */
130 uint32_t cbReadable;
131#endif
132} AUDMIXSINKIN;
133
134/**
135 * Structure for keeping audio output sink specifics.
136 * Do not use directly. Instead, use AUDMIXSINK.
137 */
138typedef struct AUDMIXSINKOUT
139{
140#ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
141 /** This sink's mixing buffer, acting as
142 * a parent buffer for all streams this sink owns. */
143 PDMAUDIOMIXBUF MixBuf;
144#else
145 /** Number of bytes available to write to the sink. */
146 uint32_t cbWritable;
147#endif
148} AUDMIXSINKOUT;
149
150/**
151 * Structure for maintaining an audio mixer sink.
152 */
153typedef struct AUDMIXSINK
154{
155 RTLISTNODE Node;
156 /** Pointer to mixer object this sink is bound to. */
157 PAUDIOMIXER pParent;
158 /** Name of this sink. */
159 char *pszName;
160 /** The sink direction, that is,
161 * if this sink handles input or output. */
162 AUDMIXSINKDIR enmDir;
163 /** Union for input/output specifics. */
164 union
165 {
166 AUDMIXSINKIN In;
167 AUDMIXSINKOUT Out;
168 };
169 /** Sink status of type AUDMIXSINK_STS_XXX. */
170 AUDMIXSINKSTS fStatus;
171 /** The sink's PCM format. */
172 PDMPCMPROPS PCMProps;
173 /** Number of streams assigned. */
174 uint8_t cStreams;
175 /** List of assigned streams.
176 * Note: All streams have the same PCM properties, so the
177 * mixer does not do any conversion. */
178 /** @todo Use something faster -- vector maybe? */
179 RTLISTANCHOR lstStreams;
180 /** The volume of this sink. The volume always will
181 * be combined with the mixer's master volume. */
182 PDMAUDIOVOLUME Volume;
183 /** The volume of this sink, combined with the last set master volume. */
184 PDMAUDIOVOLUME VolumeCombined;
185 /** Timestamp (in ns) since last update. */
186 uint64_t tsLastUpdatedNS;
187} AUDMIXSINK, *PAUDMIXSINK;
188
189/**
190 * Audio mixer operation.
191 */
192typedef enum AUDMIXOP
193{
194 /** Invalid operation, do not use. */
195 AUDMIXOP_INVALID = 0,
196 AUDMIXOP_COPY,
197 AUDMIXOP_BLEND,
198 /** The usual 32-bit hack. */
199 AUDMIXOP_32BIT_HACK = 0x7fffffff
200} AUDMIXOP;
201
202/** No flags specified. */
203#define AUDMIXSTRMCTL_FLAG_NONE 0
204
205int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);
206int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);
207void AudioMixerDestroy(PAUDIOMIXER pMixer);
208int AudioMixerGetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
209void AudioMixerInvalidate(PAUDIOMIXER pMixer);
210void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
211int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
212int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
213void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
214
215int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
216int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg, uint32_t fFlags, PAUDMIXSTREAM *ppStream);
217int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
218void AudioMixerSinkDestroy(PAUDMIXSINK pSink);
219uint32_t AudioMixerSinkGetReadable(PAUDMIXSINK pSink);
220uint32_t AudioMixerSinkGetWritable(PAUDMIXSINK pSink);
221AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
222PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
223AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
224uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
225int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
226void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
227void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
228int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PPDMPCMPROPS pPCMProps);
229int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
230void AudioMixerSinkTimerUpdate(PAUDMIXSINK pSink, uint64_t cTimerTicks, uint64_t cTicksElapsed, uint32_t *pcbToProcess);
231int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
232int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
233
234int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
235void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream);
236bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
237bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
238
239#endif /* AUDIO_MIXER_H */
240
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