Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <QtCore/qobject.h>
9#include <QtCore/qshareddata.h>
10
11#include <QtMultimedia/qtmultimediaglobal.h>
12
14
15class QAudioFormatPrivate;
16
17namespace QtPrivate {
18template <typename... Args>
19constexpr int channelConfig(Args... values) {
20 return (0 | ... | (1u << values));
21}
22}
23
25{
26public:
35
36 // This matches the speaker positions of a 22.2 audio layout. Stereo, Surround 5.1 and Surround 7.1 are subsets of these
64 static constexpr int NChannelPositions = BottomFrontRight + 1;
65
78
79 template <typename... Args>
80 static constexpr ChannelConfig channelConfig(Args... channels)
81 {
82 return ChannelConfig(QtPrivate::channelConfig(channels...));
83 }
84
85 constexpr bool isValid() const noexcept
86 {
87 return m_sampleRate > 0 && m_channelCount > 0 && m_sampleFormat != Unknown;
88 }
89
90 constexpr void setSampleRate(int sampleRate) noexcept { m_sampleRate = sampleRate; }
91 constexpr int sampleRate() const noexcept { return m_sampleRate; }
92
93 Q_MULTIMEDIA_EXPORT void setChannelConfig(ChannelConfig config) noexcept;
94 constexpr ChannelConfig channelConfig() const noexcept { return m_channelConfig; }
95
96 constexpr void setChannelCount(int channelCount) noexcept { m_channelConfig = ChannelConfigUnknown; m_channelCount = channelCount; }
97 constexpr int channelCount() const noexcept { return m_channelCount; }
98
99 Q_MULTIMEDIA_EXPORT int channelOffset(AudioChannelPosition channel) const noexcept;
100
101 constexpr void setSampleFormat(SampleFormat f) noexcept { m_sampleFormat = f; }
102 constexpr SampleFormat sampleFormat() const noexcept { return m_sampleFormat; }
103
104 // Helper functions
105 Q_MULTIMEDIA_EXPORT qint32 bytesForDuration(qint64 microseconds) const;
106 Q_MULTIMEDIA_EXPORT qint64 durationForBytes(qint32 byteCount) const;
107
108 Q_MULTIMEDIA_EXPORT qint32 bytesForFrames(qint32 frameCount) const;
109 Q_MULTIMEDIA_EXPORT qint32 framesForBytes(qint32 byteCount) const;
110
111 Q_MULTIMEDIA_EXPORT qint32 framesForDuration(qint64 microseconds) const;
112 Q_MULTIMEDIA_EXPORT qint64 durationForFrames(qint32 frameCount) const;
113
114 constexpr int bytesPerFrame() const { return bytesPerSample()*channelCount(); }
115 constexpr int bytesPerSample() const noexcept
116 {
117 switch (m_sampleFormat) {
118 case Unknown:
119 case NSampleFormats: return 0;
120 case UInt8: return 1;
121 case Int16: return 2;
122 case Int32:
123 case Float: return 4;
124 }
125 return 0;
126 }
127
128 Q_MULTIMEDIA_EXPORT float normalizedSampleValue(const void *sample) const;
129
130 friend bool operator==(const QAudioFormat &a, const QAudioFormat &b)
131 {
132 return a.m_sampleRate == b.m_sampleRate &&
133 a.m_channelCount == b.m_channelCount &&
134 a.m_sampleFormat == b.m_sampleFormat;
135 }
136 friend bool operator!=(const QAudioFormat &a, const QAudioFormat &b)
137 {
138 return !(a == b);
139 }
140
141 static Q_MULTIMEDIA_EXPORT ChannelConfig defaultChannelConfigForChannelCount(int channelCount);
142
143private:
144 SampleFormat m_sampleFormat = SampleFormat::Unknown;
145 short m_channelCount = 0;
146 ChannelConfig m_channelConfig = ChannelConfigUnknown;
147 int m_sampleRate = 0;
148 quint64 reserved = 0;
149};
150
151#ifndef QT_NO_DEBUG_STREAM
152Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QAudioFormat &);
154#endif
155
157
159
160#endif // QAUDIOFORMAT_H
IOBluetoothL2CAPChannel * channel
The QAudioFormat class stores audio stream parameter information.
Q_MULTIMEDIA_EXPORT void setChannelConfig(ChannelConfig config) noexcept
Sets the channel configuration to config.
constexpr void setSampleRate(int sampleRate) noexcept
Sets the sample rate to samplerate in Hertz.
constexpr int channelCount() const noexcept
Returns the current channel count value.
Q_MULTIMEDIA_EXPORT qint32 bytesForFrames(qint32 frameCount) const
Returns the number of bytes required for frameCount frames of this format.
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.
Q_MULTIMEDIA_EXPORT qint32 framesForDuration(qint64 microseconds) const
Returns the number of frames required to represent microseconds in this format.
static Q_MULTIMEDIA_EXPORT ChannelConfig defaultChannelConfigForChannelCount(int channelCount)
Returns a default channel configuration for channelCount.
constexpr int bytesPerSample() const noexcept
Returns the number of bytes required to represent one sample in this format.
constexpr int sampleRate() const noexcept
Returns the current sample rate in Hertz.
constexpr SampleFormat sampleFormat() const noexcept
Returns the current sample format.
Q_MULTIMEDIA_EXPORT qint32 bytesForDuration(qint64 microseconds) const
Returns the number of bytes required for this audio format for microseconds.
friend bool operator!=(const QAudioFormat &a, const QAudioFormat &b)
Returns true if audio format a is not equal to b, otherwise returns false.
static constexpr int NChannelPositions
friend bool operator==(const QAudioFormat &a, const QAudioFormat &b)
Returns true if audio format a is equal to b, otherwise returns false.
Q_MULTIMEDIA_EXPORT qint64 durationForFrames(qint32 frameCount) const
Return the number of microseconds represented by frameCount frames in this format.
static constexpr ChannelConfig channelConfig(Args... channels)
Returns the current channel configuration for the given channels.
SampleFormat
Qt will always expect and use samples in the endianness of the host platform.
constexpr int bytesPerFrame() const
Returns the number of bytes required to represent one frame (a sample in each channel) in this format...
constexpr ChannelConfig channelConfig() const noexcept
Returns the current channel configuration.
Q_MULTIMEDIA_EXPORT qint64 durationForBytes(qint32 byteCount) const
Returns the number of microseconds represented by bytes in this format.
Q_MULTIMEDIA_EXPORT float normalizedSampleValue(const void *sample) const
Normalizes the sample value to a number between -1 and 1.
constexpr bool isValid() const noexcept
Returns true if all of the parameters are valid.
Q_MULTIMEDIA_EXPORT qint32 framesForBytes(qint32 byteCount) const
Returns the number of frames represented by byteCount in this format.
constexpr void setSampleFormat(SampleFormat f) noexcept
Sets the sample format to format.
constexpr void setChannelCount(int channelCount) noexcept
Sets the channel count to channels.
ChannelConfig
\variable QAudioFormat::NChannelPositions
@ ChannelConfigSurround7Dot1
@ ChannelConfigSurround5Dot1
@ ChannelConfigSurround7Dot0
@ ChannelConfigSurround5Dot0
\inmodule QtCore
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
constexpr int channelConfig(Args... values)
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QAudioFormat &)
QAudioFormat::ChannelConfig channelConfig
EGLConfig config
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
GLenum GLsizei GLsizei GLint * values
[15]
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLfloat GLfloat f
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
int qint32
Definition qtypes.h:49
unsigned long long quint64
Definition qtypes.h:61
long long qint64
Definition qtypes.h:60