Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsoundeffectwithplayer_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSOUNDEFFECTWITHPLAYER_P_H
5#define QSOUNDEFFECTWITHPLAYER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qaudiosystem_p.h>
19#include <QtMultimedia/private/qautoresetevent_p.h>
20#include <QtMultimedia/private/qrtaudioengine_p.h>
21#include <QtMultimedia/private/qsoundeffect_p.h>
22#include <QtMultimedia/qaudiosink.h>
23#include <QtMultimedia/qmediadevices.h>
24#include <QtCore/qchronotimer.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QtMultimediaPrivate {
29
31
33{
34public:
36 float volume, bool muted, int totalLoopCount,
38
40
41 Q_MULTIMEDIA_EXPORT VoicePlayResult play(QSpan<float>) noexcept Q_DECL_NONBLOCKING_FUNCTION override;
42
44 const QAudioFormat &format() noexcept override { return m_sample->format(); }
45
46 int loopsRemaining() const { return m_loopsRemaining.load(std::memory_order_relaxed); }
48 clone(std::optional<QAudioFormat> newEngineFormat = {}) const;
49
50 Q_MULTIMEDIA_EXPORT qsizetype playVoice(QSpan<float>) noexcept Q_DECL_NONBLOCKING_FUNCTION;
51
56
58
59 float m_volume{};
60 bool m_muted{};
61
64
66};
67
68// Design notes
69// * each play() will start a new voice
70// * stop() will stop all voices
71// * the most recently created voice can be obtained via `activeVoice()`
72// * mute/volume will affect all voices
73// * loopCount/loopRemaining will be obtained from most recently created voice
74class Q_MULTIMEDIA_EXPORT QSoundEffectPrivateWithPlayer final : public QObject,
76{
77public:
79
83
84 // QSoundEffectPrivate interface
89 int loopCount() const override;
90 bool setLoopCount(int) override;
91 int loopsRemaining() const override;
92 float volume() const override;
93 bool setVolume(float) override;
94 bool muted() const override;
95 bool setMuted(bool) override;
96 void play() override;
97 void stop() override;
98 bool playing() const override;
99
100 // testing
101 const std::shared_ptr<QRtAudioEngine> &player() const { return m_player; }
102 const auto &voices() const { return m_voices; }
103
104private:
109 static bool formatIsSupported(const QAudioFormat &);
111 void resolveAudioDevice();
112
119
120 void setLoopsRemaining(int);
121 int m_loopsRemaining{ 0 };
122
125 float m_volume = 1.f;
126 bool m_muted = false;
127 int m_loopCount = 1;
128 bool m_playPending = false;
129
131
135 std::chrono::seconds(2),
136 };
137};
138
139} // namespace QtMultimediaPrivate
140
141QT_END_NAMESPACE
142
143#endif // QSOUNDEFFECTWITHPLAYER_P_H
Q_MULTIMEDIA_EXPORT ~QSoundEffectVoice()
const std::shared_ptr< const QSample > m_sample
std::shared_ptr< QSoundEffectVoice > clone(std::optional< QAudioFormat > newEngineFormat={}) const
const QAudioFormat & format() noexcept override
bool isActive() noexcept Q_DECL_NONBLOCKING_FUNCTION override