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