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
qaudioformat.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
5#ifndef QAUDIOFORMAT_H
6#define QAUDIOFORMAT_H
7
8#include <QtMultimedia/qtmultimediaglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qshareddata.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace QtPrivate {
15template <typename... Args>
16constexpr int channelConfig(Args... values) {
17 return (0 | ... | (1u << values));
18}
19}
20
22{
23public:
32
33 // This matches the speaker positions of a 22.2 audio layout. Stereo, Surround 5.1 and Surround 7.1 are subsets of these
61 static constexpr int NChannelPositions = BottomFrontRight + 1;
62
75
76 template <typename... Args>
77 static constexpr ChannelConfig channelConfig(Args... channels)
78 {
79 return ChannelConfig(QtPrivate::channelConfig(channels...));
80 }
81
82 constexpr bool isValid() const noexcept
83 {
84 return m_sampleRate > 0 && m_channelCount > 0 && m_sampleFormat != Unknown;
85 }
86
87 constexpr void setSampleRate(int sampleRate) noexcept { m_sampleRate = sampleRate; }
88 constexpr int sampleRate() const noexcept { return m_sampleRate; }
89
91 constexpr ChannelConfig channelConfig() const noexcept { return m_channelConfig; }
92
93 constexpr void setChannelCount(int channelCount) noexcept
94 {
95 m_channelConfig = ChannelConfigUnknown;
96 m_channelCount = short(channelCount);
97 }
98 constexpr int channelCount() const noexcept { return m_channelCount; }
99
100 Q_MULTIMEDIA_EXPORT int channelOffset(AudioChannelPosition channel) const noexcept;
101
102 constexpr void setSampleFormat(SampleFormat f) noexcept { m_sampleFormat = f; }
103 constexpr SampleFormat sampleFormat() const noexcept { return m_sampleFormat; }
104
105 // Helper functions
106 Q_MULTIMEDIA_EXPORT qint32 bytesForDuration(qint64 microseconds) const;
107 Q_MULTIMEDIA_EXPORT qint64 durationForBytes(qint32 byteCount) const;
108
111
114
115 constexpr int bytesPerFrame() const { return bytesPerSample()*channelCount(); }
116 constexpr int bytesPerSample() const noexcept
117 {
118 switch (m_sampleFormat) {
119 case Unknown:
120 case NSampleFormats: return 0;
121 case UInt8: return 1;
122 case Int16: return 2;
123 case Int32:
124 case Float: return 4;
125 }
126 return 0;
127 }
128
129 Q_MULTIMEDIA_EXPORT float normalizedSampleValue(const void *sample) const;
130
131 friend bool operator==(const QAudioFormat &a, const QAudioFormat &b)
132 {
133 return a.m_sampleRate == b.m_sampleRate &&
134 a.m_channelCount == b.m_channelCount &&
135 a.m_sampleFormat == b.m_sampleFormat;
136 }
137 friend bool operator!=(const QAudioFormat &a, const QAudioFormat &b)
138 {
139 return !(a == b);
140 }
141
142 static Q_MULTIMEDIA_EXPORT ChannelConfig defaultChannelConfigForChannelCount(int channelCount);
143
144private:
145 SampleFormat m_sampleFormat = SampleFormat::Unknown;
146 short m_channelCount = 0;
147 ChannelConfig m_channelConfig = ChannelConfigUnknown;
148 int m_sampleRate = 0;
149 Q_DECL_UNUSED_MEMBER quint64 reserved = 0;
150};
151
152#ifndef QT_NO_DEBUG_STREAM
153Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QAudioFormat &);
154Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAudioFormat::SampleFormat);
155#endif
156
157QT_END_NAMESPACE
158
159Q_DECLARE_METATYPE(QAudioFormat)
160
161#endif // QAUDIOFORMAT_H
The QAudioFormat class stores audio stream parameter information.
constexpr ChannelConfig channelConfig() const noexcept
Returns the current channel configuration.
constexpr SampleFormat sampleFormat() const noexcept
Returns the current sample format.
Q_MULTIMEDIA_EXPORT void setChannelConfig(ChannelConfig config) noexcept
Sets the channel configuration to config.
constexpr void setChannelCount(int channelCount) noexcept
Sets the channel count to channels.
AudioChannelPosition
Describes the possible audio channel positions.
Q_MULTIMEDIA_EXPORT int channelOffset(AudioChannelPosition channel) const noexcept
Returns the position of a certain audio channel inside an audio frame for the given format.
constexpr void setSampleFormat(SampleFormat f) noexcept
Sets the sample format to format.
friend bool operator==(const QAudioFormat &a, const QAudioFormat &b)
Returns true if audio format a is equal to b, otherwise returns false.
constexpr bool isValid() const noexcept
Returns true if all of the parameters are valid.
constexpr int sampleRate() const noexcept
Returns the current sample rate in Hertz.
static constexpr int NChannelPositions
constexpr int bytesPerFrame() const
Returns the number of bytes required to represent one frame (a sample in each channel) in this format...
static constexpr ChannelConfig channelConfig(Args... channels)
Returns the current channel configuration for the given channels.
friend bool operator!=(const QAudioFormat &a, const QAudioFormat &b)
Returns true if audio format a is not equal to b, otherwise returns false.
SampleFormat
Qt will always expect and use samples in the endianness of the host platform.
constexpr int channelCount() const noexcept
Returns the current channel count value.
constexpr int bytesPerSample() const noexcept
Returns the number of bytes required to represent one sample in this format.
Q_MULTIMEDIA_EXPORT float normalizedSampleValue(const void *sample) const
Normalizes the sample value to a number between -1 and 1.
constexpr void setSampleRate(int sampleRate) noexcept
Sets the sample rate to samplerate in Hertz.
ChannelConfig
\variable QAudioFormat::NChannelPositions
@ ChannelConfigSurround7Dot1
@ ChannelConfigSurround5Dot1
@ ChannelConfigSurround7Dot0
@ ChannelConfigSurround5Dot0
constexpr int channelConfig(Args... values)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2620