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
22 #include "bcdisplayinfo.h"
28 #include "mainprogress.h"
29 #include "pluginaclient.h"
41 class InterpolateAllEffect : public PluginAClient
44 InterpolateAllEffect(PluginServer *server);
45 ~InterpolateAllEffect();
47 const char* plugin_title();
49 int is_multichannel();
52 int process_loop(double *buffer, long &output_lenght);
70 MainProgressBar *progress;
76 REGISTER_PLUGIN(InterpolateAllEffect)
85 InterpolateAllEffect::InterpolateAllEffect(PluginServer *server)
86 : PluginAClient(server)
90 InterpolateAllEffect::~InterpolateAllEffect()
97 char* InterpolateAllEffect::plugin_title() { return N_("Interpolate"); }
98 int InterpolateAllEffect::is_realtime() { return 0; }
99 int InterpolateAllEffect::is_multichannel() { return 0; }
102 int InterpolateAllEffect::get_parameters()
107 int InterpolateAllEffect::start_loop()
110 char string[BCTEXTLEN];
111 sprintf(string, "%s...", plugin_title());
112 progress = start_progress(string, (PluginClient::end - PluginClient::start));
113 current_position = PluginClient::start;
117 int InterpolateAllEffect::stop_loop()
119 progress->stop_progress();
124 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
126 //printf("InterpolateAllEffect::process_loop 1\n");
130 // Read a certain amount before the first sample
131 int leadin = PluginClient::in_buffer_size;
132 //printf("InterpolateAllEffect::process_loop 2\n");
133 double buffer[leadin];
134 if(PluginClient::start - leadin < 0) leadin = PluginClient::start;
135 read_samples(buffer, PluginClient::start - leadin, leadin);
136 sample1 = buffer[leadin - 1];
138 // Read a certain amount before the last sample
139 leadin = PluginClient::in_buffer_size;
140 if(PluginClient::end - leadin < 0) leadin = PluginClient::end;
141 read_samples(buffer, PluginClient::end - leadin, leadin);
142 sample2 = buffer[leadin - 1];
144 current_position = PluginClient::start;
146 // Get slope and intercept
147 slope = (sample2 - sample1) /
148 (PluginClient::end - PluginClient::start);
150 //printf("InterpolateAllEffect::process_loop 3\n");
152 //printf("InterpolateAllEffect::process_loop 4\n");
154 int fragment_len = PluginClient::in_buffer_size;
155 if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
156 double intercept2 = intercept + slope * (current_position - PluginClient::start);
157 for(int i = 0; i < fragment_len; i++)
159 buffer[i] = intercept2 + slope * i;
161 current_position += fragment_len;
162 write_length = fragment_len;
163 result = progress->update(PluginClient::end -
164 PluginClient::start +
166 PluginClient::start);
167 if(current_position >= PluginClient::end) result = 1;
168 //printf("InterpolateAllEffect::process_loop 5\n");