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 <qtspatialaudioglobal_p.h>
19#include <qmutex.h>
20#include <qurl.h>
21#include <qfile.h>
22#include <qaudiodecoder.h>
23#include <qaudiobuffer.h>
24
25QT_BEGIN_NAMESPACE
26
27class QAudioEngine;
28
29class QAmbientSoundPrivate : public QObject
30{
31public:
32 QAmbientSoundPrivate(QObject *parent, int nchannels = 2)
33 : QObject(parent)
34 , nchannels(nchannels)
35 {}
36
37 template<typename T>
38 static QAmbientSoundPrivate *get(T *soundSource) { return soundSource ? soundSource->d : nullptr; }
39
40 QUrl url;
41 float volume = 1.;
42 int nchannels = 2;
43 std::unique_ptr<QAudioDecoder> decoder;
44 std::unique_ptr<QFile> sourceDeviceFile;
45 QAudioEngine *engine = nullptr;
46
47 QMutex mutex;
48 int currentBuffer = 0;
49 int bufPos = 0;
50 int m_currentLoop = 0;
51 QList<QAudioBuffer> buffers;
52 int sourceId = -1; // kInvalidSourceId
53
54 QAtomicInteger<bool> m_autoPlay = true;
55 QAtomicInteger<bool> m_playing = false;
56 QAtomicInt m_loops = 1;
57 bool m_loading = false;
58
59 void play() {
60 m_playing = true;
61 }
62 void pause() {
63 m_playing = false;
64 }
65 void stop() {
66 QMutexLocker locker(&mutex);
67 m_playing = false;
68 currentBuffer = 0;
69 bufPos = 0;
70 m_currentLoop = 0;
71 }
72
73 void load();
74 void getBuffer(float *buf, int frames, int channels);
75
76private Q_SLOTS:
77 void bufferReady();
78 void finished();
79
80};
81
82QT_END_NAMESPACE
83
84#endif // QAMBIENTSOUND_P_H
85

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/spatialaudio/qambientsound_p.h