4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "confirmsave.h"
29 #include "despikewindow.h"
38 REGISTER_PLUGIN(Despike)
42 Despike::Despike(PluginServer *server)
43 : PluginAClient(server)
54 const char* Despike::plugin_title() { return _("Despike"); }
55 int Despike::is_realtime() { return 1; }
57 NEW_WINDOW_MACRO(Despike, DespikeWindow)
59 LOAD_CONFIGURATION_MACRO(Despike, DespikeConfig)
62 int Despike::process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr)
66 double threshold = db.fromdb(config.level);
67 double change = db.fromdb(config.slope);
69 //printf("Despike::process_realtime 1\n");
70 double *output_samples = output_ptr->get_data();
71 double *input_samples = input_ptr->get_data();
72 for(int64_t i = 0; i < size; i++)
74 if(fabs(input_samples[i]) > threshold ||
75 fabs(input_samples[i]) - fabs(last_sample) > change)
77 output_samples[i] = last_sample;
81 output_samples[i] = input_samples[i];
82 last_sample = input_samples[i];
85 //printf("Despike::process_realtime 2\n");
92 void Despike::save_data(KeyFrame *keyframe)
96 // cause xml file to store data directly in text
97 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
99 output.tag.set_title("DESPIKE");
100 output.tag.set_property("LEVEL", config.level);
101 output.tag.set_property("SLOPE", config.slope);
103 output.tag.set_title("/DESPIKE");
105 output.append_newline();
106 output.terminate_string();
109 void Despike::read_data(KeyFrame *keyframe)
112 // cause xml file to read directly from text
113 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
116 result = input.read_tag();
120 if(input.tag.title_is("DESPIKE"))
122 config.level = input.tag.get_property("LEVEL", config.level);
123 config.slope = input.tag.get_property("SLOPE", config.slope);
128 void Despike::update_gui()
132 load_configuration();
133 ((DespikeWindow*)thread->window)->lock_window();
134 ((DespikeWindow*)thread->window)->level->update(config.level);
135 ((DespikeWindow*)thread->window)->slope->update(config.slope);
136 ((DespikeWindow*)thread->window)->unlock_window();
155 DespikeConfig::DespikeConfig()
161 int DespikeConfig::equivalent(DespikeConfig &that)
163 return EQUIV(level, that.level) &&
164 EQUIV(slope, that.slope);
167 void DespikeConfig::copy_from(DespikeConfig &that)
173 void DespikeConfig::interpolate(DespikeConfig &prev,
177 int64_t current_frame)
179 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
180 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
182 this->level = prev.level * prev_scale + next.level * next_scale;
183 this->slope = prev.slope * prev_scale + next.slope * next_scale;