4#include <QtMultimedia/private/qtmultimediaglobal_p.h>
10#include <QtCore/qloggingcategory.h>
11#include <private/qplatformmediadevices_p.h>
19class QSoundEffectPrivate : public
QIODevice
23 ~QSoundEffectPrivate()
override =
default;
32 qint64 bytesAvailable()
const override {
36 ? std::numeric_limits<qint64>::max() : m_runningCount * m_sample->
data().
size() - m_offset;
38 bool isSequential()
const override {
41 bool atEnd()
const override {
42 return m_runningCount == 0;
45 void setLoopsRemaining(
int loopsRemaining);
47 void setPlaying(
bool playing);
58 int m_runningCount = 0;
59 bool m_playing =
false;
65 bool m_sampleReady =
false;
73 , m_audioDevice(audioDevice)
80void QSoundEffectPrivate::sampleReady()
85 qCDebug(qLcSoundEffect) <<
this <<
"sampleReady: sample size:" << m_sample->data().size();
89 m_audioOutput =
new QAudioSink(m_audioDevice, m_sample->format());
92 m_audioOutput->setVolume(m_volume);
94 m_audioOutput->setVolume(0);
100 qCDebug(qLcSoundEffect) <<
this <<
"starting playback on audiooutput";
101 m_audioOutput->start(
this);
105void QSoundEffectPrivate::decoderError()
116 qCDebug(qLcSoundEffect) <<
this <<
"stateChanged " <<
state;
123 qCDebug(qLcSoundEffect) <<
this <<
"readData" <<
len << m_runningCount;
128 if (m_runningCount == 0 || !m_playing)
133 const int sampleSize = m_sample->data().size();
134 const char* sampleData = m_sample->data().constData();
136 while (
len && m_runningCount) {
137 int toWrite =
qMin(sampleSize - m_offset,
len);
138 memcpy(
data, sampleData + m_offset, toWrite);
143 if (m_offset >= sampleSize) {
145 setLoopsRemaining(m_runningCount - 1);
160void QSoundEffectPrivate::setLoopsRemaining(
int loopsRemaining)
162 if (m_runningCount == loopsRemaining)
164 qCDebug(qLcSoundEffect) <<
this <<
"setLoopsRemaining " << loopsRemaining;
165 m_runningCount = loopsRemaining;
166 emit q_ptr->loopsRemainingChanged();
171 qCDebug(qLcSoundEffect) <<
this <<
"setStatus" << status;
172 if (m_status == status)
174 bool oldLoaded = q_ptr->isLoaded();
176 emit q_ptr->statusChanged();
177 if (oldLoaded != q_ptr->isLoaded())
178 emit q_ptr->loadedChanged();
181void QSoundEffectPrivate::setPlaying(
bool playing)
183 qCDebug(qLcSoundEffect) <<
this <<
"setPlaying(" << playing <<
")" << m_playing;
185 m_audioOutput->stop();
186 if (playing && !m_sampleReady)
190 if (m_playing == playing)
194 if (m_audioOutput && playing)
195 m_audioOutput->start(
this);
197 emit q_ptr->playingChanged();
276 ,
d(new QSoundEffectPrivate(
this, audioDevice))
286 if (d->m_audioOutput) {
287 d->m_audioOutput->stop();
288 d->m_audioOutput->deleteLater();
289 d->m_sample->release();
337 qCDebug(qLcSoundEffect) <<
this <<
"setSource current=" << d->m_url <<
", to=" <<
url;
347 d->m_sampleReady =
false;
360 if (!d->m_sampleReady) {
364 d->m_sample->release();
365 d->m_sample =
nullptr;
368 if (d->m_audioOutput) {
370 d->m_audioOutput->stop();
371 d->m_audioOutput->deleteLater();
372 d->m_audioOutput =
nullptr;
376 d->m_sample = sampleCache()->requestSample(
url);
380 switch (d->m_sample->state()) {
420 return d->m_loopCount;
442 qWarning(
"SoundEffect: loops should be SoundEffect.Infinite, 0 or positive integer");
463 return d->m_audioDevice;
468 if (d->m_audioDevice ==
device)
471 d->m_audioDevice =
device;
489 return d->m_runningCount;
519 if (d->m_audioOutput && !d->m_muted)
520 return d->m_audioOutput->volume();
540 if (d->m_volume ==
volume)
545 if (d->m_audioOutput && !d->m_muted)
546 d->m_audioOutput->setVolume(
volume);
578 if (d->m_muted ==
muted)
581 if (
muted && d->m_audioOutput)
582 d->m_audioOutput->setVolume(0);
583 else if (!
muted && d->m_audioOutput && d->m_muted)
584 d->m_audioOutput->setVolume(d->m_volume);
624 d->setLoopsRemaining(d->m_loopCount);
625 qCDebug(qLcSoundEffect) <<
this <<
"play" << d->m_loopCount << d->m_runningCount;
706 qCDebug(qLcSoundEffect) <<
"stop()";
709 d->setPlaying(
false);
803#include "moc_qsoundeffect.cpp"
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
The QAudioSink class provides an interface for sending audio data to an audio output device.
void stateChanged(QAudio::State state)
This signal is emitted when the device state has changed.
\inmodule QtCore \reentrant
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QSoundEffect class provides a way to play low latency sound effects.
void setLoopCount(int loopCount)
Set the total number of times to play this sound effect to loopCount.
void sourceChanged()
The sourceChanged signal is emitted when the source has been changed.
int loopCount() const
Returns the total number of times that this sound effect will be played before stopping.
void setVolume(float volume)
Sets the sound effect volume to volume.
Status status
\qmlproperty enumeration QtMultimedia::SoundEffect::status
bool isMuted() const
Returns whether this sound effect is muted.
void stop()
\qmlmethod QtMultimedia::SoundEffect::stop()
~QSoundEffect()
Destroys this sound effect.
bool muted
\qmlproperty bool QtMultimedia::SoundEffect::muted
QUrl source
\qmlproperty url QtMultimedia::SoundEffect::source
void audioDeviceChanged()
bool isLoaded() const
Returns whether the sound effect has finished loading the \l source().
float volume
\qmlproperty qreal QtMultimedia::SoundEffect::volume
bool isPlaying() const
Returns true if the sound effect is currently playing, or false otherwise.
void volumeChanged()
\qmlsignal QtMultimedia::SoundEffect::loopsRemainingChanged()
void play()
\qmlmethod QtMultimedia::SoundEffect::play()
QAudioDevice audioDevice
Returns the QAudioDevice instance.
int loopsRemaining
\qmlproperty int QtMultimedia::SoundEffect::loopsRemaining
void setAudioDevice(const QAudioDevice &device)
void setMuted(bool muted)
Sets whether to mute this sound effect's playback.
static QStringList supportedMimeTypes()
Returns a list of the supported mime types for this platform.
Status
\value Null No source has been set or the source is null.
void setSource(const QUrl &url)
Set the current URL to play to url.
void mutedChanged()
\qmlsignal QtMultimedia::SoundEffect::volumeChanged()
void loopCountChanged()
\qmlsignal QtMultimedia::SoundEffect::loadedChanged()
QSoundEffect(QObject *parent=nullptr)
\qmltype SoundEffect \instantiates QSoundEffect
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
State
\value ActiveState Audio data is being processed, this state is set after start() is called and while...
Combined button and popup list for selecting options.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLenum GLsizei GLuint GLint * bytesWritten
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
#define qUtf16Printable(string)
QLatin1StringView QLatin1String
file open(QIODevice::ReadOnly)
QUrl url("example.com")
[constructor-url-reference]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
void writeData(const QByteArray &data)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent