QtAudio 名稱空間

QtAudio 名稱空間包含用於音頻類的枚舉。 更多...

頭: #include <QtAudio>
CMake: 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 An error occurred during read/write of audio device. This can happen when e.g. an external audio interface is disconnected.
QtAudio::UnderrunError 3 未以足夠快的速率,把音頻數據喂給音頻設備
QtAudio::FatalError 4 齣現不可恢復錯誤,音頻設備此時不可用。

enum QtAudio:: State

常量 描述
QtAudio::ActiveState 0 正處理音頻數據,此狀態是在調用 start() 後設置的,且音頻數據同時可用於處理。
QtAudio::SuspendedState 1 音頻流處於掛起狀態。在調用 suspend() 後 (或當另一流控製音頻設備時),進入。在後一情況下,對 resume 的調用將把音頻設備的控製返迴給此流。通常,這隻應在用戶請求時進行。
QtAudio::StoppedState 2 關閉音頻設備,且不處理任何音頻數據
QtAudio::IdleState 3 This state indicates that the audio system is temporarily idle due to a buffering condition. For a QAudioSink , IdleState means there isn’t enough data available from the QIODevice to read. For a QAudioSource , IdleState is entered when the ring buffer that feeds the QIODevice becomes full. In that case, any new audio data arriving from the audio interface is discarded until the application reads from the QIODevice , which frees up space in the buffer.

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%) 為全音量。通常,UI 音量控製應使用對數比例縮放。
QtAudio::DecibelVolumeScale 3 分貝 (dB、振幅) 對數比例縮放。 -200 為無聲而 0 為全音量。

另請參閱 QtAudio::convertVolume ().

函數文檔編製

float QtAudio:: convertVolume ( float volume , QtAudio::VolumeScale from , QtAudio::VolumeScale to )

轉換音頻 volume from 音量比例縮放 to 另一,並返迴結果。

從屬上下文,錶示音頻音量是使用不同刻度。所有擁有音頻音量的 Qt Multimedia 類都使用綫性刻度,原因是揚聲器響度是通過綫性刻度調製其電壓來控製的。另一方麵,人的耳朵以對數方式感知響度。因此,在大多數應用程序中,音量控製使用對數刻度很閤適。分貝刻度本質上是對數的,且常用於定義聲明級彆,通常用於專業音頻應用程序 UI 音量控製。立方刻度是對數刻度的便宜計算近似,它提供對較低音量級彆的更多控製。

以下範例展示如何從滑塊控件轉換音量值,先於把它傳遞給 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 ().