Phonon

pulsestream.cpp
1/*
2 Copyright (C) 2010 Colin Guthrie <cguthrie@mandriva.org>
3 Copyright (C) 2013 Harald Sitter <sitter@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) version 3, or any
9 later version accepted by the membership of KDE e.V. (or its
10 successor approved by the membership of KDE e.V.), Nokia Corporation
11 (or its successors, if any) and the KDE Free Qt Foundation, which shall
12 act as a proxy defined in Section 6 of version 3 of the license.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "pulsestream_p.h"
24
25#include <qmath.h>
26
27#include "pulsesupport.h"
28
29namespace Phonon
30{
31
32PulseStream::PulseStream(QString streamUuid, QString role)
33 : QObject()
34 , mStreamUuid(streamUuid)
35 , mIndex(PA_INVALID_INDEX)
36 , mDevice(-1)
37 , mMute(false)
38 , mCachedVolume(-1)
39 , mRole(role)
40{
41 pa_cvolume_init(&mVolume);
42}
43
44PulseStream::~PulseStream()
45{
46}
47
48QString PulseStream::uuid() const
49{
50 return mStreamUuid;
51}
52
53uint32_t PulseStream::index() const
54{
55 return mIndex;
56}
57
58void PulseStream::setIndex(uint32_t index)
59{
60 mIndex = index;
61}
62
63uint8_t PulseStream::channels() const
64{
65 return mVolume.channels;
66}
67
68void PulseStream::setDevice(int device)
69{
70 if (mDevice != device) {
71 mDevice = device;
72 emit usingDevice(device);
73 }
74}
75
76// Copied from AudioOutput
77static const qreal LOUDNESS_TO_VOLTAGE_EXPONENT = qreal(0.67);
78static const qreal VOLTAGE_TO_LOUDNESS_EXPONENT = qreal(1.0/LOUDNESS_TO_VOLTAGE_EXPONENT);
79
80void PulseStream::setVolume(const pa_cvolume *volume)
81{
82 if (mCachedVolume != -1)
83 QMetaObject::invokeMethod(this, "applyCachedVolume", Qt::QueuedConnection);
84 if (pa_cvolume_equal(&mVolume, volume) == 0) {
85 memcpy(&mVolume, volume, sizeof(mVolume));
86 qreal vol = (qreal)pa_cvolume_avg(volume) / PA_VOLUME_NORM;
87 // AudioOutput expects the "backend" to supply values that have been
88 // adjusted for Stephens' law, so we need to fudge them accordingly
89 // so that the %ages match up in KMix/the application's own slider.
90 emit volumeChanged(qPow(vol, VOLTAGE_TO_LOUDNESS_EXPONENT));
91 }
92}
93
94void PulseStream::setMute(bool mute)
95{
96 if (mMute != mute) {
97 mMute = mute;
98 emit muteChanged(mMute);
99 }
100}
101
102qreal PulseStream::cachedVolume() const
103{
104 return mCachedVolume;
105}
106
107void PulseStream::setCachedVolume(qreal volume)
108{
109 mCachedVolume = volume;
110}
111
112QString PulseStream::role() const
113{
114 return mRole;
115}
116
117void PulseStream::applyCachedVolume()
118{
119 if (mCachedVolume == -1)
120 return;
121 PulseSupport::getInstance()->setOutputVolume(mStreamUuid, mCachedVolume);
122 mCachedVolume = -1;
123}
124
125} // namespace Phonon
126
127#include "moc_pulsestream_p.cpp"
128
129// vim: sw=4 ts=4
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QueuedConnection
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.