Port FluidSim core and scenarios to C++20
This commit is contained in:
30
include/FluidSim/AudioOutputStream.hpp
Normal file
30
include/FluidSim/AudioOutputStream.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "FluidSim/SimulationRingBuffer.hpp"
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
namespace fluidsim::port {
|
||||
|
||||
class AudioOutputStream final : public sf::SoundStream {
|
||||
public:
|
||||
explicit AudioOutputStream(SimulationRingBuffer& ring, unsigned int sample_rate = 44100);
|
||||
void set_speed(double speed) { speed_.store(speed, std::memory_order_relaxed); }
|
||||
double speed() const { return speed_.load(std::memory_order_relaxed); }
|
||||
|
||||
private:
|
||||
static constexpr std::size_t block_size = 512;
|
||||
SimulationRingBuffer& ring_;
|
||||
std::array<float, block_size> temp_left_{}, temp_right_{};
|
||||
std::array<std::int16_t, block_size * 2> output_{};
|
||||
std::atomic<double> speed_{1.0};
|
||||
float previous_input_left_{}, previous_output_left_{};
|
||||
float previous_input_right_{}, previous_output_right_{};
|
||||
|
||||
bool onGetData(Chunk& data) override;
|
||||
void onSeek(sf::Time time_offset) override;
|
||||
};
|
||||
|
||||
} // namespace fluidsim::port
|
||||
Reference in New Issue
Block a user