Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Audio/AudioBackend.h
3187 views
1
#pragma once
2
3
#include <string>
4
#include <string_view>
5
#include <vector>
6
7
// For absolute minimal latency, we do not use std::function.
8
// We always request mixing to 2 channels, then if needed we can expand here.
9
typedef void (*RenderCallback)(float *dest, int framesToWrite, int sampleRateHz, void *userdata);
10
11
enum class LatencyMode {
12
Safe,
13
Aggressive
14
};
15
16
struct AudioDeviceDesc {
17
std::string name; // User-friendly name
18
std::string uniqueId; // store-able ID for settings.
19
};
20
21
inline float FramesToMs(int frames, int sampleRate) {
22
return 1000.0f * (float)frames / (float)sampleRate;
23
}
24
25
class AudioBackend {
26
public:
27
virtual ~AudioBackend() {}
28
virtual void EnumerateDevices(std::vector<AudioDeviceDesc> *outputDevices, bool captureDevices = false) = 0;
29
virtual void SetRenderCallback(RenderCallback callback, void *userdata) = 0;
30
virtual bool InitOutputDevice(std::string_view uniqueId, LatencyMode latencyMode, bool *revertedToDefault) = 0;
31
virtual int SampleRate() const = 0;
32
virtual int BufferSize() const = 0;
33
virtual int PeriodFrames() const = 0;
34
virtual void DescribeOutputFormat(char *buffer, size_t bufferSize) const { buffer[0] = '-'; buffer[1] = '\0'; }
35
virtual void FrameUpdate(bool allowAutoChange) {}
36
};
37
38