4 This file is part of PulseAudio.
6 Copyright 2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <sys/types.h>
36 #include <pulse/xmalloc.h>
37 #include <pulse/volume.h>
38 #include <pulse/channelmap.h>
40 #include <pulsecore/core-error.h>
41 #include <pulsecore/module.h>
42 #include <pulsecore/core-util.h>
43 #include <pulsecore/modargs.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/sink-input.h>
47 #include "module-position-event-sounds-symdef.h"
49 PA_MODULE_AUTHOR("Lennart Poettering");
50 PA_MODULE_DESCRIPTION("Position event sounds between L and R depending on the position on screen of the widget triggering them.");
51 PA_MODULE_VERSION(PACKAGE_VERSION
);
52 PA_MODULE_LOAD_ONCE(TRUE
);
54 static const char* const valid_modargs
[] = {
60 pa_hook_slot
*sink_input_fixate_hook_slot
;
63 static pa_bool_t
is_left(pa_channel_position_t p
) {
65 p
== PA_CHANNEL_POSITION_FRONT_LEFT
||
66 p
== PA_CHANNEL_POSITION_REAR_LEFT
||
67 p
== PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER
||
68 p
== PA_CHANNEL_POSITION_SIDE_LEFT
||
69 p
== PA_CHANNEL_POSITION_TOP_FRONT_LEFT
||
70 p
== PA_CHANNEL_POSITION_TOP_REAR_LEFT
;
73 static pa_bool_t
is_right(pa_channel_position_t p
) {
75 p
== PA_CHANNEL_POSITION_FRONT_RIGHT
||
76 p
== PA_CHANNEL_POSITION_REAR_RIGHT
||
77 p
== PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER
||
78 p
== PA_CHANNEL_POSITION_SIDE_RIGHT
||
79 p
== PA_CHANNEL_POSITION_TOP_FRONT_RIGHT
||
80 p
== PA_CHANNEL_POSITION_TOP_REAR_RIGHT
;
83 static pa_hook_result_t
sink_input_fixate_hook_callback(pa_core
*core
, pa_sink_input_new_data
*data
, struct userdata
*u
) {
87 char t
[PA_CVOLUME_SNPRINT_MAX
];
91 if (!(hpos
= pa_proplist_gets(data
->proplist
, PA_PROP_EVENT_MOUSE_HPOS
)))
94 if (pa_atod(hpos
, &f
) < 0) {
95 pa_log_warn("Failed to parse "PA_PROP_EVENT_MOUSE_HPOS
" property '%s'.", hpos
);
99 if (f
< 0.0 || f
> 1.0) {
100 pa_log_warn("Property "PA_PROP_EVENT_MOUSE_HPOS
" out of range %0.2f", f
);
104 pa_log_debug("Positioning event sound '%s' at %0.2f.", pa_strnull(pa_proplist_gets(data
->proplist
, PA_PROP_EVENT_ID
)), f
);
106 if (!data
->volume_is_set
) {
107 pa_cvolume_reset(&data
->volume
, data
->sample_spec
.channels
);
108 data
->volume_is_set
= TRUE
;
111 for (c
= 0; c
< data
->sample_spec
.channels
; c
++) {
113 if (is_left(data
->channel_map
.map
[c
]))
114 data
->volume
.values
[c
] =
115 pa_sw_volume_multiply(data
->volume
.values
[c
], (pa_volume_t
) (PA_VOLUME_NORM
* (1.0 - f
)));
117 if (is_right(data
->channel_map
.map
[c
]))
118 data
->volume
.values
[c
] =
119 pa_sw_volume_multiply(data
->volume
.values
[c
], (pa_volume_t
) (PA_VOLUME_NORM
* f
));
122 pa_log_debug("Final volume %s.", pa_cvolume_snprint(t
, sizeof(t
), &data
->volume
));
127 int pa__init(pa_module
*m
) {
128 pa_modargs
*ma
= NULL
;
133 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
134 pa_log("Failed to parse module arguments");
138 m
->userdata
= u
= pa_xnew(struct userdata
, 1);
140 u
->sink_input_fixate_hook_slot
= pa_hook_connect(&m
->core
->hooks
[PA_CORE_HOOK_SINK_INPUT_FIXATE
], (pa_hook_cb_t
) sink_input_fixate_hook_callback
, u
);
155 void pa__done(pa_module
*m
) {
160 if (!(u
= m
->userdata
))
163 if (u
->sink_input_fixate_hook_slot
)
164 pa_hook_slot_free(u
->sink_input_fixate_hook_slot
);