Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
alsound.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "common/logger.h"
28 #include "sound/sound.h"
29 
30 #include "sound/oalsound/buffer.h"
31 #include "sound/oalsound/channel.h"
32 #include "sound/oalsound/check.h"
33 
34 #include <map>
35 #include <string>
36 #include <list>
37 
38 #include <al.h>
39 
40 
41 struct OldMusic {
42  Channel* music;
43  float fadeTime;
44  float currentTime;
45 };
46 
47 class ALSound : public CSoundInterface
48 {
49 public:
50  ALSound();
51  ~ALSound();
52 
53  bool Create() OVERRIDE;
54  bool Cache(Sound, const std::string &) OVERRIDE;
55  bool CacheMusic(const std::string &) OVERRIDE;
56  bool IsCached(Sound) OVERRIDE;
57  bool IsCachedMusic(const std::string &) OVERRIDE;
58 
59  bool GetEnable() OVERRIDE;
60 
61  void SetAudioVolume(int volume) OVERRIDE;
62  int GetAudioVolume() OVERRIDE;
63  void SetMusicVolume(int volume) OVERRIDE;
64  int GetMusicVolume() OVERRIDE;
65 
66  void SetListener(const Math::Vector &eye, const Math::Vector &lookat) OVERRIDE;
67  void FrameMove(float rTime) OVERRIDE;
68 
69  int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) OVERRIDE;
70  int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) OVERRIDE;
71  bool FlushEnvelope(int channel) OVERRIDE;
72  bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) OVERRIDE;
73  bool Position(int channel, const Math::Vector &pos) OVERRIDE;
74  bool Frequency(int channel, float frequency) OVERRIDE;
75  bool Stop(int channel) OVERRIDE;
76  bool StopAll() OVERRIDE;
77  bool MuteAll(bool bMute) OVERRIDE;
78 
79  bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f) OVERRIDE;
80  bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f) OVERRIDE;
81  bool RestartMusic() OVERRIDE;
82  void SuspendMusic() OVERRIDE;
83  void StopMusic(float fadeTime=2.0f) OVERRIDE;
84  bool IsPlayingMusic() OVERRIDE;
85  bool PlayPauseMusic(const std::string &filename, bool repeat) OVERRIDE;
86  void StopPauseMusic() OVERRIDE;
87 
88 private:
89  void CleanUp();
90  int GetPriority(Sound);
91  bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
92  bool CheckChannel(int &channel);
93 
94  bool m_enabled;
95  float m_audioVolume;
96  float m_musicVolume;
97  unsigned int m_channels_limit;
98  ALCdevice* m_device;
99  ALCcontext* m_context;
100  std::map<Sound, Buffer*> m_sounds;
101  std::map<std::string, Buffer*> m_music;
102  std::map<int, Channel*> m_channels;
103  Channel *m_currentMusic;
104  std::list<OldMusic> m_oldMusic;
105  OldMusic m_previousMusic;
106  Math::Vector m_eye;
107  Math::Vector m_lookat;
108 };
109 
void SetListener(const Math::Vector &eye, const Math::Vector &lookat) OVERRIDE
Definition: alsound.cpp:603
Sound plugin interface.
bool FlushEnvelope(int channel) OVERRIDE
Definition: alsound.cpp:402
int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop=false) OVERRIDE
Definition: alsound.cpp:340
bool IsCachedMusic(const std::string &) OVERRIDE
Definition: alsound.cpp:189
bool Stop(int channel) OVERRIDE
Definition: alsound.cpp:457
void SuspendMusic() OVERRIDE
Definition: alsound.cpp:777
bool IsPlayingMusic() OVERRIDE
Definition: alsound.cpp:766
bool Position(int channel, const Math::Vector &pos) OVERRIDE
Definition: alsound.cpp:433
bool Create() OVERRIDE
Definition: alsound.cpp:88
bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f) OVERRIDE
Definition: alsound.cpp:616
void SetAudioVolume(int volume) OVERRIDE
Definition: alsound.cpp:125
void StopPauseMusic() OVERRIDE
Definition: alsound.cpp:715
OpenAL channel.
bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) OVERRIDE
Definition: alsound.cpp:414
bool Frequency(int channel, float frequency) OVERRIDE
Definition: alsound.cpp:445
int GetAudioVolume() OVERRIDE
Definition: alsound.cpp:131
SoundNext
Enum representing operation that will be performend on a sound at given time.
Definition: sound.h:137
int GetMusicVolume() OVERRIDE
Definition: alsound.cpp:150
bool StopAll() OVERRIDE
Definition: alsound.cpp:471
Sound
Sound enum representing sound file.
Definition: sound.h:44
bool IsCached(Sound) OVERRIDE
Definition: alsound.cpp:184
OpenAL buffer.
Class for logging information to file or console.
Definition: alsound.h:41
Definition: alsound.h:47
3D (3x1) vector
Definition: vector.h:52
bool CacheMusic(const std::string &) OVERRIDE
Definition: alsound.cpp:170
void SetMusicVolume(int volume) OVERRIDE
Definition: alsound.cpp:140
bool Cache(Sound, const std::string &) OVERRIDE
Definition: alsound.cpp:159
bool MuteAll(bool bMute) OVERRIDE
Definition: alsound.cpp:488
bool RestartMusic() OVERRIDE
Definition: alsound.cpp:736
void StopMusic(float fadeTime=2.0f) OVERRIDE
Definition: alsound.cpp:749
bool GetEnable() OVERRIDE
Definition: alsound.cpp:119
bool PlayPauseMusic(const std::string &filename, bool repeat) OVERRIDE
Definition: alsound.cpp:687
Sound plugin interface.
Definition: sound.h:151
void FrameMove(float rTime) OVERRIDE
Definition: alsound.cpp:507
Definition: channel.h:49