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

Classes
sound_server.cpp File Reference
#include <numeric>
#include "stratagus.h"
#include "sound_server.h"
#include "fluidsynth.h"
#include "iocompat.h"
#include "iolib.h"
#include "unit.h"
#include "SDL.h"
#include "SDL_mixer.h"

Classes

struct  SoundChannel
 Channels for sound effects and unit speech. More...
 

sound_server.cpp - The sound server (hardware layer and so on)

#define MaxChannels   64
 
uint32_t SDL_SOUND_FINISHED
 
static bool SoundInitialized
 
static bool MusicEnabled = true
 is sound initialized More...
 
static bool EffectsEnabled = true
 
static double VolumeScale = 1.0
 
static int MusicVolume = 0
 
static bool externalPlayerIsPlaying = false
 
static HANDLE g_hStatusThread
 
static HANDLE g_hDebugThread
 
static HANDLE g_hChildStd_IN_Wr
 
static PROCESS_INFORMATION pi
 
static SoundChannel Channels [MaxChannels]
 
static Mix_Music * currentMusic = NULL
 
static DWORD WINAPI StatusThreadFunction (LPVOID lpParam)
 
static DWORD WINAPI DebugThreadFunction (LPVOID lpParam)
 
static void KillPlayingProcess ()
 
static bool External_Play (const std::string &file)
 
static bool External_IsPlaying ()
 
static bool External_Stop ()
 
static bool External_Volume (int volume, int oldVolume)
 
static void ChannelFinished (int channel)
 
bool SampleIsPlaying (Mix_Chunk *sample)
 Check, if this sample is already playing. More...
 
bool UnitSoundIsPlaying (Origin *origin)
 Check if this unit plays some sound. More...
 
void HandleSoundEvent (SDL_Event &event)
 
int SetChannelVolume (int channel, int volume)
 Set the channel volume. More...
 
void SetChannelStereo (int channel, int stereo)
 Set the channel stereo. More...
 
Mix_Chunk * GetChannelSample (int channel)
 Get the sample playing on a channel. More...
 
void StopChannel (int channel)
 Stop a channel. More...
 
void StopAllChannels ()
 Stop all channels. More...
 
static Mix_Music * LoadMusic (const char *name)
 
static Mix_Chunk * ForceLoadSample (const char *name)
 
static Mix_Chunk * LoadSample (const char *name)
 
Mix_Music * LoadMusic (const std::string &name)
 Load music. More...
 
Mix_Chunk * LoadSample (const std::string &name)
 Load a sample. More...
 
void FreeSample (Mix_Chunk *sample)
 
static int PlaySample (Mix_Chunk *sample, Origin *origin, void(*callback)(int channel))
 
int PlaySample (Mix_Chunk *sample, Origin *origin)
 Play a sample. More...
 
int PlaySample (Mix_Chunk *sample, void(*callback)(int channel))
 Play a sample, registering a "finished" callback. More...
 
void SetEffectsVolume (int volume)
 Set effects volume. More...
 
int GetEffectsVolume ()
 Get effects volume. More...
 
void SetEffectsEnabled (bool enabled)
 Set effects enabled. More...
 
bool IsEffectsEnabled ()
 Check if effects are enabled. More...
 
void SetMusicFinishedCallback (void(*callback)())
 Set the music finished callback. More...
 
int PlayMusic (const std::string &file)
 Play a music file. More...
 
void StopMusic ()
 Stop music playing. More...
 
void SetMusicVolume (int volume)
 Set music volume. More...
 
int GetMusicVolume ()
 Get music volume. More...
 
void SetMusicEnabled (bool enabled)
 Set music enabled. More...
 
bool IsMusicEnabled ()
 Check if music is enabled. More...
 
bool IsMusicPlaying ()
 Check if music is playing. More...
 
bool SoundEnabled ()
 Check if sound is enabled. More...
 
static int InitSdlSound ()
 
int InitSound ()
 Initialize the sound card. More...
 
void QuitSound ()
 Cleanup sound. More...
 

Macro Definition Documentation

◆ MaxChannels

#define MaxChannels   64

Function Documentation

◆ ChannelFinished()

static void ChannelFinished ( int  channel)
static

A channel is finished playing

◆ DebugThreadFunction()

static DWORD WINAPI DebugThreadFunction ( LPVOID  lpParam)
static

◆ External_IsPlaying()

static bool External_IsPlaying ( )
static

◆ External_Play()

static bool External_Play ( const std::string &  file)
static

◆ External_Stop()

static bool External_Stop ( )
static

◆ External_Volume()

static bool External_Volume ( int  volume,
int  oldVolume 
)
static

◆ ForceLoadSample()

static Mix_Chunk* ForceLoadSample ( const char *  name)
static

◆ FreeSample()

void FreeSample ( Mix_Chunk *  sample)

Free a sample loaded with LoadSample.

Parameters
sample

◆ GetChannelSample()

Mix_Chunk* GetChannelSample ( int  channel)

Get the sample playing on a channel.

Get the sample playing on a channel

◆ GetEffectsVolume()

int GetEffectsVolume ( )

Get effects volume.

Get effects volume

◆ GetMusicVolume()

int GetMusicVolume ( )

Get music volume.

Get music volume

◆ HandleSoundEvent()

void HandleSoundEvent ( SDL_Event &  event)

◆ InitSdlSound()

static int InitSdlSound ( )
static

Initialize sound card hardware part with SDL.

Parameters
freqSample frequency (44100,22050,11025 hz).
sizeSample size (8bit, 16bit)
Returns
True if failure, false if everything ok.

◆ InitSound()

int InitSound ( )

Initialize the sound card.

Initialize sound card.

Returns
True if failure, false if everything ok.

◆ IsEffectsEnabled()

bool IsEffectsEnabled ( )

Check if effects are enabled.

Check if effects are enabled

◆ IsMusicEnabled()

bool IsMusicEnabled ( )

Check if music is enabled.

Check if music is enabled

◆ IsMusicPlaying()

bool IsMusicPlaying ( )

Check if music is playing.

Check if music is playing

◆ KillPlayingProcess()

static void KillPlayingProcess ( )
static

◆ LoadMusic() [1/2]

static Mix_Music* LoadMusic ( const char *  name)
static

◆ LoadMusic() [2/2]

Mix_Music* LoadMusic ( const std::string &  name)

Load music.

Load a music file

Parameters
nameFile name
Returns
Mix_Music pointer

◆ LoadSample() [1/2]

static Mix_Chunk* LoadSample ( const char *  name)
static

◆ LoadSample() [2/2]

Mix_Chunk* LoadSample ( const std::string &  name)

Load a sample.

Load a sample

Parameters
nameFile name of sample (short version).
Returns
General sample loaded from file into memory.
Todo:
Add streaming, caching support.

◆ PlayMusic()

int PlayMusic ( const std::string &  file)

Play a music file.

Play a music file. This also enables the music finished callback.

Parameters
fileName of music file, format is automatically detected.
Returns
0 if music is playing, -1 if not.

◆ PlaySample() [1/3]

int PlaySample ( Mix_Chunk *  sample,
Origin origin 
)

Play a sample.

◆ PlaySample() [2/3]

static int PlaySample ( Mix_Chunk *  sample,
Origin origin,
void(*)(int channel)  callback 
)
static

Play a sound sample

Parameters
sampleSample to play
Returns
Channel number, -1 for error

◆ PlaySample() [3/3]

int PlaySample ( Mix_Chunk *  sample,
void(*)(int channel)  callback 
)

Play a sample, registering a "finished" callback.

◆ QuitSound()

void QuitSound ( )

Cleanup sound.

Cleanup sound server.

◆ SampleIsPlaying()

bool SampleIsPlaying ( Mix_Chunk *  sample)

Check, if this sample is already playing.

Check if this sound is already playing

◆ SetChannelStereo()

void SetChannelStereo ( int  channel,
int  stereo 
)

Set the channel stereo.

Set the channel stereo

Parameters
channelChannel to set
stereo-128 to 127, out of range will not set the stereo
Returns
Current stereo of the channel, -1 for error

◆ SetChannelVolume()

int SetChannelVolume ( int  channel,
int  volume 
)

Set the channel volume.

Set the channel volume

Parameters
channelChannel to set
volumeNew volume 0-255, <0 will not set the volume
Returns
Current volume of the channel, -1 for error

◆ SetEffectsEnabled()

void SetEffectsEnabled ( bool  enabled)

Set effects enabled.

Set effects enabled

◆ SetEffectsVolume()

void SetEffectsVolume ( int  volume)

Set effects volume.

Set the global sound volume.

Parameters
volumethe sound volume 0-255

◆ SetMusicEnabled()

void SetMusicEnabled ( bool  enabled)

Set music enabled.

Set music enabled

◆ SetMusicFinishedCallback()

void SetMusicFinishedCallback ( void(*)()  callback)

Set the music finished callback.

Set the music finished callback

◆ SetMusicVolume()

void SetMusicVolume ( int  volume)

Set music volume.

Set the music volume.

Parameters
volumethe music volume 0-255

◆ SoundEnabled()

bool SoundEnabled ( )

Check if sound is enabled.

Check if sound is enabled

◆ StatusThreadFunction()

static DWORD WINAPI StatusThreadFunction ( LPVOID  lpParam)
static

◆ StopAllChannels()

void StopAllChannels ( )

Stop all channels.

Stop all channels

◆ StopChannel()

void StopChannel ( int  channel)

Stop a channel.

Stop a channel

Parameters
channelChannel to stop

◆ StopMusic()

void StopMusic ( )

Stop music playing.

Stop the current playing music. This does not trigger the music finished callback.

◆ UnitSoundIsPlaying()

bool UnitSoundIsPlaying ( Origin origin)

Check if this unit plays some sound.

Variable Documentation

◆ Channels

SoundChannel Channels[MaxChannels]
static

◆ currentMusic

Mix_Music* currentMusic = NULL
static

◆ EffectsEnabled

bool EffectsEnabled = true
static

◆ externalPlayerIsPlaying

bool externalPlayerIsPlaying = false
static

◆ g_hChildStd_IN_Wr

HANDLE g_hChildStd_IN_Wr
static

◆ g_hDebugThread

HANDLE g_hDebugThread
static

◆ g_hStatusThread

HANDLE g_hStatusThread
static

◆ MusicEnabled

bool MusicEnabled = true
static

is sound initialized

◆ MusicVolume

int MusicVolume = 0
static

◆ pi

PROCESS_INFORMATION pi
static

◆ SDL_SOUND_FINISHED

uint32_t SDL_SOUND_FINISHED

◆ SoundInitialized

bool SoundInitialized
static

◆ VolumeScale

double VolumeScale = 1.0
static
(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.