ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
ACMXVK/audio.hpp
Go to the documentation of this file.
1#ifndef ACMXVK_AUDIO_HPP
2#define ACMXVK_AUDIO_HPP
3
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7#include <string>
8#include <vector>
9
10namespace acmxvk::audio {
11
12 struct AudioMetrics {
13 float amplitude = 0.0F;
14 float frequency = 0.0F;
15 float peak = 0.0F;
16 float rms = 0.0F;
17 float smooth = 0.0F;
18 float low = 0.0F;
19 float mid = 0.0F;
20 float high = 0.0F;
21 };
22
24 unsigned int channels = 2;
25 float sensitivity = 1.0F;
26 int input_device = -1;
27 int output_device = -1;
28 bool pass_through = false;
29 float pass_through_gain = 1.0F;
30 float recording_gain = 1.0F;
31 };
32
34 std::vector<float> samples;
35 unsigned int sample_rate = 0;
36
37 [[nodiscard]] bool empty() const { return samples.empty(); }
38 [[nodiscard]] double duration_seconds() const {
39 return sample_rate == 0
40 ? 0.0
41 : static_cast<double>(samples.size()) /
42 static_cast<double>(sample_rate);
43 }
44 };
45
46 [[nodiscard]] bool write_wav_file(const AudioRecording &recording,
47 const std::string &filename);
48
50 public:
51 static constexpr std::size_t FFT_SIZE = 512;
52
55
56 AudioEngine(const AudioEngine &) = delete;
57 AudioEngine &operator=(const AudioEngine &) = delete;
58
59 bool open(const AudioStreamConfig &config);
60 void close();
61 [[nodiscard]] bool is_open() const;
62
63 [[nodiscard]] AudioMetrics metrics() const;
64 [[nodiscard]] unsigned int sample_rate() const;
65 void set_sensitivity(float sensitivity);
66 [[nodiscard]] float sensitivity() const;
67 [[nodiscard]] std::vector<float> spectrum() const;
68 void process_samples(const float *samples, unsigned int frame_count,
69 unsigned int channels, unsigned int sample_rate);
70 bool start_recording();
71 [[nodiscard]] AudioRecording stop_recording();
72 [[nodiscard]] bool is_recording() const;
73 [[nodiscard]] double recording_time() const;
74 void reset();
75 static constexpr std::uint32_t spectrum_bin_count() {
76 return static_cast<std::uint32_t>(FFT_SIZE / 2);
77 }
78
79 static void list_devices();
80
81 private:
82 class Impl;
83 std::unique_ptr<Impl> impl;
84 };
85
86} // namespace acmxvk::audio
87
88#endif
std::unique_ptr< Impl > impl
AudioEngine(const AudioEngine &)=delete
AudioEngine & operator=(const AudioEngine &)=delete
std::vector< float > spectrum() const
static constexpr std::uint32_t spectrum_bin_count()
AudioRecording stop_recording()
static constexpr std::size_t FFT_SIZE
void process_samples(const float *samples, unsigned int frame_count, unsigned int channels, unsigned int sample_rate)
unsigned int sample_rate() const
AudioMetrics metrics() const
bool open(const AudioStreamConfig &config)
void set_sensitivity(float sensitivity)
bool write_wav_file(const AudioRecording &recording, const std::string &filename)
std::vector< float > samples