Atrinik Client  4.0
Functions | Variables
sound.c File Reference
#include <global.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <toolkit/path.h>

Go to the source code of this file.

Functions

void sound_background_hook_register (void *ptr)
 
void sound_init (void)
 
static void sound_cache_free (void)
 
void sound_deinit (void)
 
void sound_clear_cache (void)
 
static int sound_add_effect (const char *filename, int volume, int loop)
 
void sound_play_effect (const char *filename, int volume)
 
int sound_play_effect_loop (const char *filename, int volume, int loop)
 
void sound_start_bg_music (const char *filename, int volume, int loop)
 
void sound_stop_bg_music (void)
 
void sound_pause_music (void)
 
void sound_resume_music (void)
 
void update_map_bg_music (const char *bg_music)
 
void sound_update_volume (void)
 
const char * sound_get_bg_music (void)
 
const char * sound_get_bg_music_basename (void)
 
uint8_t sound_map_background (int val)
 
uint32_t sound_music_get_offset (void)
 
int sound_music_can_seek (void)
 
void sound_music_seek (uint32_t offset)
 
uint32_t sound_music_get_duration ()
 
void socket_command_sound (uint8_t *data, size_t len, size_t pos)
 
static void sound_ambient_free (sound_ambient_struct *tmp)
 
static void sound_ambient_set_position (sound_ambient_struct *tmp)
 
void sound_ambient_mapcroll (int xoff, int yoff)
 
void sound_ambient_clear (void)
 
void socket_command_sound_ambient (uint8_t *data, size_t len, size_t pos)
 
int sound_playing_music (void)
 

Variables

static char * sound_background
 
static uint8_t sound_map_background_disabled = 0
 
static uint8_t enabled = 0
 
static sound_ambient_structsound_ambient_head = NULL
 

Detailed Description

Sound related functions.

Author
Alex Tokar

Definition in file sound.c.

Function Documentation

void socket_command_sound ( uint8_t *  data,
size_t  len,
size_t  pos 
)

Definition at line 701 of file sound.c.

void socket_command_sound_ambient ( uint8_t *  data,
size_t  len,
size_t  pos 
)

Definition at line 844 of file sound.c.

static int sound_add_effect ( const char *  filename,
int  volume,
int  loop 
)
static

Add sound effect to the playing queue.

Parameters
filenameSound file name to play. Will be loaded as needed.
volumeVolume to play at.
loopHow many times to loop, -1 for infinite number.
Returns
Channel the sound effect is being played on, -1 on failure.

Definition at line 321 of file sound.c.

void sound_ambient_clear ( void  )

Stop all ambient sound effects.

Definition at line 833 of file sound.c.

static void sound_ambient_free ( sound_ambient_struct tmp)
static

Free an ambient sound effect.

The sound effect

Parameters
tmpSound effect to free.

Definition at line 755 of file sound.c.

void sound_ambient_mapcroll ( int  xoff,
int  yoff 
)

Handle map scroll for ambient sound effects. We need to check whether the sound effect is now off-screen and if so, remove it. We also need to adjust the angle and distance effects of the channel the sound effect is playing on.

Parameters
xoffX offset.
yoffY offset.

Definition at line 809 of file sound.c.

static void sound_ambient_set_position ( sound_ambient_struct tmp)
static

Set distance and angle of an ambient sound effect.

Parameters
tmpSound effect.

Definition at line 769 of file sound.c.

void sound_background_hook_register ( void *  ptr)

Register a new sound_background_hook callback.

Parameters
ptrNew callback to register.

Definition at line 238 of file sound.c.

static void sound_cache_free ( void  )
static

Free the sound cache.

Definition at line 271 of file sound.c.

void sound_clear_cache ( void  )

Hook for clearing the sound API cache.

Definition at line 305 of file sound.c.

void sound_deinit ( void  )

Deinitialize the sound system.

Definition at line 287 of file sound.c.

const char* sound_get_bg_music ( void  )

Get the currently playing background music, if any.

Returns
Background music file name, NULL if no music is playing.

Definition at line 577 of file sound.c.

const char* sound_get_bg_music_basename ( void  )

Get the background music base file name.

Returns
The background music base file name, if any. NULL otherwise.

Definition at line 587 of file sound.c.

void sound_init ( void  )

Initialize the sound system.

Definition at line 248 of file sound.c.

uint8_t sound_map_background ( int  val)

Get or set sound_map_background_disabled.

Parameters
valIf -1, will return the current value of sound_map_background_disabled; any other value will set sound_map_background_disabled to that value.
Returns
Value of sound_map_background_disabled.

Definition at line 608 of file sound.c.

int sound_music_can_seek ( void  )

Check whether the currently playing music can seek to a different position.

Returns
1 if the music can have playing position changed, 0 otherwise.

Definition at line 642 of file sound.c.

uint32_t sound_music_get_duration ( void  )

Get duration of the currently playing background music.

Returns
The duration.

Definition at line 691 of file sound.c.

uint32_t sound_music_get_offset ( void  )

Get the offset of the background music that is being played.

Returns
The offset.

Definition at line 623 of file sound.c.

void sound_music_seek ( uint32_t  offset)

Seek the currently playing background music to the specified offset (in seconds).

Parameters
offsetOffset to seek to.

Definition at line 669 of file sound.c.

void sound_pause_music ( void  )

Pause playing background music.

Definition at line 500 of file sound.c.

void sound_play_effect ( const char *  filename,
int  volume 
)

Play a sound effect.

Parameters
filenameSound file name to play.
volumeVolume to play at.

Definition at line 367 of file sound.c.

int sound_play_effect_loop ( const char *  filename,
int  volume,
int  loop 
)

Same as sound_play_effect(), but allows specifying how many times to loop the sound effect.

Parameters
filenameSound file name to play.
volumeVolume to play at.
loopHow many times to loop the sound effect, -1 to loop it infinitely.
Returns
Channel the sound effect will be playing on, -1 on failure.

Definition at line 390 of file sound.c.

int sound_playing_music ( void  )

Check whether background music is being played.

Returns
1 if background music is being played, 0 otherwise.

Definition at line 903 of file sound.c.

void sound_resume_music ( void  )

Resume playing background music.

Definition at line 511 of file sound.c.

void sound_start_bg_music ( const char *  filename,
int  volume,
int  loop 
)

Start background music.

Parameters
filenameFilename of the music to start.
volumeVolume to use.
loopHow many times to loop, -1 for infinite number.

Definition at line 412 of file sound.c.

void sound_stop_bg_music ( void  )

Stop the background music, if there is any.

Definition at line 481 of file sound.c.

void sound_update_volume ( void  )

Update volume of the background sound being played.

Definition at line 547 of file sound.c.

void update_map_bg_music ( const char *  bg_music)

Update map's background music.

Parameters
bg_musicNew background music.

Definition at line 523 of file sound.c.

Variable Documentation

uint8_t enabled = 0
static

Whether the sound system is active.

Definition at line 48 of file sound.c.

sound_ambient_struct* sound_ambient_head = NULL
static

Doubly-linked list of all playing ambient sound effects.

Definition at line 52 of file sound.c.

char* sound_background
static

Path to the background music file being played.

Definition at line 40 of file sound.c.

uint8_t sound_map_background_disabled = 0
static

If 1, will not allow music change based on map.

Definition at line 44 of file sound.c.