15#ifdef GALAXY_WIN_PLATFORM
17#pragma warning(disable : 26401)
18#pragma warning(disable : 26409)
19#pragma warning(disable : 26461)
29 , m_capacity {capacity}
31 m_buffer =
new float[m_capacity];
43 for (
auto i = 0; i < count; i++)
45 const auto pos = (m_write_index + i) % m_capacity;
46 m_buffer[pos] = data[i];
49 m_write_index = (m_write_index + count) % m_capacity;
56 for (
auto i = 0; i < count; i++)
58 const auto pos = (m_read_index + i) % m_capacity;
59 data[i] = m_buffer[pos];
62 m_read_index = (m_read_index + count) % m_capacity;
69 float* result = &m_buffer[m_read_index % m_capacity];
70 m_read_index = (m_read_index + count) % m_capacity;
81 const auto gain = (std::max(std::min(volume, 1.0f), 0.0f) * 50) - 50;
82 const auto factor = std::pow(10, gain * 0.05f);
84 m_volume =
static_cast<float>(std::max(std::min(1.0 * factor, 1.0), 0.0));
94#ifdef GALAXY_WIN_PLATFORM
float m_volume
Current volume of audio.
int read(float *data, int count) noexcept
Read data from buffer.
int m_write_index
Current index for writing to buffer.
int write(float *data, const int count) noexcept
Write data to ring buffer.
int m_capacity
Amount of data buffer can hold in total.
void set_volume(const float volume) noexcept
Sets audio volume of the buffer.
float * m_buffer
Data buffer.
int available_bytes() const noexcept
Available bytes left in the ring buffer.
RingBuffer()=delete
Constructor.
int m_read_index
Current index for reading from buffer.
float get_volume() const noexcept
Gets current buffer volume.
~RingBuffer() noexcept
Destructor.
float * direct_read_pointer(const int count) noexcept
Read the ring buffer.