Add configuration for OpenAL effects usage.

This commit is contained in:
John Preston 2018-11-09 16:28:15 +04:00
parent 9a1069c1ae
commit 2d05281ba9
3 changed files with 20 additions and 3 deletions

View File

@ -45,12 +45,14 @@ namespace {
Player::Mixer *MixerInstance = nullptr;
#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
struct PlaybackSpeedData {
ALuint uiEffectSlot = 0;
ALuint uiEffect = 0;
ALuint uiFilter = 0;
};
PlaybackSpeedData _playbackSpeedData;
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS
// Thread: Any.
bool ContextErrorHappened() {
@ -152,6 +154,7 @@ bool CreatePlaybackDevice() {
alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f);
alListenerfv(AL_ORIENTATION, v);
#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
// playback speed related init
// generate an effect slot and an effect
alGenAuxiliaryEffectSlots(1, &_playbackSpeedData.uiEffectSlot);
@ -169,6 +172,7 @@ bool CreatePlaybackDevice() {
alFilterf(_playbackSpeedData.uiFilter, AL_LOWPASS_GAIN, 0.f);
// to use the modified playback speed:
// connect both the effect slot and filter with the stream source and set AL_PITCH
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS
alDistanceModel(AL_NONE);
@ -181,6 +185,7 @@ void ClosePlaybackDevice() {
LOG(("Audio Info: Closing audio playback device."));
#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
// playback speed related
alDeleteFilters(1, &_playbackSpeedData.uiFilter);
alDeleteEffects(1, &_playbackSpeedData.uiEffect);
@ -188,6 +193,7 @@ void ClosePlaybackDevice() {
_playbackSpeedData.uiFilter = 0;
_playbackSpeedData.uiEffect = 0;
_playbackSpeedData.uiEffectSlot = 0;
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS
if (Player::mixer()) {
Player::mixer()->detachTracks();
@ -1031,6 +1037,7 @@ void Mixer::updatePlaybackSpeed(Track *track, bool doubled) {
if (!track->isStreamCreated()) {
return;
}
#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
const auto source = track->stream.source;
// Note: This alters the playback speed AND the pitch
alSourcef(source, AL_PITCH, doubled ? 2. : 1.);
@ -1046,6 +1053,7 @@ void Mixer::updatePlaybackSpeed(Track *track, bool doubled) {
// disconnect the filter
alSourcei(source, AL_DIRECT_FILTER, AL_FILTER_NULL);
}
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS
}
void Mixer::stopAndClear() {

View File

@ -259,7 +259,7 @@ void Widget::handleSeekFinished(float64 progress) {
void Widget::resizeEvent(QResizeEvent *e) {
auto right = st::mediaPlayerCloseRight;
_close->moveToRight(right, st::mediaPlayerPlayTop); right += _close->width();
if (_type == AudioMsgId::Type::Voice) {
if (hasPlaybackSpeedControl()) {
_playbackSpeed->moveToRight(right, st::mediaPlayerPlayTop); right += _playbackSpeed->width();
}
_repeatTrack->moveToRight(right, st::mediaPlayerPlayTop); right += _repeatTrack->width();
@ -345,7 +345,7 @@ int Widget::getLabelsRight() const {
auto result = st::mediaPlayerCloseRight + _close->width();
if (_type == AudioMsgId::Type::Song) {
result += _repeatTrack->width() + _volumeToggle->width();
} else if (_type == AudioMsgId::Type::Voice) {
} else if (hasPlaybackSpeedControl()) {
result += _playbackSpeed->width();
}
result += st::mediaPlayerPadding;
@ -391,12 +391,20 @@ void Widget::checkForTypeChange() {
}
}
bool Widget::hasPlaybackSpeedControl() const {
#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
return (_type == AudioMsgId::Type::Voice);
#else // TDESKTOP_DISABLE_OPENAL_EFFECTS
return false;
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS
}
void Widget::setType(AudioMsgId::Type type) {
if (_type != type) {
_type = type;
_repeatTrack->setVisible(_type == AudioMsgId::Type::Song);
_volumeToggle->setVisible(_type == AudioMsgId::Type::Song);
_playbackSpeed->setVisible(_type == AudioMsgId::Type::Voice);
_playbackSpeed->setVisible(hasPlaybackSpeedControl());
if (!_shadow->isHidden()) {
_playbackSlider->setVisible(_type == AudioMsgId::Type::Song);
}

View File

@ -70,6 +70,7 @@ private:
void createPrevNextButtons();
void destroyPrevNextButtons();
bool hasPlaybackSpeedControl() const;
void updateVolumeToggleIcon();
void checkForTypeChange();