_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sound_server.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2005 by Lutz Sammer, Fabrice Rossi, and
14 // Jimmy Salmon
15 //
16 // This program is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; only version 2 of the License.
19 //
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 // 02111-1307, USA.
29 //
30 
31 #ifndef __SOUND_SERVER_H__
32 #define __SOUND_SERVER_H__
33 
35 
36 /*----------------------------------------------------------------------------
37 -- Includes
38 ----------------------------------------------------------------------------*/
39 
40 #include "sound.h"
41 
42 /*----------------------------------------------------------------------------
43 -- Definitons
44 ----------------------------------------------------------------------------*/
45 
46 #define MaxVolume 255
47 #define SOUND_BUFFER_SIZE 65536
48 
52 class CSample
53 {
54 public:
56  Buffer(NULL), Pos(0), Len(0) {}
57  virtual ~CSample() {}
58 
59  virtual int Read(void *buf, int len) = 0;
60 
61  unsigned char Channels;
62  unsigned char SampleSize;
63  unsigned int Frequency;
64  unsigned short BitsPerSample;
65 
66  unsigned char *Buffer;
67  int Pos;
68  int Len;
69 };
70 
79 };
80 
84 #ifdef USE_FLUIDSYNTH
86 {
90 };
91 #endif
92 
93 /*----------------------------------------------------------------------------
94 -- Functions
95 ----------------------------------------------------------------------------*/
96 
97 extern CSample *LoadWav(const char *name, int flags);
98 extern CSample *LoadVorbis(const char *name, int flags);
99 extern CSample *LoadMikMod(const char *name, int flags);
100 extern CSample *LoadFluidSynth(const char *name, int flags);
101 
103 extern int SetChannelVolume(int channel, int volume);
105 extern int SetChannelStereo(int channel, int stereo);
107 extern void SetChannelFinishedCallback(int channel, void (*callback)(int channel));
109 extern CSample *GetChannelSample(int channel);
111 extern void StopChannel(int channel);
113 extern void StopAllChannels();
114 
116 extern bool UnitSoundIsPlaying(Origin *origin);
118 extern bool SampleIsPlaying(CSample *sample);
120 extern CSample *LoadSample(const std::string &name);
122 extern int PlaySample(CSample *sample, Origin *origin = NULL);
124 extern int PlaySoundFile(const std::string &name);
125 
127 extern void SetEffectsVolume(int volume);
129 extern int GetEffectsVolume();
131 extern void SetEffectsEnabled(bool enabled);
133 extern bool IsEffectsEnabled();
134 
136 void SetMusicFinishedCallback(void (*callback)());
138 extern int PlayMusic(CSample *sample);
140 extern int PlayMusic(const std::string &file);
142 extern void StopMusic();
144 extern void SetMusicVolume(int volume);
146 extern int GetMusicVolume();
148 extern void SetMusicEnabled(bool enabled);
150 extern bool IsMusicEnabled();
152 extern bool IsMusicPlaying();
153 
155 extern bool SoundEnabled();
157 extern int InitSound();
159 extern void QuitSound();
160 
161 #ifdef USE_FLUIDSYNTH
165 extern int InitFluidSynth();
166 // Cleans all FluidSynth data
167 extern void CleanFluidSynth(bool reinit = false);
168 #endif
169 
171 
172 #endif // !__SOUND_SERVER_H__
void SetMusicEnabled(bool enabled)
Set music enabled.
Definition: sound_server.cpp:753
Definition: sound_server.h:88
void SetEffectsEnabled(bool enabled)
Set effects enabled.
Definition: sound_server.cpp:643
CSample * LoadFluidSynth(const char *name, int flags)
Load a module file.
Definition: fluidsynth.cpp:249
Definition: sound.h:145
int GetEffectsVolume()
Get effects volume.
Definition: sound_server.cpp:635
Load compressed in memory.
Definition: sound_server.h:77
bool SampleIsPlaying(CSample *sample)
Check, if this sample is already playing.
Definition: sound_server.cpp:363
void SetEffectsVolume(int volume)
Set effects volume.
Definition: sound_server.cpp:626
virtual ~CSample()
Definition: sound_server.h:57
int GetMusicVolume()
Get music volume.
Definition: sound_server.cpp:745
int PlayMusic(CSample *sample)
Play a music file.
Definition: sound_server.cpp:675
unsigned int Frequency
sample size in bits
Definition: sound_server.h:63
CSample()
Definition: sound_server.h:55
unsigned short BitsPerSample
frequency in hz
Definition: sound_server.h:64
_play_audio_flags_
Definition: sound_server.h:74
unsigned char Channels
Definition: sound_server.h:61
int PlaySoundFile(const std::string &name)
Play a sound file.
Definition: sound_server.cpp:612
virtual int Read(void *buf, int len)=0
CSample * GetChannelSample(int channel)
Get the sample playing on a channel.
Definition: sound_server.cpp:499
SynthState
Definition: sound_server.h:85
void SetMusicVolume(int volume)
Set music volume.
Definition: sound_server.cpp:736
void StopAllChannels()
Stop all channels.
Definition: sound_server.cpp:526
CSample * LoadVorbis(const char *name, int flags)
Load a wav file.
Definition: ogg.cpp:390
bool IsMusicPlaying()
Check if music is playing.
Definition: sound_server.cpp:774
int Len
buffer position
Definition: sound_server.h:68
int InitSound()
Initialize the sound card.
Definition: sound_server.cpp:831
bool UnitSoundIsPlaying(Origin *origin)
Check if this unit plays some sound.
Definition: sound_server.cpp:373
int InitFluidSynth()
Init FluidSynth library.
Definition: fluidsynth.cpp:190
bool SoundEnabled()
Check if sound is enabled.
Definition: sound_server.cpp:786
void CleanFluidSynth(bool reinit=false)
Definition: fluidsynth.cpp:166
bool IsEffectsEnabled()
Check if effects are enabled.
Definition: sound_server.cpp:651
int Pos
sample buffer
Definition: sound_server.h:67
Definition: sound_server.h:87
void QuitSound()
Cleanup sound.
Definition: sound_server.cpp:866
Preload file into memory.
Definition: sound_server.h:78
void SetChannelFinishedCallback(int channel, void(*callback)(int channel))
Set the channel's callback for when a sound finishes playing.
Definition: sound_server.cpp:488
void StopChannel(int channel)
Stop a channel.
Definition: sound_server.cpp:512
CSample * LoadSample(const std::string &name)
Load a sample.
Definition: sound_server.cpp:575
SynthState GetFluidSynthState()
Gets the state of Fluidsynth player.
Definition: fluidsynth.cpp:157
void SetMusicFinishedCallback(void(*callback)())
Set the music finished callback.
Definition: sound_server.cpp:663
Definition: sound_server.h:75
unsigned char * Buffer
bits in a sample 8/16/32
Definition: sound_server.h:66
int SetChannelStereo(int channel, int stereo)
Set the channel stereo.
Definition: sound_server.cpp:463
CSample * LoadMikMod(const char *name, int flags)
Load a vorbis file.
Definition: mikmod.cpp:196
Definition: sound_server.h:89
Definition: sound_server.h:52
Stream the file from medium.
Definition: sound_server.h:76
unsigned char SampleSize
mono or stereo
Definition: sound_server.h:62
bool IsMusicEnabled()
Check if music is enabled.
Definition: sound_server.cpp:766
int SetChannelVolume(int channel, int volume)
Load a MIDI file.
Definition: sound_server.cpp:436
int PlaySample(CSample *sample, Origin *origin=NULL)
Play a sample.
Definition: sound_server.cpp:593
void StopMusic()
Stop music playing.
Definition: sound_server.cpp:718
CSample * LoadWav(const char *name, int flags)
Definition: wav.cpp:230
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.