Debian Codegraph @

engine/include/sound_server.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name sound_server.h - The sound server header file. */
11 //
12 // (c) Copyright 1998-2008 by Lutz Sammer, Fabrice Rossi, and
13 // Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28
29 #ifndef __SOUND_SERVER_H__
30 #define __SOUND_SERVER_H__
31
32 //@{
33
34 /*----------------------------------------------------------------------------
35 -- Definitons
36 ----------------------------------------------------------------------------*/
37
38 #define MaxVolume 255
39 #define SOUND_BUFFER_SIZE 65536
40
41 /**
42 ** RAW samples.
43 */
44 class CSample {
45 public:
46 CSample() : Channels(0), SampleSize(0), Frequency(0), BitsPerSample(0),
47 Buffer(NULL), Pos(0), Len(0) {}
48 virtual ~CSample() {}
49
50 virtual int Read(void *buf, int len) = 0;
51
52 unsigned char Channels; /// mono or stereo
53 unsigned char SampleSize; /// sample size in bits
54 unsigned int Frequency; /// frequency in hz
55 unsigned short BitsPerSample; /// bits in a sample 8/16/32
56
57 unsigned char *Buffer; /// sample buffer
58 int Pos; /// buffer position
59 int Len; /// length of filled buffer
60 };
61
62 /**
63 ** Play audio flags.
64 */
65 enum _play_audio_flags_ {
66 PlayAudioStream = 1, /// Stream the file from medium
67 PlayAudioPreLoad = 2, /// Load compressed in memory
68 PlayAudioLoadInMemory = 4, /// Preload file into memory
69 PlayAudioLoadOnDemand = 8, /// Load only if needed.
70 };
71
72 /*----------------------------------------------------------------------------
73 -- Functions
74 ----------------------------------------------------------------------------*/
75
76 extern CSample *LoadWav(const std::string &name, int flags); /// Load a wav file
77 extern CSample *LoadVorbis(const std::string &name, int flags); /// Load a vorbis file
78
79 /// Set the channel volume
80 extern int SetChannelVolume(int channel, int volume);
81 /// Set the channel stereo
82 extern int SetChannelStereo(int channel, int stereo);
83 /// Set the channel's callback for when a sound finishes playing
84 extern void SetChannelFinishedCallback(int channel, void (*callback)(int channel));
85 /// Get the sample playing on a channel
86 extern CSample *GetChannelSample(int channel);
87 /// Stop a channel
88 extern void StopChannel(int channel);
89 /// Stop all channels
90 extern void StopAllChannels();
91
92 /// Load a sample
93 extern CSample *LoadSample(const std::string &name);
94 /// Play a sample
95 extern int PlaySample(CSample *sample);
96 /// Play a sound file
97 extern int PlaySoundFile(const std::string &name);
98
99 /// Set effects volume
100 extern void SetEffectsVolume(int volume);
101 /// Get effects volume
102 extern int GetEffectsVolume(void);
103 /// Set effects enabled
104 extern void SetEffectsEnabled(bool enabled);
105 /// Check if effects are enabled
106 extern bool IsEffectsEnabled(void);
107
108 /// Set the music finished callback
109 void SetMusicFinishedCallback(void (*callback)(void));
110 /// Play a music file
111 extern int PlayMusic(CSample *sample);
112 /// Play a music file
113 extern int PlayMusic(const std::string &file);
114 /// Stop music playing
115 extern void StopMusic(void);
116 /// Set music volume
117 extern void SetMusicVolume(int volume);
118 /// Get music volume
119 extern int GetMusicVolume(void);
120 /// Set music enabled
121 extern void SetMusicEnabled(bool enabled);
122 /// Check if music is enabled
123 extern bool IsMusicEnabled(void);
124 /// Check if music is playing
125 extern bool IsMusicPlaying(void);
126
127 /// Check if sound is enabled
128 extern bool SoundEnabled(void);
129 /// Initialize the sound card.
130 extern int InitSound(void);
131 /// Cleanup sound.
132 extern void QuitSound(void);
133
134 //@}
135
136 #endif // !__SOUND_SERVER_H__