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
qaudiobuffer_support_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-2.0-only OR GPL-3.0-only
3
4#ifndef QAUDIOBUFFER_SUPPORT_P_H
5#define QAUDIOBUFFER_SUPPORT_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/qaudiobuffer.h>
19#include <QtCore/qspan.h>
20
21QT_BEGIN_NAMESPACE
22
23namespace QtPrivate {
24
29
32
33// LATER: c++23 has std::views::stride(3)
34template <typename SampleType>
36{
37 SampleType &operator[](int frame) { return m_buffer[frame * m_numberOfChannels + m_channel]; }
38
40 const int m_channel;
42};
43
44template <typename SampleType>
45void validateBufferFormat(const QAudioBuffer &buffer, int channel)
46{
47 Q_ASSERT(channel < buffer.format().channelCount());
48
49 if constexpr (std::is_same_v<std::remove_const_t<SampleType>, float>) {
50 Q_ASSERT(buffer.format().sampleFormat() == QAudioFormat::SampleFormat::Float);
51 } else if constexpr (std::is_same_v<std::remove_const_t<SampleType>, int32_t>) {
52 Q_ASSERT(buffer.format().sampleFormat() == QAudioFormat::SampleFormat::Int32);
53 } else if constexpr (std::is_same_v<std::remove_const_t<SampleType>, int16_t>) {
54 Q_ASSERT(buffer.format().sampleFormat() == QAudioFormat::SampleFormat::Int16);
55 } else if constexpr (std::is_same_v<std::remove_const_t<SampleType>, uint8_t>) {
56 Q_ASSERT(buffer.format().sampleFormat() == QAudioFormat::SampleFormat::UInt8);
57 }
58}
59
60template <typename T, bool Predicate>
62
63template <typename SampleType>
73
74template <typename SampleType>
76{
78
79 QAudioBufferChannelView<SampleType> operator[](int channel)
80 {
81 return makeChannelView<SampleType>(m_buffer, channel);
82 }
83
84 QAudioBufferChannelView<const SampleType> operator[](int channel) const
85 {
86 return makeChannelView<const SampleType>(m_buffer, channel);
87 }
88
89 explicit QAudioBufferDeinterleaveAdaptor(BufferType &buffer) : m_buffer(buffer) { }
90
91private:
92 BufferType &m_buffer;
93 int m_numberOfChannels = m_buffer.format().channelCount();
94};
95
96} // namespace QtPrivate
97
98QT_END_NAMESPACE
99
100#endif // QAUDIOBUFFER_SUPPORT_P_H
auto makeChannelView(add_const_if_t< QAudioBuffer, std::is_const_v< SampleType > > &buffer, int channel)
void validateBufferFormat(const QAudioBuffer &buffer, int channel)
constexpr Mutability QAudioBufferMutable
constexpr Mutability QAudioBufferImmutable
QAudioBufferChannelView< const SampleType > operator[](int channel) const
QAudioBufferChannelView< SampleType > operator[](int channel)