diff options
Diffstat (limited to 'src/multimedia')
22 files changed, 386 insertions, 85 deletions
diff --git a/src/multimedia/audio/audio.pri b/src/multimedia/audio/audio.pri index 96cfb1ce4..4706fd23e 100644 --- a/src/multimedia/audio/audio.pri +++ b/src/multimedia/audio/audio.pri @@ -19,7 +19,8 @@ PRIVATE_HEADERS += \ audio/qaudiodevicefactory_p.h \ audio/qwavedecoder_p.h \ audio/qsamplecache_p.h \ - audio/qaudiohelpers_p.h + audio/qaudiohelpers_p.h \ + audio/qaudiosystempluginext_p.h SOURCES += \ audio/qaudio.cpp \ diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp index c708fa4f8..d4f89e898 100644 --- a/src/multimedia/audio/qaudio.cpp +++ b/src/multimedia/audio/qaudio.cpp @@ -39,16 +39,20 @@ #include <qaudio.h> +#include <qmath.h> #include <QDebug> QT_BEGIN_NAMESPACE +#define LOG100 4.60517018599 + static void qRegisterAudioMetaTypes() { qRegisterMetaType<QAudio::Error>(); qRegisterMetaType<QAudio::State>(); qRegisterMetaType<QAudio::Mode>(); qRegisterMetaType<QAudio::Role>(); + qRegisterMetaType<QAudio::VolumeScale>(); } Q_CONSTRUCTOR_FUNCTION(qRegisterAudioMetaTypes) @@ -111,6 +115,134 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterAudioMetaTypes) \sa QMediaPlayer::setAudioRole() */ +/*! + \enum QAudio::VolumeScale + + This enum defines the different audio volume scales. + + \value LinearVolumeScale Linear scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full + volume. All Qt Multimedia classes that have an audio volume use + a linear scale. + \value CubicVolumeScale Cubic scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full + volume. + \value LogarithmicVolumeScale Logarithmic Scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is + full volume. UI volume controls should usually use a logarithmic + scale. + \value DecibelVolumeScale Decibel (dB, amplitude) logarithmic scale. \c -200 is silence + and \c 0 is full volume. + + \since 5.8 + \sa QAudio::convertVolume() +*/ + +namespace QAudio +{ + +/*! + \fn qreal QAudio::convertVolume(qreal volume, VolumeScale from, VolumeScale to) + + Converts an audio \a volume \a from a volume scale \a to another, and returns the result. + + Depending on the context, different scales are used to represent audio volume. All Qt Multimedia + classes that have an audio volume use a linear scale, the reason is that the loudness of a + speaker is controlled by modulating its voltage on a linear scale. The human ear on the other + hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls + is therefore appropriate in most applications. The decibel scale is logarithmic by nature and + is commonly used to define sound levels, it is usually used for UI volume controls in + professional audio applications. The cubic scale is a computationally cheap approximation of a + logarithmic scale, it provides more control over lower volume levels. + + The following example shows how to convert the volume value from a slider control before passing + it to a QMediaPlayer. As a result, the perceived increase in volume is the same when increasing + the volume slider from 20 to 30 as it is from 50 to 60: + + \snippet multimedia-snippets/audio.cpp Volume conversion + + \since 5.8 + \sa VolumeScale, QMediaPlayer::setVolume(), QAudioOutput::setVolume(), + QAudioInput::setVolume(), QSoundEffect::setVolume(), QMediaRecorder::setVolume() +*/ +qreal convertVolume(qreal volume, VolumeScale from, VolumeScale to) +{ + switch (from) { + case LinearVolumeScale: + volume = qMax(qreal(0), volume); + switch (to) { + case LinearVolumeScale: + return volume; + case CubicVolumeScale: + return qPow(volume, qreal(1 / 3.0)); + case LogarithmicVolumeScale: + return 1 - std::exp(-volume * LOG100); + case DecibelVolumeScale: + if (volume < 0.001) + return qreal(-200); + else + return qreal(20.0) * std::log10(volume); + } + break; + case CubicVolumeScale: + volume = qMax(qreal(0), volume); + switch (to) { + case LinearVolumeScale: + return volume * volume * volume; + case CubicVolumeScale: + return volume; + case LogarithmicVolumeScale: + return 1 - std::exp(-volume * volume * volume * LOG100); + case DecibelVolumeScale: + if (volume < 0.001) + return qreal(-200); + else + return qreal(3.0 * 20.0) * std::log10(volume); + } + break; + case LogarithmicVolumeScale: + volume = qMax(qreal(0), volume); + switch (to) { + case LinearVolumeScale: + if (volume > 0.99) + return 1; + else + return -std::log(1 - volume) / LOG100; + case CubicVolumeScale: + if (volume > 0.99) + return 1; + else + return qPow(-std::log(1 - volume) / LOG100, qreal(1 / 3.0)); + case LogarithmicVolumeScale: + return volume; + case DecibelVolumeScale: + if (volume < 0.001) + return qreal(-200); + else if (volume > 0.99) + return 0; + else + return qreal(20.0) * std::log10(-std::log(1 - volume) / LOG100); + } + break; + case DecibelVolumeScale: + switch (to) { + case LinearVolumeScale: + return qPow(qreal(10.0), volume / qreal(20.0)); + case CubicVolumeScale: + return qPow(qreal(10.0), volume / qreal(3.0 * 20.0)); + case LogarithmicVolumeScale: + if (qFuzzyIsNull(volume)) + return 1; + else + return 1 - std::exp(-qPow(qreal(10.0), volume / qreal(20.0)) * LOG100); + case DecibelVolumeScale: + return volume; + } + break; + } + + return volume; +} + +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, QAudio::Error error) { @@ -210,6 +342,28 @@ QDebug operator<<(QDebug dbg, QAudio::Role role) } return dbg; } + +QDebug operator<<(QDebug dbg, QAudio::VolumeScale scale) +{ + QDebugStateSaver saver(dbg); + dbg.nospace(); + switch (scale) { + case QAudio::LinearVolumeScale: + dbg << "LinearVolumeScale"; + break; + case QAudio::CubicVolumeScale: + dbg << "CubicVolumeScale"; + break; + case QAudio::LogarithmicVolumeScale: + dbg << "LogarithmicVolumeScale"; + break; + case QAudio::DecibelVolumeScale: + dbg << "DecibelVolumeScale"; + break; + } + return dbg; +} + #endif diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h index 449ddefae..457a3b621 100644 --- a/src/multimedia/audio/qaudio.h +++ b/src/multimedia/audio/qaudio.h @@ -70,6 +70,15 @@ namespace QAudio SonificationRole, GameRole }; + + enum VolumeScale { + LinearVolumeScale, + CubicVolumeScale, + LogarithmicVolumeScale, + DecibelVolumeScale + }; + + Q_MULTIMEDIA_EXPORT qreal convertVolume(qreal volume, VolumeScale from, VolumeScale to); } #ifndef QT_NO_DEBUG_STREAM @@ -77,6 +86,7 @@ Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Error error); Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::State state); Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Mode mode); Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Role role); +Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::VolumeScale role); #endif QT_END_NAMESPACE @@ -85,5 +95,6 @@ Q_DECLARE_METATYPE(QAudio::Error) Q_DECLARE_METATYPE(QAudio::State) Q_DECLARE_METATYPE(QAudio::Mode) Q_DECLARE_METATYPE(QAudio::Role) +Q_DECLARE_METATYPE(QAudio::VolumeScale) #endif // QAUDIO_H diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp index 83e1a6c0b..c3e4929b3 100644 --- a/src/multimedia/audio/qaudiodevicefactory.cpp +++ b/src/multimedia/audio/qaudiodevicefactory.cpp @@ -41,6 +41,7 @@ #include "qaudiosystem.h" #include "qaudiosystemplugin.h" +#include "qaudiosystempluginext_p.h" #include "qmediapluginloader_p.h" #include "qaudiodevicefactory_p.h" @@ -139,41 +140,53 @@ QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode) return devices; } -QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() +QAudioDeviceInfo QAudioDeviceFactory::defaultDevice(QAudio::Mode mode) { #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) - QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(audioLoader()->instance(defaultKey())); - if (plugin) { - QList<QByteArray> list = plugin->availableDevices(QAudio::AudioInput); - if (list.size() > 0) - return QAudioDeviceInfo(defaultKey(), list.at(0), QAudio::AudioInput); - } + QMediaPluginLoader* l = audioLoader(); - // if no plugin is marked as default or if the default plugin doesn't have any input device, - // return the first input available from other plugins. - QList<QAudioDeviceInfo> inputDevices = availableDevices(QAudio::AudioInput); - if (!inputDevices.isEmpty()) - return inputDevices.first(); -#endif + // Check if there is a default plugin. + QAudioSystemFactoryInterface *plugin = qobject_cast<QAudioSystemFactoryInterface *>(l->instance(defaultKey())); + if (plugin) { + // Check if the plugin has the extension interface. + QAudioSystemPluginExtension *pluginExt = qobject_cast<QAudioSystemPluginExtension *>(l->instance(defaultKey())); + // Ask for the default device. + if (pluginExt) { + const QByteArray &device = pluginExt->defaultDevice(mode); + if (!device.isEmpty()) + return QAudioDeviceInfo(defaultKey(), device, mode); + } - return QAudioDeviceInfo(); -} + // If there were no default devices, e.g., if the plugin did not implement the extent-ion interface, + // then just pick the first device that's available. + const auto &devices = plugin->availableDevices(mode); + if (!devices.isEmpty()) + return QAudioDeviceInfo(defaultKey(), devices.first(), mode); + } -QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() -{ -#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) - QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(audioLoader()->instance(defaultKey())); - if (plugin) { - QList<QByteArray> list = plugin->availableDevices(QAudio::AudioOutput); - if (list.size() > 0) - return QAudioDeviceInfo(defaultKey(), list.at(0), QAudio::AudioOutput); + // If no plugin is marked as default, check the other plugins. + // Note: We're going to prioritize plugins that report a default device. + const auto &keys = l->keys(); + QAudioDeviceInfo fallbackDevice; + for (const auto &key : keys) { + if (key == defaultKey()) + continue; + QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(l->instance(key)); + if (plugin) { + // Check if the plugin has the extent-ion interface. + QAudioSystemPluginExtension *pluginExt = qobject_cast<QAudioSystemPluginExtension *>(l->instance(key)); + if (pluginExt) { + const QByteArray &device = pluginExt->defaultDevice(mode); + if (!device.isEmpty()) + return QAudioDeviceInfo(key, device, mode); + } else if (fallbackDevice.isNull()) { + const auto &devices = plugin->availableDevices(mode); + if (!devices.isEmpty()) + fallbackDevice = QAudioDeviceInfo(key, devices.first(), mode); + } + } } - // if no plugin is marked as default or if the default plugin doesn't have any output device, - // return the first output available from other plugins. - QList<QAudioDeviceInfo> outputDevices = availableDevices(QAudio::AudioOutput); - if (!outputDevices.isEmpty()) - return outputDevices.first(); #endif return QAudioDeviceInfo(); @@ -196,12 +209,12 @@ QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &re QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format) { - return createInputDevice(defaultInputDevice(), format); + return createInputDevice(defaultDevice(QAudio::AudioInput), format); } QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format) { - return createOutputDevice(defaultOutputDevice(), format); + return createOutputDevice(defaultDevice(QAudio::AudioOutput), format); } QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h index 833184075..7ad5e4e78 100644 --- a/src/multimedia/audio/qaudiodevicefactory_p.h +++ b/src/multimedia/audio/qaudiodevicefactory_p.h @@ -71,8 +71,7 @@ class QAudioDeviceFactory public: static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode); - static QAudioDeviceInfo defaultInputDevice(); - static QAudioDeviceInfo defaultOutputDevice(); + static QAudioDeviceInfo defaultDevice(QAudio::Mode mode); static QAbstractAudioDeviceInfo* audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp index 945b415e8..f4f548017 100644 --- a/src/multimedia/audio/qaudiodeviceinfo.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo.cpp @@ -419,7 +419,7 @@ QList<QAudioFormat::SampleType> QAudioDeviceInfo::supportedSampleTypes() const */ QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice() { - return QAudioDeviceFactory::defaultInputDevice(); + return QAudioDeviceFactory::defaultDevice(QAudio::AudioInput); } /*! @@ -428,7 +428,7 @@ QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice() */ QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice() { - return QAudioDeviceFactory::defaultOutputDevice(); + return QAudioDeviceFactory::defaultDevice(QAudio::AudioOutput); } /*! diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp index 07165240b..872dce819 100644 --- a/src/multimedia/audio/qaudioinput.cpp +++ b/src/multimedia/audio/qaudioinput.cpp @@ -330,10 +330,15 @@ int QAudioInput::notifyInterval() const /*! Sets the input volume to \a volume. + The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this + range will be clamped. + If the device does not support adjusting the input volume then \a volume will be ignored and the input volume will remain at 1.0. + The default volume is \c 1.0. + Note: Adjustments to the volume will change the volume of this audio stream, not the global volume. */ void QAudioInput::setVolume(qreal volume) @@ -343,7 +348,7 @@ void QAudioInput::setVolume(qreal volume) } /*! - Returns the input volume (gain). + Returns the input volume. If the device does not support adjusting the input volume the returned value will be 1.0. diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp index e96d24dd7..e37da9bdf 100644 --- a/src/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/audio/qaudiooutput.cpp @@ -349,9 +349,18 @@ QAudio::State QAudioOutput::state() const } /*! - Sets the volume. - Where \a volume is between 0.0 and 1.0 inclusive. + Sets the output volume to \a volume. + + The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this + range will be clamped. + + The default volume is \c 1.0. + Note: Adjustments to the volume will change the volume of this audio stream, not the global volume. + + UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale + will produce linear changes in perceived loudness, which is what a user would normally expect + from a volume control. See QAudio::convertVolume() for more details. */ void QAudioOutput::setVolume(qreal volume) { diff --git a/src/multimedia/audio/qaudiosystemplugin.cpp b/src/multimedia/audio/qaudiosystemplugin.cpp index 904cb22e9..636b614d4 100644 --- a/src/multimedia/audio/qaudiosystemplugin.cpp +++ b/src/multimedia/audio/qaudiosystemplugin.cpp @@ -39,6 +39,7 @@ #include "qaudiosystemplugin.h" +#include "qaudiosystempluginext_p.h" QT_BEGIN_NAMESPACE @@ -46,6 +47,10 @@ QAudioSystemFactoryInterface::~QAudioSystemFactoryInterface() { } +QAudioSystemPluginExtension::~QAudioSystemPluginExtension() +{ +} + /*! \class QAudioSystemPlugin \brief The QAudioSystemPlugin class provides an abstract base for audio plugins. @@ -72,25 +77,15 @@ QAudioSystemFactoryInterface::~QAudioSystemFactoryInterface() \sa QAbstractAudioDeviceInfo, QAbstractAudioOutput, QAbstractAudioInput - Qt supports win32, linux(alsa) and \macos standard (builtin to the - QtMultimedia library at compile time). - - You can support other backends other than these predefined ones by - creating a plugin subclassing QAudioSystemPlugin, QAbstractAudioDeviceInfo, - QAbstractAudioOutput and QAbstractAudioInput. - - - -audio-backend configure option will force compiling in of the builtin backend - into the QtMultimedia library at compile time. This is automatic by default - and will only be compiled into the library if the dependencies are installed. - eg. alsa-devel package installed for linux. + Qt comes with plugins for Windows (WinMM and WASAPI), Linux (ALSA and PulseAudio), \macos / iOS + (CoreAudio), Android (OpenSL ES) and QNX. - If the builtin backend is not compiled into the QtMultimedia library and - no audio plugins are available a fallback dummy backend will be used. - This should print out warnings if this is the case when you try and use QAudioInput or QAudioOutput. To fix this problem - reconfigure Qt using -audio-backend or create your own plugin with a default - key to always override the dummy fallback. The easiest way to determine - if you have only a dummy backend is to get a list of available audio devices. + If no audio plugins are available, a fallback dummy backend will be used. + This should print out warnings if this is the case when you try and use QAudioInput + or QAudioOutput. To fix this problem, make sure the dependencies for the Qt plugins are + installed on the system and reconfigure Qt (e.g. alsa-devel package on Linux), or create your + own plugin with a default key to always override the dummy fallback. The easiest way to + determine if you have only a dummy backend is to get a list of available audio devices. QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).size() = 0 (dummy backend) */ diff --git a/src/multimedia/audio/qaudiosystempluginext_p.h b/src/multimedia/audio/qaudiosystempluginext_p.h new file mode 100644 index 000000000..380bc5afa --- /dev/null +++ b/src/multimedia/audio/qaudiosystempluginext_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QAUDIOSYSTEMPLUGINEXT_P_H +#define QAUDIOSYSTEMPLUGINEXT_P_H + +#include <QtMultimedia/qtmultimediadefs.h> +#include <QtMultimedia/qaudio.h> +#include <QtCore/qplugin.h> + +QT_BEGIN_NAMESPACE + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +struct Q_MULTIMEDIA_EXPORT QAudioSystemPluginExtension +{ + virtual QByteArray defaultDevice(QAudio::Mode) const = 0; + virtual ~QAudioSystemPluginExtension(); +}; + +#define QAudioSystemPluginExtension_iid "org.qt-project.qt.audiosystempluginextension" +Q_DECLARE_INTERFACE(QAudioSystemPluginExtension, QAudioSystemPluginExtension_iid) + +QT_END_NAMESPACE + +#endif // QAUDIOSYSTEMPLUGINEXT_P_H diff --git a/src/multimedia/audio/qsoundeffect.cpp b/src/multimedia/audio/qsoundeffect.cpp index f7237679b..f8b8d7b18 100644 --- a/src/multimedia/audio/qsoundeffect.cpp +++ b/src/multimedia/audio/qsoundeffect.cpp @@ -258,12 +258,22 @@ int QSoundEffect::loopsRemaining() const /*! \qmlproperty qreal QtMultimedia::SoundEffect::volume - This property holds the volume of the sound effect playback, from 0.0 (silent) to 1.0 (maximum volume). + This property holds the volume of the sound effect playback. + + The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this + range will be clamped. + + The default volume is \c 1.0. + + UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale + will produce linear changes in perceived loudness, which is what a user would normally expect + from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()} + for more details. */ /*! \property QSoundEffect::volume - This property holds the volume of the sound effect playback, from 0.0 (silent) to 1.0 (maximum volume). + This property holds the volume of the sound effect playback, from 0.0 (silence) to 1.0 (full volume). */ /*! @@ -275,7 +285,16 @@ qreal QSoundEffect::volume() const } /*! - Sets the volume to play the sound effect at to \a volume, from 0.0 (silent) to 1.0 (maximum volume). + Sets the sound effect volume to \a volume. + + The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this + range will be clamped. + + The default volume is \c 1.0. + + UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale + will produce linear changes in perceived loudness, which is what a user would normally expect + from a volume control. See QAudio::convertVolume() for more details. */ void QSoundEffect::setVolume(qreal volume) { diff --git a/src/multimedia/controls/qmediaplayercontrol.cpp b/src/multimedia/controls/qmediaplayercontrol.cpp index cd56dffcb..46de05b51 100644 --- a/src/multimedia/controls/qmediaplayercontrol.cpp +++ b/src/multimedia/controls/qmediaplayercontrol.cpp @@ -175,6 +175,8 @@ QMediaPlayerControl::QMediaPlayerControl(QObject *parent): \fn QMediaPlayerControl::setVolume(int volume) Sets the audio \a volume of a player control. + + The volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume). */ /*! diff --git a/src/multimedia/controls/qmediarecordercontrol.cpp b/src/multimedia/controls/qmediarecordercontrol.cpp index abffc6811..e4667d369 100644 --- a/src/multimedia/controls/qmediarecordercontrol.cpp +++ b/src/multimedia/controls/qmediarecordercontrol.cpp @@ -160,15 +160,15 @@ QMediaRecorderControl::~QMediaRecorderControl() /*! \fn qreal QMediaRecorderControl::volume() const - Returns the linear audio gain of media recorder. + Returns the audio volume of a media recorder control. */ /*! - \fn void QMediaRecorderControl::setVolume(qreal gain) + \fn void QMediaRecorderControl::setVolume(qreal volume) - Sets the audio \a gain of a media recorder control. + Sets the audio \a volume of a media recorder control. - The gain is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume). + The volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume). */ /*! diff --git a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp index 310206405..9646b708e 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp @@ -47,6 +47,7 @@ #include "qaudiooutput.h" #include "qaudioprobe.h" #include "qaudiodecoder.h" +#include "qmediaplayer.h" class AudioInputExample : public QObject { Q_OBJECT @@ -247,3 +248,18 @@ void AudioDecodingExample::decode() // Now wait for bufferReady() signal and call decoder->read() //! [Local audio decoding] } + +QMediaPlayer player; + +//! [Volume conversion] +void applyVolume(int volumeSliderValue) +{ + // volumeSliderValue is in the range [0..100] + + qreal linearVolume = QAudio::convertVolume(volumeSliderValue / qreal(100.0), + QAudio::LogarithmicVolumeScale, + QAudio::LinearVolumeScale); + + player.setVolume(qRound(linearVolume * 100)); +} +//! [Volume conversion] diff --git a/src/multimedia/doc/src/multimedia.qdoc b/src/multimedia/doc/src/multimedia.qdoc index 84df488d2..944d8c4d7 100644 --- a/src/multimedia/doc/src/multimedia.qdoc +++ b/src/multimedia/doc/src/multimedia.qdoc @@ -177,7 +177,7 @@ what changed, and what you might need to change when porting code. \section2 QML Types The QML types are accessed by using: \code -import QtMultimedia 5.7 +import QtMultimedia 5.8 \endcode \annotatedlist multimedia_qml The following types are accessed by using \l{Qt Audio Engine QML Types}{Qt Audio Engine}: diff --git a/src/multimedia/doc/src/qtmultimedia-index.qdoc b/src/multimedia/doc/src/qtmultimedia-index.qdoc index a474a355e..484338dc8 100644 --- a/src/multimedia/doc/src/qtmultimedia-index.qdoc +++ b/src/multimedia/doc/src/qtmultimedia-index.qdoc @@ -54,7 +54,7 @@ import statement in your \c {.qml} file. \code - import QtMultimedia 5.7 + import QtMultimedia 5.8 \endcode If you intend to use the C++ classes in your application, include the C++ diff --git a/src/multimedia/doc/src/qtmultimedia5.qdoc b/src/multimedia/doc/src/qtmultimedia5.qdoc index bc200819b..29ef2734e 100644 --- a/src/multimedia/doc/src/qtmultimedia5.qdoc +++ b/src/multimedia/doc/src/qtmultimedia5.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! -\qmlmodule QtMultimedia 5.7 +\qmlmodule QtMultimedia 5.8 \title Qt Multimedia QML Types \ingroup qmlmodules \brief Provides QML types for multimedia support. @@ -42,7 +42,7 @@ The QML types for \l{Qt Multimedia} support the basic use cases such as: The QML types can be imported into your application using the following import statement in your .qml file: \code -import QtMultimedia 5.7 +import QtMultimedia 5.8 \endcode \section1 QML types diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index fdb7ef7fa..c9b9b4fc1 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -143,7 +143,7 @@ public: bool hasStreamPlaybackFeature; QMediaPlaylist *parentPlaylist(QMediaPlaylist *pls); - bool isInChain(QUrl url); + bool isInChain(const QUrl &url); void setMedia(const QMediaContent &media, QIODevice *stream = 0); @@ -175,7 +175,7 @@ QMediaPlaylist *QMediaPlayerPrivate::parentPlaylist(QMediaPlaylist *pls) return 0; } -bool QMediaPlayerPrivate::isInChain(QUrl url) +bool QMediaPlayerPrivate::isInChain(const QUrl &url) { // Check whether a URL is already in the chain of playlists. // Also see a comment in parentPlaylist(). @@ -1372,8 +1372,14 @@ QList<QAudio::Role> QMediaPlayer::supportedAudioRoles() const \property QMediaPlayer::volume \brief the current playback volume. - The playback volume is linear in effect and the value can range from 0 - - 100, values outside this range will be clamped. + The playback volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume). + Values outside this range will be clamped. + + By default the volume is \c 100. + + UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale + will produce linear changes in perceived loudness, which is what a user would normally expect + from a volume control. See QAudio::convertVolume() for more details. */ /*! diff --git a/src/multimedia/qmediaopenglhelper_p.h b/src/multimedia/qmediaopenglhelper_p.h index 602116976..0a65b9f53 100644 --- a/src/multimedia/qmediaopenglhelper_p.h +++ b/src/multimedia/qmediaopenglhelper_p.h @@ -72,7 +72,7 @@ inline bool QMediaOpenGLHelper::isANGLE() #else bool isANGLE = false; -# if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && (defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_DYNAMIC)) +# if defined(Q_OS_WIN) && (defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_DYNAMIC)) if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { // Although unlikely, technically LibGLES could mean a non-ANGLE EGL/GLES2 implementation too. // Verify that it is indeed ANGLE. @@ -104,7 +104,7 @@ inline bool QMediaOpenGLHelper::isANGLE() # endif // QT_OPENGL_ES_2_ANGLE_STATIC } -# endif // Q_OS_WIN && !Q_OS_WINCE && (QT_OPENGL_ES_2 || QT_OPENGL_DYNAMIC) +# endif // Q_OS_WIN && (QT_OPENGL_ES_2 || QT_OPENGL_DYNAMIC) return isANGLE; #endif // Q_OS_WINRT diff --git a/src/multimedia/qmediastoragelocation.cpp b/src/multimedia/qmediastoragelocation.cpp index 04aa79758..7bd1e84f4 100644 --- a/src/multimedia/qmediastoragelocation.cpp +++ b/src/multimedia/qmediastoragelocation.cpp @@ -131,7 +131,7 @@ QString QMediaStorageLocation::generateFileName(const QString &prefix, .arg(extension); const QString path = dir.absoluteFilePath(name); - if (!QFileInfo(path).exists()) { + if (!QFileInfo::exists(path)) { m_lastUsedIndex[lastMediaKey] = lastMediaIndex + 1; return path; } diff --git a/src/multimedia/qmediatimerange.cpp b/src/multimedia/qmediatimerange.cpp index 7739c704f..700dcd087 100644 --- a/src/multimedia/qmediatimerange.cpp +++ b/src/multimedia/qmediatimerange.cpp @@ -665,16 +665,7 @@ bool QMediaTimeRange::contains(qint64 time) const */ bool operator==(const QMediaTimeRange &a, const QMediaTimeRange &b) { - if (a.intervals().count() != b.intervals().count()) - return false; - - for (int i = 0; i < a.intervals().count(); i++) - { - if(a.intervals()[i] != b.intervals()[i]) - return false; - } - - return true; + return a.intervals() == b.intervals(); } /*! diff --git a/src/multimedia/recording/qmediarecorder.cpp b/src/multimedia/recording/qmediarecorder.cpp index 65eaed159..d3962b78f 100644 --- a/src/multimedia/recording/qmediarecorder.cpp +++ b/src/multimedia/recording/qmediarecorder.cpp @@ -556,7 +556,16 @@ void QMediaRecorder::setMuted(bool muted) /*! \property QMediaRecorder::volume - \brief the linear audio gain of media recorder. + \brief the current recording audio volume. + + The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this + range will be clamped. + + The default volume is \c 1.0. + + UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale + will produce linear changes in perceived loudness, which is what a user would normally expect + from a volume control. See QAudio::convertVolume() for more details. */ qreal QMediaRecorder::volume() const |