pnmixer
Volume mixer for the system tray
Data Structures | Typedefs | Functions
audio.c File Reference

Audio subsystem. More...

#include <glib.h>
#include "audio.h"
#include "alsa.h"
#include "prefs.h"
#include "support-log.h"
Include dependency graph for audio.c:

Go to the source code of this file.

Data Structures

struct  audio_handler
 
struct  audio
 

Typedefs

typedef struct audio_handler AudioHandler
 

Functions

static const gchar * audio_user_to_str (AudioUser user)
 
static const gchar * audio_signal_to_str (AudioSignal signal)
 
static void audio_event_free (AudioEvent *event)
 
static AudioEventaudio_event_new (Audio *audio, AudioSignal signal, AudioUser user)
 
static void audio_handler_free (AudioHandler *handler)
 
static AudioHandleraudio_handler_new (AudioCallback callback, gpointer data)
 
static gint audio_handler_cmp (AudioHandler *h1, AudioHandler *h2)
 
static GSList * audio_handler_list_append (GSList *list, AudioHandler *handler)
 
static GSList * audio_handler_list_remove (GSList *list, AudioHandler *handler)
 
static void invoke_handlers (Audio *audio, AudioSignal signal, AudioUser user)
 
static void on_alsa_event (enum alsa_event event, gpointer data)
 
void audio_signals_disconnect (Audio *audio, AudioCallback callback, gpointer data)
 
void audio_signals_connect (Audio *audio, AudioCallback callback, gpointer data)
 
const char * audio_get_card (Audio *audio)
 
const char * audio_get_channel (Audio *audio)
 
gboolean audio_has_mute (Audio *audio)
 
gboolean audio_is_muted (Audio *audio)
 
void audio_toggle_mute (Audio *audio, AudioUser user)
 
gdouble audio_get_volume (Audio *audio)
 
void _audio_set_volume (Audio *audio, AudioUser user, gdouble cur_volume, gdouble new_volume, gint dir)
 
void audio_set_volume (Audio *audio, AudioUser user, gdouble new_volume, gint dir)
 
void audio_lower_volume (Audio *audio, AudioUser user)
 
void audio_raise_volume (Audio *audio, AudioUser user)
 
static void audio_unhook_soundcard (Audio *audio)
 
static void audio_hook_soundcard (Audio *audio)
 
void audio_reload (Audio *audio)
 
void audio_free (Audio *audio)
 
Audioaudio_new (void)
 
GSList * audio_get_card_list (void)
 
GSList * audio_get_channel_list (const char *card_name)
 

Detailed Description

Audio subsystem.

This file holds the audio related code. It is a middleman between the low-level audio backend (alsa), and the high-level ui code. This abstraction layer allows the high-level code to be completely unaware of the underlying audio implementation, may it be alsa or whatever.

Definition in file audio.c.

Typedef Documentation

◆ AudioHandler

typedef struct audio_handler AudioHandler

Definition at line 121 of file audio.c.

Function Documentation

◆ _audio_set_volume()

void _audio_set_volume ( Audio audio,
AudioUser  user,
gdouble  cur_volume,
gdouble  new_volume,
gint  dir 
)

Set the volume.

Parameters
audioan Audio instance.
userthe user who performs the action.
cur_volumethe current volume value, in percent.
new_volumethe volume value to set, in percent.
dirthe direction for the volume change (-1: lowering, +1: raising, 0: setting).

Definition at line 458 of file audio.c.

◆ audio_event_free()

static void audio_event_free ( AudioEvent event)
static

Definition at line 78 of file audio.c.

◆ audio_event_new()

static AudioEvent* audio_event_new ( Audio audio,
AudioSignal  signal,
AudioUser  user 
)
static

Definition at line 88 of file audio.c.

◆ audio_free()

void audio_free ( Audio audio)

Free an audio instance, therefore unhooking the sound card and freeing any allocated ressources.

Parameters
audioan Audio instance.

Definition at line 691 of file audio.c.

◆ audio_get_card()

const char* audio_get_card ( Audio audio)

Get the name of the card currently hooked. This is an internal string that shouldn't be modified.

Parameters
audioan Audio instance.
Returns
the name of the card.

Definition at line 353 of file audio.c.

◆ audio_get_card_list()

GSList* audio_get_card_list ( void  )

Return the list of playable cards as a GSList. Must be freed using g_slist_free_full() and g_free().

Returns
a list of playable cards.

Definition at line 726 of file audio.c.

◆ audio_get_channel()

const char* audio_get_channel ( Audio audio)

Get the name of the channel currently in use. This is an internal string that shouldn't be modified.

Parameters
audioa Audio instance.
Returns
the name of the channel.

Definition at line 366 of file audio.c.

◆ audio_get_channel_list()

GSList* audio_get_channel_list ( const char *  card_name)

For a given card name, return the list of playable channels as a GSList. Must be freed using g_slist_free_full() and g_free().

Parameters
card_namethe name of the card for which we list the channels
Returns
a list of playable channels.

Definition at line 739 of file audio.c.

◆ audio_get_volume()

gdouble audio_get_volume ( Audio audio)

Get the volume in percent (value between 0 and 100).

Parameters
audioan Audio instance.
Returns
the volume in percent.

Definition at line 437 of file audio.c.

◆ audio_handler_cmp()

static gint audio_handler_cmp ( AudioHandler h1,
AudioHandler h2 
)
static

Definition at line 147 of file audio.c.

◆ audio_handler_free()

static void audio_handler_free ( AudioHandler handler)
static

Definition at line 125 of file audio.c.

◆ audio_handler_list_append()

static GSList* audio_handler_list_append ( GSList *  list,
AudioHandler handler 
)
static

Definition at line 156 of file audio.c.

◆ audio_handler_list_remove()

static GSList* audio_handler_list_remove ( GSList *  list,
AudioHandler handler 
)
static

Definition at line 175 of file audio.c.

◆ audio_handler_new()

static AudioHandler* audio_handler_new ( AudioCallback  callback,
gpointer  data 
)
static

Definition at line 132 of file audio.c.

◆ audio_has_mute()

gboolean audio_has_mute ( Audio audio)

Whether the card has mute capabilities.

Parameters
audioan Audio instance.
Returns
TRUE if the card can be muted, FALSE otherwise.

Definition at line 378 of file audio.c.

◆ audio_hook_soundcard()

static void audio_hook_soundcard ( Audio audio)
static

Attempt to hook an audio soundcard. Try everything possible, the goal is to have a working soundcard. So if the selected soundcard fails, we try any others until at some point we have a working soundcard.

Parameters
audioan Audio instance.

Definition at line 579 of file audio.c.

◆ audio_is_muted()

gboolean audio_is_muted ( Audio audio)

Get the mute state, either TRUE or FALSE.

Parameters
audioan Audio instance.
Returns
TRUE if the card is muted, FALSE otherwise.

Definition at line 395 of file audio.c.

◆ audio_lower_volume()

void audio_lower_volume ( Audio audio,
AudioUser  user 
)

Lower the volume.

Parameters
audioan Audio instance.
userthe user who performs the action.

Definition at line 516 of file audio.c.

◆ audio_new()

Audio* audio_new ( void  )

Create a new Audio instance. This does almost nothing actually, all the heavy job is done in the audio_hook_soundcard() function.

Returns
a newly allocated Audio instance.

Definition at line 710 of file audio.c.

◆ audio_raise_volume()

void audio_raise_volume ( Audio audio,
AudioUser  user 
)

Raise the volume.

Parameters
audioan Audio instance.
userthe user who performs the action.

Definition at line 536 of file audio.c.

◆ audio_reload()

void audio_reload ( Audio audio)

Reload the current preferences, and reload the hooked soundcard. This has to be called each time the preferences are modified.

Parameters
audioan Audio instance.

Definition at line 669 of file audio.c.

◆ audio_set_volume()

void audio_set_volume ( Audio audio,
AudioUser  user,
gdouble  new_volume,
gint  dir 
)

Definition at line 500 of file audio.c.

◆ audio_signal_to_str()

static const gchar* audio_signal_to_str ( AudioSignal  signal)
static

Definition at line 48 of file audio.c.

◆ audio_signals_connect()

void audio_signals_connect ( Audio audio,
AudioCallback  callback,
gpointer  data 
)

Connect a signal handler designed by 'callback' and 'data'. Remember to always pair 'connect' calls with 'disconnect' calls, otherwise you'll be in trouble.

Parameters
audioan Audio instance.
callbackthe callback to connect.
datathe data to pass to the callback.

Definition at line 337 of file audio.c.

◆ audio_signals_disconnect()

void audio_signals_disconnect ( Audio audio,
AudioCallback  callback,
gpointer  data 
)

Disconnect a signal handler designed by 'callback' and 'data'.

Parameters
audioan Audio instance.
callbackthe callback to disconnect.
datathe data to pass to the callback.

Definition at line 318 of file audio.c.

◆ audio_toggle_mute()

void audio_toggle_mute ( Audio audio,
AudioUser  user 
)

Toggle the mute state.

Parameters
audioan Audio instance.
userthe user who performs the action.

Definition at line 412 of file audio.c.

◆ audio_unhook_soundcard()

static void audio_unhook_soundcard ( Audio audio)
static

Unhook the currently hooked audio card.

Parameters
audioan Audio instance.

Definition at line 555 of file audio.c.

◆ audio_user_to_str()

static const gchar* audio_user_to_str ( AudioUser  user)
static

Definition at line 33 of file audio.c.

◆ invoke_handlers()

static void invoke_handlers ( Audio audio,
AudioSignal  signal,
AudioUser  user 
)
static

Convenient function to invoke the handlers

Parameters
audioan Audio instance.
signalthe signal to dispatch.
userthe user that made the action.

Definition at line 225 of file audio.c.

◆ on_alsa_event()

static void on_alsa_event ( enum alsa_event  event,
gpointer  data 
)
static

Callback invoked when an alsa event happens.

Parameters
eventthe event that happened.
dataassociated data.

Definition at line 258 of file audio.c.