1 #include "bcdisplayinfo.h"
7 #include "mainprogress.h"
8 #include "pluginaclient.h"
20 class InterpolateAllEffect : public PluginAClient
23 InterpolateAllEffect(PluginServer *server);
24 ~InterpolateAllEffect();
28 int is_multichannel();
31 int process_loop(double *buffer, long &output_lenght);
49 MainProgressBar *progress;
55 REGISTER_PLUGIN(InterpolateAllEffect)
64 InterpolateAllEffect::InterpolateAllEffect(PluginServer *server)
65 : PluginAClient(server)
69 InterpolateAllEffect::~InterpolateAllEffect()
76 char* InterpolateAllEffect::plugin_title() { return N_("Interpolate"); }
77 int InterpolateAllEffect::is_realtime() { return 0; }
78 int InterpolateAllEffect::is_multichannel() { return 0; }
81 int InterpolateAllEffect::get_parameters()
86 int InterpolateAllEffect::start_loop()
89 char string[BCTEXTLEN];
90 sprintf(string, "%s...", plugin_title());
91 progress = start_progress(string, (PluginClient::end - PluginClient::start));
92 current_position = PluginClient::start;
96 int InterpolateAllEffect::stop_loop()
98 progress->stop_progress();
103 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
105 //printf("InterpolateAllEffect::process_loop 1\n");
109 // Read a certain amount before the first sample
110 int leadin = PluginClient::in_buffer_size;
111 //printf("InterpolateAllEffect::process_loop 2\n");
112 double buffer[leadin];
113 if(PluginClient::start - leadin < 0) leadin = PluginClient::start;
114 read_samples(buffer, PluginClient::start - leadin, leadin);
115 sample1 = buffer[leadin - 1];
117 // Read a certain amount before the last sample
118 leadin = PluginClient::in_buffer_size;
119 if(PluginClient::end - leadin < 0) leadin = PluginClient::end;
120 read_samples(buffer, PluginClient::end - leadin, leadin);
121 sample2 = buffer[leadin - 1];
123 current_position = PluginClient::start;
125 // Get slope and intercept
126 slope = (sample2 - sample1) /
127 (PluginClient::end - PluginClient::start);
129 //printf("InterpolateAllEffect::process_loop 3\n");
131 //printf("InterpolateAllEffect::process_loop 4\n");
133 int fragment_len = PluginClient::in_buffer_size;
134 if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
135 double intercept2 = intercept + slope * (current_position - PluginClient::start);
136 for(int i = 0; i < fragment_len; i++)
138 buffer[i] = intercept2 + slope * i;
140 current_position += fragment_len;
141 write_length = fragment_len;
142 result = progress->update(PluginClient::end -
143 PluginClient::start +
145 PluginClient::start);
146 if(current_position >= PluginClient::end) result = 1;
147 //printf("InterpolateAllEffect::process_loop 5\n");