Раздели PCM-сессии и исправь частоту и перемотку звука
This commit is contained in:
1 parent
40b974b29c
commit
217e5795bf
13 files changed
+226
-134
No files matched your search
@@ -73,13 +73,17 @@ int VoicePlayer::decodeOpusFile(const QString& filePath, std::vector<int16_t>& o
|
||||
|
||||
static unsigned s_decodeGeneration = 0; /* Только GUI-поток. */
|
||||
static bool s_decoding = false;
|
||||
static uint64_t s_playbackId = 0;
|
||||
|
||||
void VoicePlayer::cancelPending() { s_decodeGeneration++; }
|
||||
void VoicePlayer::stop() { cancelPending(); SoundManager::instance()->stopPcm(s_playbackId); s_playbackId = 0; }
|
||||
bool VoicePlayer::isPlaying() { return SoundManager::instance()->isPcmPlaying(s_playbackId); }
|
||||
uint64_t VoicePlayer::playbackId() { return s_playbackId; }
|
||||
bool VoicePlayer::isPreparing() { return s_decoding; }
|
||||
|
||||
/* Декодирование и выделение PCM выполняются в worker; GUI принимает готовый буфер. */
|
||||
void VoicePlayer::playOpusFile(const QString& filePath, QObject* context, std::function<void(float)> ready) {
|
||||
if (s_decoding) { DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "voice: decoder busy"); ready(0); return; }
|
||||
void VoicePlayer::playOpusFile(const QString& filePath, QObject* context, std::function<void(float, uint64_t)> ready) {
|
||||
if (s_decoding) { DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "voice: decoder busy"); ready(0, 0); return; }
|
||||
struct Result {
|
||||
std::shared_ptr<std::vector<int16_t>> pcm = std::make_shared<std::vector<int16_t>>();
|
||||
int rate = 0, channels = 0;
|
||||
@@ -101,9 +105,13 @@ void VoicePlayer::playOpusFile(const QString& filePath, QObject* context, std::f
|
||||
QObject::connect(thread, &QThread::finished, QCoreApplication::instance(), [result, receiver, ready, generation]() {
|
||||
s_decoding = false;
|
||||
if (!receiver || generation != s_decodeGeneration) return;
|
||||
if (result->duration > 0) SoundManager::instance()->playRawPcm(result->pcm->data(),
|
||||
(int)(result->pcm->size() / result->channels), result->rate, result->channels, result->pcm);
|
||||
ready(result->duration);
|
||||
if (result->duration > 0) {
|
||||
SoundManager::instance()->stopPcm(s_playbackId);
|
||||
s_playbackId = SoundManager::instance()->playRawPcm(result->pcm->data(),
|
||||
(int)(result->pcm->size() / result->channels), result->rate, result->channels, result->pcm);
|
||||
if (!s_playbackId) result->duration = 0;
|
||||
}
|
||||
ready(result->duration, s_playbackId);
|
||||
});
|
||||
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
||||
thread->start();
|
||||
|
||||
Reference in new issue
Block a user