Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
test_signal.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <array>
6#include <atomic>
7#include <cmath>
8#include <cstdint>
9#include <memory>
10#include <string>
11
12namespace pulp::format {
13
14enum class TestSignalType { none, sine, file, noise };
15
18 float sine_frequency_hz = 440.0f;
19 float sine_amplitude = 0.5f; // linear, 0–1
20};
21
25public:
26 TestSignalSource() = default;
27
28 void set_sample_rate(double sr) { sample_rate_ = sr; }
29
30 // ── Config (UI thread) ──────────────────────────────────────────────
31 void set_config(const TestSignalConfig& cfg);
33 bool is_active() const { return active_.load(std::memory_order_relaxed); }
34
35 // ── File playback (UI thread) ───────────────────────────────────────
36 bool load_file(const std::string& path);
38 bool has_file() const { return file_data_ != nullptr; }
39 const audio::AudioFileData* file_data() const { return file_data_.get(); }
40
41 void play();
42 void stop();
43 void set_loop(bool loop) { file_loop_.store(loop, std::memory_order_relaxed); }
44 bool is_playing() const { return file_playing_.load(std::memory_order_relaxed); }
45 bool is_looping() const { return file_loop_.load(std::memory_order_relaxed); }
46 int64_t file_position() const { return file_position_.load(std::memory_order_relaxed); }
47
48 // ── Audio thread ────────────────────────────────────────────────────
51 void fill(float* const* output, int num_channels, int num_samples);
52
53 void reset();
54
55private:
56 double sample_rate_ = 48000.0;
57 std::atomic<bool> active_{false};
58
59 // Config sync: UI writes via TripleBuffer, audio thread reads latest
60 TestSignalConfig config_; // Audio thread's working copy
62
63 // Sine state (audio thread only)
64 double sine_phase_ = 0.0;
65
66 // White-noise generator state (audio thread only). Seeded per channel so the
67 // two output channels are decorrelated.
68 std::array<std::uint32_t, 2> noise_state_ = {0x9e3779b9u, 0x1b56c4e9u};
69
70 // File playback
71 std::unique_ptr<audio::AudioFileData> file_data_;
72 std::atomic<int64_t> file_position_{0};
73 std::atomic<bool> file_playing_{false};
74 std::atomic<bool> file_loop_{false};
75};
76
77} // namespace pulp::format
TestSignalConfig config() const
bool is_active() const
Definition test_signal.hpp:33
int64_t file_position() const
Definition test_signal.hpp:46
void set_config(const TestSignalConfig &cfg)
void set_loop(bool loop)
Definition test_signal.hpp:43
void fill(float *const *output, int num_channels, int num_samples)
Fill output buffers with test signal.
void set_sample_rate(double sr)
Definition test_signal.hpp:28
bool load_file(const std::string &path)
const audio::AudioFileData * file_data() const
Definition test_signal.hpp:39
bool is_looping() const
Definition test_signal.hpp:45
bool is_playing() const
Definition test_signal.hpp:44
bool has_file() const
Definition test_signal.hpp:38
Lock-free triple buffer for publishing the latest value from a writer thread to a reader thread witho...
Definition triple_buffer.hpp:45
What the product grants a device: the quota table indexed by capability tier and live thermal state.
Definition aax_editor.hpp:31
TestSignalType
Definition test_signal.hpp:14
@ none
Definition test_signal.hpp:14
@ file
Definition test_signal.hpp:14
@ sine
Definition test_signal.hpp:14
@ noise
Definition test_signal.hpp:14
@ none
no window: an offscreen or headless editor
Definition editor_host.hpp:316
Definition audio_file.hpp:24
Definition test_signal.hpp:16
TestSignalType type
Definition test_signal.hpp:17
float sine_amplitude
Definition test_signal.hpp:19
float sine_frequency_hz
Definition test_signal.hpp:18
Lock-free latest-value publication between two threads.