Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qaudiobuffer.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QAUDIOBUFFER_H
5#define QAUDIOBUFFER_H
6
7#include <QtCore/qshareddata.h>
8
9#include <QtMultimedia/qtmultimediaglobal.h>
10
11#include <QtMultimedia/qaudio.h>
12#include <QtMultimedia/qaudioformat.h>
13
15
16namespace QtPrivate {
17template <QAudioFormat::SampleFormat> struct AudioSampleFormatHelper
18{
19};
20
21template <> struct AudioSampleFormatHelper<QAudioFormat::UInt8>
22{
23 using value_type = unsigned char;
24 static constexpr value_type Default = 128;
25};
26
28{
29 using value_type = short;
30 static constexpr value_type Default = 0;
31};
32
34{
35 using value_type = int;
36 static constexpr value_type Default = 0;
37};
38
40{
41 using value_type = float;
42 static constexpr value_type Default = 0.;
43};
44
45}
46
47template <QAudioFormat::ChannelConfig config, QAudioFormat::SampleFormat format>
49{
50private:
51 // popcount in qalgorithms.h is unfortunately not constexpr on MSVC.
52 // Use this here as a fallback
53 static constexpr int constexprPopcount(quint32 i)
54 {
55 i = i - ((i >> 1) & 0x55555555); // add pairs of bits
56 i = (i & 0x33333333) + ((i >> 2) & 0x33333333); // quads
57 i = (i + (i >> 4)) & 0x0F0F0F0F; // groups of 8
58 return (i * 0x01010101) >> 24; // horizontal sum of bytes
59 }
60 static constexpr int nChannels = constexprPopcount(config);
61public:
63 value_type channels[nChannels];
65 {
66 if (!(config & (1u << pos)))
67 return -1;
68
69 uint maskedChannels = config & ((1u << pos) - 1);
70 return qPopulationCount(maskedChannels);
71 }
72
73
75 int idx = positionToIndex(pos);
76 if (idx < 0)
78 return channels[idx];
79 }
81 int idx = positionToIndex(pos);
82 if (idx < 0)
83 return;
84 channels[idx] = val;
85 }
87 return value(pos);
88 }
89 constexpr void clear() {
90 for (int i = 0; i < nChannels; ++i)
92 }
93};
94
95template <QAudioFormat::SampleFormat Format>
97
98template <QAudioFormat::SampleFormat Format>
100
101template <QAudioFormat::SampleFormat Format>
103
104template <QAudioFormat::SampleFormat Format>
106
107template <QAudioFormat::SampleFormat Format>
109
110
113
114class Q_MULTIMEDIA_EXPORT QAudioBuffer
115{
116public:
117 QAudioBuffer() noexcept;
120 QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime = -1); // Initialized to empty
122
123 QAudioBuffer& operator=(const QAudioBuffer &other);
124
125 QAudioBuffer(QAudioBuffer &&other) noexcept = default;
126 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAudioBuffer)
127 void swap(QAudioBuffer &other) noexcept
128 { d.swap(other.d); }
129
130 bool isValid() const noexcept { return d != nullptr; };
131
132 void detach();
133
134 QAudioFormat format() const noexcept;
135
136 qsizetype frameCount() const noexcept;
137 qsizetype sampleCount() const noexcept;
138 qsizetype byteCount() const noexcept;
139
140 qint64 duration() const noexcept;
141 qint64 startTime() const noexcept;
142
143 // Structures for easier access to data
148
153
154 template <typename T> const T* constData() const {
155 return static_cast<const T*>(constData());
156 }
157 template <typename T> const T* data() const {
158 return static_cast<const T*>(data());
159 }
160 template <typename T> T* data() {
161 return static_cast<T*>(data());
162 }
163private:
164 const void* constData() const noexcept;
165 const void* data() const noexcept;
166 void *data();
167
169};
170
172
174
175#endif // QAUDIOBUFFER_H
\inmodule QtMultimedia
QAudioBuffer() noexcept
Create a new, empty, invalid buffer.
bool isValid() const noexcept
Returns true if this is a valid buffer.
const T * data() const
The QAudioFormat class stores audio stream parameter information.
AudioChannelPosition
Describes the possible audio channel positions.
\inmodule QtCore
Definition qbytearray.h:57
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR uint qPopulationCount(quint32 v) noexcept
qint64 startTime
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1504
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLuint GLfloat * val
#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:25
unsigned int quint32
Definition qtypes.h:45
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned int uint
Definition qtypes.h:29
long long qint64
Definition qtypes.h:55
QSharedPointer< T > other(t)
[5]
static constexpr int positionToIndex(QAudioFormat::AudioChannelPosition pos)
void setValue(QAudioFormat::AudioChannelPosition pos, value_type val)
value_type channels[nChannels]
constexpr void clear()
value_type value(QAudioFormat::AudioChannelPosition pos) const
value_type operator[](QAudioFormat::AudioChannelPosition pos) const
typename QtPrivate::AudioSampleFormatHelper< format >::value_type value_type