linux-wallpaperengine/src/WallpaperEngine/Render/Objects/CSound.cpp
2025-09-11 17:10:23 +02:00

39 lines
1.1 KiB
C++

#include <SDL.h>
#include "CSound.h"
#include "WallpaperEngine/FileSystem/Container.h"
using namespace WallpaperEngine::Render::Objects;
CSound::CSound (Wallpapers::CScene& scene, const Sound& sound) :
CObject (scene, sound),
m_sound (sound) {
if (this->getContext ().getApp ().getContext ().settings.audio.enabled)
this->load ();
}
CSound::~CSound() {
// free all the sound buffers and streams
for (const auto& stream : this->m_audioStreams) {
delete stream;
}
}
void CSound::load () {
for (const auto& cur : this->m_sound.sounds) {
uint32_t filesize = 0;
auto filebuffer = this->getContainer ().read (cur);
auto stream = new Audio::CAudioStream (this->getScene ().getAudioContext (), filebuffer, filesize);
stream->setRepeat (this->m_sound.playbackmode.has_value() && this->m_sound.playbackmode == "loop");
this->m_audioStreams.push_back (stream);
// add the stream to the context so it can be played
this->getScene ().getAudioContext ().addStream (stream);
}
}
void CSound::render () {}