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 
35 #include <al.h>
36 
37 
38 class ALSound : public CSoundInterface
39 {
40 public:
41  ALSound();
42  ~ALSound();
43 
44  bool Create(bool b3D);
45  bool Cache(Sound, std::string);
46  bool CacheMusic(std::string);
47 
48  bool GetEnable();
49 
50  void SetSound3D(bool bMode);
51  bool GetSound3D();
52  bool GetSound3DCap();
53 
54  void SetAudioVolume(int volume);
55  int GetAudioVolume();
56  void SetMusicVolume(int volume);
57  int GetMusicVolume();
58 
59  void SetListener(Math::Vector eye, Math::Vector lookat);
60  void FrameMove(float rTime);
61 
62  int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
63  int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
64  bool FlushEnvelope(int channel);
65  bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
66  bool Position(int channel, Math::Vector pos);
67  bool Frequency(int channel, float frequency);
68  bool Stop(int channel);
69  bool StopAll();
70  bool MuteAll(bool bMute);
71 
72  bool PlayMusic(int rank, bool bRepeat);
73  bool PlayMusic(std::string filename, bool bRepeat);
74  bool RestartMusic();
75  void SuspendMusic();
76  void StopMusic();
77  bool IsPlayingMusic();
78 
79  // plugin interface
80  std::string PluginName();
81  int PluginVersion();
82  void InstallPlugin();
83  bool UninstallPlugin(std::string &);
84 
85 private:
86  void CleanUp();
87  int GetPriority(Sound);
88  bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
89  void ComputeVolumePan2D(int channel, Math::Vector &pos);
90 
91  bool m_enabled;
92  bool m_3D;
93  float m_audioVolume;
94  float m_musicVolume;
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  Math::Vector m_eye;
102  Math::Vector m_lookat;
103 };
104 
bool GetEnable()
Definition: alsound.cpp:131
bool Create(bool b3D)
Definition: alsound.cpp:80
Sound plugin interface.
void SetListener(Math::Vector eye, Math::Vector lookat)
Definition: alsound.cpp:588
bool Position(int channel, Math::Vector pos)
Definition: alsound.cpp:424
bool MuteAll(bool bMute)
Definition: alsound.cpp:499
bool RestartMusic()
Definition: alsound.cpp:666
bool GetSound3DCap()
Definition: alsound.cpp:124
int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop=false)
Definition: alsound.cpp:334
void SetMusicVolume(int volume)
Definition: alsound.cpp:152
void FrameMove(float rTime)
Definition: alsound.cpp:524
void StopMusic()
Definition: alsound.cpp:678
bool Stop(int channel)
Definition: alsound.cpp:467
bool IsPlayingMusic()
Definition: alsound.cpp:689
OpenAL channel.
bool StopAll()
Definition: alsound.cpp:484
bool GetSound3D()
Definition: alsound.cpp:118
bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper)
Definition: alsound.cpp:402
SoundNext
Enum representing operation that will be performend on a sound at given time.
Definition: sound.h:135
void SuspendMusic()
Definition: alsound.cpp:700
bool FlushEnvelope(int channel)
Definition: alsound.cpp:390
Sound
Sound enum representing sound file.
Definition: sound.h:42
bool CacheMusic(std::string)
Definition: alsound.cpp:182
OpenAL buffer.
bool Frequency(int channel, float frequency)
Definition: alsound.cpp:452
Class for logging information to file or console.
void SetAudioVolume(int volume)
Definition: alsound.cpp:137
bool Cache(Sound, std::string)
Definition: alsound.cpp:171
Definition: alsound.h:38
3D (3x1) vector
Definition: vector.h:49
int GetAudioVolume()
Definition: alsound.cpp:143
void SetSound3D(bool bMode)
Definition: alsound.cpp:112
bool PlayMusic(int rank, bool bRepeat)
Definition: alsound.cpp:622
int GetMusicVolume()
Definition: alsound.cpp:162
Sound plugin interface.
Definition: sound.h:149
Definition: channel.h:46