载入中...
搜索中...
未找到
Audio.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Data.h"
6#include "common/Module.h"
7#include "common/Result.h"
8
9#include <AL/alc.h>
10
11#include <atomic>
12#include <condition_variable>
13#include <memory>
14#include <mutex>
15#include <thread>
16#include <vector>
17
18namespace eve {
19namespace sound {
20class SoundData;
21class Decoder;
22} // namespace sound
23namespace audio {
24
25class Source;
26class AudioCapabilities;
27class PcmStream;
28struct PcmStreamState;
29
35public:
37
39 Audio();
41 ~Audio() override;
42
47 Source *newSource(sound::SoundData *data);
49 Source *newSourceFromDecoder(sound::Decoder *decoder, std::string type);
51 Source *newSourceFromData(Data *data, std::string type);
52
64 [[nodiscard]] Result<std::unique_ptr<PcmStream>> newPcmStream(int sampleRate, int channels);
65
67 void play(Source *s);
69 void stop(Source *s);
71 void stopAll();
73 [[nodiscard]] int getSourceCount();
75 void pause(Source *s);
76
78 void setVolume(float v);
80 float getVolume() const;
81
83 void setPosition(float x, float y, float z);
85 void setVelocity(float x, float y, float z);
87 void setOrientation(float fx, float fy, float fz, float ux, float uy, float uz);
88
90 void pump();
91
93 void registerStream(Source *s);
95 void unregisterStream(Source *s);
97 void unregisterSource(Source *s);
99 void notifyWorker();
100
101private:
102 void workerMain();
103 std::unique_ptr<AudioCapabilities> capabilities_;
104
105 ALCdevice *device = nullptr;
106 ALCcontext *context = nullptr;
107 float masterVolume = 1.f;
108
109 std::mutex mutex;
110 std::condition_variable cv;
111 std::atomic<bool> running{true};
112 std::thread worker;
113 std::vector<Source *> streamSources;
114 std::vector<Source *> allSources;
115 std::vector<std::weak_ptr<PcmStreamState>> pcmStreams;
116};
117
118} // namespace audio
119} // namespace eve
double z
double y
double x
std::map< std::string, std::vector< Key >, std::less<> > channels
Audio * audio
const std::string & s
std::mutex mutex
#define EVENGINE_API_BACKENDS
Definition Export.h:108
vkb::Device & device
float v
Move-only, checked operation results for the common layer.
const VegetationPresetContext & context
Data public API.
Definition Data.h:8
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Move-only operation result carrying either a value or Status.
Definition Result.h:176
OpenAL audio module: device management, master listener state, and Source factory....
Definition Audio.h:34
A playable audio source (static buffer or streaming decoder). Not thread-safe for playback control ex...
Definition Source.h:30
Streaming audio decoder (medialoader-backed). Native builds own encoded bytes and decode incrementall...
Definition Decoder.h:23
Raw PCM audio buffer with format metadata (samples/rate/bit depth/channels).
Definition SoundData.h:15
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16