Skip to content

Commit

Permalink
pcmDriver forward functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 12, 2023
1 parent 88ff32e commit 9c89311
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ namespace HyperSonicDrivers::audio
virtual uint32_t getRate() const = 0;
virtual bool endOfData() const = 0;
virtual bool isEnded() const { return endOfData(); }
//virtual void forward(const uint32_t ms) = 0;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ namespace HyperSonicDrivers::audio::streams
return m_curPos == m_sound->dataSize;
}

void PCMStream::forward(const uint32_t bytes) noexcept
{
m_curPos += bytes;
m_curPos = std::min(m_curPos, m_sound->dataSize);
}

std::shared_ptr<PCMSound> PCMStream::getSound() const noexcept
{
return m_sound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace HyperSonicDrivers::audio::streams
uint32_t getRate() const override;
bool endOfData() const override;

void forward(const uint32_t bytes) noexcept;
std::shared_ptr<PCMSound> getSound() const noexcept;
private:
std::shared_ptr<PCMSound> m_sound;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>
#include <HyperSonicDrivers/drivers/PCMDriver.hpp>
#include <HyperSonicDrivers/utils/sound.hpp>

namespace HyperSonicDrivers::drivers
{
Expand Down Expand Up @@ -98,6 +99,12 @@ namespace HyperSonicDrivers::drivers
releaseStreams_();
}

void PCMDriver::forward(const uint32_t ms) noexcept
{
for (const auto& [stream, _] : m_PCMStreams_channels)
stream->forward(utils::ms_toPos(ms, stream->getSound()));
}

void PCMDriver::releaseEndedStreams_() noexcept
{
for (auto it = m_PCMStreams_channels.begin(); it != m_PCMStreams_channels.end();)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace HyperSonicDrivers::drivers
void stop(const std::shared_ptr<audio::PCMSound>& sound, const bool releaseEndedStreams = true);
void stop() noexcept;

void forward(const uint32_t ms) noexcept;

const uint8_t max_streams;
private:
std::shared_ptr<audio::IMixer> m_mixer;
Expand Down

0 comments on commit 9c89311

Please sign in to comment.