2014-10-14 13:11:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2016-02-13 13:11:30 +00:00
|
|
|
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-08-22 14:40:02 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
2014-10-14 13:11:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
*/
|
2012-09-20 18:38:14 +00:00
|
|
|
|
2013-05-26 17:34:05 +00:00
|
|
|
/**
|
|
|
|
* \file alsound.h
|
|
|
|
* \brief OpenAL implementation of sound system
|
|
|
|
*/
|
2012-09-20 18:38:14 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-05-26 17:34:05 +00:00
|
|
|
#include "sound/sound.h"
|
|
|
|
|
2016-07-10 12:56:34 +00:00
|
|
|
#include "common/thread/worker_thread.h"
|
|
|
|
|
2013-05-26 17:34:05 +00:00
|
|
|
#include "sound/oalsound/buffer.h"
|
|
|
|
#include "sound/oalsound/channel.h"
|
|
|
|
#include "sound/oalsound/check.h"
|
|
|
|
|
2012-09-20 18:38:14 +00:00
|
|
|
#include <map>
|
2015-07-15 20:24:26 +00:00
|
|
|
#include <memory>
|
2012-09-20 18:38:14 +00:00
|
|
|
#include <string>
|
2013-12-28 11:30:46 +00:00
|
|
|
#include <list>
|
2012-09-20 18:38:14 +00:00
|
|
|
|
2013-10-23 08:02:41 +00:00
|
|
|
#include <al.h>
|
2012-09-20 18:38:14 +00:00
|
|
|
|
|
|
|
|
2015-07-05 11:00:48 +00:00
|
|
|
struct OldMusic
|
|
|
|
{
|
2015-08-15 22:06:27 +00:00
|
|
|
OldMusic() = default;
|
|
|
|
|
|
|
|
OldMusic(const OldMusic&) = delete;
|
|
|
|
OldMusic& operator=(const OldMusic&) = delete;
|
|
|
|
|
|
|
|
// Workaround for MSVC2013
|
|
|
|
OldMusic(OldMusic&& other)
|
|
|
|
: music(std::move(other.music)),
|
|
|
|
fadeTime(std::move(other.fadeTime)),
|
|
|
|
currentTime(std::move(other.currentTime))
|
|
|
|
{}
|
|
|
|
|
|
|
|
OldMusic& operator=(OldMusic&& other)
|
|
|
|
{
|
|
|
|
music = std::move(other.music);
|
|
|
|
fadeTime = std::move(other.fadeTime);
|
|
|
|
currentTime = std::move(other.currentTime);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:05:14 +00:00
|
|
|
std::unique_ptr<CChannel> music;
|
2015-07-15 20:24:26 +00:00
|
|
|
float fadeTime = 0.0f;
|
|
|
|
float currentTime = 0.0f;
|
|
|
|
|
|
|
|
inline friend bool operator<(const OldMusic & l, const OldMusic & r)
|
|
|
|
{
|
|
|
|
return l.currentTime < r.currentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline friend bool operator==(const OldMusic & l, const OldMusic & r)
|
|
|
|
{
|
|
|
|
return l.currentTime == r.currentTime;
|
|
|
|
}
|
2013-12-28 11:30:46 +00:00
|
|
|
};
|
|
|
|
|
2015-10-03 20:05:14 +00:00
|
|
|
class CALSound : public CSoundInterface
|
2012-09-20 18:38:14 +00:00
|
|
|
{
|
2013-05-26 17:34:05 +00:00
|
|
|
public:
|
2015-10-03 20:05:14 +00:00
|
|
|
CALSound();
|
|
|
|
~CALSound();
|
2013-05-26 17:34:05 +00:00
|
|
|
|
2015-06-25 22:24:32 +00:00
|
|
|
bool Create() override;
|
2015-07-05 11:00:48 +00:00
|
|
|
bool Cache(SoundType, const std::string &) override;
|
2016-07-10 12:56:34 +00:00
|
|
|
void CacheMusic(const std::string &) override;
|
2015-07-05 11:00:48 +00:00
|
|
|
bool IsCached(SoundType) override;
|
2015-06-25 22:24:32 +00:00
|
|
|
bool IsCachedMusic(const std::string &) override;
|
|
|
|
|
|
|
|
bool GetEnable() override;
|
|
|
|
void SetAudioVolume(int volume) override;
|
|
|
|
int GetAudioVolume() override;
|
|
|
|
void SetMusicVolume(int volume) override;
|
|
|
|
int GetMusicVolume() override;
|
|
|
|
|
|
|
|
void SetListener(const Math::Vector &eye, const Math::Vector &lookat) override;
|
|
|
|
void FrameMove(float rTime) override;
|
|
|
|
|
2015-07-05 11:00:48 +00:00
|
|
|
int Play(SoundType sound, float amplitude=1.0f, float frequency=1.0f, bool loop = false) override;
|
|
|
|
int Play(SoundType sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool loop = false) override;
|
2015-06-25 22:24:32 +00:00
|
|
|
bool FlushEnvelope(int channel) override;
|
|
|
|
bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) override;
|
|
|
|
bool Position(int channel, const Math::Vector &pos) override;
|
|
|
|
bool Frequency(int channel, float frequency) override;
|
|
|
|
bool Stop(int channel) override;
|
|
|
|
bool StopAll() override;
|
2015-07-05 11:00:48 +00:00
|
|
|
bool MuteAll(bool mute) override;
|
2015-06-25 22:24:32 +00:00
|
|
|
|
2016-07-10 12:56:34 +00:00
|
|
|
void PlayMusic(const std::string &filename, bool repeat, float fadeTime = 2.0f) override;
|
2015-06-25 22:24:32 +00:00
|
|
|
void StopMusic(float fadeTime=2.0f) override;
|
|
|
|
bool IsPlayingMusic() override;
|
2016-07-10 12:56:34 +00:00
|
|
|
void PlayPauseMusic(const std::string &filename, bool repeat) override;
|
2015-06-25 22:24:32 +00:00
|
|
|
void StopPauseMusic() override;
|
2014-01-18 02:42:07 +00:00
|
|
|
|
2013-05-26 17:34:05 +00:00
|
|
|
private:
|
|
|
|
void CleanUp();
|
2015-07-05 11:00:48 +00:00
|
|
|
int GetPriority(SoundType);
|
|
|
|
bool SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoaded);
|
2014-06-21 00:58:41 +00:00
|
|
|
bool CheckChannel(int &channel);
|
2013-05-26 17:34:05 +00:00
|
|
|
|
|
|
|
bool m_enabled;
|
|
|
|
float m_audioVolume;
|
|
|
|
float m_musicVolume;
|
2015-07-15 20:24:26 +00:00
|
|
|
unsigned int m_channelsLimit;
|
2013-05-26 17:34:05 +00:00
|
|
|
ALCdevice* m_device;
|
|
|
|
ALCcontext* m_context;
|
2015-10-03 20:05:14 +00:00
|
|
|
std::map<SoundType, std::unique_ptr<CBuffer>> m_sounds;
|
|
|
|
std::map<std::string, std::unique_ptr<CBuffer>> m_music;
|
|
|
|
std::map<int, std::unique_ptr<CChannel>> m_channels;
|
|
|
|
std::unique_ptr<CChannel> m_currentMusic;
|
2013-12-28 11:30:46 +00:00
|
|
|
std::list<OldMusic> m_oldMusic;
|
2013-12-31 15:58:21 +00:00
|
|
|
OldMusic m_previousMusic;
|
2013-05-26 17:34:05 +00:00
|
|
|
Math::Vector m_eye;
|
|
|
|
Math::Vector m_lookat;
|
2016-07-10 12:56:34 +00:00
|
|
|
CWorkerThread m_thread;
|
2012-09-20 18:38:14 +00:00
|
|
|
};
|