Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
audio.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
#include "support.h"
#include "audio_none.h"
#include "client_main.h"
#include "music.h"
#include "options.h"
#include "audio.h"

Go to the source code of this file.

Data Structures

struct  mfcb_data
 

Macros

#define MAX_NUM_PLUGINS   2
 
#define SNDSPEC_SUFFIX   ".soundspec"
 
#define MUSICSPEC_SUFFIX   ".musicspec"
 
#define SOUNDSPEC_CAPSTR   "+Freeciv-3.2-soundset"
 
#define MUSICSPEC_CAPSTR   "+Freeciv-3.2-musicspec"
 

Functions

static int audio_play_tag (struct section_file *sfile, const char *tag, bool repeat, int exclude, bool keep_old_style)
 
static void audio_shutdown_atexit (void)
 
const struct strvecget_soundplugin_list (const struct option *poption)
 
static const struct strvecget_audio_speclist (const char *suffix, struct strvec **audio_list)
 
const struct strvecget_soundset_list (const struct option *poption)
 
const struct strvecget_musicset_list (const struct option *poption)
 
void audio_add_plugin (struct audio_plugin *p)
 
bool audio_select_plugin (const char *const name)
 
void audio_init (void)
 
static const charaudiospec_fullname (const char *audioset_name, bool music)
 
static bool check_audiofile_capstr (struct section_file *sfile, const char *filename, const char *our_cap, const char *opt_path)
 
void audio_real_init (const char *const soundset_name, const char *const musicset_name, const char *const preferred_plugin_name)
 
void audio_restart (const char *soundset_name, const char *musicset_name)
 
static void music_finished_callback (void)
 
static bool audio_play_sound_tag (const char *tag, bool repeat)
 
static int audio_play_music_tag (const char *tag, bool repeat, bool keep_old_style)
 
void audio_play_sound (const char *const tag, const char *const alt_tag, const char *const alt_tag2)
 
static void real_audio_play_music (const char *const tag, char *const alt_tag, bool keep_old_style)
 
void audio_play_music (const char *const tag, char *const alt_tag, enum music_usage usage)
 
void audio_play_track (const char *const tag, char *const alt_tag)
 
void audio_pause (void)
 
void audio_resume (void)
 
void audio_stop (void)
 
void audio_stop_usage (void)
 
double audio_get_volume (void)
 
void audio_set_volume (double volume)
 
void audio_shutdown (bool play_quit_tag)
 
const charaudio_get_all_plugin_names (void)
 

Variables

static struct section_filess_tagfile = NULL
 
static struct section_filems_tagfile = NULL
 
static struct audio_plugin plugins [MAX_NUM_PLUGINS]
 
static int num_plugins_used = 0
 
static int selected_plugin = -1
 
static int current_track = -1
 
static enum music_usage current_usage
 
static bool switching_usage = FALSE
 
static bool let_single_track_play = FALSE
 
static struct mfcb_data mfcb
 

Macro Definition Documentation

◆ MAX_NUM_PLUGINS

#define MAX_NUM_PLUGINS   2

Definition at line 44 of file audio.c.

◆ MUSICSPEC_CAPSTR

#define MUSICSPEC_CAPSTR   "+Freeciv-3.2-musicspec"

Definition at line 49 of file audio.c.

◆ MUSICSPEC_SUFFIX

#define MUSICSPEC_SUFFIX   ".musicspec"

Definition at line 46 of file audio.c.

◆ SNDSPEC_SUFFIX

#define SNDSPEC_SUFFIX   ".soundspec"

Definition at line 45 of file audio.c.

◆ SOUNDSPEC_CAPSTR

#define SOUNDSPEC_CAPSTR   "+Freeciv-3.2-soundset"

Definition at line 48 of file audio.c.

Function Documentation

◆ audio_add_plugin()

void audio_add_plugin ( struct audio_plugin p)

Add a plugin.

Definition at line 136 of file audio.c.

Referenced by audio_none_init(), and audio_sdl_init().

◆ audio_get_all_plugin_names()

const char * audio_get_all_plugin_names ( void  )

Returns a string which list all available plugins. You don't have to free the string.

Definition at line 694 of file audio.c.

Referenced by audio_select_plugin(), and client_main().

◆ audio_get_volume()

double audio_get_volume ( void  )

Get sound volume currently in use.

Definition at line 639 of file audio.c.

◆ audio_init()

void audio_init ( void  )

Initialize base audio system. Note that this function is called very early at the client startup. So for example logging isn't available.

Definition at line 188 of file audio.c.

Referenced by client_main().

◆ audio_pause()

void audio_pause ( void  )

Pause sound.

Definition at line 606 of file audio.c.

Referenced by timer_callback().

◆ audio_play_music()

void audio_play_music ( const char *const  tag,
char *const  alt_tag,
enum music_usage  usage 
)

Loop music as suggested by sound tags

Definition at line 578 of file audio.c.

Referenced by start_menu_music(), and start_style_music().

◆ audio_play_music_tag()

static int audio_play_music_tag ( const char tag,
bool  repeat,
bool  keep_old_style 
)
static

Play tag from music set

Definition at line 519 of file audio.c.

Referenced by real_audio_play_music().

◆ audio_play_sound()

void audio_play_sound ( const char *const  tag,
const char *const  alt_tag,
const char *const  alt_tag2 
)

◆ audio_play_sound_tag()

static bool audio_play_sound_tag ( const char tag,
bool  repeat 
)
static

Play tag from sound set

Definition at line 511 of file audio.c.

Referenced by audio_play_sound().

◆ audio_play_tag()

static int audio_play_tag ( struct section_file sfile,
const char tag,
bool  repeat,
int  exclude,
bool  keep_old_style 
)
static

INTERNAL. Returns id (>= 0) of the tag selected for playing, 0 when there's no alternative tags, or negative value in case of error.

Definition at line 426 of file audio.c.

Referenced by audio_play_music_tag(), audio_play_sound_tag(), and music_finished_callback().

◆ audio_play_track()

void audio_play_track ( const char *const  tag,
char *const  alt_tag 
)

Play single track as suggested by sound tags

Definition at line 589 of file audio.c.

Referenced by play_single_track().

◆ audio_real_init()

void audio_real_init ( const char *const  soundset_name,
const char *const  musicset_name,
const char *const  preferred_plugin_name 
)

Initialize audio system and autoselect a plugin

Definition at line 274 of file audio.c.

Referenced by audio_restart(), and client_main().

◆ audio_restart()

void audio_restart ( const char soundset_name,
const char musicset_name 
)

◆ audio_resume()

void audio_resume ( void  )

Resume sound.

Definition at line 614 of file audio.c.

Referenced by timer_callback().

◆ audio_select_plugin()

bool audio_select_plugin ( const char *const  name)

Choose plugin. Returns TRUE on success, FALSE if not

Definition at line 146 of file audio.c.

Referenced by audio_real_init().

◆ audio_set_volume()

void audio_set_volume ( double  volume)

Set sound volume to use.

Definition at line 647 of file audio.c.

◆ audio_shutdown()

void audio_shutdown ( bool  play_quit_tag)

Call this at end of program only.

Parameters
play_quit_tagPlay exit sound

Definition at line 657 of file audio.c.

Referenced by audio_shutdown_atexit(), and client_exit().

◆ audio_shutdown_atexit()

static void audio_shutdown_atexit ( void  )
static

Called as atexit handler.

Definition at line 684 of file audio.c.

Referenced by audio_real_init().

◆ audio_stop()

void audio_stop ( void  )

Stop sound. Music should die down in a few seconds.

Definition at line 622 of file audio.c.

Referenced by audio_play_track(), audio_restart(), and audio_shutdown().

◆ audio_stop_usage()

void audio_stop_usage ( void  )

Stop looping sound. Music should die down in a few seconds.

Definition at line 630 of file audio.c.

Referenced by stop_menu_music(), and stop_style_music().

◆ audiospec_fullname()

static const char * audiospec_fullname ( const char audioset_name,
bool  music 
)
static

Returns the filename for the given audio set. Returns NULL if set couldn't be found. Caller has to free the return value.

Definition at line 204 of file audio.c.

Referenced by audio_real_init(), and audiospec_fullname().

◆ check_audiofile_capstr()

static bool check_audiofile_capstr ( struct section_file sfile,
const char filename,
const char our_cap,
const char opt_path 
)
static

Check capabilities of the audio specfile

Definition at line 239 of file audio.c.

Referenced by audio_real_init().

◆ get_audio_speclist()

static const struct strvec * get_audio_speclist ( const char suffix,
struct strvec **  audio_list 
)
static

Returns a static string vector of audiosets of given type available on the system by searching all data directories for files matching suffix. The list is NULL-terminated.

Definition at line 103 of file audio.c.

Referenced by get_musicset_list(), and get_soundset_list().

◆ get_musicset_list()

const struct strvec * get_musicset_list ( const struct option poption)

Returns a static string vector of musicsets available on the system.

Definition at line 126 of file audio.c.

◆ get_soundplugin_list()

const struct strvec * get_soundplugin_list ( const struct option poption)

Returns a static string vector of all sound plugins available on the system. This function is unfortunately similar to audio_get_all_plugin_names().

Definition at line 80 of file audio.c.

◆ get_soundset_list()

const struct strvec * get_soundset_list ( const struct option poption)

Returns a static string vector of soundsets available on the system.

Definition at line 116 of file audio.c.

◆ music_finished_callback()

static void music_finished_callback ( void  )
static

Callback to start new track

Definition at line 388 of file audio.c.

Referenced by audio_play_tag().

◆ real_audio_play_music()

static void real_audio_play_music ( const char *const  tag,
char *const  alt_tag,
bool  keep_old_style 
)
static

Play music, either in loop or just one track in the middle of the style music.

Definition at line 554 of file audio.c.

Referenced by audio_play_music(), and audio_play_track().

Variable Documentation

◆ current_track

int current_track = -1
static

Definition at line 58 of file audio.c.

Referenced by audio_play_track(), music_finished_callback(), and real_audio_play_music().

◆ current_usage

enum music_usage current_usage
static

Definition at line 59 of file audio.c.

Referenced by audio_play_music(), and music_finished_callback().

◆ let_single_track_play

bool let_single_track_play = FALSE
static

Definition at line 61 of file audio.c.

Referenced by audio_play_track(), and music_finished_callback().

◆ mfcb

struct mfcb_data mfcb
static

◆ ms_tagfile

struct section_file* ms_tagfile = NULL
static

Definition at line 53 of file audio.c.

Referenced by audio_play_music_tag(), audio_real_init(), and audio_shutdown().

◆ num_plugins_used

int num_plugins_used = 0
static

◆ plugins

◆ selected_plugin

int selected_plugin = -1
static

◆ ss_tagfile

struct section_file* ss_tagfile = NULL
static

Definition at line 52 of file audio.c.

Referenced by audio_play_sound_tag(), audio_real_init(), and audio_shutdown().

◆ switching_usage

bool switching_usage = FALSE
static

Definition at line 60 of file audio.c.

Referenced by audio_stop_usage(), and music_finished_callback().