2 * Copyright (C) 2009 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file amp_filter.c Paraslash's amplify filter. */
10 #include "amp_filter.cmdline.h"
18 /** The size of the output data buffer. */
19 #define AMP_CHUNK_SIZE 40960
21 extern char *stat_item_values
[NUM_STAT_ITEMS
];
23 /** Data specific to the amplify filter. */
24 struct private_amp_data
{
25 /** Points to the configuration data for this instance of this filter. */
26 struct amp_filter_args_info
*conf
;
27 /** Amplification factor. */
31 static ssize_t
amp_convert(char *inbuf
, size_t inbuf_len
, struct filter_node
*fn
)
33 size_t i
, length
= PARA_MIN((inbuf_len
/ 2) * 2,
34 (fn
->bufsize
- fn
->loaded
) / 2 * 2);
35 struct private_amp_data
*pad
= fn
->private_data
;
36 int16_t *ip
= (int16_t *)inbuf
, *op
= (int16_t *)(fn
->buf
+ fn
->loaded
);
40 for (i
= 0; i
< length
/ 2; i
++) {
41 int x
= (PARA_ABS(*ip
) * (64 + pad
->amp
)) >> 6;
42 *op
++ = *ip
++ > 0? PARA_MIN(x
, 32767) : PARA_MAX(-x
, -32768);
48 static void amp_close(struct filter_node
*fn
)
50 free(fn
->private_data
);
54 static int amp_parse_config(int argc
, char **argv
, void **config
)
56 struct amp_filter_args_info
*amp_conf
= para_calloc(sizeof(*amp_conf
));
57 int ret
= -E_AMP_SYNTAX
;
59 if (amp_cmdline_parser(argc
, argv
, amp_conf
))
61 ret
= -ERRNO_TO_PARA_ERROR(EINVAL
);
62 if (amp_conf
->amp_arg
< 0)
64 PARA_NOTICE_LOG("amplification: %u (scaling factor: %1.2f)\n",
65 amp_conf
->amp_arg
, amp_conf
->amp_arg
/ 64.0 + 1.0);
73 static void amp_open(struct filter_node
*fn
)
75 struct private_amp_data
*pad
= para_calloc(sizeof(*pad
));
78 fn
->private_data
= pad
;
79 if (!pad
->conf
->amp_given
&& stat_item_values
[SI_AMPLIFICATION
]) {
80 int i
= SI_AMPLIFICATION
;
81 char *s
= stat_item_values
[i
] + strlen(status_item_list
[i
]) + 1;
82 sscanf(s
, "%u", &pad
->amp
);
84 pad
->amp
= pad
->conf
->amp_arg
;
85 fn
->bufsize
= AMP_CHUNK_SIZE
;
86 fn
->buf
= para_malloc(fn
->bufsize
);
90 * The init function of the amplify filter.
92 * \param f Pointer to the struct to initialize.
94 void amp_filter_init(struct filter
*f
)
96 struct amp_filter_args_info dummy
;
98 amp_cmdline_parser_init(&dummy
);
100 f
->close
= amp_close
;
101 f
->convert
= amp_convert
;
102 f
->parse_config
= amp_parse_config
;
103 f
->help
= (struct ggo_help
) {
104 .short_help
= amp_filter_args_info_help
,
105 .detailed_help
= amp_filter_args_info_detailed_help