World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
OpenALSoundProvider.cpp
См. документацию.
2 
3 #include <AL/al.h>
4 #include <AL/alc.h>
5 
6 #include <atomic>
7 #include <memory>
8 #include <queue>
9 #include <string>
10 #include <thread>
11 #include <functional>
12 
13 #include <cassert>
14 #include <cmath>
15 #include <cstdarg>
16 #include <cstddef>
17 #include <cstdio>
18 #include <cstring>
19 
20 #include "Engine/ErrorHandling.h"
21 #include "Engine/Log.h"
22 #include "Media/MediaPlayer.h"
23 
24 void log(const char *format, ...) {
25  va_list va;
26  va_start(va, format);
27  vprintf(format, va);
28  va_end(va);
29 }
30 
31 bool CheckError() {
32  ALenum code1 = alGetError();
33  if (code1 == AL_NO_ERROR) {
34  return false;
35  }
36 
37  const char *message = alGetString(code1);
38  log("al: error #%d \"%s\"\n", code1, message);
39 
40  return true;
41 }
42 
44  device = nullptr;
45  context = nullptr;
46 }
47 
49 
51  const char *device_names = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
52  if (!device_names) {
53  device_names = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
54  }
55 
56  if (device_names) {
57  for (const char *device_name = device_names; device_name[0];
58  device_name += strlen(device_name) + 1) {
59  log("al: device found \"%s\"", device_name);
60  }
61  }
62 
63  const char *defname = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
64 
65  device = alcOpenDevice(defname);
66  if (device == nullptr) {
67  CheckError();
68  log("al: Default sound device not present");
69  return false;
70  }
71 
72  context = alcCreateContext(device, nullptr);
73  if (context == nullptr) {
74  CheckError();
75  Release();
76  return false;
77  }
78 
79  if (alcMakeContextCurrent(context) != ALC_TRUE) {
80  CheckError();
81  Release();
82  return false;
83  }
84 
85  alListener3f(AL_POSITION, 0.f, 0.f, 0.f);
86  alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f);
87  ALfloat listenerOri[] = {0.f, 1.f, 0.f, 0.f, 0.f, -1.f};
88  alListenerfv(AL_ORIENTATION, listenerOri);
89 
90  return true;
91 }
92 
93 void OpenALSoundProvider::SetListenerPosition(float x, float y, float z) {
94  alListener3f(AL_POSITION, x, y, z);
95 }
96 
97 void OpenALSoundProvider::SetOrientation(float yaw, float pitch) {
98  float x = cos(pitch) * cos(yaw);
99  float y = sin(yaw) * cos(pitch);
100  float z = -sin(pitch);
101 
102  ALfloat listenerOri[] = {-x, y, z, 0.f, 0.f, 1.f};
103  alListenerfv(AL_ORIENTATION, listenerOri);
104 }
105 
107  alcMakeContextCurrent(nullptr);
108  if (context) {
110  }
111  if (device) {
113  }
114 }
115 
117  if (!buffer && !*buffer) return;
118  auto track = *buffer;
119 
120  int status;
121  alGetSourcei(track->source_id, AL_SOURCE_STATE, &status);
122  if (status == AL_PLAYING) {
123  alSourceStop(track->source_id);
124  if (CheckError()) assert(false);
125  }
126 
127  int num_processed_buffers = 0;
128  int num_queued_buffers = 0;
129  alGetSourcei(track->source_id, AL_BUFFERS_PROCESSED,
130  &num_processed_buffers);
131  alGetSourcei(track->source_id, AL_BUFFERS_QUEUED, &num_queued_buffers);
132  // int num_track_buffers = num_queued_buffers + num_processed_buffers;
133  for (int i = 0; i < num_processed_buffers; ++i) {
134  unsigned int buffer_id;
135  alSourceUnqueueBuffers(track->source_id, 1, &buffer_id);
136  if (!CheckError()) {
137  alDeleteBuffers(1, &buffer_id);
138  } else {
139  assert(false);
140  }
141  }
142 
143  alDeleteSources(1, &track->source_id);
144  CheckError();
145 
146  delete *buffer;
147  *buffer = nullptr;
148 }
149 
151  alDeleteBuffers(1, &(*buffer)->buffer_id);
152  CheckError();
153 
154  delete *buffer;
155  *buffer = nullptr;
156 }
157 
159  int size, bits, channels, freq;
160 
161  alGetBufferi(buffer, AL_SIZE, &size);
162  alGetBufferi(buffer, AL_BITS, &bits);
163  alGetBufferi(buffer, AL_CHANNELS, &channels);
164  alGetBufferi(buffer, AL_FREQUENCY, &freq);
165  if (CheckError()) {
166  return 0.f;
167  }
168 
169  return (ALfloat)((ALuint)size / channels / (bits / 8)) / (ALfloat)freq;
170 }
171 
173 OpenALSoundProvider::CreateStreamingTrack16(int num_channels, int sample_rate,
174  int bytes_per_sample) {
175  Assert(bytes_per_sample == 2,
176  "OpenALSoundProvider: unsupported sample size: %u",
177  bytes_per_sample);
178 
179  ALenum sound_format;
180  switch (num_channels) {
181  case 1:
182  sound_format = AL_FORMAT_MONO16;
183  break;
184  case 2:
185  sound_format = AL_FORMAT_STEREO16;
186  break;
187  default:
188  if (alIsExtensionPresent("AL_EXT_MCFORMATS")) {
189  switch (num_channels) {
190  case 4:
191  sound_format = alGetEnumValue("AL_FORMAT_QUAD16");
192  break;
193  case 6:
194  sound_format = alGetEnumValue("AL_FORMAT_51CHN16");
195  break;
196  case 7:
197  sound_format = alGetEnumValue("AL_FORMAT_61CHN16");
198  break;
199  case 8:
200  sound_format = alGetEnumValue("AL_FORMAT_71CHN16");
201  break;
202  }
203  }
204  Error("Unsupported number of audio channels: %u", num_channels);
205  }
206 
207  unsigned int al_source = -1;
208  alGenSources(1, &al_source);
209  if (CheckError()) {
210  return nullptr;
211  }
212 
213  alSourcei(al_source, AL_LOOPING, AL_FALSE);
214  alSourcef(al_source, AL_PITCH, 1.f);
215  alSourcef(al_source, AL_GAIN, 1.f);
216  alSource3f(al_source, AL_POSITION, 0.f, 0.f, 0.f);
217  alSource3f(al_source, AL_VELOCITY, 0.f, 0.f, 0.f);
218 
220  ret->source_id = al_source;
221  ret->sample_format = sound_format;
222  ret->sample_rate = sample_rate;
223  return ret;
224 }
225 
227  int num_samples, const void *samples,
228  bool wait) {
229  if (buffer == nullptr) {
230  return;
231  }
232 
233  int bytes_per_sample = 2;
234 
235  int num_processed_buffers = 0;
236  alGetSourcei(buffer->source_id, AL_BUFFERS_PROCESSED,
237  &num_processed_buffers);
238  if (num_processed_buffers > 0) {
239  unsigned int *processed_buffer_ids =
240  new unsigned int[num_processed_buffers];
241  alSourceUnqueueBuffers(buffer->source_id, num_processed_buffers,
242  processed_buffer_ids);
243  if (CheckError()) {
244  log("OpenAL: Faile to get played buffers.");
245  } else {
246  alDeleteBuffers(num_processed_buffers, processed_buffer_ids);
247  if (CheckError()) {
248  log("OpenAL: Faile to delete played buffers.");
249  }
250  }
251  delete[] processed_buffer_ids;
252  }
253 
254  unsigned int al_buffer;
255  alGenBuffers(1, &al_buffer);
256  alBufferData(al_buffer, buffer->sample_format, samples,
257  num_samples * bytes_per_sample, buffer->sample_rate);
258  if (CheckError()) {
259  alDeleteBuffers(1, &al_buffer);
260  return;
261  }
262 
263  alSourceQueueBuffers(buffer->source_id, 1, &al_buffer);
264  if (CheckError()) {
265  alDeleteBuffers(1, &al_buffer);
266  return;
267  }
268 
269  volatile int status;
270  alGetSourcei(buffer->source_id, AL_SOURCE_STATE, (int *)&status);
271  if (status != AL_PLAYING) {
272  alSourcePlay(buffer->source_id);
273  if (CheckError()) {
274  assert(false);
275  }
276 
277  if (wait) {
278  do {
279  alGetSourcei(buffer->source_id, AL_SOURCE_STATE,
280  (int *)&status);
281  } while (status == AL_PLAYING);
282  }
283  }
284 }
285 
287  int num_channels, int sample_rate, const void *data, size_t size) {
288  ALenum sound_format;
289  switch (num_channels) {
290  case 1: {
291  sound_format = AL_FORMAT_MONO16;
292  break;
293  }
294  case 2: {
295  sound_format = AL_FORMAT_STEREO16;
296  break;
297  }
298  default: {
299  if (alIsExtensionPresent("AL_EXT_MCFORMATS")) {
300  switch (num_channels) {
301  case 4:
302  sound_format = alGetEnumValue("AL_FORMAT_QUAD16");
303  break;
304  case 6:
305  sound_format = alGetEnumValue("AL_FORMAT_51CHN16");
306  break;
307  case 7:
308  sound_format = alGetEnumValue("AL_FORMAT_61CHN16");
309  break;
310  case 8:
311  sound_format = alGetEnumValue("AL_FORMAT_71CHN16");
312  break;
313  }
314  }
315  Error("Unsupported number of audio channels: %u", num_channels);
316  }
317  }
318 
319  ALuint al_source = -1;
320  alGenSources((ALuint)1, &al_source);
321  if (CheckError()) {
322  return nullptr;
323  }
324 
325  alSourcei(al_source, AL_LOOPING, AL_FALSE);
326  alSourcef(al_source, AL_PITCH, 1.f);
327  alSourcef(al_source, AL_GAIN, 1.f);
328  alSource3f(al_source, AL_POSITION, 0.f, 0.f, 0.f);
329  alSource3f(al_source, AL_VELOCITY, 0.f, 0.f, 0.f);
330 
331  ALuint al_buffer = -1;
332  alGenBuffers(1, &al_buffer);
333  if (CheckError()) {
334  alDeleteSources(1, &al_source);
335  return nullptr;
336  }
337 
338  alBufferData(al_buffer, sound_format, data, size, sample_rate);
339  if (CheckError()) {
340  alDeleteSources(1, &al_source);
341  alDeleteBuffers(1, &al_buffer);
342  return nullptr;
343  }
344 
345  alSourcei(al_source, AL_BUFFER, al_buffer);
346  if (CheckError()) {
347  alDeleteSources(1, &al_source);
348  alDeleteBuffers(1, &al_buffer);
349  return nullptr;
350  }
351 
352  TrackBuffer *ret = new TrackBuffer;
353  ret->source_id = al_source;
354  ret->buffer_id = al_buffer;
355  return ret;
356 }
357 
359  bool wait) {
360  int status;
361  alGetSourcei(buffer->source_id, AL_SOURCE_STATE, (int *)&status);
362  if (status == AL_PLAYING) {
363  return;
364  }
365 
366  alSourcei(buffer->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
367  alSourcePlay(buffer->source_id);
368  if (CheckError()) {
369  assert(false);
370  }
371 
372  if (wait && !loop) {
373  float track_length = alBufferLength(buffer->buffer_id);
374  do {
375  float track_offset = 0;
376  alGetSourcef(buffer->source_id, AL_SEC_OFFSET, &track_offset);
377  log("playing: %.4f/%.4f\n", track_offset, track_length);
378 
379  alGetSourcei(buffer->source_id, AL_SOURCE_STATE, (int *)&status);
380  } while (status == AL_PLAYING);
381  }
382 }
383 
384 // CallBackTimer
385 
387  public:
388  CallBackTimer() : bRunning(false) {}
389  virtual ~CallBackTimer() {
390  if (bRunning.load(std::memory_order_acquire)) {
391  Stop();
392  }
393  }
394 
395  void Start(int interval, std::function<void(void)> func) {
396  if (bRunning.load(std::memory_order_acquire)) {
397  Stop();
398  }
399  bRunning.store(true, std::memory_order_release);
400  theThread = std::thread([this, interval, func]() {
401  while (bRunning.load(std::memory_order_acquire)) {
402  func();
403  std::this_thread::sleep_for(
404  std::chrono::milliseconds(interval));
405  }
406  });
407  }
408 
409  void Stop() {
410  bRunning.store(false, std::memory_order_release);
411  if (theThread.joinable()) {
412  theThread.join();
413  }
414  }
415 
416  bool IsRunning() const noexcept {
417  return (bRunning.load(std::memory_order_acquire) &&
418  theThread.joinable());
419  }
420 
421  private:
422  std::atomic<bool> bRunning;
423  std::thread theThread;
424 };
425 
426 // AudioTrack
427 
428 class AudioTrackS16 : public IAudioTrack {
429  public:
430  AudioTrackS16();
431  virtual ~AudioTrackS16();
432 
433  virtual bool Open(PAudioDataSource data_source);
434  virtual bool IsValid();
435 
436  virtual bool Play();
437  virtual bool Stop();
438  virtual bool Pause();
439  virtual bool Resume();
440  virtual bool SetVolume(float volume);
441  virtual float GetVolume();
442 
443  protected:
444  void Close();
445  void DrainBuffers();
446  void Update();
447 
455 };
456 
458  al_format = AL_FORMAT_STEREO16;
459  al_source = -1;
460  al_sample_rate = 0;
461  uiReservedData = 0;
463 }
464 
466 
468  pDataSource = data_source;
469  if (!pDataSource) {
470  return false;
471  }
472 
473  if (!pDataSource->Open()) {
474  return false;
475  }
476 
478  if (CheckError()) {
479  return false;
480  }
481 
482  alSourcei(al_source, AL_LOOPING, AL_FALSE);
483  alSourcef(al_source, AL_PITCH, 1.f);
484  alSourcef(al_source, AL_GAIN, 1.f);
485  alSourcei(al_source, AL_SOURCE_RELATIVE, AL_TRUE);
486  alSource3f(al_source, AL_POSITION, 0.f, 0.f, 0.f);
487  alSource3f(al_source, AL_VELOCITY, 0.f, 0.f, 0.f);
488 
489  al_sample_rate = pDataSource->GetSampleRate();
490 
491  uiReservedData = 0;
492  uiReservedDataMinimum = 1000 * (al_sample_rate / 1000) * 4;
493 
494  return true;
495 }
496 
497 bool AudioTrackS16::IsValid() { return (alIsSource(al_source) != 0); }
498 
500  if (!IsValid()) {
501  return false;
502  }
503 
504  ALint status;
505  alGetSourcei(al_source, AL_SOURCE_STATE, &status);
506  if (status == AL_PLAYING) {
507  return true;
508  }
509 
510  Update();
511 
513  if (CheckError()) {
514  return false;
515  }
516 
517  updater.Start(10, [this]() { Update(); });
518 
519  return true;
520 }
521 
523  if (!IsValid()) {
524  return false;
525  }
526 
527  Close();
528 
529  return true;
530 }
531 
533  if (!IsValid()) {
534  return false;
535  }
536 
538  if (CheckError()) {
539  return false;
540  }
541 
542  updater.Stop();
543 
544  return true;
545 }
546 
547 bool AudioTrackS16::Resume() { return Play(); }
548 
549 bool AudioTrackS16::SetVolume(float volume) {
550  if (!IsValid()) {
551  return false;
552  }
553 
554  alSourcef(al_source, AL_GAIN, volume);
555  if (CheckError()) {
556  return false;
557  }
558 
559  return true;
560 }
561 
563  if (!IsValid()) {
564  return 0.f;
565  }
566 
567  ALfloat volume = 0.f;
568  alGetSourcef(al_source, AL_GAIN, &volume);
569  if (CheckError()) {
570  volume = 0.f;
571  }
572  return volume;
573 }
574 
576  updater.Stop();
577  if (pDataSource) {
578  pDataSource->Close();
579  }
580 
581  if (alIsSource(al_source) != 0) {
583  CheckError();
585  CheckError();
586  }
587 
588  al_source = -1;
589  al_sample_rate = 0;
590  uiReservedData = 0;
592 }
593 
595  ALint num_processed_buffers = 0;
596  alGetSourcei(al_source, AL_BUFFERS_PROCESSED, &num_processed_buffers);
597  if (num_processed_buffers <= 0) {
598  return;
599  }
600 
601  ALuint *processed_buffer_ids = new ALuint[num_processed_buffers];
602  if (CheckError()) {
603  log("OpenAL: Faile to get played buffers.");
604  } else {
605  for (ALint i = 0; i < num_processed_buffers; i++) {
606  ALuint buffer = processed_buffer_ids[i];
608  if (CheckError()) {
609  log("OpenAL: Faile to unqueue played buffer.");
610  } else {
611  ALint size = 0;
612  alGetBufferi(buffer, AL_SIZE, &size);
613  uiReservedData -= size;
614  alDeleteBuffers(1, &buffer);
615  if (CheckError()) {
616  log("OpenAL: Faile to delete played buffer.");
617  }
618  }
619  }
620  }
621  delete[] processed_buffer_ids;
622 }
623 
625  DrainBuffers();
626 
628  PMemBuffer buffer = pDataSource->GetNextBuffer();
629 
630  if (!buffer) {
631  return;
632  }
633 
634  ALuint al_buffer = -1;
635  alGenBuffers(1, &al_buffer);
636  if (CheckError()) {
637  Close();
638  return;
639  }
640 
641  alBufferData(al_buffer, al_format, buffer->GetData(), buffer->GetSize(), al_sample_rate);
642  if (CheckError()) {
643  Close();
644  return;
645  }
646 
647  alSourceQueueBuffers(al_source, 1, &al_buffer);
648  if (CheckError()) {
649  Close();
650  return;
651  }
652 
653  uiReservedData += buffer->GetSize();
654  }
655 }
656 
658  std::shared_ptr<AudioTrackS16> track = std::make_shared<AudioTrackS16>();
659 
661  if (!track->Open(source)) {
662  track = nullptr;
663  }
664 
665  return std::dynamic_pointer_cast<IAudioTrack, AudioTrackS16>(track);
666 }
667 
668 class AudioSample16 : public IAudioSample {
669  public:
670  AudioSample16();
671  virtual ~AudioSample16();
672 
673  virtual bool Open(PAudioDataSource data_source);
674  virtual bool IsValid();
675 
676  virtual bool Play(bool loop = false, bool positioned = false);
677  virtual bool Stop();
678  virtual bool SetVolume(float volume);
679  virtual bool SetPosition(float x, float y, float z, float max_dist);
680 
681  protected:
682  void Close();
683 
689 
690  bool loop;
692 };
693 
695  al_format = AL_FORMAT_STEREO16;
696  al_source = -1;
697  al_sample_rate = 0;
698  loop = false;
699  positioned = true;
700 }
701 
703 
705  updater.Stop();
706  if (pDataSource) {
707  pDataSource->Close();
708  }
709 
710  if (alIsSource(al_source) != 0) {
712  CheckError();
714  CheckError();
715  }
716 
717  al_source = -1;
718  al_sample_rate = 0;
719 }
720 
722  pDataSource = data_source;
723  if (!pDataSource) {
724  return false;
725  }
726 
727  if (!pDataSource->Open()) {
728  return false;
729  }
730 
732  if (CheckError()) {
733  return false;
734  }
735 
736  alSourcei(al_source, AL_LOOPING, AL_FALSE);
737  alSourcef(al_source, AL_PITCH, 1.f);
738  alSourcef(al_source, AL_GAIN, 1.f);
739  alSourcef(al_source, AL_REFERENCE_DISTANCE, 6.5f); // 300 / 50
740  alSourcef(al_source, AL_MAX_DISTANCE, 2000.f);
741  alSource3f(al_source, AL_POSITION, 0.f, 0.f, 0.f);
742  alSource3f(al_source, AL_VELOCITY, 0.f, 0.f, 0.f);
743 
744  al_sample_rate = pDataSource->GetSampleRate();
745 
746  unsigned int num_channels = data_source->GetChannelCount();
747  switch (num_channels) {
748  case 1:
749  al_format = AL_FORMAT_MONO16;
750  break;
751  case 2:
752  al_format = AL_FORMAT_STEREO16;
753  break;
754  default:
755  if (alIsExtensionPresent("AL_EXT_MCFORMATS")) {
756  switch (num_channels) {
757  case 4:
758  al_format = alGetEnumValue("AL_FORMAT_QUAD16");
759  break;
760  case 6:
761  al_format = alGetEnumValue("AL_FORMAT_51CHN16");
762  break;
763  case 7:
764  al_format = alGetEnumValue("AL_FORMAT_61CHN16");
765  break;
766  case 8:
767  al_format = alGetEnumValue("AL_FORMAT_71CHN16");
768  break;
769  }
770  }
771  Error("Unsupported number of audio channels: %u", num_channels);
772  }
773 
774  while (true) {
775  PMemBuffer buffer = pDataSource->GetNextBuffer();
776  if (!buffer) {
777  break;
778  }
779 
780  ALuint al_buffer = -1;
781  alGenBuffers(1, &al_buffer);
782  if (CheckError()) {
783  Close();
784  break;
785  }
786 
787  alBufferData(al_buffer, al_format, buffer->GetData(), buffer->GetSize(), al_sample_rate);
788  if (CheckError()) {
789  Close();
790  break;
791  }
792 
793  alSourceQueueBuffers(al_source, 1, &al_buffer);
794  if (CheckError()) {
795  Close();
796  break;
797  }
798  }
799 
800  return true;
801 }
802 
803 bool AudioSample16::SetPosition(float x, float y, float z, float max_dist) {
804  if (!IsValid()) {
805  return false;
806  }
807 
808  alSource3f(al_source, AL_POSITION, x, y, z);
809  alSourcef(al_source, AL_MAX_DISTANCE, max_dist);
810  if (CheckError()) {
811  return false;
812  }
813 
814  return true;
815 }
816 
817 bool AudioSample16::IsValid() { return (alIsSource(al_source) != 0); }
818 
819 bool AudioSample16::Play(bool loop_, bool positioned_) {
820  if (!IsValid()) {
821  return false;
822  }
823 
824  loop = loop_;
825  positioned = positioned_;
826 
827  alSourcei(al_source, AL_SOURCE_RELATIVE, positioned ? AL_FALSE : AL_TRUE);
828  // alSource3f(al_source, AL_POSITION, 0.f, 0.f, 0.f);
829  alSource3f(al_source, AL_VELOCITY, 0.f, 0.f, 0.f);
830 
831  alSourcei(al_source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
832 
833  ALint status;
834  alGetSourcei(al_source, AL_SOURCE_STATE, &status);
835  if (status == AL_PLAYING) {
836  return true;
837  }
838 
840  if (CheckError()) {
841  return false;
842  }
843 
844  return true;
845 }
846 
848  if (!IsValid()) {
849  return false;
850  }
851 
853  if (CheckError()) {
854  return false;
855  }
856 
857  return true;
858 }
859 
860 bool AudioSample16::SetVolume(float volume) {
861  if (!IsValid()) {
862  return false;
863  }
864 
865  alSourcef(al_source, AL_GAIN, volume);
866  if (CheckError()) {
867  return false;
868  }
869 
870  return true;
871 }
872 
874  std::shared_ptr<AudioSample16> sample = std::make_shared<AudioSample16>();
875 
877  if (!sample->Open(source)) {
878  sample = nullptr;
879  }
880 
881  return std::dynamic_pointer_cast<IAudioSample, AudioSample16>(sample);
882 }
OpenALSoundProvider::CreateTrack16
TrackBuffer * CreateTrack16(int num_channels, int sample_rate, const void *data, size_t size)
Definition: OpenALSoundProvider.cpp:286
AudioSample16::Stop
virtual bool Stop()
Definition: OpenALSoundProvider.cpp:847
alGenSources
AL_API void AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
AudioSample16::SetVolume
virtual bool SetVolume(float volume)
Definition: OpenALSoundProvider.cpp:860
alcGetString
const ALC_API ALCchar *ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)
OpenALSoundProvider::context
ALCcontext * context
Definition: OpenALSoundProvider.h:47
CheckError
bool CheckError()
Definition: OpenALSoundProvider.cpp:31
OpenALSoundProvider::~OpenALSoundProvider
virtual ~OpenALSoundProvider()
Definition: OpenALSoundProvider.cpp:48
AudioTrackS16::Open
virtual bool Open(PAudioDataSource data_source)
Definition: OpenALSoundProvider.cpp:467
ALenum
int ALenum
Definition: al.h:65
OpenALSoundProvider::StreamingTrackBuffer
Definition: OpenALSoundProvider.h:19
alcDestroyContext
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
alSourcef
AL_API void AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value)
OpenALSoundProvider::SetOrientation
void SetOrientation(float yaw, float pitch)
Definition: OpenALSoundProvider.cpp:97
source
GLsizei GLsizei GLchar * source
Definition: SDL_opengl_glext.h:680
message
GLuint GLsizei const GLchar * message
Definition: SDL_opengl_glext.h:2486
z
GLdouble GLdouble z
Definition: SDL_opengl_glext.h:407
CallBackTimer::Start
void Start(int interval, std::function< void(void)> func)
Definition: OpenALSoundProvider.cpp:395
OpenALSoundProvider::Initialize
bool Initialize()
Definition: OpenALSoundProvider.cpp:50
AudioSample16::~AudioSample16
virtual ~AudioSample16()
Definition: OpenALSoundProvider.cpp:702
AudioTrackS16::al_format
ALenum al_format
Definition: OpenALSoundProvider.cpp:450
PAudioDataSource
std::shared_ptr< IAudioDataSource > PAudioDataSource
Definition: Media.h:20
AudioTrackS16::Update
void Update()
Definition: OpenALSoundProvider.cpp:624
alIsExtensionPresent
AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extname)
CreateAudioBufferDataSource
PAudioDataSource CreateAudioBufferDataSource(PMemBuffer buffer)
Definition: MediaPlayer.cpp:1176
AudioSample16::IsValid
virtual bool IsValid()
Definition: OpenALSoundProvider.cpp:817
AudioSample16::al_format
ALenum al_format
Definition: OpenALSoundProvider.cpp:686
AudioSample16::loop
bool loop
Definition: OpenALSoundProvider.cpp:690
alBufferData
AL_API void AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
al.h
alSourceUnqueueBuffers
AL_API void AL_APIENTRY alSourceUnqueueBuffers(ALuint source, ALsizei nb, ALuint *buffers)
func
GLenum func
Definition: SDL_opengl_glext.h:660
AudioTrackS16::al_source
ALuint al_source
Definition: OpenALSoundProvider.cpp:451
alSourceStop
AL_API void AL_APIENTRY alSourceStop(ALuint source)
OpenALSoundProvider::DeleteBuffer16
void DeleteBuffer16(TrackBuffer **buffer)
Definition: OpenALSoundProvider.cpp:150
alGetString
const AL_API ALchar *AL_APIENTRY alGetString(ALenum param)
alListener3f
AL_API void AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
format
SDL_AudioFormat format
Definition: SDL_audio.h:194
CallBackTimer::Stop
void Stop()
Definition: OpenALSoundProvider.cpp:409
buffer
EGLContext EGLenum EGLClientBuffer buffer
Definition: SDL_egl.h:952
OpenALSoundProvider::StreamingTrackBuffer::sample_format
ALenum sample_format
Definition: OpenALSoundProvider.h:21
y
EGLSurface EGLint EGLint y
Definition: SDL_egl.h:1596
AudioTrackS16::Close
void Close()
Definition: OpenALSoundProvider.cpp:575
AudioTrackS16::Pause
virtual bool Pause()
Definition: OpenALSoundProvider.cpp:532
CreateAudioTrack
PAudioTrack CreateAudioTrack(const std::string &file_path)
Definition: OpenALSoundProvider.cpp:657
ErrorHandling.h
OpenALSoundProvider::CreateStreamingTrack16
StreamingTrackBuffer * CreateStreamingTrack16(int num_channels, int sample_rate, int bytes_per_sample)
Definition: OpenALSoundProvider.cpp:173
x
EGLSurface EGLint x
Definition: SDL_egl.h:1596
PAudioTrack
std::shared_ptr< IAudioTrack > PAudioTrack
Definition: Media.h:40
alGetSourcei
AL_API void AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value)
CallBackTimer::~CallBackTimer
virtual ~CallBackTimer()
Definition: OpenALSoundProvider.cpp:389
alSourceQueueBuffers
AL_API void AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const ALuint *buffers)
OpenALSoundProvider::TrackBuffer::source_id
unsigned int source_id
Definition: OpenALSoundProvider.h:15
AudioTrackS16::~AudioTrackS16
virtual ~AudioTrackS16()
Definition: OpenALSoundProvider.cpp:465
AudioTrackS16::uiReservedData
size_t uiReservedData
Definition: OpenALSoundProvider.cpp:453
CreateAudioSample
PAudioSample CreateAudioSample(PMemBuffer buffer)
Definition: OpenALSoundProvider.cpp:873
PAudioSample
std::shared_ptr< IAudioSample > PAudioSample
Definition: Media.h:57
AudioTrackS16::IsValid
virtual bool IsValid()
Definition: OpenALSoundProvider.cpp:497
OpenALSoundProvider::DeleteStreamingTrack
void DeleteStreamingTrack(StreamingTrackBuffer **buffer)
Definition: OpenALSoundProvider.cpp:116
AudioSample16::SetPosition
virtual bool SetPosition(float x, float y, float z, float max_dist)
Definition: OpenALSoundProvider.cpp:803
alGetBufferi
AL_API void AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value)
AudioSample16::Open
virtual bool Open(PAudioDataSource data_source)
Definition: OpenALSoundProvider.cpp:721
OpenALSoundProvider::StreamingTrackBuffer::sample_rate
int sample_rate
Definition: OpenALSoundProvider.h:22
AudioTrackS16::SetVolume
virtual bool SetVolume(float volume)
Definition: OpenALSoundProvider.cpp:549
MediaPlayer.h
AudioSample16::al_source
ALuint al_source
Definition: OpenALSoundProvider.cpp:687
AudioTrackS16
Definition: OpenALSoundProvider.cpp:428
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
AudioSample16::Close
void Close()
Definition: OpenALSoundProvider.cpp:704
alc.h
CreateAudioFileDataSource
PAudioDataSource CreateAudioFileDataSource(const std::string &file_name)
Definition: MediaPlayer.cpp:1169
AudioSample16::al_sample_rate
ALsizei al_sample_rate
Definition: OpenALSoundProvider.cpp:688
OpenALSoundProvider::TrackBuffer::buffer_id
unsigned int buffer_id
Definition: OpenALSoundProvider.h:16
AudioTrackS16::Stop
virtual bool Stop()
Definition: OpenALSoundProvider.cpp:522
IAudioSample
Definition: Media.h:44
OpenALSoundProvider::alBufferLength
float alBufferLength(unsigned int buffer)
Definition: OpenALSoundProvider.cpp:158
CallBackTimer::bRunning
std::atomic< bool > bRunning
Definition: OpenALSoundProvider.cpp:422
AudioTrackS16::pDataSource
PAudioDataSource pDataSource
Definition: OpenALSoundProvider.cpp:448
alcOpenDevice
ALC_API ALCdevice *ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
AudioTrackS16::DrainBuffers
void DrainBuffers()
Definition: OpenALSoundProvider.cpp:594
alDeleteBuffers
AL_API void AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
alIsSource
AL_API ALboolean AL_APIENTRY alIsSource(ALuint source)
AudioSample16
Definition: OpenALSoundProvider.cpp:668
alSource3f
AL_API void AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
IAudioTrack
Definition: Media.h:25
alListenerfv
AL_API void AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
alGetError
AL_API ALenum AL_APIENTRY alGetError(void)
OpenALSoundProvider::Stream16
void Stream16(StreamingTrackBuffer *buffer, int num_samples, const void *samples, bool wait=false)
Definition: OpenALSoundProvider.cpp:226
OpenALSoundProvider.h
AudioTrackS16::Play
virtual bool Play()
Definition: OpenALSoundProvider.cpp:499
CallBackTimer
Definition: OpenALSoundProvider.cpp:386
ALint
int ALint
Definition: al.h:56
alSourcePlay
AL_API void AL_APIENTRY alSourcePlay(ALuint source)
AudioSample16::updater
CallBackTimer updater
Definition: OpenALSoundProvider.cpp:685
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
alDeleteSources
AL_API void AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
alSourcei
AL_API void AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value)
alcCloseDevice
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
alSourcePause
AL_API void AL_APIENTRY alSourcePause(ALuint source)
alGetEnumValue
AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *ename)
CallBackTimer::theThread
std::thread theThread
Definition: OpenALSoundProvider.cpp:423
CallBackTimer::IsRunning
bool IsRunning() const noexcept
Definition: OpenALSoundProvider.cpp:416
ALuint
unsigned int ALuint
Definition: al.h:59
OpenALSoundProvider::Release
void Release()
Definition: OpenALSoundProvider.cpp:106
log
void log(const char *format,...)
Definition: OpenALSoundProvider.cpp:24
AudioSample16::Play
virtual bool Play(bool loop=false, bool positioned=false)
Definition: OpenALSoundProvider.cpp:819
ALsizei
int ALsizei
Definition: al.h:62
AudioTrackS16::uiReservedDataMinimum
size_t uiReservedDataMinimum
Definition: OpenALSoundProvider.cpp:454
OpenALSoundProvider::PlayTrack16
void PlayTrack16(TrackBuffer *buffer, bool loop=false, bool wait=false)
Definition: OpenALSoundProvider.cpp:358
alGenBuffers
AL_API void AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
AudioSample16::positioned
bool positioned
Definition: OpenALSoundProvider.cpp:691
bits
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
Definition: SDL_opengl_glext.h:6179
alcMakeContextCurrent
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
alcCreateContext
ALC_API ALCcontext *ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrlist)
AudioTrackS16::Resume
virtual bool Resume()
Definition: OpenALSoundProvider.cpp:547
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:691
AudioTrackS16::updater
CallBackTimer updater
Definition: OpenALSoundProvider.cpp:449
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
AudioTrackS16::AudioTrackS16
AudioTrackS16()
Definition: OpenALSoundProvider.cpp:457
AudioSample16::AudioSample16
AudioSample16()
Definition: OpenALSoundProvider.cpp:694
CallBackTimer::CallBackTimer
CallBackTimer()
Definition: OpenALSoundProvider.cpp:388
OpenALSoundProvider::SetListenerPosition
void SetListenerPosition(float x, float y, float z)
Definition: OpenALSoundProvider.cpp:93
ALfloat
float ALfloat
Definition: al.h:68
AudioSample16::pDataSource
PAudioDataSource pDataSource
Definition: OpenALSoundProvider.cpp:684
PMemBuffer
std::shared_ptr< IMemBuffer > PMemBuffer
Definition: MemBuffer.h:13
OpenALSoundProvider::StreamingTrackBuffer::source_id
unsigned int source_id
Definition: OpenALSoundProvider.h:20
AudioTrackS16::al_sample_rate
ALsizei al_sample_rate
Definition: OpenALSoundProvider.cpp:452
AudioTrackS16::GetVolume
virtual float GetVolume()
Definition: OpenALSoundProvider.cpp:562
Log.h
samples
GLsizei samples
Definition: SDL_opengl_glext.h:1188
OpenALSoundProvider::device
ALCdevice * device
Definition: OpenALSoundProvider.h:46
OpenALSoundProvider::OpenALSoundProvider
OpenALSoundProvider()
Definition: OpenALSoundProvider.cpp:43
OpenALSoundProvider::TrackBuffer
Definition: OpenALSoundProvider.h:14
alGetSourcef
AL_API void AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value)