载入中...
搜索中...
未找到
Audio.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Module.h"
4#include "common/Data.h"
5
6#include <AL/alc.h>
7
8#include <atomic>
9#include <condition_variable>
10#include <mutex>
11#include <thread>
12#include <vector>
13
14namespace eve {
15namespace sound {
16class SoundData;
17class Decoder;
18} // namespace sound
19namespace audio {
20
21class Source;
22
27class Audio : public Module {
28public:
30
31 Audio();
32 ~Audio() override;
33
40 Source *newSourceFromDecoder(sound::Decoder *decoder, std::string type);
42 Source *newSourceFromData(Data *data, std::string type);
43
45 void play(Source *s);
47 void stop(Source *s);
49 void stopAll();
51 void pause(Source *s);
52
54 void setVolume(float v);
55 float getVolume() const;
56
58 void setPosition(float x, float y, float z);
60 void setVelocity(float x, float y, float z);
62 void setOrientation(float fx, float fy, float fz, float ux, float uy, float uz);
63
65 void pump();
66
68 void registerStream(Source *s);
74 void notifyWorker();
75
76private:
77 void workerMain();
78
79 ALCdevice *device = nullptr;
80 ALCcontext *context = nullptr;
81 float masterVolume = 1.f;
82
83 std::mutex mutex;
84 std::condition_variable cv;
85 std::atomic<bool> running{true};
86 std::thread worker;
87 std::vector<Source *> streamSources;
88 std::vector<Source *> allSources;
89};
90
91} // namespace audio
92} // namespace eve
std::string type
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int v
uint32_t s
Definition Weather.cpp:28
OpenAL audio module: device management, master listener state, and Source factory....
Definition Audio.h:27
void pause(Source *s)
Pauses a source (no-op when s is null).
Definition Audio.cpp:148
Source * newSourceFromDecoder(sound::Decoder *decoder, std::string type)
Creates a Source from a decoder; type must be "static" or "stream".
Definition Audio.cpp:103
float getVolume() const
Definition Audio.cpp:167
void unregisterSource(Source *s)
Internal: removes a source from all module tracking.
Definition Audio.cpp:84
void setVolume(float v)
Sets master volume (clamped to >= 0) applied to the OpenAL listener.
Definition Audio.cpp:163
void stop(Source *s)
Stops playback of a source (no-op when s is null).
Definition Audio.cpp:144
void setVelocity(float x, float y, float z)
Sets the listener velocity (used by OpenAL doppler).
Definition Audio.cpp:170
void stopAll()
Stops every live source registered with this module.
Definition Audio.cpp:152
void setPosition(float x, float y, float z)
Sets the listener position in world units.
Definition Audio.cpp:169
Source * newSourceFromData(Data *data, std::string type)
Creates a Source from raw encoded data; type must be "static" or "stream".
Definition Audio.cpp:125
Source * newSource(sound::SoundData *data)
Creates a static (non-streaming) Source from decoded sound data.
Definition Audio.cpp:96
void play(Source *s)
Starts playback of a source (no-op when s is null).
Definition Audio.cpp:140
~Audio() override
Definition Audio.cpp:35
void registerStream(Source *s)
Internal: registers a streaming source with the decode worker.
Definition Audio.cpp:79
void unregisterStream(Source *s)
Internal: removes a source from worker tracking.
Definition Audio.cpp:90
void setOrientation(float fx, float fy, float fz, float ux, float uy, float uz)
Sets the listener forward and up orientation vectors.
Definition Audio.cpp:171
void pump()
Advances streaming sources; call once per frame from the main thread.
Definition Audio.cpp:176
void notifyWorker()
Internal: wakes the decode worker thread.
Definition Audio.cpp:94
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). Owns the raw encoded bytes and decodes incrementally vi...
Definition Decoder.h:20
Raw PCM audio buffer with format metadata (samples/rate/bit depth/channels).
Definition SoundData.h:13
Definition Build.cpp:11