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 "gainwindow.h"
40 GainConfig::GainConfig()
45 int GainConfig::equivalent(GainConfig &that)
47 return EQUIV(level, that.level);
50 void GainConfig::copy_from(GainConfig &that)
52 this->level = that.level;
55 void GainConfig::interpolate(GainConfig &prev,
59 int64_t current_frame)
61 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
62 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
63 level = prev.level * prev_scale + next.level * next_scale;
74 Gain::Gain(PluginServer *server)
75 : PluginAClient(server)
85 const char* Gain::plugin_title() { return N_("Gain"); }
86 int Gain::is_realtime() { return 1; }
89 NEW_WINDOW_MACRO(Gain, GainWindow)
90 LOAD_CONFIGURATION_MACRO(Gain, GainConfig)
92 int Gain::process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr)
96 double gain = db.fromdb(config.level);
97 double *output_samples = output_ptr->get_data();
98 double *input_samples = input_ptr->get_data();
100 for(int64_t i = 0; i < size; i++)
102 output_samples[i] = input_samples[i] * gain;
111 void Gain::save_data(KeyFrame *keyframe)
115 // cause xml file to store data directly in text
116 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
118 output.tag.set_title("GAIN");
119 output.tag.set_property("LEVEL", config.level);
121 output.tag.set_title("/GAIN");
123 output.append_newline();
124 output.terminate_string();
127 void Gain::read_data(KeyFrame *keyframe)
130 // cause xml file to read directly from text
131 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
134 result = input.read_tag();
138 if(input.tag.title_is("GAIN"))
140 config.level = input.tag.get_property("LEVEL", config.level);
145 void Gain::update_gui()
149 load_configuration();
150 thread->window->lock_window();
151 ((GainWindow*)thread->window)->level->update(config.level);
152 thread->window->unlock_window();