4#include <QtMultimedia/private/qtmultimediaglobal_p.h>
11#include <QtCore/qloggingcategory.h>
12#include <private/qplatformmediadevices_p.h>
13#include <private/qplatformmediaintegration_p.h>
14#include <private/qplatformaudioresampler_p.h>
24struct AudioSinkDeleter
36 void operator ()(
QSample* sample)
const
60 return std::numeric_limits<qint64>::max();
87 std::unique_ptr<QSample, SampleDeleter>
m_sample;
99 , m_audioDevice(audioDevice)
111 qCDebug(qLcSoundEffect) <<
this <<
"sampleReady: sample size:" <<
m_sample->data().size();
115 const auto audioDevice =
118 if (audioDevice.isNull()) {
120 qCCritical(qLcSoundEffect) <<
"Failed to play sound. No audio devices present.";
125 const auto &sampleFormat =
m_sample->format();
126 const auto sampleChannelConfig =
129 : sampleFormat.channelConfig();
131 if (sampleChannelConfig != audioDevice.channelConfiguration()
133 qCDebug(qLcSoundEffect) <<
"Create resampler for channels mapping: config"
134 << sampleFormat.channelConfig() <<
"=> config"
135 << audioDevice.channelConfiguration();
136 auto outputFormat = sampleFormat;
137 outputFormat.setChannelConfig(audioDevice.channelConfiguration());
145 qCDebug(qLcSoundEffect) <<
"Cannot create resampler for channels mapping";
163 qCDebug(qLcSoundEffect) <<
this <<
"starting playback on audiooutput";
179 qCDebug(qLcSoundEffect) <<
this <<
"stateChanged " <<
state;
227 qCDebug(qLcSoundEffect) <<
this <<
"setLoopsRemaining " << loopsRemaining;
234 qCDebug(qLcSoundEffect) <<
this <<
"setStatus" << status;
246 qCDebug(qLcSoundEffect) <<
this <<
"setPlaying(" << playing <<
")" <<
m_playing;
397 qCDebug(qLcSoundEffect) <<
this <<
"setSource current=" << d->
m_url <<
", to=" <<
url;
434 d->
m_sample.reset(sampleCache()->requestSample(
url));
500 qWarning(
"SoundEffect: loops should be SoundEffect.Infinite, 0 or positive integer");
764 qCDebug(qLcSoundEffect) <<
"stop()";
861#include "moc_qsoundeffect.cpp"
IOBluetoothDevice * device
bool isValid() const noexcept
Returns true if this is a valid buffer.
qsizetype byteCount() const noexcept
Returns the size of this buffer, in bytes.
const T * constData() const
Returns a pointer to this buffer's data.
QAudioFormat format() const noexcept
Returns the \l {QAudioFormat}{format} of this buffer.
The QAudioDevice class provides an information about audio devices and their functionality.
bool isNull() const
Returns whether this QAudioDevice object holds a valid device definition.
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
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
std::unique_ptr< QAudioSink, AudioSinkDeleter > m_audioSink
QAudioBuffer m_audioBuffer
void setLoopsRemaining(int loopsRemaining)
qint64 writeData(const char *data, qint64 len) override
Writes up to maxSize bytes from data to the device.
QSoundEffectPrivate(QSoundEffect *q, const QAudioDevice &audioDevice=QAudioDevice())
~QSoundEffectPrivate() override=default
qint64 readData(char *data, qint64 len) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
QSoundEffect::Status m_status
qint64 size() const override
For open random-access devices, this function returns the size of the device.
void stateChanged(QAudio::State)
void setPlaying(bool playing)
bool atEnd() const override
Returns true if the current read and write position is at the end of the device (i....
qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
std::unique_ptr< QSample, SampleDeleter > m_sample
QAudioDevice m_audioDevice
void setStatus(QSoundEffect::Status status)
bool isSequential() const override
Returns true if this device is sequential; otherwise returns false.
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.
void playingChanged()
\qmlsignal QtMultimedia::SoundEffect::mutedChanged()
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()
void loopsRemainingChanged()
\qmlsignal QtMultimedia::SoundEffect::loopCountChanged()
bool isLoaded() const
Returns whether the sound effect has finished loading the \l source().
void loadedChanged()
\qmlsignal QtMultimedia::SoundEffect::sourceChanged()
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()
void statusChanged()
\qmlsignal QtMultimedia::SoundEffect::playingChanged()
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.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
#define qCCritical(category,...)
#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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLsizei GLenum GLboolean sink
#define qUtf16Printable(string)
QLatin1StringView QLatin1String
QUrl url("example.com")
[constructor-url-reference]
myObject disconnect()
[26]