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. */
13 #include "amp_filter.cmdline.h"
17 #include "buffer_tree.h"
22 /** The size of the output data buffer. */
23 #define AMP_CHUNK_SIZE 40960
25 extern char *stat_item_values
[NUM_STAT_ITEMS
];
27 /** Data specific to the amplify filter. */
28 struct private_amp_data
{
29 /** Points to the configuration data for this instance of this filter. */
30 struct amp_filter_args_info
*conf
;
31 /** Amplification factor. */
35 static ssize_t
amp_convert(char *inbuf
, size_t inbuf_len
, struct filter_node
*fn
)
37 size_t i
, length
= PARA_MIN((inbuf_len
/ 2),
38 (fn
->bufsize
- fn
->loaded
) / 2);
39 struct private_amp_data
*pad
= fn
->private_data
;
40 int16_t *ip
= (int16_t *)inbuf
, *op
= (int16_t *)(fn
->buf
+ fn
->loaded
);
41 int factor
= 64 + pad
->amp
;
47 memcpy(op
, ip
, length
* 2);
50 for (i
= 0; i
< length
; i
++) {
51 int x
= (ip
[i
] * factor
) >> 6;
55 op
[i
] = (x
>= 32768)? 32767 : -32768;
58 fn
->loaded
+= length
* 2;
62 static void amp_close(struct filter_node
*fn
)
64 free(fn
->private_data
);
68 static int amp_parse_config(int argc
, char **argv
, void **config
)
70 struct amp_filter_args_info
*amp_conf
= para_calloc(sizeof(*amp_conf
));
71 int ret
= -E_AMP_SYNTAX
;
73 if (amp_cmdline_parser(argc
, argv
, amp_conf
))
75 ret
= -ERRNO_TO_PARA_ERROR(EINVAL
);
76 if (amp_conf
->amp_arg
< 0)
78 PARA_NOTICE_LOG("amplification: %u (scaling factor: %1.2f)\n",
79 amp_conf
->amp_arg
, amp_conf
->amp_arg
/ 64.0 + 1.0);
87 static void amp_open(struct filter_node
*fn
)
89 struct private_amp_data
*pad
= para_calloc(sizeof(*pad
));
92 fn
->private_data
= pad
;
93 if (!pad
->conf
->amp_given
&& stat_item_values
[SI_AMPLIFICATION
])
94 sscanf(stat_item_values
[SI_AMPLIFICATION
], "%u", &pad
->amp
);
96 pad
->amp
= pad
->conf
->amp_arg
;
97 fn
->bufsize
= AMP_CHUNK_SIZE
;
98 fn
->buf
= para_malloc(fn
->bufsize
);
102 * The init function of the amplify filter.
104 * \param f Pointer to the struct to initialize.
106 void amp_filter_init(struct filter
*f
)
108 struct amp_filter_args_info dummy
;
110 amp_cmdline_parser_init(&dummy
);
112 f
->close
= amp_close
;
113 f
->convert
= amp_convert
;
114 f
->parse_config
= amp_parse_config
;
115 f
->help
= (struct ggo_help
) {
116 .short_help
= amp_filter_args_info_help
,
117 .detailed_help
= amp_filter_args_info_detailed_help