forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoboe_bridge.h
More file actions
62 lines (51 loc) · 1.98 KB
/
Copy pathoboe_bridge.h
File metadata and controls
62 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#pragma once
#include <oboe/Oboe.h>
#include <oboe/LatencyTuner.h>
#include <oboe/StabilizedCallback.h>
#include <atomic>
#include <mutex>
#include <functional>
#include <memory>
/// Callback function type for providing PCM audio data to the Oboe stream.
/// Returns the number of frames actually written to the buffer.
typedef int32_t (*OboeAudioProvider)(void* audioData, int32_t numFrames);
/// Low-latency audio bridge using Google's Oboe library.
class OboeBridge : public oboe::AudioStreamCallback {
public:
OboeBridge();
~OboeBridge();
bool open(int32_t sampleRate = 0);
bool start();
void stop();
double getOutputLatencyMs() const;
bool isActive() const;
int32_t getSampleRate() const;
int32_t getFramesPerBurst() const;
int32_t getBufferSizeInFrames() const;
bool isAAudio() const;
bool isMMap() const;
void setProvider(OboeAudioProvider provider);
const char* getLastError() const;
// oboe::AudioStreamCallback
oboe::DataCallbackResult onAudioReady(
oboe::AudioStream* stream, void* audioData, int32_t numFrames) override;
void onErrorBeforeClose(oboe::AudioStream* stream, oboe::Result error) override;
void onErrorAfterClose(oboe::AudioStream* stream, oboe::Result error) override;
private:
std::shared_ptr<oboe::AudioStream> stream_;
std::shared_ptr<oboe::StabilizedCallback> stabilizedCallback_;
std::unique_ptr<oboe::LatencyTuner> tuner_;
mutable std::mutex streamLock_;
std::atomic<bool> active_{false};
std::atomic<double> latencyMs_{-1.0};
std::atomic<uint32_t> callbackCount_{0};
std::atomic<OboeAudioProvider> provider_{nullptr};
std::atomic<bool> affinitySet_{false};
int32_t requestedSampleRate_{0};
std::string lastError_;
mutable std::mutex errorLock_;
void updateLatency();
bool reopenAndRestart();
};