File indexing completed on 2025-02-09 05:31:52
0001 /* 0002 Copyright (C) 2010 Colin Guthrie <cguthrie@mandriva.org> 0003 Copyright (C) 2013 Harald Sitter <sitter@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Lesser General Public 0007 License as published by the Free Software Foundation; either 0008 version 2.1 of the License, or (at your option) version 3, or any 0009 later version accepted by the membership of KDE e.V. (or its 0010 successor approved by the membership of KDE e.V.), Nokia Corporation 0011 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0012 act as a proxy defined in Section 6 of version 3 of the license. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public 0020 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "pulsestream_p.h" 0024 0025 #include <qmath.h> 0026 0027 #include "pulsesupport.h" 0028 0029 namespace Phonon 0030 { 0031 0032 PulseStream::PulseStream(QString streamUuid, QString role) 0033 : QObject() 0034 , mStreamUuid(streamUuid) 0035 , mIndex(PA_INVALID_INDEX) 0036 , mDevice(-1) 0037 , mMute(false) 0038 , mCachedVolume(-1) 0039 , mRole(role) 0040 { 0041 pa_cvolume_init(&mVolume); 0042 } 0043 0044 PulseStream::~PulseStream() 0045 { 0046 } 0047 0048 QString PulseStream::uuid() const 0049 { 0050 return mStreamUuid; 0051 } 0052 0053 uint32_t PulseStream::index() const 0054 { 0055 return mIndex; 0056 } 0057 0058 void PulseStream::setIndex(uint32_t index) 0059 { 0060 mIndex = index; 0061 } 0062 0063 uint8_t PulseStream::channels() const 0064 { 0065 return mVolume.channels; 0066 } 0067 0068 void PulseStream::setDevice(int device) 0069 { 0070 if (mDevice != device) { 0071 mDevice = device; 0072 emit usingDevice(device); 0073 } 0074 } 0075 0076 // Copied from AudioOutput 0077 static const qreal LOUDNESS_TO_VOLTAGE_EXPONENT = qreal(0.67); 0078 static const qreal VOLTAGE_TO_LOUDNESS_EXPONENT = qreal(1.0/LOUDNESS_TO_VOLTAGE_EXPONENT); 0079 0080 void PulseStream::setVolume(const pa_cvolume *volume) 0081 { 0082 if (mCachedVolume != -1) 0083 QMetaObject::invokeMethod(this, "applyCachedVolume", Qt::QueuedConnection); 0084 if (pa_cvolume_equal(&mVolume, volume) == 0) { 0085 memcpy(&mVolume, volume, sizeof(mVolume)); 0086 qreal vol = (qreal)pa_cvolume_avg(volume) / PA_VOLUME_NORM; 0087 // AudioOutput expects the "backend" to supply values that have been 0088 // adjusted for Stephens' law, so we need to fudge them accordingly 0089 // so that the %ages match up in KMix/the application's own slider. 0090 emit volumeChanged(qPow(vol, VOLTAGE_TO_LOUDNESS_EXPONENT)); 0091 } 0092 } 0093 0094 void PulseStream::setMute(bool mute) 0095 { 0096 if (mMute != mute) { 0097 mMute = mute; 0098 emit muteChanged(mMute); 0099 } 0100 } 0101 0102 qreal PulseStream::cachedVolume() const 0103 { 0104 return mCachedVolume; 0105 } 0106 0107 void PulseStream::setCachedVolume(qreal volume) 0108 { 0109 mCachedVolume = volume; 0110 } 0111 0112 QString PulseStream::role() const 0113 { 0114 return mRole; 0115 } 0116 0117 void PulseStream::applyCachedVolume() 0118 { 0119 if (mCachedVolume == -1) 0120 return; 0121 PulseSupport::getInstance()->setOutputVolume(mStreamUuid, mCachedVolume); 0122 mCachedVolume = -1; 0123 } 0124 0125 } // namespace Phonon 0126 0127 #include "moc_pulsestream_p.cpp" 0128 0129 // vim: sw=4 ts=4