2 This file is part of PulseAudio.
4 Copyright 2004-2008 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.1 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
22 /* TODO: Some plugins cause latency, and some even report it by using a control
23 out port. We don't currently use the latency information. */
29 #include <pulse/xmalloc.h>
30 #include <pulse/i18n.h>
32 #include <pulsecore/core-error.h>
33 #include <pulsecore/namereg.h>
34 #include <pulsecore/sink.h>
35 #include <pulsecore/module.h>
36 #include <pulsecore/core-util.h>
37 #include <pulsecore/modargs.h>
38 #include <pulsecore/log.h>
39 #include <pulsecore/thread.h>
40 #include <pulsecore/thread-mq.h>
41 #include <pulsecore/rtpoll.h>
42 #include <pulsecore/sample-util.h>
43 #include <pulsecore/ltdl-helper.h>
45 #include "module-ladspa-sink-symdef.h"
48 PA_MODULE_AUTHOR("Lennart Poettering");
49 PA_MODULE_DESCRIPTION(_("Virtual LADSPA sink"));
50 PA_MODULE_VERSION(PACKAGE_VERSION
);
51 PA_MODULE_LOAD_ONCE(FALSE
);
53 _("sink_name=<name for the sink> "
54 "sink_properties=<properties for the sink> "
55 "master=<name of sink to filter> "
56 "format=<sample format> "
58 "channels=<number of channels> "
59 "channel_map=<channel map> "
60 "plugin=<ladspa plugin name> "
61 "label=<ladspa plugin label> "
62 "control=<comma seperated list of input control values>"));
64 #define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
70 pa_sink_input
*sink_input
;
72 const LADSPA_Descriptor
*descriptor
;
74 LADSPA_Handle handle
[PA_CHANNELS_MAX
];
75 LADSPA_Data
*input
, *output
;
77 unsigned long input_port
, output_port
;
80 /* This is a dummy buffer. Every port must be connected, but we don't care
81 about control out ports. We connect them all to this single buffer. */
82 LADSPA_Data control_out
;
84 pa_memblockq
*memblockq
;
89 static const char* const valid_modargs
[] = {
103 /* Called from I/O thread context */
104 static int sink_process_msg_cb(pa_msgobject
*o
, int code
, void *data
, int64_t offset
, pa_memchunk
*chunk
) {
105 struct userdata
*u
= PA_SINK(o
)->userdata
;
109 case PA_SINK_MESSAGE_GET_LATENCY
:
111 /* The sink is _put() before the sink input is, so let's
112 * make sure we don't access it in that time. Also, the
113 * sink input is first shut down, the sink second. */
114 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
115 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
)) {
116 *((pa_usec_t
*) data
) = 0;
120 *((pa_usec_t
*) data
) =
122 /* Get the latency of the master sink */
123 pa_sink_get_latency_within_thread(u
->sink_input
->sink
) +
125 /* Add the latency internal to our sink input on top */
126 pa_bytes_to_usec(pa_memblockq_get_length(u
->sink_input
->thread_info
.render_memblockq
), &u
->sink_input
->sink
->sample_spec
);
131 return pa_sink_process_msg(o
, code
, data
, offset
, chunk
);
134 /* Called from main context */
135 static int sink_set_state_cb(pa_sink
*s
, pa_sink_state_t state
) {
138 pa_sink_assert_ref(s
);
139 pa_assert_se(u
= s
->userdata
);
141 if (!PA_SINK_IS_LINKED(state
) ||
142 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
145 pa_sink_input_cork(u
->sink_input
, state
== PA_SINK_SUSPENDED
);
149 /* Called from I/O thread context */
150 static void sink_request_rewind_cb(pa_sink
*s
) {
153 pa_sink_assert_ref(s
);
154 pa_assert_se(u
= s
->userdata
);
156 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
157 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
))
160 /* Just hand this one over to the master sink */
161 pa_sink_input_request_rewind(u
->sink_input
,
162 s
->thread_info
.rewind_nbytes
+
163 pa_memblockq_get_length(u
->memblockq
), TRUE
, FALSE
, FALSE
);
166 /* Called from I/O thread context */
167 static void sink_update_requested_latency_cb(pa_sink
*s
) {
170 pa_sink_assert_ref(s
);
171 pa_assert_se(u
= s
->userdata
);
173 if (!PA_SINK_IS_LINKED(u
->sink
->thread_info
.state
) ||
174 !PA_SINK_INPUT_IS_LINKED(u
->sink_input
->thread_info
.state
))
177 /* Just hand this one over to the master sink */
178 pa_sink_input_set_requested_latency_within_thread(
180 pa_sink_get_requested_latency_within_thread(s
));
183 /* Called from main context */
184 static void sink_set_volume_cb(pa_sink
*s
) {
187 pa_sink_assert_ref(s
);
188 pa_assert_se(u
= s
->userdata
);
190 if (!PA_SINK_IS_LINKED(pa_sink_get_state(s
)) ||
191 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
194 pa_sink_input_set_volume(u
->sink_input
, &s
->real_volume
, s
->save_volume
, TRUE
);
197 /* Called from main context */
198 static void sink_set_mute_cb(pa_sink
*s
) {
201 pa_sink_assert_ref(s
);
202 pa_assert_se(u
= s
->userdata
);
204 if (!PA_SINK_IS_LINKED(pa_sink_get_state(s
)) ||
205 !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u
->sink_input
)))
208 pa_sink_input_set_mute(u
->sink_input
, s
->muted
, s
->save_muted
);
211 /* Called from I/O thread context */
212 static int sink_input_pop_cb(pa_sink_input
*i
, size_t nbytes
, pa_memchunk
*chunk
) {
219 pa_sink_input_assert_ref(i
);
221 pa_assert_se(u
= i
->userdata
);
223 /* Hmm, process any rewind request that might be queued up */
224 pa_sink_process_rewind(u
->sink
, 0);
226 while (pa_memblockq_peek(u
->memblockq
, &tchunk
) < 0) {
229 pa_sink_render(u
->sink
, nbytes
, &nchunk
);
230 pa_memblockq_push(u
->memblockq
, &nchunk
);
231 pa_memblock_unref(nchunk
.memblock
);
234 tchunk
.length
= PA_MIN(nbytes
, tchunk
.length
);
235 pa_assert(tchunk
.length
> 0);
237 fs
= pa_frame_size(&i
->sample_spec
);
238 n
= (unsigned) (PA_MIN(tchunk
.length
, u
->block_size
) / fs
);
243 chunk
->length
= n
*fs
;
244 chunk
->memblock
= pa_memblock_new(i
->sink
->core
->mempool
, chunk
->length
);
246 pa_memblockq_drop(u
->memblockq
, chunk
->length
);
248 src
= (float*) ((uint8_t*) pa_memblock_acquire(tchunk
.memblock
) + tchunk
.index
);
249 dst
= (float*) pa_memblock_acquire(chunk
->memblock
);
251 for (c
= 0; c
< u
->channels
; c
++) {
252 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, u
->input
, sizeof(float), src
+c
, u
->channels
*sizeof(float), n
);
253 u
->descriptor
->run(u
->handle
[c
], n
);
254 pa_sample_clamp(PA_SAMPLE_FLOAT32NE
, dst
+c
, u
->channels
*sizeof(float), u
->output
, sizeof(float), n
);
257 pa_memblock_release(tchunk
.memblock
);
258 pa_memblock_release(chunk
->memblock
);
260 pa_memblock_unref(tchunk
.memblock
);
265 /* Called from I/O thread context */
266 static void sink_input_process_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
270 pa_sink_input_assert_ref(i
);
271 pa_assert_se(u
= i
->userdata
);
273 if (u
->sink
->thread_info
.rewind_nbytes
> 0) {
276 max_rewrite
= nbytes
+ pa_memblockq_get_length(u
->memblockq
);
277 amount
= PA_MIN(u
->sink
->thread_info
.rewind_nbytes
, max_rewrite
);
278 u
->sink
->thread_info
.rewind_nbytes
= 0;
283 pa_memblockq_seek(u
->memblockq
, - (int64_t) amount
, PA_SEEK_RELATIVE
, TRUE
);
285 pa_log_debug("Resetting plugin");
287 /* Reset the plugin */
288 if (u
->descriptor
->deactivate
)
289 for (c
= 0; c
< u
->channels
; c
++)
290 u
->descriptor
->deactivate(u
->handle
[c
]);
291 if (u
->descriptor
->activate
)
292 for (c
= 0; c
< u
->channels
; c
++)
293 u
->descriptor
->activate(u
->handle
[c
]);
297 pa_sink_process_rewind(u
->sink
, amount
);
298 pa_memblockq_rewind(u
->memblockq
, nbytes
);
301 /* Called from I/O thread context */
302 static void sink_input_update_max_rewind_cb(pa_sink_input
*i
, size_t nbytes
) {
305 pa_sink_input_assert_ref(i
);
306 pa_assert_se(u
= i
->userdata
);
308 pa_memblockq_set_maxrewind(u
->memblockq
, nbytes
);
309 pa_sink_set_max_rewind_within_thread(u
->sink
, nbytes
);
312 /* Called from I/O thread context */
313 static void sink_input_update_max_request_cb(pa_sink_input
*i
, size_t nbytes
) {
316 pa_sink_input_assert_ref(i
);
317 pa_assert_se(u
= i
->userdata
);
319 pa_sink_set_max_request_within_thread(u
->sink
, nbytes
);
322 /* Called from I/O thread context */
323 static void sink_input_update_sink_latency_range_cb(pa_sink_input
*i
) {
326 pa_sink_input_assert_ref(i
);
327 pa_assert_se(u
= i
->userdata
);
329 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
332 /* Called from I/O thread context */
333 static void sink_input_update_sink_fixed_latency_cb(pa_sink_input
*i
) {
336 pa_sink_input_assert_ref(i
);
337 pa_assert_se(u
= i
->userdata
);
339 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
342 /* Called from I/O thread context */
343 static void sink_input_detach_cb(pa_sink_input
*i
) {
346 pa_sink_input_assert_ref(i
);
347 pa_assert_se(u
= i
->userdata
);
349 pa_sink_detach_within_thread(u
->sink
);
351 pa_sink_set_rtpoll(u
->sink
, NULL
);
354 /* Called from I/O thread context */
355 static void sink_input_attach_cb(pa_sink_input
*i
) {
358 pa_sink_input_assert_ref(i
);
359 pa_assert_se(u
= i
->userdata
);
361 pa_sink_set_rtpoll(u
->sink
, i
->sink
->thread_info
.rtpoll
);
362 pa_sink_set_latency_range_within_thread(u
->sink
, i
->sink
->thread_info
.min_latency
, i
->sink
->thread_info
.max_latency
);
363 pa_sink_set_fixed_latency_within_thread(u
->sink
, i
->sink
->thread_info
.fixed_latency
);
364 pa_sink_set_max_request_within_thread(u
->sink
, pa_sink_input_get_max_request(i
));
365 pa_sink_set_max_rewind_within_thread(u
->sink
, pa_sink_input_get_max_rewind(i
));
367 pa_sink_attach_within_thread(u
->sink
);
370 /* Called from main context */
371 static void sink_input_kill_cb(pa_sink_input
*i
) {
374 pa_sink_input_assert_ref(i
);
375 pa_assert_se(u
= i
->userdata
);
377 /* The order here matters! We first kill the sink input, followed
378 * by the sink. That means the sink callbacks must be protected
379 * against an unconnected sink input! */
380 pa_sink_input_unlink(u
->sink_input
);
381 pa_sink_unlink(u
->sink
);
383 pa_sink_input_unref(u
->sink_input
);
384 u
->sink_input
= NULL
;
386 pa_sink_unref(u
->sink
);
389 pa_module_unload_request(u
->module
, TRUE
);
392 /* Called from IO thread context */
393 static void sink_input_state_change_cb(pa_sink_input
*i
, pa_sink_input_state_t state
) {
396 pa_sink_input_assert_ref(i
);
397 pa_assert_se(u
= i
->userdata
);
399 /* If we are added for the first time, ask for a rewinding so that
400 * we are heard right-away. */
401 if (PA_SINK_INPUT_IS_LINKED(state
) &&
402 i
->thread_info
.state
== PA_SINK_INPUT_INIT
) {
403 pa_log_debug("Requesting rewind due to state change.");
404 pa_sink_input_request_rewind(i
, 0, FALSE
, TRUE
, TRUE
);
408 /* Called from main context */
409 static pa_bool_t
sink_input_may_move_to_cb(pa_sink_input
*i
, pa_sink
*dest
) {
412 pa_sink_input_assert_ref(i
);
413 pa_assert_se(u
= i
->userdata
);
415 return u
->sink
!= dest
;
418 /* Called from main context */
419 static void sink_input_moving_cb(pa_sink_input
*i
, pa_sink
*dest
) {
422 pa_sink_input_assert_ref(i
);
423 pa_assert_se(u
= i
->userdata
);
426 pa_sink_set_asyncmsgq(u
->sink
, dest
->asyncmsgq
);
427 pa_sink_update_flags(u
->sink
, PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
, dest
->flags
);
429 pa_sink_set_asyncmsgq(u
->sink
, NULL
);
431 if (u
->auto_desc
&& dest
) {
435 pl
= pa_proplist_new();
436 z
= pa_proplist_gets(dest
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
437 pa_proplist_setf(pl
, PA_PROP_DEVICE_DESCRIPTION
, "LADSPA Plugin %s on %s",
438 pa_proplist_gets(u
->sink
->proplist
, "device.ladspa.name"), z
? z
: dest
->name
);
440 pa_sink_update_proplist(u
->sink
, PA_UPDATE_REPLACE
, pl
);
441 pa_proplist_free(pl
);
445 /* Called from main context */
446 static void sink_input_volume_changed_cb(pa_sink_input
*i
) {
449 pa_sink_input_assert_ref(i
);
450 pa_assert_se(u
= i
->userdata
);
452 pa_sink_volume_changed(u
->sink
, &i
->volume
);
455 /* Called from main context */
456 static void sink_input_mute_changed_cb(pa_sink_input
*i
) {
459 pa_sink_input_assert_ref(i
);
460 pa_assert_se(u
= i
->userdata
);
462 pa_sink_mute_changed(u
->sink
, i
->muted
);
465 int pa__init(pa_module
*m
) {
472 pa_sink_input_new_data sink_input_data
;
473 pa_sink_new_data sink_data
;
474 const char *plugin
, *label
;
475 LADSPA_Descriptor_Function descriptor_func
;
476 const char *e
, *cdata
;
477 const LADSPA_Descriptor
*d
;
478 unsigned long input_port
, output_port
, p
, j
, n_control
;
480 pa_bool_t
*use_default
= NULL
;
485 pa_assert_cc(sizeof(LADSPA_Data
) == sizeof(float));
487 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
488 pa_log("Failed to parse module arguments.");
492 if (!(master
= pa_namereg_get(m
->core
, pa_modargs_get_value(ma
, "master", NULL
), PA_NAMEREG_SINK
))) {
493 pa_log("Master sink not found");
497 ss
= master
->sample_spec
;
498 ss
.format
= PA_SAMPLE_FLOAT32
;
499 map
= master
->channel_map
;
500 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
501 pa_log("Invalid sample format specification or channel map");
505 if (!(plugin
= pa_modargs_get_value(ma
, "plugin", NULL
))) {
506 pa_log("Missing LADSPA plugin name");
510 if (!(label
= pa_modargs_get_value(ma
, "label", NULL
))) {
511 pa_log("Missing LADSPA plugin label");
515 cdata
= pa_modargs_get_value(ma
, "control", NULL
);
517 u
= pa_xnew0(struct userdata
, 1);
521 pa_silence_memchunk_get(&m
->core
->silence_cache
, m
->core
->mempool
, &silence
, &ss
, 0);
522 u
->memblockq
= pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH
, 0, pa_frame_size(&ss
), 1, 1, 0, &silence
);
523 pa_memblock_unref(silence
.memblock
);
525 if (!(e
= getenv("LADSPA_PATH")))
528 /* FIXME: This is not exactly thread safe */
529 t
= pa_xstrdup(lt_dlgetsearchpath());
530 lt_dlsetsearchpath(e
);
531 m
->dl
= lt_dlopenext(plugin
);
532 lt_dlsetsearchpath(t
);
536 pa_log("Failed to load LADSPA plugin: %s", lt_dlerror());
540 if (!(descriptor_func
= (LADSPA_Descriptor_Function
) pa_load_sym(m
->dl
, NULL
, "ladspa_descriptor"))) {
541 pa_log("LADSPA module lacks ladspa_descriptor() symbol.");
547 if (!(d
= descriptor_func(j
))) {
548 pa_log("Failed to find plugin label '%s' in plugin '%s'.", label
, plugin
);
552 if (strcmp(d
->Label
, label
) == 0)
558 pa_log_debug("Module: %s", plugin
);
559 pa_log_debug("Label: %s", d
->Label
);
560 pa_log_debug("Unique ID: %lu", d
->UniqueID
);
561 pa_log_debug("Name: %s", d
->Name
);
562 pa_log_debug("Maker: %s", d
->Maker
);
563 pa_log_debug("Copyright: %s", d
->Copyright
);
565 input_port
= output_port
= (unsigned long) -1;
568 for (p
= 0; p
< d
->PortCount
; p
++) {
570 if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
572 if (strcmp(d
->PortNames
[p
], "Input") == 0) {
573 pa_assert(input_port
== (unsigned long) -1);
576 pa_log("Found audio input port on plugin we cannot handle: %s", d
->PortNames
[p
]);
580 } else if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_AUDIO(d
->PortDescriptors
[p
])) {
582 if (strcmp(d
->PortNames
[p
], "Output") == 0) {
583 pa_assert(output_port
== (unsigned long) -1);
586 pa_log("Found audio output port on plugin we cannot handle: %s", d
->PortNames
[p
]);
590 } else if (LADSPA_IS_PORT_INPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
593 pa_assert(LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
]) && LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]));
594 pa_log_debug("Ignored control output port \"%s\".", d
->PortNames
[p
]);
598 if ((input_port
== (unsigned long) -1) || (output_port
== (unsigned long) -1)) {
599 pa_log("Failed to identify input and output ports. "
600 "Right now this module can only deal with plugins which provide an 'Input' and an 'Output' audio port. "
605 u
->block_size
= pa_frame_align(pa_mempool_block_size_max(m
->core
->mempool
), &ss
);
607 u
->input
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
608 if (LADSPA_IS_INPLACE_BROKEN(d
->Properties
))
609 u
->output
= (LADSPA_Data
*) pa_xnew(uint8_t, (unsigned) u
->block_size
);
611 u
->output
= u
->input
;
613 u
->channels
= ss
.channels
;
615 for (c
= 0; c
< ss
.channels
; c
++) {
616 if (!(u
->handle
[c
] = d
->instantiate(d
, ss
.rate
))) {
617 pa_log("Failed to instantiate plugin %s with label %s for channel %i", plugin
, d
->Label
, c
);
621 d
->connect_port(u
->handle
[c
], input_port
, u
->input
);
622 d
->connect_port(u
->handle
[c
], output_port
, u
->output
);
625 if (!cdata
&& n_control
> 0) {
626 pa_log("This plugin requires specification of %lu control parameters.", n_control
);
631 const char *state
= NULL
;
635 u
->control
= pa_xnew(LADSPA_Data
, (unsigned) n_control
);
636 use_default
= pa_xnew(pa_bool_t
, (unsigned) n_control
);
639 while ((k
= pa_split(cdata
, ",", &state
)) && p
< n_control
) {
643 use_default
[p
++] = TRUE
;
648 if (pa_atod(k
, &f
) < 0) {
649 pa_log("Failed to parse control value '%s'", k
);
656 use_default
[p
] = FALSE
;
657 u
->control
[p
++] = (LADSPA_Data
) f
;
660 /* The previous loop doesn't take the last control value into account
661 if it is left empty, so we do it here. */
662 if (*cdata
== 0 || cdata
[strlen(cdata
) - 1] == ',') {
664 use_default
[p
] = TRUE
;
668 if (p
> n_control
|| k
) {
669 pa_log("Too many control values passed, %lu expected.", n_control
);
675 pa_log("Not enough control values passed, %lu expected, %lu passed.", n_control
, p
);
680 for (p
= 0; p
< d
->PortCount
; p
++) {
681 LADSPA_PortRangeHintDescriptor hint
= d
->PortRangeHints
[p
].HintDescriptor
;
683 if (!LADSPA_IS_PORT_CONTROL(d
->PortDescriptors
[p
]))
686 if (LADSPA_IS_PORT_OUTPUT(d
->PortDescriptors
[p
])) {
687 for (c
= 0; c
< ss
.channels
; c
++)
688 d
->connect_port(u
->handle
[c
], p
, &u
->control_out
);
692 pa_assert(h
< n_control
);
694 if (use_default
[h
]) {
695 LADSPA_Data lower
, upper
;
697 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint
)) {
698 pa_log("Control port value left empty but plugin defines no default.");
702 lower
= d
->PortRangeHints
[p
].LowerBound
;
703 upper
= d
->PortRangeHints
[p
].UpperBound
;
705 if (LADSPA_IS_HINT_SAMPLE_RATE(hint
)) {
706 lower
*= (LADSPA_Data
) ss
.rate
;
707 upper
*= (LADSPA_Data
) ss
.rate
;
710 switch (hint
& LADSPA_HINT_DEFAULT_MASK
) {
712 case LADSPA_HINT_DEFAULT_MINIMUM
:
713 u
->control
[h
] = lower
;
716 case LADSPA_HINT_DEFAULT_MAXIMUM
:
717 u
->control
[h
] = upper
;
720 case LADSPA_HINT_DEFAULT_LOW
:
721 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
722 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.75 + log(upper
) * 0.25);
724 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.75 + upper
* 0.25);
727 case LADSPA_HINT_DEFAULT_MIDDLE
:
728 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
729 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.5 + log(upper
) * 0.5);
731 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.5 + upper
* 0.5);
734 case LADSPA_HINT_DEFAULT_HIGH
:
735 if (LADSPA_IS_HINT_LOGARITHMIC(hint
))
736 u
->control
[h
] = (LADSPA_Data
) exp(log(lower
) * 0.25 + log(upper
) * 0.75);
738 u
->control
[h
] = (LADSPA_Data
) (lower
* 0.25 + upper
* 0.75);
741 case LADSPA_HINT_DEFAULT_0
:
745 case LADSPA_HINT_DEFAULT_1
:
749 case LADSPA_HINT_DEFAULT_100
:
753 case LADSPA_HINT_DEFAULT_440
:
758 pa_assert_not_reached();
762 if (LADSPA_IS_HINT_INTEGER(hint
))
763 u
->control
[h
] = roundf(u
->control
[h
]);
765 pa_log_debug("Binding %f to port %s", u
->control
[h
], d
->PortNames
[p
]);
767 for (c
= 0; c
< ss
.channels
; c
++)
768 d
->connect_port(u
->handle
[c
], p
, &u
->control
[h
]);
773 pa_assert(h
== n_control
);
777 for (c
= 0; c
< u
->channels
; c
++)
778 d
->activate(u
->handle
[c
]);
781 pa_sink_new_data_init(&sink_data
);
782 sink_data
.driver
= __FILE__
;
783 sink_data
.module
= m
;
784 if (!(sink_data
.name
= pa_xstrdup(pa_modargs_get_value(ma
, "sink_name", NULL
))))
785 sink_data
.name
= pa_sprintf_malloc("%s.ladspa", master
->name
);
786 pa_sink_new_data_set_sample_spec(&sink_data
, &ss
);
787 pa_sink_new_data_set_channel_map(&sink_data
, &map
);
788 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_MASTER_DEVICE
, master
->name
);
789 pa_proplist_sets(sink_data
.proplist
, PA_PROP_DEVICE_CLASS
, "filter");
790 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.module", plugin
);
791 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.label", d
->Label
);
792 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.name", d
->Name
);
793 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.maker", d
->Maker
);
794 pa_proplist_sets(sink_data
.proplist
, "device.ladspa.copyright", d
->Copyright
);
795 pa_proplist_setf(sink_data
.proplist
, "device.ladspa.unique_id", "%lu", (unsigned long) d
->UniqueID
);
797 if (pa_modargs_get_proplist(ma
, "sink_properties", sink_data
.proplist
, PA_UPDATE_REPLACE
) < 0) {
798 pa_log("Invalid properties");
799 pa_sink_new_data_done(&sink_data
);
803 if ((u
->auto_desc
= !pa_proplist_contains(sink_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
))) {
806 z
= pa_proplist_gets(master
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
807 pa_proplist_setf(sink_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
, "LADSPA Plugin %s on %s", d
->Name
, z
? z
: master
->name
);
810 u
->sink
= pa_sink_new(m
->core
, &sink_data
,
811 PA_SINK_HW_MUTE_CTRL
|PA_SINK_HW_VOLUME_CTRL
|PA_SINK_DECIBEL_VOLUME
|
812 (master
->flags
& (PA_SINK_LATENCY
|PA_SINK_DYNAMIC_LATENCY
)));
813 pa_sink_new_data_done(&sink_data
);
816 pa_log("Failed to create sink.");
820 u
->sink
->parent
.process_msg
= sink_process_msg_cb
;
821 u
->sink
->set_state
= sink_set_state_cb
;
822 u
->sink
->update_requested_latency
= sink_update_requested_latency_cb
;
823 u
->sink
->request_rewind
= sink_request_rewind_cb
;
824 u
->sink
->set_volume
= sink_set_volume_cb
;
825 u
->sink
->set_mute
= sink_set_mute_cb
;
826 u
->sink
->userdata
= u
;
828 pa_sink_set_asyncmsgq(u
->sink
, master
->asyncmsgq
);
830 /* Create sink input */
831 pa_sink_input_new_data_init(&sink_input_data
);
832 sink_input_data
.driver
= __FILE__
;
833 sink_input_data
.module
= m
;
834 sink_input_data
.sink
= master
;
835 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_NAME
, "LADSPA Stream");
836 pa_proplist_sets(sink_input_data
.proplist
, PA_PROP_MEDIA_ROLE
, "filter");
837 pa_sink_input_new_data_set_sample_spec(&sink_input_data
, &ss
);
838 pa_sink_input_new_data_set_channel_map(&sink_input_data
, &map
);
840 pa_sink_input_new(&u
->sink_input
, m
->core
, &sink_input_data
);
841 pa_sink_input_new_data_done(&sink_input_data
);
846 u
->sink_input
->pop
= sink_input_pop_cb
;
847 u
->sink_input
->process_rewind
= sink_input_process_rewind_cb
;
848 u
->sink_input
->update_max_rewind
= sink_input_update_max_rewind_cb
;
849 u
->sink_input
->update_max_request
= sink_input_update_max_request_cb
;
850 u
->sink_input
->update_sink_latency_range
= sink_input_update_sink_latency_range_cb
;
851 u
->sink_input
->update_sink_fixed_latency
= sink_input_update_sink_fixed_latency_cb
;
852 u
->sink_input
->kill
= sink_input_kill_cb
;
853 u
->sink_input
->attach
= sink_input_attach_cb
;
854 u
->sink_input
->detach
= sink_input_detach_cb
;
855 u
->sink_input
->state_change
= sink_input_state_change_cb
;
856 u
->sink_input
->may_move_to
= sink_input_may_move_to_cb
;
857 u
->sink_input
->moving
= sink_input_moving_cb
;
858 u
->sink_input
->volume_changed
= sink_input_volume_changed_cb
;
859 u
->sink_input
->mute_changed
= sink_input_mute_changed_cb
;
860 u
->sink_input
->userdata
= u
;
862 pa_sink_put(u
->sink
);
863 pa_sink_input_put(u
->sink_input
);
867 pa_xfree(use_default
);
875 pa_xfree(use_default
);
882 int pa__get_n_used(pa_module
*m
) {
886 pa_assert_se(u
= m
->userdata
);
888 return pa_sink_linked_by(u
->sink
);
891 void pa__done(pa_module
*m
) {
897 if (!(u
= m
->userdata
))
900 /* See comments in sink_input_kill_cb() above regarding
901 * destruction order! */
904 pa_sink_input_unlink(u
->sink_input
);
907 pa_sink_unlink(u
->sink
);
910 pa_sink_input_unref(u
->sink_input
);
913 pa_sink_unref(u
->sink
);
915 for (c
= 0; c
< u
->channels
; c
++)
917 if (u
->descriptor
->deactivate
)
918 u
->descriptor
->deactivate(u
->handle
[c
]);
919 u
->descriptor
->cleanup(u
->handle
[c
]);
922 if (u
->output
!= u
->input
)
926 pa_memblockq_free(u
->memblockq
);
929 pa_xfree(u
->control
);