QtAudio Namespace
QtAudio 命名空间包含音频类使用的枚举。更多
头文件: | #include <QtAudio> |
CMake.QtAudio | find_package(Qt6 REQUIRED COMPONENTS Multimedia) 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, QtAudio::VolumeScale from, QtAudio::VolumeScale to) |
类型文档
enum QtAudio::Error
常数 | 值 | 说明 |
---|---|---|
QtAudio::NoError | 0 | 未发生错误 |
QtAudio::OpenError | 1 | 打开音频设备时发生错误 |
QtAudio::IOError | 2 | 读/写音频设备时发生错误 |
QtAudio::UnderrunError | 3 | 音频数据输入音频设备的速度不够快 |
QtAudio::FatalError | 4 | 发生了不可恢复的错误,音频设备暂时无法使用。 |
enum QtAudio::State
常数 | 值 | 说明 |
---|---|---|
QtAudio::ActiveState | 0 | 正在处理音频数据,此状态在调用 start() 后和音频数据可被处理时设置。 |
QtAudio::SuspendedState | 1 | 音频流处于暂停状态。在调用 suspend() 后或音频设备由其他流控制时进入。在后一种情况下,调用 resume 会将音频设备的控制权返回给该音频流。通常只有在用户请求时才会这样做。 |
QtAudio::StoppedState | 2 | 音频设备已关闭,且未处理任何音频数据 |
QtAudio::IdleState | 3 | 传入的QIODevice 没有数据,音频系统的缓冲区为空,这种状态在调用 start() 后设置,并且没有音频数据可供处理。 |
enum QtAudio::VolumeScale
该枚举定义了不同的音频音量标度。
常数 | 值 | 说明 |
---|---|---|
QtAudio::LinearVolumeScale | 0 | 线性刻度。 0.0 (0%)为静音,1.0 (100%)为全音量。所有具有音频音量的Qt Multimedia 类别都使用线性刻度。 |
QtAudio::CubicVolumeScale | 1 | 立方刻度。 0.0 (0%)为静音,1.0 (100%)为全音量。 |
QtAudio::LogarithmicVolumeScale | 2 | 对数刻度。 0.0 (0%)为静音,1.0 (100%)为全音量。用户界面音量控制通常应使用对数刻度。 |
QtAudio::DecibelVolumeScale | 3 | -200 为静音,0 为全音量。 |
另请参阅 QtAudio::convertVolume().
函数文档
float QtAudio::convertVolume(float volume, QtAudio::VolumeScale from, QtAudio::VolumeScale to)
转换音频volume from 音量刻度to 并返回结果。
根据语境的不同,音频音量会使用不同的标度。所有具有音频音量的Qt Multimedia 类都使用线性标度,原因是扬声器的响度是通过在线性标度上调节电压来控制的。而人耳是以对数方式感知响度的。因此,在大多数应用中,使用对数刻度来控制音量是合适的。分贝标度本质上是对数标度,常用于定义音量,通常用于专业音频应用中的用户界面音量控制。立方音阶是对数音阶的近似值,计算成本低,对较低音量的控制能力更强。
下面的示例展示了如何将来自滑块控件的音量值转换为QMediaPlayer 。因此,当音量滑块从 20 增大到 30 时,音量增加的感觉与从 50 增大到 60 时是一样的:
void applyVolume(int volumeSliderValue) { // volumeSliderValue is in the range [0..100] qreal linearVolume = QtAudio::convertVolume(volumeSliderValue / qreal(100.0), QtAudio::LogarithmicVolumeScale, QtAudio::LinearVolumeScale); player.setVolume(qRound(linearVolume * 100)); }
另请参阅 VolumeScale,QAudioSink::setVolume(),QAudioSource::setVolume() 和QSoundEffect::setVolume() 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.