2 This file is part of PulseAudio.
4 Copyright 2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <sys/types.h>
34 #include <pulse/xmalloc.h>
35 #include <pulse/volume.h>
36 #include <pulse/channelmap.h>
38 #include <pulsecore/core-error.h>
39 #include <pulsecore/module.h>
40 #include <pulsecore/core-util.h>
41 #include <pulsecore/modargs.h>
42 #include <pulsecore/log.h>
43 #include <pulsecore/sink-input.h>
45 #include "module-position-event-sounds-symdef.h"
47 PA_MODULE_AUTHOR("Lennart Poettering");
48 PA_MODULE_DESCRIPTION("Position event sounds between L and R depending on the position on screen of the widget triggering them.");
49 PA_MODULE_VERSION(PACKAGE_VERSION
);
50 PA_MODULE_LOAD_ONCE(TRUE
);
52 static const char* const valid_modargs
[] = {
58 pa_hook_slot
*sink_input_fixate_hook_slot
;
61 static pa_bool_t
is_left(pa_channel_position_t p
) {
63 p
== PA_CHANNEL_POSITION_FRONT_LEFT
||
64 p
== PA_CHANNEL_POSITION_REAR_LEFT
||
65 p
== PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER
||
66 p
== PA_CHANNEL_POSITION_SIDE_LEFT
||
67 p
== PA_CHANNEL_POSITION_TOP_FRONT_LEFT
||
68 p
== PA_CHANNEL_POSITION_TOP_REAR_LEFT
;
71 static pa_bool_t
is_right(pa_channel_position_t p
) {
73 p
== PA_CHANNEL_POSITION_FRONT_RIGHT
||
74 p
== PA_CHANNEL_POSITION_REAR_RIGHT
||
75 p
== PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER
||
76 p
== PA_CHANNEL_POSITION_SIDE_RIGHT
||
77 p
== PA_CHANNEL_POSITION_TOP_FRONT_RIGHT
||
78 p
== PA_CHANNEL_POSITION_TOP_REAR_RIGHT
;
81 static pa_hook_result_t
sink_input_fixate_hook_callback(pa_core
*core
, pa_sink_input_new_data
*data
, struct userdata
*u
) {
85 char t
[PA_CVOLUME_SNPRINT_MAX
];
89 if (!(hpos
= pa_proplist_gets(data
->proplist
, PA_PROP_EVENT_MOUSE_HPOS
)))
92 if (pa_atod(hpos
, &f
) < 0) {
93 pa_log_warn("Failed to parse "PA_PROP_EVENT_MOUSE_HPOS
" property '%s'.", hpos
);
97 if (f
< 0.0 || f
> 1.0) {
98 pa_log_warn("Property "PA_PROP_EVENT_MOUSE_HPOS
" out of range %0.2f", f
);
102 pa_log_debug("Positioning event sound '%s' at %0.2f.", pa_strnull(pa_proplist_gets(data
->proplist
, PA_PROP_EVENT_ID
)), f
);
104 if (!data
->volume_is_set
) {
105 pa_cvolume_reset(&data
->volume
, data
->sample_spec
.channels
);
106 data
->volume_is_set
= TRUE
;
109 for (c
= 0; c
< data
->sample_spec
.channels
; c
++) {
111 if (is_left(data
->channel_map
.map
[c
]))
112 data
->volume
.values
[c
] =
113 pa_sw_volume_multiply(data
->volume
.values
[c
], (pa_volume_t
) (PA_VOLUME_NORM
* (1.0 - f
)));
115 if (is_right(data
->channel_map
.map
[c
]))
116 data
->volume
.values
[c
] =
117 pa_sw_volume_multiply(data
->volume
.values
[c
], (pa_volume_t
) (PA_VOLUME_NORM
* f
));
120 pa_log_debug("Final volume %s.", pa_cvolume_snprint(t
, sizeof(t
), &data
->volume
));
125 int pa__init(pa_module
*m
) {
126 pa_modargs
*ma
= NULL
;
131 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
132 pa_log("Failed to parse module arguments");
136 m
->userdata
= u
= pa_xnew(struct userdata
, 1);
138 u
->sink_input_fixate_hook_slot
= pa_hook_connect(&m
->core
->hooks
[PA_CORE_HOOK_SINK_INPUT_FIXATE
], PA_HOOK_EARLY
, (pa_hook_cb_t
) sink_input_fixate_hook_callback
, u
);
153 void pa__done(pa_module
*m
) {
158 if (!(u
= m
->userdata
))
161 if (u
->sink_input_fixate_hook_slot
)
162 pa_hook_slot_free(u
->sink_input_fixate_hook_slot
);