SoundSystem.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "SoundSystem.h"
  2. SoundSystem::SoundSystem():
  3. device(nullptr),
  4. context(nullptr)
  5. {
  6. device = alcOpenDevice(nullptr);
  7. if (!device)
  8. return;
  9. context = alcCreateContext(device, nullptr);
  10. if (!context)
  11. return;
  12. alcMakeContextCurrent(context);
  13. }
  14. SoundSystem::~SoundSystem()
  15. {
  16. for (auto sound : sounds)
  17. delete sound;
  18. alcMakeContextCurrent(nullptr);
  19. alcDestroyContext(context);
  20. alcCloseDevice(device);
  21. }
  22. void SoundSystem::SetListener(const Vec3f& inPos, const Vec3f& inVel, const Vec3f& inOri)
  23. {
  24. ALfloat orientation[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
  25. alListenerfv(AL_POSITION, inPos.v);
  26. alListenerfv(AL_VELOCITY, inVel.v);
  27. alListenerfv(AL_ORIENTATION, orientation);
  28. }
  29. unsigned int SoundSystem::LoadSound(const char* inWavPath, bool inLooping)
  30. {
  31. Sound* sound = new Sound(inWavPath, inLooping);
  32. sounds.push_back(sound);
  33. return sounds.size() - 1;
  34. }
  35. Sound* SoundSystem::GetSound(unsigned int inID)
  36. {
  37. if (inID > sounds.size())
  38. return nullptr;
  39. return sounds[inID];
  40. }