diff --git a/Telegram/SourceFiles/media/media_audio.cpp b/Telegram/SourceFiles/media/media_audio.cpp index 622f321c6..b9301e413 100644 --- a/Telegram/SourceFiles/media/media_audio.cpp +++ b/Telegram/SourceFiles/media/media_audio.cpp @@ -140,7 +140,11 @@ bool CreatePlaybackDevice() { return false; } - ALCint attributes[] = { ALC_STEREO_SOURCES, 128, 0 }; + ALCint attributes[] = { + ALC_STEREO_SOURCES, 128, + ALC_FREQUENCY, Media::Player::kDefaultFrequency, + 0 + }; AudioContext = alcCreateContext(AudioDevice, attributes); alcMakeContextCurrent(AudioContext); if (ContextErrorHappened()) { @@ -256,7 +260,7 @@ namespace Player { namespace { constexpr auto kVolumeRound = 10000; -constexpr auto kPreloadSamples = 2LL * 48000; // preload next part if less than 2 seconds remains +constexpr auto kPreloadSamples = 2LL * kDefaultFrequency; // preload next part if less than 2 seconds remains constexpr auto kFadeDuration = TimeMs(500); constexpr auto kCheckPlaybackPositionTimeout = TimeMs(100); // 100ms per check audio position constexpr auto kCheckPlaybackPositionDelta = 2400LL; // update position called each 2400 samples diff --git a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp index 038e385c2..f29b89beb 100644 --- a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp @@ -252,7 +252,7 @@ bool FFMpegLoader::open(qint64 &position) { return false; } - if (_samplesFrequency != 44100 && _samplesFrequency != 48000) { + if (_samplesFrequency != Media::Player::kDefaultFrequency) { sampleSize = -1; // convert needed } @@ -265,7 +265,7 @@ bool FFMpegLoader::open(qint64 &position) { int64_t src_ch_layout = layout, dst_ch_layout = AudioToChannelLayout; srcRate = _samplesFrequency; AVSampleFormat src_sample_fmt = inputFormat, dst_sample_fmt = AudioToFormat; - dstRate = (_samplesFrequency != 44100 && _samplesFrequency != 48000) ? Media::Player::kDefaultFrequency : _samplesFrequency; + dstRate = Media::Player::kDefaultFrequency; av_opt_set_int(swrContext, "in_channel_layout", src_ch_layout, 0); av_opt_set_int(swrContext, "in_sample_rate", srcRate, 0); diff --git a/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp index bb7e57e66..a586a2b43 100644 --- a/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp @@ -76,7 +76,7 @@ bool ChildFFMpegLoader::open(qint64 &position) { _sampleSize = -1; // convert needed break; } - if (_parentData->frequency != 44100 && _parentData->frequency != 48000) { + if (_parentData->frequency != Media::Player::kDefaultFrequency) { _sampleSize = -1; // convert needed } @@ -89,7 +89,7 @@ bool ChildFFMpegLoader::open(qint64 &position) { int64_t src_ch_layout = layout, dst_ch_layout = AudioToChannelLayout; _srcRate = _parentData->frequency; AVSampleFormat src_sample_fmt = _inputFormat, dst_sample_fmt = AudioToFormat; - _dstRate = (_parentData->frequency != 44100 && _parentData->frequency != 48000) ? Media::Player::kDefaultFrequency : _parentData->frequency; + _dstRate = Media::Player::kDefaultFrequency; av_opt_set_int(_swrContext, "in_channel_layout", src_ch_layout, 0); av_opt_set_int(_swrContext, "in_sample_rate", _srcRate, 0);