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
qambientsound_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
3
4#ifndef QAMBIENTSOUND_P_H
5#define QAMBIENTSOUND_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 for the convenience
12// of other Qt classes. 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 <QtSpatialAudio/qambientsound.h>
19#include <QtSpatialAudio/private/qtspatialaudioglobal_p.h>
20#include <QtCore/qmutex.h>
21#include <QtCore/qurl.h>
22#include <QtCore/qfile.h>
23#include <QtCore/private/qobject_p.h>
24#include <QtMultimedia/qaudiodecoder.h>
25#include <QtMultimedia/qaudiobuffer.h>
26#include <QtMultimedia/private/qmultimedia_source_resolver_p.h>
27
28#include <atomic>
29#include <memory>
30
31QT_BEGIN_NAMESPACE
32
33class QAudioEngine;
34
36{
37 Q_DECLARE_PUBLIC(QAmbientSound)
38
39public:
41
42 template <typename T>
44 {
45 return soundSource ? soundSource->d_func() : nullptr;
46 }
47
48 QUrl url() const { return m_url; }
49 void setUrl(const QUrl &url);
50
51private:
52 QUrl m_url; // unresolved URL
53
54public:
55 float volume = 1.;
56 int nchannels = 2;
59 QAudioEngine *engine = nullptr;
60
63 int bufPos = 0;
66 int sourceId = -1; // kInvalidSourceId
67
68 std::atomic_bool m_autoPlay = true;
69 std::atomic_bool m_playing = false;
70 std::atomic_int m_loops = 1;
71 std::atomic_bool m_loading = false;
72
73 void play() {
74 m_playing = true;
75 }
76 void pause() {
77 m_playing = false;
78 }
79 void stop() {
80 QMutexLocker locker(&mutex);
81 m_playing = false;
82 currentBuffer = 0;
83 bufPos = 0;
84 m_currentLoop = 0;
85 }
86
87 void load();
88 void getBuffer(float *buf, int frames, int channels);
89
94};
95
96QT_END_NAMESPACE
97
98#endif // QAMBIENTSOUND_P_H
std::unique_ptr< QAudioDecoder > decoder
QAudioEngine * engine
std::atomic_int m_loops
std::unique_ptr< const AbstractSourceResolver > m_sourceResolver
QList< QAudioBuffer > buffers
std::atomic_bool m_playing
std::atomic_bool m_loading
void getBuffer(float *buf, int frames, int channels)
std::unique_ptr< QFile > sourceDeviceFile
std::atomic_bool m_autoPlay