载入中...
搜索中...
未找到
Source.cpp
浏览该文件的文档.
1#include "Source.h"
2#include "Audio.h"
3
4#include "common/Exception.h"
5#include "sound/Decoder.h"
6#include "sound/SoundData.h"
7
8#include <algorithm>
9#include <cmath>
10#include <cstring>
11
12#ifndef AL_STEREO_ANGLES
13#define AL_STEREO_ANGLES 0x1030
14#endif
15#ifndef AL_SOURCE_SPATIALIZE_SOFT
16#define AL_SOURCE_SPATIALIZE_SOFT 0x1214
17#endif
18
19namespace eve {
20namespace audio {
21
22namespace {
23constexpr size_t kMaxPendingChunks = 8;
24
25bool hasAlExtension(const char* name) { return name && alIsExtensionPresent(name) == AL_TRUE; }
26
27Diagnostic invalidAudioArg(const char* message, const char* path = "audio.source") {
29}
30} // namespace
31
32Source::Source(Audio* audio, sound::SoundData* data) : audio(audio), staticData(data), streaming(false) {
33 if (!audio || !data) throw eve::Exception("Invalid Source arguments");
34 alGenSources(1, &alSource);
35 ensureStaticBuffer();
36 applyGainPitch();
37 alSourcei(alSource, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
38}
39
40Source::Source(Audio *audio, sound::Decoder *decoder, bool streaming, bool takeDecoderOwnership)
41 : audio(audio), decoder(decoder), ownsDecoder(takeDecoderOwnership), streaming(streaming) {
42 if (!audio || !decoder) throw eve::Exception("Invalid Source arguments");
43 alGenSources(1, &alSource);
44 if (streaming) {
45 streamBufferCount = kStreamBufferCount;
46 alGenBuffers(streamBufferCount, streamBuffers);
47 wantsData = true;
48 audio->registerStream(this);
49 audio->notifyWorker();
50 } else {
51 // Decode fully to static buffer via temporary SoundData path in Audio factory.
52 throw eve::Exception("Non-stream Decoder Source should be created via SoundData");
53 }
54 applyGainPitch();
55}
56
58 stop();
59 if (audio) {
60 // Static sources are tracked in allSources but never registered as streams;
61 // always detach so stopAll cannot touch a deleted Source.
62 audio->unregisterSource(this);
63 audio = nullptr;
64 }
65 if (alSource) {
66 alSourcei(alSource, AL_BUFFER, 0);
67 alDeleteSources(1, &alSource);
68 alSource = 0;
69 }
70 if (alBuffer) {
71 alDeleteBuffers(1, &alBuffer);
72 alBuffer = 0;
73 }
74 if (streamBufferCount > 0) {
75 alDeleteBuffers(streamBufferCount, streamBuffers);
76 streamBufferCount = 0;
77 }
78 {
79 // Audio::workerMain()/pump()/stopAll() hold Audio::mutex across the whole
80 // dispatch loop, and unregisterSource() above took that same mutex, so no
81 // in-flight fillPendingFromDecoder() can still reference this Source. The
82 // decoderMutex lock below remains as defense in depth before freeing the
83 // decoder (and the mutexes themselves are destroyed only after this body).
84 std::lock_guard<std::mutex> lock(decoderMutex);
85 if (ownsDecoder) {
86 delete decoder;
87 decoder = nullptr;
88 }
89 }
90}
91
92ALenum Source::alFormat() const {
93 int ch = 0, bits = 0;
94 if (staticData) {
95 ch = staticData->getChannelCount();
96 bits = staticData->getBitDepth();
97 } else {
98 std::lock_guard<std::mutex> lock(decoderMutex);
99 if (decoder) {
100 ch = decoder->getChannelCount();
101 bits = decoder->getBitDepth();
102 }
103 }
104 if (ch == 1 && bits == 8) return AL_FORMAT_MONO8;
105 if (ch == 1 && bits == 16) return AL_FORMAT_MONO16;
106 if (ch == 2 && bits == 8) return AL_FORMAT_STEREO8;
107 if (ch == 2 && bits == 16) return AL_FORMAT_STEREO16;
108 throw eve::Exception("Unsupported PCM format for OpenAL");
109}
110
111int Source::decoderSampleRateOr(int fallback) const {
112 std::lock_guard<std::mutex> lock(decoderMutex);
113 return decoder ? decoder->getSampleRate() : fallback;
114}
115
117 if (staticData) return staticData->getChannelCount();
118 std::lock_guard<std::mutex> lock(decoderMutex);
119 return decoder ? decoder->getChannelCount() : 0;
120}
121
122void Source::ensureStaticBuffer() {
123 if (alBuffer || !staticData) return;
124 alGenBuffers(1, &alBuffer);
125 alBufferData(alBuffer, alFormat(), staticData->getData(), static_cast<ALsizei>(staticData->getSize()),
126 staticData->getSampleRate());
127 alSourcei(alSource, AL_BUFFER, static_cast<ALint>(alBuffer));
128}
129
130float Source::currentAudibleVolume() const noexcept { return fading_ ? audibleVolume_ : volume; }
131
132void Source::applyGainPitch() {
133 float master = audio ? audio->getVolume() : 1.f;
134 const float audible = fading_ ? audibleVolume_ : volume;
135 alSourcef(alSource, AL_GAIN, audible * master * (fading_ ? 1.f : fadeWeight_));
136 alSourcef(alSource, AL_PITCH, pitch);
137}
138
139void Source::applyRolloff() {
140 if (alSource) alSourcef(alSource, AL_ROLLOFF_FACTOR, rolloffFactor_);
141}
142
143void Source::applyBalanceToAl() {
144 if (!alSource) return;
145 if (balanceUsesStereoAngles_) {
146 // OpenAL Soft: angles are radians from forward; +/- (pi/2)*(1-|balance|) style pan.
147 const float halfPi = 1.57079632679f;
148 const float left = -halfPi + balance_ * halfPi;
149 const float right = halfPi + balance_ * halfPi;
150 const float angles[2] = {left, right};
151 alSourcefv(alSource, AL_STEREO_ANGLES, angles);
152 return;
153 }
154 if (balanceUsesMonoPosition_) {
155 alSource3f(alSource, AL_POSITION, balance_, positionY_, positionZ_);
156 return;
157 }
158 alSource3f(alSource, AL_POSITION, positionX_, positionY_, positionZ_);
159}
160
162 if (streaming) {
163 playing = true;
164 wantsData = true;
165 if (audio) audio->notifyWorker();
166 alSourcePlay(alSource);
167 return;
168 }
169 ensureStaticBuffer();
170 applyGainPitch();
171 alSourcePlay(alSource);
172 playing = true;
173}
174
176 alSourcePause(alSource);
177 playing = false;
178}
179
181 if (!alSource) return;
182 alSourceStop(alSource);
183 playing = false;
184 if (streaming) {
185 // Unqueue all
186 ALint processed = 0;
187 alGetSourcei(alSource, AL_BUFFERS_PROCESSED, &processed);
188 while (processed-- > 0) {
189 ALuint b = 0;
190 alSourceUnqueueBuffers(alSource, 1, &b);
191 }
192 ALint queued = 0;
193 alGetSourcei(alSource, AL_BUFFERS_QUEUED, &queued);
194 while (queued-- > 0) {
195 ALuint b = 0;
196 alSourceUnqueueBuffers(alSource, 1, &b);
197 }
198 {
199 std::lock_guard<std::mutex> lock(pendingMutex);
200 while (!pending.empty()) pending.pop();
201 }
202 {
203 std::lock_guard<std::mutex> lock(decoderMutex);
204 if (decoder) decoder->rewind();
205 }
206 wantsData = true;
207 } else {
208 alSourceRewind(alSource);
209 }
210}
211
212bool Source::isPlaying() const {
213 ALint state = 0;
214 alGetSourcei(alSource, AL_SOURCE_STATE, &state);
215 return state == AL_PLAYING;
216}
217
218void Source::setVolume(float v) {
219 volume = std::max(0.f, v);
220 if (!fading_) {
221 audibleVolume_ = volume;
222 applyGainPitch();
223 }
224}
225float Source::getVolume() const { return currentAudibleVolume(); }
226
227void Source::setPitch(float p) {
228 pitch = std::max(0.001f, p);
229 applyGainPitch();
230}
231float Source::getPitch() const { return pitch; }
232
233void Source::setLooping(bool l) {
234 looping = l;
235 if (!streaming) alSourcei(alSource, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
236}
237bool Source::isLooping() const { return looping; }
238
239bool Source::seek(double seconds) {
240 if (streaming) {
241 {
242 std::lock_guard<std::mutex> lock(decoderMutex);
243 if (!decoder || !decoder->isSeekable()) return false;
244 }
245 // stop() takes decoderMutex itself (for rewind), so it must not be held here.
246 stop();
247 {
248 std::lock_guard<std::mutex> lock(decoderMutex);
249 if (!decoder || !decoder->seek(seconds)) return false;
250 }
251 wantsData = true;
252 if (audio) audio->notifyWorker();
253 return true;
254 }
255 alSourcef(alSource, AL_SEC_OFFSET, static_cast<ALfloat>(seconds));
256 return true;
257}
258
259double Source::tell() const {
260 ALfloat sec = 0.f;
261 alGetSourcef(alSource, AL_SEC_OFFSET, &sec);
262 return static_cast<double>(sec);
263}
264
265double Source::getDuration() const {
266 if (staticData) return staticData->getDuration();
267 std::lock_guard<std::mutex> lock(decoderMutex);
268 if (decoder) return decoder->getDuration();
269 return -1.0;
270}
271
272void Source::setPosition(float x, float y, float z) {
273 positionX_ = x;
274 positionY_ = y;
275 positionZ_ = z;
276 if (balanceUsesMonoPosition_) {
277 alSource3f(alSource, AL_POSITION, balance_, positionY_, positionZ_);
278 return;
279 }
280 alSource3f(alSource, AL_POSITION, x, y, z);
281}
282void Source::setVelocity(float x, float y, float z) { alSource3f(alSource, AL_VELOCITY, x, y, z); }
283void Source::setDirection(float x, float y, float z) { alSource3f(alSource, AL_DIRECTION, x, y, z); }
285 relative_ = relative;
286 alSourcei(alSource, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
287}
288void Source::setAttenuationDistances(float ref, float max) {
289 alSourcef(alSource, AL_REFERENCE_DISTANCE, ref);
290 alSourcef(alSource, AL_MAX_DISTANCE, max);
291 applyRolloff();
292}
293
295 if (!std::isfinite(factor) || factor < 0.f)
296 return Result<void>::failure(invalidAudioArg("rolloff factor must be finite and >= 0", "rolloff"));
297 rolloffFactor_ = factor;
298 applyRolloff();
299 return Result<void>::success();
300}
301
303 if (!std::isfinite(blend) || blend < 0.f || blend > 1.f)
304 return Result<void>::failure(invalidAudioArg("spatial blend must be finite and in [0,1]", "spatialBlend"));
305 const int channels = getChannelCount();
306 const bool softSpatialize = hasAlExtension("AL_SOFT_source_spatialize");
307 if (channels == 2 && blend > 0.f && !softSpatialize)
309 invalidAudioArg("stereo spatialBlend>0 requires AL_SOFT_source_spatialize; use mono or configureAmbientBed",
310 "spatialBlend"));
311 if (softSpatialize && alSource) alSourcei(alSource, AL_SOURCE_SPATIALIZE_SOFT, blend > 0.f ? AL_TRUE : AL_FALSE);
312
313 spatialBlend_ = blend;
314 if (blend <= 0.f) {
315 setRelative(true);
316 rolloffFactor_ = 0.f;
317 } else {
318 setRelative(false);
319 rolloffFactor_ = blend;
320 }
321 applyRolloff();
322 return Result<void>::success();
323}
324
326 if (!std::isfinite(balance) || balance < -1.f || balance > 1.f)
327 return Result<void>::failure(invalidAudioArg("balance must be finite and in [-1,1]", "balance"));
328 const int channels = getChannelCount();
329 const bool stereoAngles = hasAlExtension("AL_EXT_STEREO_ANGLES");
330 balanceUsesStereoAngles_ = false;
331 balanceUsesMonoPosition_ = false;
332 if (stereoAngles && channels == 2) {
333 balance_ = balance;
334 balanceUsesStereoAngles_ = true;
335 applyBalanceToAl();
336 return Result<void>::success();
337 }
338 if (relative_ && channels == 1) {
339 balance_ = balance;
340 balanceUsesMonoPosition_ = true;
341 applyBalanceToAl();
342 return Result<void>::success();
343 }
344 if (channels == 2)
345 return Result<void>::failure(invalidAudioArg("stereo balance requires AL_EXT_STEREO_ANGLES", "balance"));
346 if (!relative_)
348 invalidAudioArg("mono balance without stereo angles requires a relative source", "balance"));
349 return Result<void>::failure(invalidAudioArg("balance is unsupported for this source format", "balance"));
350}
351
352Result<void> Source::beginFade(float targetVolume, float durationSeconds, float now, bool stopWhenSilent) {
353 if (!std::isfinite(targetVolume) || targetVolume < 0.f || !std::isfinite(durationSeconds) ||
354 durationSeconds < 0.f || !std::isfinite(now))
356 invalidAudioArg("fade requires finite now, non-negative duration and volume", "fade"));
357 if (durationSeconds == 0.f) {
358 fading_ = false;
359 stopWhenSilent_ = false;
360 fadeWeight_ = 1.f;
361 volume = targetVolume;
362 audibleVolume_ = targetVolume;
363 applyGainPitch();
364 if (stopWhenSilent && targetVolume == 0.f) stop();
365 return Result<void>::success();
366 }
367 fadeFrom_ = currentAudibleVolume();
368 fadeToVolume_ = targetVolume;
369 fadeStart_ = now;
370 fadeEnd_ = now + durationSeconds;
371 fadeWeight_ = 0.f;
372 fading_ = true;
373 stopWhenSilent_ = stopWhenSilent;
374 audibleVolume_ = fadeFrom_;
375 applyGainPitch();
376 return Result<void>::success();
377}
378
379Result<void> Source::fadeTo(float targetVolume, float durationSeconds, float now) {
380 return beginFade(targetVolume, durationSeconds, now, false);
381}
382
383Result<void> Source::fadeOutAndStop(float durationSeconds, float now) {
384 return beginFade(0.f, durationSeconds, now, true);
385}
386
388 if (!fading_) return Result<void>::success();
389 volume = audibleVolume_;
390 fading_ = false;
391 stopWhenSilent_ = false;
392 fadeWeight_ = 1.f;
393 applyGainPitch();
394 return Result<void>::success();
395}
396
398 if (!std::isfinite(now)) return Result<void>::failure(invalidAudioArg("advanceFade requires finite now", "fade"));
399 if (!fading_) return Result<void>::success();
400 if (now <= fadeStart_) {
401 fadeWeight_ = 0.f;
402 audibleVolume_ = fadeFrom_;
403 applyGainPitch();
404 return Result<void>::success();
405 }
406 if (now >= fadeEnd_ || fadeEnd_ <= fadeStart_) {
407 volume = fadeToVolume_;
408 audibleVolume_ = fadeToVolume_;
409 fadeWeight_ = 1.f;
410 fading_ = false;
411 const bool shouldStop = stopWhenSilent_ && fadeToVolume_ == 0.f;
412 stopWhenSilent_ = false;
413 applyGainPitch();
414 if (shouldStop) stop();
415 return Result<void>::success();
416 }
417 const float progress = (now - fadeStart_) / (fadeEnd_ - fadeStart_);
418 fadeWeight_ = progress;
419 audibleVolume_ = fadeFrom_ + (fadeToVolume_ - fadeFrom_) * progress;
420 applyGainPitch();
421 return Result<void>::success();
422}
423
425 if (!streaming || !wantsData.load()) return;
426 {
427 std::lock_guard<std::mutex> lock(pendingMutex);
428 if (pending.size() >= kMaxPendingChunks) return;
429 }
430
431 // Guard the whole decode step: `decoder` may be deleted concurrently by
432 // Source::~Source() running on another thread (e.g. main/script thread
433 // destroying this Source while the Audio worker is mid-decode here).
434 PcmChunk chunk;
435 {
436 std::lock_guard<std::mutex> decoderLock(decoderMutex);
437 if (!decoder) return;
438 int n = decoder->decode();
439 if (n <= 0) {
440 if (looping && decoder->rewind()) {
441 n = decoder->decode();
442 } else {
443 wantsData = false;
444 return;
445 }
446 }
447 if (n <= 0) return;
448 auto *buf = static_cast<const uint8_t *>(decoder->getBuffer());
449 chunk.bytes.assign(buf, buf + n);
450 }
451
452 std::lock_guard<std::mutex> lock(pendingMutex);
453 pending.push(std::move(chunk));
454}
455
457 if (!streaming || !alSource) return;
458
459 ALint processed = 0;
460 alGetSourcei(alSource, AL_BUFFERS_PROCESSED, &processed);
461 while (processed-- > 0) {
462 ALuint b = 0;
463 alSourceUnqueueBuffers(alSource, 1, &b);
464 PcmChunk chunk;
465 {
466 std::lock_guard<std::mutex> lock(pendingMutex);
467 if (pending.empty()) {
468 // Recycle empty: leave buffer unused until data arrives
469 // Re-queue nothing; keep buffer id available by... we need free list.
470 // Simpler: if no pending, push buffer id back by queuing silence? Skip.
471 // Keep a free list via re-queue of zero later - for now re-store by
472 // temporarily using pending empty and regenerating: actually alGen keeps
473 // buffer; we must not lose buffer id. Queue a tiny silence.
474 std::vector<uint8_t> silence(256, 0);
475 alBufferData(b, alFormat(), silence.data(), static_cast<ALsizei>(silence.size()),
476 decoderSampleRateOr(44100));
477 alSourceQueueBuffers(alSource, 1, &b);
478 continue;
479 }
480 chunk = std::move(pending.front());
481 pending.pop();
482 }
483 alBufferData(b, alFormat(), chunk.bytes.data(), static_cast<ALsizei>(chunk.bytes.size()),
484 decoderSampleRateOr(44100));
485 alSourceQueueBuffers(alSource, 1, &b);
486 }
487
488 // Initial fill: queue unused buffers
489 ALint queued = 0;
490 alGetSourcei(alSource, AL_BUFFERS_QUEUED, &queued);
491 for (int i = queued; i < streamBufferCount; ++i) {
492 PcmChunk chunk;
493 {
494 std::lock_guard<std::mutex> lock(pendingMutex);
495 if (pending.empty()) break;
496 chunk = std::move(pending.front());
497 pending.pop();
498 }
499 // Find a buffer not currently queued — for initial, buffers 0..n unused
500 // Use streamBuffers[queued] style
501 ALuint buf = streamBuffers[queued];
502 alBufferData(buf, alFormat(), chunk.bytes.data(), static_cast<ALsizei>(chunk.bytes.size()),
503 decoderSampleRateOr(44100));
504 alSourceQueueBuffers(alSource, 1, &buf);
505 alGetSourcei(alSource, AL_BUFFERS_QUEUED, &queued);
506 }
507
508 if (playing && !isPlaying()) {
509 ALint q = 0;
510 alGetSourcei(alSource, AL_BUFFERS_QUEUED, &q);
511 if (q > 0) alSourcePlay(alSource);
512 }
513
514 wantsData = true;
515 if (audio) audio->notifyWorker();
516}
517
518} // namespace audio
519} // namespace eve
double z
double y
double x
std::map< std::string, std::vector< Key >, std::less<> > channels
Vec3 relative
Definition AnimSmr.cpp:164
Audio * audio
glm::vec4 p[6]
std::string name
Definition ECS.cpp:154
std::vector< double > angles
std::string message
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
float v
HexVec3 left
HexVec3 right
float blend
MeleePoint3 b
Definition MeleeHit.cpp:41
size_t queued
Definition OnnxGpgpu.cpp:60
std::string path
Definition PlayHost.cpp:111
#define AL_SOURCE_SPATIALIZE_SOFT
Definition Source.cpp:16
#define AL_STEREO_ANGLES
Definition Source.cpp:13
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
OpenAL audio module: device management, master listener state, and Source factory....
Definition Audio.h:34
float getVolume() const
Returns the volume.
Definition Audio.cpp:192
void unregisterSource(Source *s)
Internal: removes a source from all module tracking.
Definition Audio.cpp:102
void notifyWorker()
Internal: wakes the decode worker thread.
Definition Audio.cpp:110
void fillPendingFromDecoder()
Called by the Audio worker thread. Internally synchronized against concurrent decoder teardown (see d...
Definition Source.cpp:424
void play()
Starts (or resumes) playback.
Definition Source.cpp:161
void pause()
Pauses playback, keeping the play position.
Definition Source.cpp:175
Result< void > cancelFade()
Abort an active fade, keeping the current audible volume.
Definition Source.cpp:387
void setVolume(float v)
Sets source gain (clamped to >= 0). Does not cancel an active fade target.
Definition Source.cpp:218
int getChannelCount() const
Channel count of the bound buffer/decoder (1 or 2), or 0 when unknown.
Definition Source.cpp:116
float getVolume() const
Returns the audible user volume after the last advanceFade (or committed volume).
Definition Source.cpp:225
Result< void > fadeOutAndStop(float durationSeconds, float now)
Fade audible volume to zero then stop when the ramp completes.
Definition Source.cpp:383
void setVelocity(float x, float y, float z)
Sets the source velocity (used by OpenAL doppler).
Definition Source.cpp:282
bool isPlaying() const
True when playing.
Definition Source.cpp:212
Result< void > setBalance(float balance)
Stereo/ambient balance in [-1,1] (left..right).
Definition Source.cpp:325
float getPitch() const
Returns the pitch.
Definition Source.cpp:231
void setRelative(bool relative)
Makes the source ignore the listener position (head-relative).
Definition Source.cpp:284
void setPosition(float x, float y, float z)
Sets the source position in world units.
Definition Source.cpp:272
void stop()
Stops playback and rewinds the play position.
Definition Source.cpp:180
Result< void > fadeTo(float targetVolume, float durationSeconds, float now)
Ramp audible volume toward targetVolume using injected simulation time.
Definition Source.cpp:379
Result< void > setRolloffFactor(float factor)
Sets OpenAL rolloff factor (clamped to >= 0).
Definition Source.cpp:294
double getDuration() const
Total duration in seconds (0 for live/unbounded streams).
Definition Source.cpp:265
Result< void > setSpatialBlend(float blend)
Continuous 2D/3D mix: 0 = ambient bed (relative, no rolloff), 1 = full world.
Definition Source.cpp:302
Result< void > advanceFade(float now)
Advance an active fade envelope to absolute simulation time now.
Definition Source.cpp:397
double tell() const
Current play time in seconds.
Definition Source.cpp:259
void setAttenuationDistances(float ref, float max)
Sets OpenAL reference and maximum attenuation distances.
Definition Source.cpp:288
~Source()
Source.
Definition Source.cpp:57
bool seek(double seconds)
Seeks to a time in seconds; false when seeking is unsupported.
Definition Source.cpp:239
Source(Audio *audio, sound::SoundData *data)
Creates a static source from decoded audio (both arguments required).
Definition Source.cpp:32
void setLooping(bool l)
Enables/disables looping.
Definition Source.cpp:233
void setDirection(float x, float y, float z)
Sets the source directional cone orientation.
Definition Source.cpp:283
bool isLooping() const
True when looping.
Definition Source.cpp:237
void pump()
Main thread: queues/unqueues AL buffers for a streaming source.
Definition Source.cpp:456
void setPitch(float p)
Sets playback pitch (clamped to >= 0).
Definition Source.cpp:227
Streaming audio decoder (medialoader-backed). Native builds own encoded bytes and decode incrementall...
Definition Decoder.h:23
void * getBuffer() const
Internal decoded buffer.
Definition Decoder.cpp:82
double getDuration()
Total duration in seconds.
Definition Decoder.cpp:90
int getSampleRate() const
Returns the sample rate.
Definition Decoder.cpp:89
bool isSeekable()
True when seeking is supported.
Definition Decoder.cpp:85
int getChannelCount() const
Format metadata.
Definition Decoder.cpp:87
bool rewind()
Rewinds to the start; false when unsupported.
Definition Decoder.cpp:84
bool seek(double seconds)
Seeks to a time in seconds; false when unsupported.
Definition Decoder.cpp:83
int getBitDepth() const
Returns the bit depth.
Definition Decoder.cpp:88
int decode()
Decodes the next chunk; returns bytes produced (0 = end/error).
Definition Decoder.cpp:80
Raw PCM audio buffer with format metadata (samples/rate/bit depth/channels).
Definition SoundData.h:15
double getDuration() const
Duration in seconds.
Definition SoundData.cpp:40
void * getData() const
Raw PCM access.
Definition SoundData.cpp:46
int getBitDepth() const
Returns the bit depth.
Definition SoundData.cpp:37
int getChannelCount() const
Returns the channel count.
Definition SoundData.cpp:38
int getSampleRate() const
Returns the sample rate.
Definition SoundData.cpp:36
size_t getSize() const
Returns the size.
Definition SoundData.cpp:47
constexpr int kStreamBufferCount
流式 Source 的 OpenAL 缓冲数量。
Definition AudioTypes.h:11
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
解码后待排队的一帧 PCM 数据。
Definition AudioTypes.h:16
std::vector< uint8_t > bytes
Definition AudioTypes.h:17