Colobot
channel.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-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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 "math/vector.h"
28 
29 #include "sound/sound.h"
30 
31 #include "sound/oalsound/check.h"
32 
33 #include <string>
34 #include <deque>
35 #include <cassert>
36 
37 #include <al.h>
38 #include <alc.h>
39 
40 class CBuffer;
41 
42 struct SoundOper
43 {
44  float finalAmplitude = 0.0f;
45  float finalFrequency = 0.0f;
46  float totalTime = 0.0f;
47  float currentTime = 0.0f;
48  SoundNext nextOper = SOPER_CONTINUE;
49 };
50 
51 
52 class CChannel
53 {
54 public:
55  CChannel();
56  ~CChannel();
57 
58  bool Play();
59  bool Pause();
60  bool Stop();
61 
62  bool SetPosition(const Math::Vector &pos);
63 
64  bool SetFrequency(float freq);
65  float GetFrequency();
66 
67  float GetCurrentTime();
68  void SetCurrentTime(float current);
69  float GetDuration();
70 
71  bool SetVolume(float vol);
72  float GetVolume();
73  void SetVolumeAtrib(float volume);
74  float GetVolumeAtrib();
75 
76  bool IsPlaying();
77  bool IsReady();
78  bool IsLoaded();
79 
80  bool SetBuffer(CBuffer *buffer);
81 
82  bool HasEnvelope();
83  SoundOper& GetEnvelope();
84  void PopEnvelope();
85 
86  int GetPriority();
87  void SetPriority(int pri);
88 
89  void SetStartAmplitude(float gain);
90  void SetStartFrequency(float freq);
91  void SetChangeFrequency(float freq);
92 
93  float GetStartAmplitude();
94  float GetStartFrequency();
95  float GetChangeFrequency();
96  float GetInitFrequency();
97 
98  void AddOper(SoundOper oper);
99  void ResetOper();
100  SoundType GetSoundType();
101  void SetLoop(bool loop);
102  void Mute(bool mute);
103  bool IsMuted();
104 
105  void Reset();
106  int GetId();
107 
108 private:
109  CBuffer *m_buffer;
110  ALuint m_source;
111 
112  int m_priority;
113  int m_id;
114  float m_startAmplitude;
115  float m_startFrequency;
116  float m_changeFrequency;
117  float m_initFrequency;
118  float m_volume;
119  std::deque<SoundOper> m_oper;
120  bool m_ready;
121  bool m_loop;
122  bool m_mute;
123  Math::Vector m_position;
124 };
125 
Sound plugin interface.
Definition: buffer.h:35
Definition: sound.h:48
SoundNext
Enum representing operation that will be performend on a sound at given time.
Definition: sound.h:46
Definition: channel.h:42
Definition: channel.h:52
Vector struct and related functions.
SoundType
Enum representing sound file.
Definition: sound_type.h:34
3D (3x1) vector
Definition: vector.h:53