1 | /* $Id: AudioMixer.cpp 55379 2015-04-22 13:39:36Z 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-2015 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 | #include "AudioMixer.h"
|
---|
21 | #include "AudioMixBuffer.h"
|
---|
22 |
|
---|
23 | #include <VBox/vmm/pdm.h>
|
---|
24 | #include <VBox/err.h>
|
---|
25 | #include <VBox/vmm/mm.h>
|
---|
26 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
27 |
|
---|
28 | #include <iprt/alloc.h>
|
---|
29 | #include <iprt/asm-math.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 |
|
---|
33 | #ifdef LOG_GROUP
|
---|
34 | # undef LOG_GROUP
|
---|
35 | #endif
|
---|
36 | #define LOG_GROUP LOG_GROUP_DEV_AUDIO
|
---|
37 | #include <VBox/log.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | static int audioMixerUpdateSinkVolume(PAUDMIXSINK pSink, const PPDMAUDIOVOLUME pVolMaster, const PPDMAUDIOVOLUME pVolSink);
|
---|
41 |
|
---|
42 |
|
---|
43 | int audioMixerAddSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink)
|
---|
44 | {
|
---|
45 | AssertPtrReturn(pMixer, VERR_INVALID_POINTER);
|
---|
46 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
47 | /** ppSink is optional. */
|
---|
48 |
|
---|
49 | int rc = VINF_SUCCESS;
|
---|
50 |
|
---|
51 | PAUDMIXSINK pSink = (PAUDMIXSINK)RTMemAllocZ(sizeof(AUDMIXSINK));
|
---|
52 | if (pSink)
|
---|
53 | {
|
---|
54 | pSink->pszName = RTStrDup(pszName);
|
---|
55 | if (!pSink->pszName)
|
---|
56 | rc = VERR_NO_MEMORY;
|
---|
57 |
|
---|
58 | if (RT_SUCCESS(rc))
|
---|
59 | {
|
---|
60 | pSink->pParent = pMixer;
|
---|
61 | pSink->cStreams = 0;
|
---|
62 | pSink->enmDir = enmDir;
|
---|
63 | RTListInit(&pSink->lstStreams);
|
---|
64 |
|
---|
65 | /* Set initial volume to max. */
|
---|
66 | pSink->Volume.fMuted = false;
|
---|
67 | pSink->Volume.uLeft = 0x7F;
|
---|
68 | pSink->Volume.uRight = 0x7F;
|
---|
69 |
|
---|
70 | RTListAppend(&pMixer->lstSinks, &pSink->Node);
|
---|
71 | pMixer->cSinks++;
|
---|
72 |
|
---|
73 | LogFlowFunc(("pMixer=%p, pSink=%p, cSinks=%RU8\n",
|
---|
74 | pMixer, pSink, pMixer->cSinks));
|
---|
75 |
|
---|
76 | if (ppSink)
|
---|
77 | *ppSink = pSink;
|
---|
78 | }
|
---|
79 | else
|
---|
80 | RTMemFree(pSink);
|
---|
81 | }
|
---|
82 | else
|
---|
83 | rc = VERR_NO_MEMORY;
|
---|
84 |
|
---|
85 | return rc;
|
---|
86 | }
|
---|
87 |
|
---|
88 | int audioMixerAddStreamIn(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMIN pStream,
|
---|
89 | uint32_t uFlags, PAUDMIXSTREAM *ppStream)
|
---|
90 | {
|
---|
91 | AssertPtrReturn(pSink, VERR_INVALID_POINTER);
|
---|
92 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
93 | /** @todo Add flag validation. */
|
---|
94 | /* ppStream is optional. */
|
---|
95 |
|
---|
96 | int rc;
|
---|
97 |
|
---|
98 | if (pSink->cStreams == UINT8_MAX) /* 255 streams per sink max. */
|
---|
99 | return VERR_TOO_MUCH_DATA;
|
---|
100 |
|
---|
101 | PAUDMIXSTREAM pMixStream
|
---|
102 | = (PAUDMIXSTREAM)RTMemAllocZ(sizeof(AUDMIXSTREAM));
|
---|
103 | if (pMixStream)
|
---|
104 | {
|
---|
105 | pMixStream->pConn = pConnector;
|
---|
106 | pMixStream->pIn = pStream;
|
---|
107 | /** @todo Process flags. */
|
---|
108 |
|
---|
109 | RTListAppend(&pSink->lstStreams, &pMixStream->Node);
|
---|
110 | pSink->cStreams++;
|
---|
111 |
|
---|
112 | LogFlowFunc(("%s: pStream=%p, cStreams=%RU8\n",
|
---|
113 | pSink->pszName, pMixStream, pSink->cStreams));
|
---|
114 |
|
---|
115 | if (ppStream)
|
---|
116 | *ppStream = pMixStream;
|
---|
117 |
|
---|
118 | rc = VINF_SUCCESS;
|
---|
119 | }
|
---|
120 | else
|
---|
121 | rc = VERR_NO_MEMORY;
|
---|
122 |
|
---|
123 | return rc;
|
---|
124 | }
|
---|
125 |
|
---|
126 | int audioMixerAddStreamOut(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMOUT pStream,
|
---|
127 | uint32_t uFlags, PAUDMIXSTREAM *ppStream)
|
---|
128 | {
|
---|
129 | AssertPtrReturn(pSink, VERR_INVALID_POINTER);
|
---|
130 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
131 | /** @todo Add flag validation. */
|
---|
132 | /* ppStream is optional. */
|
---|
133 |
|
---|
134 | int rc;
|
---|
135 |
|
---|
136 | if (pSink->cStreams == UINT8_MAX) /* 255 streams per sink max. */
|
---|
137 | return VERR_TOO_MUCH_DATA;
|
---|
138 |
|
---|
139 | PAUDMIXSTREAM pMixStream
|
---|
140 | = (PAUDMIXSTREAM)RTMemAllocZ(sizeof(AUDMIXSTREAM));
|
---|
141 | if (pMixStream)
|
---|
142 | {
|
---|
143 | pMixStream->pConn = pConnector;
|
---|
144 | pMixStream->pOut = pStream;
|
---|
145 | /** @todo Process flags. */
|
---|
146 |
|
---|
147 | RTListAppend(&pSink->lstStreams, &pMixStream->Node);
|
---|
148 | pSink->cStreams++;
|
---|
149 |
|
---|
150 | LogFlowFunc(("%s: pStream=%p, cStreams=%RU8\n",
|
---|
151 | pSink->pszName, pMixStream, pSink->cStreams));
|
---|
152 |
|
---|
153 | if (ppStream)
|
---|
154 | *ppStream = pMixStream;
|
---|
155 |
|
---|
156 | rc = VINF_SUCCESS;
|
---|
157 | }
|
---|
158 | else
|
---|
159 | rc = VERR_NO_MEMORY;
|
---|
160 |
|
---|
161 | return rc;
|
---|
162 | }
|
---|
163 |
|
---|
164 | int audioMixerControlStream(PAUDIOMIXER pMixer, PAUDMIXSTREAM pHandle)
|
---|
165 | {
|
---|
166 | return VERR_NOT_IMPLEMENTED;
|
---|
167 | }
|
---|
168 |
|
---|
169 | int audioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer)
|
---|
170 | {
|
---|
171 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
172 | /** @todo Add flag validation. */
|
---|
173 | AssertPtrReturn(ppMixer, VERR_INVALID_POINTER);
|
---|
174 |
|
---|
175 | int rc = VINF_SUCCESS;
|
---|
176 |
|
---|
177 | PAUDIOMIXER pMixer = (PAUDIOMIXER)RTMemAllocZ(sizeof(AUDIOMIXER));
|
---|
178 | if (pMixer)
|
---|
179 | {
|
---|
180 | pMixer->pszName = RTStrDup(pszName);
|
---|
181 | if (!pMixer->pszName)
|
---|
182 | rc = VERR_NO_MEMORY;
|
---|
183 |
|
---|
184 | if (RT_SUCCESS(rc))
|
---|
185 | {
|
---|
186 | pMixer->cSinks = 0;
|
---|
187 | RTListInit(&pMixer->lstSinks);
|
---|
188 |
|
---|
189 | pMixer->VolMaster.fMuted = false;
|
---|
190 | pMixer->VolMaster.uLeft = UINT32_MAX;
|
---|
191 | pMixer->VolMaster.uRight = UINT32_MAX;
|
---|
192 |
|
---|
193 | LogFlowFunc(("Created %p ...\n", pMixer));
|
---|
194 |
|
---|
195 | *ppMixer = pMixer;
|
---|
196 | }
|
---|
197 | else
|
---|
198 | RTMemFree(pMixer);
|
---|
199 | }
|
---|
200 | else
|
---|
201 | rc = VERR_NO_MEMORY;
|
---|
202 |
|
---|
203 | LogFlowFuncLeaveRC(rc);
|
---|
204 | return rc;
|
---|
205 | }
|
---|
206 |
|
---|
207 | void audioMixerDestroy(PAUDIOMIXER pMixer)
|
---|
208 | {
|
---|
209 | if (pMixer)
|
---|
210 | {
|
---|
211 | LogFlowFunc(("Destroying %s ...\n", pMixer->pszName));
|
---|
212 |
|
---|
213 | PAUDMIXSINK pSink = RTListGetFirst(&pMixer->lstSinks, AUDMIXSINK, Node);
|
---|
214 | while (pSink)
|
---|
215 | {
|
---|
216 | PAUDMIXSINK pNext = RTListNodeGetNext(&pSink->Node, AUDMIXSINK, Node);
|
---|
217 | bool fLast = RTListNodeIsLast(&pMixer->lstSinks, &pSink->Node);
|
---|
218 |
|
---|
219 | audioMixerRemoveSink(pMixer, pSink);
|
---|
220 |
|
---|
221 | if (fLast)
|
---|
222 | break;
|
---|
223 |
|
---|
224 | pSink = pNext;
|
---|
225 | }
|
---|
226 |
|
---|
227 | Assert(pMixer->cSinks == 0);
|
---|
228 |
|
---|
229 | RTStrFree(pMixer->pszName);
|
---|
230 |
|
---|
231 | RTMemFree(pMixer);
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | static void audioMixerDestroySink(PAUDMIXSINK pSink)
|
---|
236 | {
|
---|
237 | AssertPtrReturnVoid(pSink);
|
---|
238 | if (!pSink)
|
---|
239 | return;
|
---|
240 |
|
---|
241 | RTStrFree(pSink->pszName);
|
---|
242 |
|
---|
243 | RTMemFree(pSink);
|
---|
244 | }
|
---|
245 |
|
---|
246 | static void audioMixerDestroyStream(PAUDMIXSTREAM pStream)
|
---|
247 | {
|
---|
248 | AssertPtrReturnVoid(pStream);
|
---|
249 | if (!pStream)
|
---|
250 | return;
|
---|
251 |
|
---|
252 | RTMemFree(pStream);
|
---|
253 | }
|
---|
254 |
|
---|
255 | uint32_t audioMixerGetStreamCount(PAUDIOMIXER pMixer)
|
---|
256 | {
|
---|
257 | AssertPtrReturn(pMixer, 0);
|
---|
258 |
|
---|
259 | uint32_t cStreams = 0;
|
---|
260 |
|
---|
261 | PAUDMIXSINK pSink;
|
---|
262 | RTListForEach(&pMixer->lstSinks, pSink, AUDMIXSINK, Node)
|
---|
263 | cStreams += pSink->cStreams;
|
---|
264 |
|
---|
265 | return cStreams;
|
---|
266 | }
|
---|
267 |
|
---|
268 | void audioMixerInvalidate(PAUDIOMIXER pMixer)
|
---|
269 | {
|
---|
270 | AssertPtrReturnVoid(pMixer);
|
---|
271 |
|
---|
272 | LogFlowFunc(("%s: Invalidating ...\n", pMixer->pszName));
|
---|
273 |
|
---|
274 | /* Propagate new master volume to all connected sinks. */
|
---|
275 | PAUDMIXSINK pSink;
|
---|
276 | RTListForEach(&pMixer->lstSinks, pSink, AUDMIXSINK, Node)
|
---|
277 | {
|
---|
278 | int rc2 = audioMixerUpdateSinkVolume(pSink, &pMixer->VolMaster, &pSink->Volume);
|
---|
279 | AssertRC(rc2);
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 | int audioMixerProcessSinkIn(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed)
|
---|
284 | {
|
---|
285 | AssertPtrReturn(pSink, VERR_INVALID_POINTER);
|
---|
286 | AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
|
---|
287 | AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
|
---|
288 | /* pcbProcessed is optional. */
|
---|
289 |
|
---|
290 | /** @todo Handle mixing operation enmOp! */
|
---|
291 |
|
---|
292 | uint8_t *pvMixBuf = (uint8_t *)RTMemAlloc(cbBuf);
|
---|
293 | if (!pvMixBuf)
|
---|
294 | return VERR_NO_MEMORY;
|
---|
295 |
|
---|
296 | int rc = VERR_NOT_FOUND;
|
---|
297 | uint32_t cbProcessed = 0;
|
---|
298 |
|
---|
299 | LogFlowFunc(("%s: pvBuf=%p, cbBuf=%zu\n", pSink->pszName, pvBuf, cbBuf));
|
---|
300 |
|
---|
301 | PAUDMIXSTREAM pStream;
|
---|
302 | RTListForEach(&pSink->lstStreams, pStream, AUDMIXSTREAM, Node)
|
---|
303 | {
|
---|
304 | /** @todo Support output sinks as well! */
|
---|
305 | if (!pStream->pConn->pfnIsActiveIn(pStream->pConn, pStream->pIn))
|
---|
306 | continue;
|
---|
307 |
|
---|
308 | uint32_t cbTotalRead = 0;
|
---|
309 | uint32_t cbToRead = cbBuf;
|
---|
310 |
|
---|
311 | while (cbToRead)
|
---|
312 | {
|
---|
313 | uint32_t cbRead;
|
---|
314 | AssertPtr(pStream->pConn);
|
---|
315 | rc = pStream->pConn->pfnRead(pStream->pConn, pStream->pIn,
|
---|
316 | (uint8_t *)pvMixBuf + cbTotalRead, cbToRead, &cbRead);
|
---|
317 | if ( RT_FAILURE(rc)
|
---|
318 | || !cbRead)
|
---|
319 | break;
|
---|
320 |
|
---|
321 | AssertBreakStmt(cbRead <= cbToRead, rc = VERR_BUFFER_OVERFLOW);
|
---|
322 | cbToRead -= cbRead;
|
---|
323 | cbTotalRead += cbRead;
|
---|
324 | }
|
---|
325 |
|
---|
326 | if (RT_FAILURE(rc))
|
---|
327 | continue;
|
---|
328 |
|
---|
329 | cbProcessed = RT_MAX(cbProcessed, cbTotalRead);
|
---|
330 | }
|
---|
331 |
|
---|
332 | if (RT_SUCCESS(rc))
|
---|
333 | {
|
---|
334 | memcpy(pvBuf, pvMixBuf, cbProcessed); /* @todo Use an intermediate mixing buffer per sink! */
|
---|
335 |
|
---|
336 | if (pcbProcessed)
|
---|
337 | *pcbProcessed = cbProcessed;
|
---|
338 | }
|
---|
339 |
|
---|
340 | RTMemFree(pvMixBuf);
|
---|
341 |
|
---|
342 | LogFlowFunc(("cbProcessed=%RU32, rc=%Rrc\n", cbProcessed, rc));
|
---|
343 | return rc;
|
---|
344 | }
|
---|
345 |
|
---|
346 | int audioMixerProcessSinkOut(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed)
|
---|
347 | {
|
---|
348 | return VERR_NOT_IMPLEMENTED;
|
---|
349 | }
|
---|
350 |
|
---|
351 | void audioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink)
|
---|
352 | {
|
---|
353 | AssertPtrReturnVoid(pMixer);
|
---|
354 | if (!pSink)
|
---|
355 | return;
|
---|
356 |
|
---|
357 | PAUDMIXSTREAM pStream = RTListGetFirst(&pSink->lstStreams, AUDMIXSTREAM, Node);
|
---|
358 | while (pStream)
|
---|
359 | {
|
---|
360 | PAUDMIXSTREAM pNext = RTListNodeGetNext(&pStream->Node, AUDMIXSTREAM, Node);
|
---|
361 | bool fLast = RTListNodeIsLast(&pSink->lstStreams, &pStream->Node);
|
---|
362 |
|
---|
363 | audioMixerRemoveStream(pSink, pStream);
|
---|
364 |
|
---|
365 | if (fLast)
|
---|
366 | break;
|
---|
367 |
|
---|
368 | pStream = pNext;
|
---|
369 | }
|
---|
370 |
|
---|
371 | Assert(pSink->cStreams == 0);
|
---|
372 |
|
---|
373 | RTListNodeRemove(&pSink->Node);
|
---|
374 | Assert(pMixer->cSinks);
|
---|
375 | pMixer->cSinks--;
|
---|
376 |
|
---|
377 | LogFlowFunc(("%s: pSink=%s, cSinks=%RU8\n",
|
---|
378 | pMixer->pszName, pSink->pszName, pMixer->cSinks));
|
---|
379 |
|
---|
380 | audioMixerDestroySink(pSink);
|
---|
381 | }
|
---|
382 |
|
---|
383 | void audioMixerRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream)
|
---|
384 | {
|
---|
385 | AssertPtrReturnVoid(pSink);
|
---|
386 | if (!pStream)
|
---|
387 | return;
|
---|
388 |
|
---|
389 | Assert(pSink->cStreams);
|
---|
390 | RTListNodeRemove(&pStream->Node);
|
---|
391 | pSink->cStreams--;
|
---|
392 |
|
---|
393 | const char *pszStream = pSink->enmDir == AUDMIXSINKDIR_INPUT
|
---|
394 | ? pStream->pIn->MixBuf.pszName : pStream->pOut->MixBuf.pszName;
|
---|
395 |
|
---|
396 | LogFlowFunc(("%s: pStream=%s, cStreams=%RU8\n",
|
---|
397 | pSink->pszName, pszStream, pSink->cStreams));
|
---|
398 |
|
---|
399 | audioMixerDestroyStream(pStream);
|
---|
400 | }
|
---|
401 |
|
---|
402 | int audioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg)
|
---|
403 | {
|
---|
404 | AssertPtrReturn(pMixer, VERR_INVALID_POINTER);
|
---|
405 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
406 |
|
---|
407 | /** @todo Perform a deep copy, if needed. */
|
---|
408 | pMixer->devFmt = *pCfg;
|
---|
409 |
|
---|
410 | return VINF_SUCCESS;
|
---|
411 | }
|
---|
412 |
|
---|
413 | static inline PDMAUDIOVOLUME audioMixerVolCalc(PPDMAUDIOVOLUME pVol)
|
---|
414 | {
|
---|
415 | uint32_t u32VolumeLeft = pVol->uLeft;
|
---|
416 | uint32_t u32VolumeRight = pVol->uRight;
|
---|
417 | /* 0x00..0xff => 0x01..0x100 */
|
---|
418 | if (u32VolumeLeft)
|
---|
419 | u32VolumeLeft++;
|
---|
420 | if (u32VolumeRight)
|
---|
421 | u32VolumeRight++;
|
---|
422 |
|
---|
423 | PDMAUDIOVOLUME volOut;
|
---|
424 | volOut.fMuted = pVol->fMuted;
|
---|
425 | volOut.uLeft = u32VolumeLeft * 0x80000000; /* Maximum is 0x80000000 */
|
---|
426 | volOut.uRight = u32VolumeRight * 0x80000000; /* Maximum is 0x80000000 */
|
---|
427 |
|
---|
428 | return volOut;
|
---|
429 | }
|
---|
430 |
|
---|
431 | static inline PDMAUDIOVOLUME audioMixerVolMix(const PPDMAUDIOVOLUME pVolMaster, PPDMAUDIOVOLUME pVol)
|
---|
432 | {
|
---|
433 | PDMAUDIOVOLUME volOut;
|
---|
434 | volOut.fMuted = pVolMaster->fMuted || pVol->fMuted;
|
---|
435 | volOut.uLeft = ASMMultU64ByU32DivByU32(pVolMaster->uLeft, pVol->uLeft, 0x80000000U); /* Maximum is 0x80000000U */
|
---|
436 | volOut.uRight = ASMMultU64ByU32DivByU32(pVolMaster->uRight, pVol->uRight, 0x80000000U); /* Maximum is 0x80000000U */
|
---|
437 |
|
---|
438 | LogFlowFunc(("pMaster=%p, fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
439 | pVolMaster, pVolMaster->fMuted, pVolMaster->uLeft, pVolMaster->uRight));
|
---|
440 | LogFlowFunc(("pVol=%p, fMuted=%RTbool, lVol=%RU32, rVol=%RU32 => fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
441 | pVol, pVol->fMuted, pVol->uLeft, pVol->uRight, volOut.fMuted, volOut.uLeft, volOut.uRight));
|
---|
442 |
|
---|
443 | return volOut;
|
---|
444 | }
|
---|
445 |
|
---|
446 | static int audioMixerUpdateSinkVolume(PAUDMIXSINK pSink, const PPDMAUDIOVOLUME pVolMaster, const PPDMAUDIOVOLUME pVolSink)
|
---|
447 | {
|
---|
448 | AssertPtrReturn(pSink, VERR_INVALID_POINTER);
|
---|
449 | AssertPtrReturn(pVolMaster, VERR_INVALID_POINTER);
|
---|
450 | AssertPtrReturn(pVolSink, VERR_INVALID_POINTER);
|
---|
451 |
|
---|
452 | LogFlowFunc(("Master fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
453 | pVolMaster->fMuted, pVolMaster->uLeft, pVolMaster->uRight));
|
---|
454 | LogFlowFunc(("%s: fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
455 | pSink->pszName, pSink->Volume.fMuted, pSink->Volume.uLeft, pSink->Volume.uRight));
|
---|
456 |
|
---|
457 | /** @todo Very crude implementation for now -- needs more work! */
|
---|
458 |
|
---|
459 | PDMAUDIOVOLUME volSink;
|
---|
460 | volSink.fMuted = pVolMaster->fMuted || pVolSink->fMuted;
|
---|
461 | volSink.uLeft = (pVolSink->uLeft * pVolMaster->uLeft) / UINT8_MAX;
|
---|
462 | volSink.uRight = (pVolSink->uRight * pVolMaster->uRight) / UINT8_MAX;
|
---|
463 |
|
---|
464 | LogFlowFunc(("\t-> fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
465 | volSink.fMuted, volSink.uLeft, volSink.uRight));
|
---|
466 |
|
---|
467 | bool fOut = pSink->enmDir == AUDMIXSINKDIR_OUTPUT;
|
---|
468 |
|
---|
469 | /* Propagate new sink volume to all streams in the sink. */
|
---|
470 | PAUDMIXSTREAM pStream;
|
---|
471 | RTListForEach(&pSink->lstStreams, pStream, AUDMIXSTREAM, Node)
|
---|
472 | {
|
---|
473 | if (fOut)
|
---|
474 | audioMixBufSetVolume(&pStream->pOut->MixBuf, &volSink);
|
---|
475 | else
|
---|
476 | audioMixBufSetVolume(&pStream->pIn->MixBuf, &volSink);
|
---|
477 | }
|
---|
478 |
|
---|
479 | return VINF_SUCCESS;
|
---|
480 | }
|
---|
481 |
|
---|
482 | int audioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol)
|
---|
483 | {
|
---|
484 | AssertPtrReturn(pMixer, VERR_INVALID_POINTER);
|
---|
485 | AssertPtrReturn(pVol, VERR_INVALID_POINTER);
|
---|
486 |
|
---|
487 | pMixer->VolMaster = *pVol; //= audioMixerVolCalc(pVol);
|
---|
488 |
|
---|
489 | LogFlowFunc(("%s: lVol=%RU32, rVol=%RU32 => fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
|
---|
490 | pMixer->pszName, pVol->uLeft, pVol->uRight,
|
---|
491 | pMixer->VolMaster.fMuted, pMixer->VolMaster.uLeft, pMixer->VolMaster.uRight));
|
---|
492 |
|
---|
493 | audioMixerInvalidate(pMixer);
|
---|
494 | return VINF_SUCCESS;
|
---|
495 | }
|
---|
496 |
|
---|
497 | int audioMixerSetSinkVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol)
|
---|
498 | {
|
---|
499 | AssertPtrReturn(pSink, VERR_INVALID_POINTER);
|
---|
500 | AssertPtrReturn(pVol, VERR_INVALID_POINTER);
|
---|
501 |
|
---|
502 | LogFlowFunc(("%s: fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n", pSink->pszName, pVol->fMuted, pVol->uLeft, pVol->uRight));
|
---|
503 |
|
---|
504 | AssertPtr(pSink->pParent);
|
---|
505 | return audioMixerUpdateSinkVolume(pSink, &pSink->pParent->VolMaster, pVol);
|
---|
506 | }
|
---|
507 |
|
---|