QAudio 名称空间包含用于音频类的枚举。 更多...
头: | #include <QAudio> |
CMake: |
find_package(Qt6 COMPONENTS Multimedia REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
enum | Error { NoError, OpenError, IOError, UnderrunError, FatalError } |
enum | State { ActiveState, SuspendedState, StoppedState, IdleState } |
enum | VolumeScale { LinearVolumeScale, CubicVolumeScale, LogarithmicVolumeScale, DecibelVolumeScale } |
float | convertVolume (float volume , QAudio::VolumeScale from , QAudio::VolumeScale to ) |
常量 | 值 | 描述 |
---|---|---|
QAudio::NoError
|
0
|
没有出现错误 |
QAudio::OpenError
|
1
|
An error occurred opening the audio device |
QAudio::IOError
|
2
|
An error occurred during read/write of audio device |
QAudio::UnderrunError
|
3
|
Audio data is not being fed to the audio device at a fast enough rate |
QAudio::FatalError
|
4
|
A non-recoverable error has occurred, the audio device is not usable at this time. |
常量 | 值 | 描述 |
---|---|---|
QAudio::ActiveState
|
0
|
Audio data is being processed, this state is set after start() is called and while audio data is available to be processed. |
QAudio::SuspendedState
|
1
|
The audio stream is in a suspended state. Entered after suspend() is called or when another stream takes control of the audio device. In the later case, a call to resume will return control of the audio device to this stream. This should usually only be done upon user request. |
QAudio::StoppedState
|
2
|
The audio device is closed, and is not processing any audio data |
QAudio::IdleState
|
3
|
QIODevice passed in has no data and audio system's buffer is empty, this state is set after start() is called and while no audio data is available to be processed. |
此枚举定义不同音频音量的比例缩放。
常量 | 值 | 描述 |
---|---|---|
QAudio::LinearVolumeScale
|
0
|
线性比例缩放。
0.0
(0%) 为无声而
1.0
(100%) is full volume. All Qt Multimedia classes that have an audio volume use a linear scale.
|
QAudio::CubicVolumeScale
|
1
|
立方比例缩放。
0.0
(0%) 为无声而
1.0
(100%) 为全音量。
|
QAudio::LogarithmicVolumeScale
|
2
|
对数比例缩放。
0.0
(0%) 为无声而
1.0
(100%) is full volume. UI volume controls should usually use a logarithmic scale.
|
QAudio::DecibelVolumeScale
|
3
|
分贝 (dB、振幅) 对数比例缩放。
-200
为无声而
0
为全音量。
|
另请参阅 QAudio::convertVolume ().
转换音频 volume from 音量比例缩放 to 另一,并返回结果。
从属上下文,表示音频音量是使用不同刻度。所有拥有音频音量的 Qt Multimedia 类都使用线性刻度,原因是扬声器响度是通过线性刻度调制其电压来控制的。另一方面,人的耳朵以对数方式感知响度。因此,在大多数应用程序中,音量控制使用对数刻度很合适。分贝刻度本质上是对数的,且常用于定义声明级别,通常用于专业音频应用程序 UI 音量控制。立方刻度是对数刻度的便宜计算近似,它提供对较低音量级别的更多控制。
以下范例展示如何从滑块控件转换音量值,先于把它传递给 QMediaPlayer 。因此,感知音量递增一样,当把音量滑块从 20 递增到 30 时,就像从 50 到 60:
void applyVolume(int volumeSliderValue) { // volumeSliderValue is in the range [0..100] qreal linearVolume = QAudio::convertVolume(volumeSliderValue / qreal(100.0), QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale); player.setVolume(qRound(linearVolume * 100)); }
另请参阅 VolumeScale , QAudioSink::setVolume (), QAudioSource::setVolume (),和 QSoundEffect::setVolume ().