From fb82db00170696da2c08102fdbd49a4d496e0930 Mon Sep 17 00:00:00 2001 From: cat Date: Mon, 6 Oct 2025 18:17:35 +0300 Subject: [PATCH] Exposing the ChargeAudio::Sound on API --- src/ChargeVideo.hpp | 4 +++- src/Video.cpp | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ChargeVideo.hpp b/src/ChargeVideo.hpp index a895ac7..1375e01 100644 --- a/src/ChargeVideo.hpp +++ b/src/ChargeVideo.hpp @@ -80,6 +80,9 @@ public: // SAR and Scaling Vector2i Dimensions{0, 0}; + // Audio + ChargeAudio::SoundContainer Sound; + private: // Contextes _ffmpeg::AVFormatContext *ctx; @@ -98,7 +101,6 @@ private: // Audio ChargeAudio::Engine *audioEngine; - ChargeAudio::SoundContainer bufferedAudio; // Audio Channel data _ffmpeg::AVChannelLayout outLayout; diff --git a/src/Video.cpp b/src/Video.cpp index 2ae0fc8..9a8fba4 100644 --- a/src/Video.cpp +++ b/src/Video.cpp @@ -99,7 +99,7 @@ Video::Video(std::string path, ChargeAudio::Engine *engine, swr_init(swrCtx); // Creating buffered audio - bufferedAudio = audioEngine->CreateSound(10); + Sound = audioEngine->CreateSound(10); } bufferMaxFrames = av_q2d(videoStream->avg_frame_rate) * BufferLenghtInSeconds; @@ -123,7 +123,7 @@ void Video::Play() { } ID = Time::hookVideo(std::bind(&Video::continueVideo, this)); if (audioStreamNum != -1) { - bufferedAudio->Play(); + Sound->Play(); } isVideoPaused = false; isVideoOver = false; @@ -135,7 +135,7 @@ void Video::Pause() { } Time::unhookVideo(ID); if (audioStreamNum != -1) { - bufferedAudio->Pause(); + Sound->Pause(); } ID = 0; isVideoPaused = true; @@ -167,8 +167,8 @@ void Video::continueVideo() { // Timing // Audio Synced if (audioStreamNum != -1) { - clock = (double)bufferedAudio->GetPlayedSampleCount() / - audioEngine->GetSampleRate(); + clock = + (double)Sound->GetPlayedSampleCount() / audioEngine->GetSampleRate(); } else { clock += Time::DeltaTime; } @@ -187,8 +187,8 @@ void Video::continueVideo() { } if (audioStreamNum != -1 && - bufferedAudio->GetState() != ChargeAudio::Sound::SoundState::Playing) - bufferedAudio->Play(); + Sound->GetState() != ChargeAudio::Sound::SoundState::Playing) + Sound->Play(); } // ======================== HELPERS ======================== @@ -214,8 +214,8 @@ std::pair> Video::loadNextFrame() { swr_convert_frame(swrCtx, convertedAudioFrame, audioFrame); - bufferedAudio->WriteToRingBuffer(convertedAudioFrame->data[0], - convertedAudioFrame->linesize[0]); + Sound->WriteToRingBuffer(convertedAudioFrame->data[0], + convertedAudioFrame->linesize[0]); } } @@ -367,8 +367,8 @@ void Video::restartVideo() { void Video::dumpAndRefillBuffer() { std::map().swap(frameBuffer); if (audioStreamNum != -1) { - bufferedAudio.release(); - bufferedAudio = audioEngine->CreateSound(10); + Sound.release(); + Sound = audioEngine->CreateSound(10); } loadTexture(loadNextFrame().second); }