| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "SoundSystem.h"
- SoundSystem::SoundSystem():
- device(nullptr),
- context(nullptr)
- {
- device = alcOpenDevice(nullptr);
- if (!device)
- return;
- context = alcCreateContext(device, nullptr);
- if (!context)
- return;
- alcMakeContextCurrent(context);
- }
- SoundSystem::~SoundSystem()
- {
- for (auto sound : sounds)
- delete sound;
- alcMakeContextCurrent(nullptr);
- alcDestroyContext(context);
- alcCloseDevice(device);
- }
- void SoundSystem::SetListener(const Vec3f& inPos, const Vec3f& inVel, const Vec3f& inOri)
- {
- ALfloat orientation[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
-
- alListenerfv(AL_POSITION, inPos.v);
- alListenerfv(AL_VELOCITY, inVel.v);
- alListenerfv(AL_ORIENTATION, orientation);
- }
- unsigned int SoundSystem::LoadSound(const char* inWavPath, bool inLooping)
- {
- Sound* sound = new Sound(inWavPath, inLooping);
- sounds.push_back(sound);
- return sounds.size() - 1;
- }
- Sound* SoundSystem::GetSound(unsigned int inID)
- {
- if (inID > sounds.size())
- return nullptr;
- return sounds[inID];
- }
|