Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qwavedecoder.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 WAVEDECODER_H
5#define WAVEDECODER_H
6
7#include <QtCore/qiodevice.h>
8#include <QtMultimedia/qaudioformat.h>
9
10
12
13
14
15class Q_MULTIMEDIA_EXPORT QWaveDecoder : public QIODevice
16{
18
19public:
20 explicit QWaveDecoder(QIODevice *device, QObject *parent = nullptr);
22 QObject *parent = nullptr);
24
25 QAudioFormat audioFormat() const;
27 int duration() const;
28 static qint64 headerLength();
29
30 bool open(QIODevice::OpenMode mode) override;
31 void close() override;
32 bool seek(qint64 pos) override;
33 qint64 pos() const override;
35 qint64 size() const override;
36 bool isSequential() const override;
37 qint64 bytesAvailable() const override;
38
42
43private Q_SLOTS:
44 void handleData();
45
46private:
47 qint64 readData(char *data, qint64 maxlen) override;
48 qint64 writeData(const char *data, qint64 len) override;
49
50 bool writeHeader();
51 bool writeDataLength();
52 bool enoughDataAvailable();
53 bool findChunk(const char *chunkId);
54 void discardBytes(qint64 numBytes);
55 void parsingFailed();
56
57 enum State {
58 InitialState,
59 WaitingForFormatState,
60 WaitingForDataState
61 };
62
63 struct chunk
64 {
65 char id[4];
67 };
68 bool peekChunk(chunk* pChunk, bool handleEndianness = true);
69
70 struct RIFFHeader
71 {
72 chunk descriptor;
73 char type[4];
74 };
75 struct WAVEHeader
76 {
77 chunk descriptor;
78 quint16 audioFormat;
79 quint16 numChannels;
80 quint32 sampleRate;
81 quint32 byteRate;
82 quint16 blockAlign;
83 quint16 bitsPerSample;
84 };
85
86 struct DATAHeader
87 {
88 chunk descriptor;
89 };
90
91 struct CombinedHeader
92 {
93 RIFFHeader riff;
94 WAVEHeader wave;
95 DATAHeader data;
96 };
97 static const int HeaderLength = sizeof(CombinedHeader);
98
99 bool haveFormat = false;
100 bool haveHeader = false;
101 qint64 dataSize = 0;
102 QIODevice *device = nullptr;
104 State state = InitialState;
105 quint32 junkToSkip = 0;
106 bool bigEndian = false;
107 bool byteSwap = false;
108 int bps = 0;
109};
110
112
113#endif // WAVEDECODER_H
IOBluetoothDevice * device
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual qint64 writeData(const char *data, qint64 len)=0
Writes up to maxSize bytes from data to the device.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
\inmodule QtCore
Definition qobject.h:90
void formatKnown()
void parsingError()
void setIODevice(QIODevice *device)
else opt state
[0]
Combined button and popup list for selecting options.
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLsizei dataSize
GLenum type
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLenum GLsizei len
static QByteArray getDevice(const QString &rootPath)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
unsigned int quint32
Definition qtypes.h:45
unsigned short quint16
Definition qtypes.h:43
long long qint64
Definition qtypes.h:55
QByteArray readData()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent