Added fallback of waveform data to transcribed round messages.

This commit is contained in:
23rd 2022-10-28 10:02:25 +03:00 committed by John Preston
parent af6ca8d4f1
commit 3078a94404

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/media/history_view_document.h"
#include "base/random.h"
#include "lang/lang_keys.h"
#include "storage/localstorage.h"
#include "main/main_session.h"
@ -74,6 +75,24 @@ constexpr auto kAudioVoiceMsgUpdateView = crl::time(100);
return result;
}
void FillWaveform(VoiceData *roundData) {
if (!roundData->waveform.empty()) {
return;
}
const auto &size = ::Media::Player::kWaveformSamplesCount;
auto randomBytes = bytes::vector(size);
base::RandomFill(randomBytes.data(), randomBytes.size());
roundData->waveform.resize(size);
for (auto i = 1; i < size; i += 2) {
const auto peak = uchar(randomBytes[i]) % 31;
roundData->waveform[i - 1] = char(std::max(
0,
peak - (uchar(randomBytes[i - 1]) % 3 + 2)));
roundData->waveform[i] = char(peak);
}
roundData->wavemax = *ranges::max_element(roundData->waveform);
}
void PaintWaveform(
Painter &p,
const PaintContext &context,
@ -674,6 +693,9 @@ void Document::draw(
p.save();
p.translate(nameleft, st.padding.top() - topMinus);
if (_transcribedRound) {
FillWaveform(_data->round());
}
PaintWaveform(p,
context,
_transcribedRound ? _data->round() : _data->voice(),