Use 1.7x instead of 2x in voice messages.

This commit is contained in:
John Preston 2018-11-30 18:33:12 +04:00
parent 679330c1c0
commit 3bd0efa91e
7 changed files with 28 additions and 24 deletions

View File

@ -635,7 +635,7 @@ struct Data {
bool SuggestEmoji = true;
bool SuggestStickersByEmoji = true;
base::Observable<void> ReplaceEmojiChanged;
float64 VoiceMsgPlaybackSpeed = 1.;
bool VoiceMsgPlaybackDoubled = false;
bool SoundNotify = true;
bool DesktopNotify = true;
bool RestoreSoundNotifyFromTray = false;
@ -765,7 +765,7 @@ DefineVar(Global, bool, ReplaceEmoji);
DefineVar(Global, bool, SuggestEmoji);
DefineVar(Global, bool, SuggestStickersByEmoji);
DefineRefVar(Global, base::Observable<void>, ReplaceEmojiChanged);
DefineVar(Global, float64, VoiceMsgPlaybackSpeed);
DefineVar(Global, bool, VoiceMsgPlaybackDoubled);
DefineVar(Global, bool, SoundNotify);
DefineVar(Global, bool, DesktopNotify);
DefineVar(Global, bool, RestoreSoundNotifyFromTray);

View File

@ -298,7 +298,7 @@ DeclareVar(bool, ReplaceEmoji);
DeclareVar(bool, SuggestEmoji);
DeclareVar(bool, SuggestStickersByEmoji);
DeclareRefVar(base::Observable<void>, ReplaceEmojiChanged);
DeclareVar(float64, VoiceMsgPlaybackSpeed);
DeclareVar(bool, VoiceMsgPlaybackDoubled);
DeclareVar(bool, SoundNotify);
DeclareVar(bool, DesktopNotify);
DeclareVar(bool, RestoreSoundNotifyFromTray);

View File

@ -33,6 +33,8 @@ ALCcontext *AudioContext = nullptr;
constexpr auto kSuppressRatioAll = 0.2;
constexpr auto kSuppressRatioSong = 0.05;
constexpr auto kPlaybackSpeedMultiplier = 1.7;
constexpr auto kPlaybackSpeedTune = -9;
auto VolumeMultiplierAll = 1.;
auto VolumeMultiplierSong = 1.;
@ -162,7 +164,7 @@ bool CreatePlaybackDevice() {
// initialize the pitch shifter effect
alEffecti(_playbackSpeedData.uiEffect, AL_EFFECT_TYPE, AL_EFFECT_PITCH_SHIFTER);
// 12 semitones = 1 octave
alEffecti(_playbackSpeedData.uiEffect, AL_PITCH_SHIFTER_COARSE_TUNE, -12);
alEffecti(_playbackSpeedData.uiEffect, AL_PITCH_SHIFTER_COARSE_TUNE, kPlaybackSpeedTune);
// connect the effect with the effect slot
alAuxiliaryEffectSloti(_playbackSpeedData.uiEffectSlot, AL_EFFECTSLOT_EFFECT, _playbackSpeedData.uiEffect);
// initialize a filter to disable the direct (dry) path
@ -1030,7 +1032,7 @@ void Mixer::stop(const AudioMsgId &audio, State state) {
// Thread: Any. Must be locked: AudioMutex.
void Mixer::updatePlaybackSpeed(Track *track) {
const auto doubled = (_voicePlaybackSpeed.loadAcquire() == 2);
const auto doubled = (_voicePlaybackDoubled.loadAcquire() == 1);
updatePlaybackSpeed(track, doubled);
}
@ -1041,7 +1043,7 @@ void Mixer::updatePlaybackSpeed(Track *track, bool doubled) {
#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.);
alSourcef(source, AL_PITCH, doubled ? kPlaybackSpeedMultiplier : 1.);
// fix the pitch using effects and filters
if (doubled) {
// connect the effect slot with the stream
@ -1159,9 +1161,8 @@ void Mixer::reattachTracks() {
}
// Thread: Any. Locks AudioMutex.
void Mixer::setVoicePlaybackSpeed(float64 speed) {
const auto doubled = (std::round(speed) == 2);
_voicePlaybackSpeed.storeRelease(doubled ? 2 : 1);
void Mixer::setVoicePlaybackDoubled(bool doubled) {
_voicePlaybackDoubled.storeRelease(doubled ? 1 : 0);
QMutexLocker lock(&AudioMutex);
for (auto &track : _audioTracks) {

View File

@ -140,7 +140,7 @@ public:
float64 getVideoVolume() const;
// Thread: Any. Locks AudioMutex.
void setVoicePlaybackSpeed(float64 speed);
void setVoicePlaybackDoubled(bool doubled);
~Mixer();
@ -239,7 +239,7 @@ private:
QAtomicInt _volumeVideo;
QAtomicInt _volumeSong;
QAtomicInt _voicePlaybackSpeed;
QAtomicInt _voicePlaybackDoubled = { 0 };
friend class Fader;
friend class Loaders;

View File

@ -133,9 +133,9 @@ Widget::Widget(QWidget *parent) : RpWidget(parent)
updatePlaybackSpeedIcon();
_playbackSpeed->setClickedCallback([=] {
const auto updated = (3. - Global::VoiceMsgPlaybackSpeed());
Global::SetVoiceMsgPlaybackSpeed(updated);
mixer()->setVoicePlaybackSpeed(updated);
const auto doubled = !Global::VoiceMsgPlaybackDoubled();
Global::SetVoiceMsgPlaybackDoubled(doubled);
mixer()->setVoicePlaybackDoubled(doubled);
updatePlaybackSpeedIcon();
Local::writeUserSettings();
});
@ -371,10 +371,13 @@ void Widget::updateRepeatTrackIcon() {
}
void Widget::updatePlaybackSpeedIcon() {
const auto playbackSpeed = Global::VoiceMsgPlaybackSpeed();
const auto isDefaultSpeed = std::round(playbackSpeed) == 1.f;
_playbackSpeed->setIconOverride(isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIcon : nullptr, isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIconOver : nullptr);
_playbackSpeed->setRippleColorOverride(isDefaultSpeed ? &st::mediaPlayerSpeedDisabledRippleBg : nullptr);
const auto doubled = Global::VoiceMsgPlaybackDoubled();
const auto isDefaultSpeed = !doubled;
_playbackSpeed->setIconOverride(
isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIcon : nullptr,
isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIconOver : nullptr);
_playbackSpeed->setRippleColorOverride(
isDefaultSpeed ? &st::mediaPlayerSpeedDisabledRippleBg : nullptr);
}
void Widget::checkForTypeChange() {

View File

@ -508,8 +508,8 @@ void Messenger::startMtp() {
// Skip all pending self updates so that we won't Local::writeSelf.
Notify::peerUpdatedSendDelayed();
Media::Player::mixer()->setVoicePlaybackSpeed(
Global::VoiceMsgPlaybackSpeed());
Media::Player::mixer()->setVoicePlaybackDoubled(
Global::VoiceMsgPlaybackDoubled());
}
}
@ -987,8 +987,8 @@ void Messenger::loggedOut() {
}
clearPasscodeLock();
Media::Player::mixer()->stopAndClear();
Global::SetVoiceMsgPlaybackSpeed(1.);
Media::Player::mixer()->setVoicePlaybackSpeed(1.);
Global::SetVoiceMsgPlaybackDoubled(false);
Media::Player::mixer()->setVoicePlaybackDoubled(false);
if (const auto w = getActiveWindow()) {
w->tempDirDelete(Local::ClearManagerAll);
w->setupIntro();

View File

@ -1766,7 +1766,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
stream >> v;
if (!_checkStreamStatus(stream)) return false;
Global::SetVoiceMsgPlaybackSpeed((v == 2) ? 2. : 1.);
Global::SetVoiceMsgPlaybackDoubled(v == 2);
} break;
default:
@ -2039,7 +2039,7 @@ void _writeUserSettings() {
if (!userData.isEmpty()) {
data.stream << quint32(dbiAuthSessionSettings) << userData;
}
data.stream << quint32(dbiPlaybackSpeed) << qint32(std::round(Global::VoiceMsgPlaybackSpeed()));
data.stream << quint32(dbiPlaybackSpeed) << qint32(Global::VoiceMsgPlaybackDoubled() ? 2 : 1);
{
data.stream << quint32(dbiRecentEmoji) << recentEmojiPreloadData;