summaryrefslogtreecommitdiffstats
path: root/src/multimedia/doc/src/audiooverview.qdoc
blob: d4c3116baf69897dd194e040a5318a18dd0501a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt for Multimedia module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\page audiooverview.html
\title Audio Overview
\inlineimage sound-wave-small.jpg
\brief Playback, recording and processing of Audio.

\section1 Audio Features

Qt Multimedia offers a range of audio classes that cover both low and
high level approaches to: audio input, output and processing.

\section1 Audio Implementation Details

\section2 Playing Compressed Audio
For playing media or audio files that are not simple, uncompressed audio, you
can use the QMediaPlayer C++ class, or the \l{MediaPlayer} QML type.
The QMediaPlayer class and associated QML types are also capable of playing
\l{multimedia-playing-video}{video}, if required. The compressed audio formats
supported depends on:
\list
    \li The operating system environment.
    \li Any decoder plugins the user may have installed.
\endlist

Here is how you play a local file using C++:

    \snippet multimedia-snippets/media.cpp Local playback

\section2 Recording Audio to a File
For recording audio to a file, the QMediaRecorder class allows you
to compress audio data from an input device and record it.

    \snippet multimedia-snippets/media.cpp Media recorder

QMediaCaptureSession provides support for more complex use cases involving the
capturing and recording of audio.

\section2 Low Latency Sound Effects

In addition to \l{raw access} to sound devices, the QSoundEffect
class (and \l{SoundEffect} QML type) offers a more abstract way to play
sounds. This class allows you to specify a \b{WAV format} file, which can
then be played with low latency when necessary.

You can adjust the:
\list
    \li \l{QSoundEffect::loopCount()}{Number of loops} in which a sound effect
    is played.
    \li \l{QSoundEffect::setVolume()}{Volume} of the sound effect.
    \li \l{QSoundEffect::setMuted()}{Muting} of the sound effect.
\endlist

\target raw access
\section2 Low Level Audio Playback and Recording

Qt Multimedia offers classes for raw access to audio input and output
facilities, allowing applications to receive raw data from devices like
microphones, and to write raw data to speakers or other devices. Generally
these classes do not do any audio decoding, or other processing, but they
can support different types of raw audio data.

The QAudioSink class offers raw audio data output, while QAudioSource
offers raw audio data input. The available hardware
determines what audio outputs and inputs are available.

\section3 Push and Pull
The low level audio classes can operate in two modes - \c push and \c pull.
In \c pull mode, the audio device is started by giving it a QIODevice.  For
an output device, the QAudioSink class will pull data from the QIODevice
(using \l QIODevice::read()) when more audio data is required.  Conversely,
for \c pull mode with QAudioSource, when audio data is available then the
data will be written directly to the QIODevice.

In \c push mode, the audio device provides a QIODevice instance that
can be written or read to as needed. Typically, this results in simpler
code but more buffering, which may affect latency.

\section2 Decoding Compressed Audio to Memory

In some cases you may want to decode a compressed audio file and do further
processing yourself. For example, mixing multiple samples or using custom
digital signal processing algorithms. QAudioDecoder supports decoding local
files or data streams from QIODevice instances.

Here's an example of decoding a local file:

    \snippet multimedia-snippets/audio.cpp Local audio decoding

\section1 Examples

There are both C++ and QML examples available.

\section2 C++ Examples

\annotatedlist audio_examples

\section1 Reference Documentation

\section2 C++ Classes

\annotatedlist multimedia_audio

\section2 QML Types

\annotatedlist multimedia_audio_qml

*/