00001 #include "bcdisplayinfo.h"
00002 #include "clip.h"
00003 #include "bchash.h"
00004 #include "guicast.h"
00005 #include "filexml.h"
00006 #include "language.h"
00007 #include "mainprogress.h"
00008 #include "pluginaclient.h"
00009
00010 #include <string.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 class InterpolateAllEffect : public PluginAClient
00021 {
00022 public:
00023 InterpolateAllEffect(PluginServer *server);
00024 ~InterpolateAllEffect();
00025
00026 char* plugin_title();
00027 int is_realtime();
00028 int is_multichannel();
00029 int get_parameters();
00030 int start_loop();
00031 int process_loop(double *buffer, long &output_lenght);
00032 int stop_loop();
00033
00034
00035
00036
00037 int state;
00038 enum
00039 {
00040 READING,
00041 WRITING
00042 };
00043 double sample1;
00044 double sample2;
00045 int current_position;
00046 double slope;
00047 double intercept;
00048
00049 MainProgressBar *progress;
00050 };
00051
00052
00053
00054
00055 REGISTER_PLUGIN(InterpolateAllEffect)
00056
00057
00058
00059
00060
00061
00062
00063
00064 InterpolateAllEffect::InterpolateAllEffect(PluginServer *server)
00065 : PluginAClient(server)
00066 {
00067 }
00068
00069 InterpolateAllEffect::~InterpolateAllEffect()
00070 {
00071 }
00072
00073
00074
00075
00076 char* InterpolateAllEffect::plugin_title() { return N_("Interpolate"); }
00077 int InterpolateAllEffect::is_realtime() { return 0; }
00078 int InterpolateAllEffect::is_multichannel() { return 0; }
00079
00080
00081 int InterpolateAllEffect::get_parameters()
00082 {
00083 return 0;
00084 }
00085
00086 int InterpolateAllEffect::start_loop()
00087 {
00088 state = READING;
00089 char string[BCTEXTLEN];
00090 sprintf(string, "%s...", plugin_title());
00091 progress = start_progress(string, (PluginClient::end - PluginClient::start));
00092 current_position = PluginClient::start;
00093 return 0;
00094 }
00095
00096 int InterpolateAllEffect::stop_loop()
00097 {
00098 progress->stop_progress();
00099 delete progress;
00100 return 0;
00101 }
00102
00103 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
00104 {
00105
00106 int result = 0;
00107 if(state == READING)
00108 {
00109
00110 int leadin = PluginClient::in_buffer_size;
00111
00112 double buffer[leadin];
00113 if(PluginClient::start - leadin < 0) leadin = PluginClient::start;
00114 read_samples(buffer, PluginClient::start - leadin, leadin);
00115 sample1 = buffer[leadin - 1];
00116
00117
00118 leadin = PluginClient::in_buffer_size;
00119 if(PluginClient::end - leadin < 0) leadin = PluginClient::end;
00120 read_samples(buffer, PluginClient::end - leadin, leadin);
00121 sample2 = buffer[leadin - 1];
00122 state = WRITING;
00123 current_position = PluginClient::start;
00124
00125
00126 slope = (sample2 - sample1) /
00127 (PluginClient::end - PluginClient::start);
00128 intercept = sample1;
00129
00130 }
00131
00132
00133 int fragment_len = PluginClient::in_buffer_size;
00134 if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
00135 double intercept2 = intercept + slope * (current_position - PluginClient::start);
00136 for(int i = 0; i < fragment_len; i++)
00137 {
00138 buffer[i] = intercept2 + slope * i;
00139 }
00140 current_position += fragment_len;
00141 write_length = fragment_len;
00142 result = progress->update(PluginClient::end -
00143 PluginClient::start +
00144 current_position -
00145 PluginClient::start);
00146 if(current_position >= PluginClient::end) result = 1;
00147
00148
00149
00150 return result;
00151 }
00152
00153
00154