QAudio 名称空间

QAudio 名称空间包含音频类使用的枚举。 更多...

头: #include <QAudio>
qmake: QT += multimedia

类型

enum Error { NoError, OpenError, IOError, UnderrunError, FatalError }
enum Mode { AudioOutput, AudioInput }
enum 角色 { UnknownRole, MusicRole, VideoRole, VoiceCommunicationRole, ..., GameRole }
enum State { ActiveState, SuspendedState, StoppedState, IdleState }
enum VolumeScale { LinearVolumeScale, CubicVolumeScale, LogarithmicVolumeScale, DecibelVolumeScale }

函数

qreal convertVolume (qreal volume , VolumeScale from , VolumeScale to )

详细描述

QAudio 名称空间包含音频类使用的枚举。

类型文档编制

enum QAudio:: Error

常量 描述
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.

enum QAudio:: Mode

常量 描述
QAudio::AudioOutput 1 音频输出设备
QAudio::AudioInput 0 音频输入设备

enum QAudio:: 角色

此枚举描述音频流的角色。

常量 描述
QAudio::UnknownRole 0 角色未知或未定义字节序
QAudio::MusicRole 1 Music
QAudio::VideoRole 2 Soundtrack from a movie or a video
QAudio::VoiceCommunicationRole 3 Voice communications, such as telephony
QAudio::AlarmRole 4 闹钟
QAudio::NotificationRole 5 Notification, such as an incoming e-mail or a chat request
QAudio::RingtoneRole 6 手机铃声
QAudio::AccessibilityRole 7 For accessibility, such as with a screen reader
QAudio::SonificationRole 8 Sonification, such as with user interface sounds
QAudio::GameRole 9 游戏音频

该枚举在 Qt 5.6 引入或被修改。

另请参阅 QMediaPlayer::setAudioRole ().

enum QAudio:: State

常量 描述
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 device is in a suspended state, this state will only be entered after suspend() is called.
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.

enum QAudio:: VolumeScale

此枚举定义不同音频音量的比例缩放。

常量 描述
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 为全音量。

该枚举在 Qt 5.8 引入或被修改。

另请参阅 QAudio::convertVolume ().

函数文档编制

qreal QAudio:: convertVolume ( qreal volume , VolumeScale from , VolumeScale to )

转换音频 volume from 音量比例缩放 to 另一,并返回结果。

Depending on the context, different scales are used to represent audio volume. All Qt Multimedia classes that have an audio volume use a linear scale, the reason is that the loudness of a speaker is controlled by modulating its voltage on a linear scale. The human ear on the other hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls is therefore appropriate in most applications. The decibel scale is logarithmic by nature and is commonly used to define sound levels, it is usually used for UI volume controls in professional audio applications. The cubic scale is a computationally cheap approximation of a logarithmic scale, it provides more control over lower volume levels.

The following example shows how to convert the volume value from a slider control before passing it to a QMediaPlayer . As a result, the perceived increase in volume is the same when increasing the volume slider from 20 to 30 as it is from 50 to 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));
}
					

该函数在 Qt 5.8 引入。

另请参阅 VolumeScale , QMediaPlayer::setVolume (), QAudioOutput::setVolume (), QAudioInput::setVolume (), QSoundEffect::setVolume (),和 QMediaRecorder::setVolume ().