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
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
qint64 duration() const override
void setAudioFormat(const QAudioFormat &format) override
bool bufferAvailable() const override
QUrl source() const override
void setSourceDevice(QIODevice *device) override
QAudioFormat audioFormat() const override
QAudioBuffer read() override
qint64 position() const override
QIODevice * sourceDevice() const override
bool streamPlaybackSupported() const override
bool isAudioAvailable() const override
void handleError(QMediaPlayer::Error errorCode, const QString &errorString, bool isFatal)
qreal playbackRate() const override
QMediaMetaData metaData() const override
const QIODevice * mediaStream() const override
void pause() override
void setActiveTrack(TrackType type, int index) override
void setAudioOutput(QPlatformAudioOutput *output) override
QMediaMetaData trackMetaData(TrackType type, int trackNumber) override
void handleStatusChanged(QMediaPlayer::MediaStatus)
void setPlaybackRate(qreal rate) override
void setMedia(const QUrl &media, QIODevice *stream) override
void play() override
int activeTrack(TrackType type) override
QUrl media() const override
QMediaTimeRange availablePlaybackRanges() const override
MFPlayerControl(QMediaPlayer *player)
float bufferProgress() const override
void setVideoSink(QVideoSink *sink) override
bool isVideoAvailable() const override
void handleSeekableUpdate(bool seekable)
qint64 duration() const override
qint64 position() const override
void handleDurationUpdate(qint64 duration)
int trackCount(TrackType type) override
void setPosition(qint64 position) override
bool isSeekable() const override
void stop() override
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
int capture(const QString &fileName) override
virtual ~QWindowsImageCapture()
QImageEncoderSettings imageSettings() const override
void setImageSettings(const QImageEncoderSettings &settings) override
void setCaptureSession(QPlatformMediaCaptureSession *session)
bool isReadyForCapture() const override
QPlatformImageCapture * imageCapture() override
void setCamera(QPlatformCamera *camera) override
void setAudioInput(QPlatformAudioInput *) override
QPlatformCamera * camera() override
QPlatformMediaRecorder * mediaRecorder() override
void setImageCapture(QPlatformImageCapture *imageCapture) override
void setAudioOutput(QPlatformAudioOutput *output) override
void setMediaRecorder(QPlatformMediaRecorder *recorder) override
QWindowsMediaDeviceSession * session() const
void setMetaData(const QMediaMetaData &metaData) override
QMediaRecorder::RecorderState state() const override
void setCaptureSession(QPlatformMediaCaptureSession *session)
QMediaMetaData metaData() const override
bool isLocationWritable(const QUrl &location) const override
qint64 duration() const override
void record(QMediaEncoderSettings &settings) override
q23::expected< QPlatformVideoSink *, QString > createVideoSink(QVideoSink *sink) override
QPlatformMediaFormatInfo * createFormatInfo() override
q23::expected< QPlatformAudioDecoder *, QString > createAudioDecoder(QAudioDecoder *decoder) override
q23::expected< QPlatformCamera *, QString > createCamera(QCamera *camera) override
q23::expected< QPlatformImageCapture *, QString > createImageCapture(QImageCapture *imageCapture) override
QPlatformVideoDevices * createVideoDevices() override
q23::expected< QPlatformMediaRecorder *, QString > createRecorder(QMediaRecorder *recorder) override
q23::expected< QPlatformMediaPlayer *, QString > createPlayer(QMediaPlayer *parent) override
q23::expected< QPlatformMediaCaptureSession *, QString > createCaptureSession() override
Combined button and popup list for selecting options.
constexpr int channelConfig(Args... values)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582