Exposing the ChargeAudio::Sound on API

This commit is contained in:
2025-10-06 18:17:35 +03:00
parent 7cf786b61d
commit fb82db0017
2 changed files with 14 additions and 12 deletions

View File

@@ -80,6 +80,9 @@ public:
// SAR and Scaling // SAR and Scaling
Vector2i Dimensions{0, 0}; Vector2i Dimensions{0, 0};
// Audio
ChargeAudio::SoundContainer Sound;
private: private:
// Contextes // Contextes
_ffmpeg::AVFormatContext *ctx; _ffmpeg::AVFormatContext *ctx;
@@ -98,7 +101,6 @@ private:
// Audio // Audio
ChargeAudio::Engine *audioEngine; ChargeAudio::Engine *audioEngine;
ChargeAudio::SoundContainer bufferedAudio;
// Audio Channel data // Audio Channel data
_ffmpeg::AVChannelLayout outLayout; _ffmpeg::AVChannelLayout outLayout;

View File

@@ -99,7 +99,7 @@ Video::Video(std::string path, ChargeAudio::Engine *engine,
swr_init(swrCtx); swr_init(swrCtx);
// Creating buffered audio // Creating buffered audio
bufferedAudio = audioEngine->CreateSound(10); Sound = audioEngine->CreateSound(10);
} }
bufferMaxFrames = av_q2d(videoStream->avg_frame_rate) * BufferLenghtInSeconds; bufferMaxFrames = av_q2d(videoStream->avg_frame_rate) * BufferLenghtInSeconds;
@@ -123,7 +123,7 @@ void Video::Play() {
} }
ID = Time::hookVideo(std::bind(&Video::continueVideo, this)); ID = Time::hookVideo(std::bind(&Video::continueVideo, this));
if (audioStreamNum != -1) { if (audioStreamNum != -1) {
bufferedAudio->Play(); Sound->Play();
} }
isVideoPaused = false; isVideoPaused = false;
isVideoOver = false; isVideoOver = false;
@@ -135,7 +135,7 @@ void Video::Pause() {
} }
Time::unhookVideo(ID); Time::unhookVideo(ID);
if (audioStreamNum != -1) { if (audioStreamNum != -1) {
bufferedAudio->Pause(); Sound->Pause();
} }
ID = 0; ID = 0;
isVideoPaused = true; isVideoPaused = true;
@@ -167,8 +167,8 @@ void Video::continueVideo() {
// Timing // Timing
// Audio Synced // Audio Synced
if (audioStreamNum != -1) { if (audioStreamNum != -1) {
clock = (double)bufferedAudio->GetPlayedSampleCount() / clock =
audioEngine->GetSampleRate(); (double)Sound->GetPlayedSampleCount() / audioEngine->GetSampleRate();
} else { } else {
clock += Time::DeltaTime; clock += Time::DeltaTime;
} }
@@ -187,8 +187,8 @@ void Video::continueVideo() {
} }
if (audioStreamNum != -1 && if (audioStreamNum != -1 &&
bufferedAudio->GetState() != ChargeAudio::Sound::SoundState::Playing) Sound->GetState() != ChargeAudio::Sound::SoundState::Playing)
bufferedAudio->Play(); Sound->Play();
} }
// ======================== HELPERS ======================== // ======================== HELPERS ========================
@@ -214,7 +214,7 @@ std::pair<double, Containers::Array<char>> Video::loadNextFrame() {
swr_convert_frame(swrCtx, convertedAudioFrame, audioFrame); swr_convert_frame(swrCtx, convertedAudioFrame, audioFrame);
bufferedAudio->WriteToRingBuffer(convertedAudioFrame->data[0], Sound->WriteToRingBuffer(convertedAudioFrame->data[0],
convertedAudioFrame->linesize[0]); convertedAudioFrame->linesize[0]);
} }
} }
@@ -367,8 +367,8 @@ void Video::restartVideo() {
void Video::dumpAndRefillBuffer() { void Video::dumpAndRefillBuffer() {
std::map<double, Image2D>().swap(frameBuffer); std::map<double, Image2D>().swap(frameBuffer);
if (audioStreamNum != -1) { if (audioStreamNum != -1) {
bufferedAudio.release(); Sound.release();
bufferedAudio = audioEngine->CreateSound(10); Sound = audioEngine->CreateSound(10);
} }
loadTexture(loadNextFrame().second); loadTexture(loadNextFrame().second);
} }