载入中...
搜索中...
未找到
Source.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <AL/al.h>
6#include <AL/alc.h>
7
8#include <atomic>
9#include <mutex>
10#include <queue>
11#include <string>
12#include <vector>
13
14#include "AudioTypes.h"
15
16namespace eve {
17namespace sound {
18class SoundData;
19class Decoder;
20} // namespace sound
21namespace audio {
22
23class Audio;
24
31public:
35 Source(Audio *audio, sound::Decoder *decoder, bool streaming, bool takeDecoderOwnership = false);
37 ~Source();
38
40 void play();
42 void pause();
44 void stop();
46 bool isPlaying() const;
47
49 void setVolume(float v);
51 float getVolume() const;
53 void setPitch(float p);
55 float getPitch() const;
57 void setLooping(bool l);
59 bool isLooping() const;
60
62 bool seek(double seconds);
64 double tell() const;
66 double getDuration() const;
67
69 void setPosition(float x, float y, float z);
71 void setVelocity(float x, float y, float z);
73 void setDirection(float x, float y, float z);
75 void setRelative(bool relative);
77 void setAttenuationDistances(float ref, float max);
78
80 bool isStreaming() const { return streaming; }
82 void pump();
83
89 void fillPendingFromDecoder();
90
91private:
92 friend class Audio;
93
94 void applyGainPitch();
95 ALenum alFormat() const;
96 void ensureStaticBuffer();
97 int decoderSampleRateOr(int fallback) const;
98
99 Audio *audio = nullptr;
100 sound::SoundData *staticData = nullptr;
101 sound::Decoder *decoder = nullptr;
102 bool ownsDecoder = false;
103 bool streaming = false;
104
105 ALuint alSource = 0;
106 ALuint alBuffer = 0;
107 ALuint streamBuffers[kStreamBufferCount]{};
108 int streamBufferCount = 0;
109
110 float volume = 1.f;
111 float pitch = 1.f;
112 bool looping = false;
113
114 // Guards all access to `decoder` (including its lifetime): the Audio worker
115 // thread reads/decodes via fillPendingFromDecoder() while other threads may
116 // seek/stop/destroy the Source (and delete its Decoder) concurrently.
117 mutable std::mutex decoderMutex;
118
119 std::mutex pendingMutex;
120 std::queue<PcmChunk> pending;
121 std::atomic<bool> playing{false};
122 std::atomic<bool> wantsData{false};
123};
124
125} // namespace audio
126} // namespace eve
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
Vec3 relative
Definition AnimSmr.cpp:164
OwnedAudio audio
double volume
std::vector< QuestEvent > pending
glm::vec4 p[6]
#define EVENGINE_API_BACKENDS
Definition Export.h:108
float v
OpenAL audio module: device management, master listener state, and Source factory....
Definition Audio.h:29
A playable audio source (static buffer or streaming decoder). Not thread-safe for playback control ex...
Definition Source.h:30
bool isStreaming() const
True when streaming.
Definition Source.h:80
Streaming audio decoder (medialoader-backed). Owns the raw encoded bytes and decodes incrementally vi...
Definition Decoder.h:22
Raw PCM audio buffer with format metadata (samples/rate/bit depth/channels).
Definition SoundData.h:15
constexpr int kStreamBufferCount
流式 Source 的 OpenAL 缓冲数量。
Definition AudioTypes.h:11
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16