Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / interpolateall / interpolateall.C
blobc9bc99309d8ce8c3bba68f3ed73681f5d0b04915
1 #include "bcdisplayinfo.h"
2 #include "clip.h"
3 #include "bchash.h"
4 #include "guicast.h"
5 #include "filexml.h"
6 #include "language.h"
7 #include "mainprogress.h"
8 #include "pluginaclient.h"
10 #include <string.h>
20 class InterpolateAllEffect : public PluginAClient
22 public:
23         InterpolateAllEffect(PluginServer *server);
24         ~InterpolateAllEffect();
26         char* plugin_title();
27         int is_realtime();
28         int is_multichannel();
29         int get_parameters();
30         int start_loop();
31         int process_loop(double *buffer, long &output_lenght);
32         int stop_loop();
37         int state;
38         enum
39         {
40                 READING,
41                 WRITING
42         };
43         double sample1;
44         double sample2;
45         int current_position;
46         double slope;
47         double intercept;
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()
83         return 0;
86 int InterpolateAllEffect::start_loop()
88         state = READING;
89         char string[BCTEXTLEN];
90         sprintf(string, "%s...", plugin_title());
91         progress = start_progress(string, (PluginClient::end - PluginClient::start));
92         current_position = PluginClient::start;
93         return 0;
96 int InterpolateAllEffect::stop_loop()
98         progress->stop_progress();
99         delete progress;
100         return 0;
103 int InterpolateAllEffect::process_loop(double *buffer, long &write_length)
105 //printf("InterpolateAllEffect::process_loop 1\n");
106         int result = 0;
107         if(state == READING)
108         {
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];
122                 state = WRITING;
123                 current_position = PluginClient::start;
125 // Get slope and intercept
126                 slope = (sample2 - sample1) /
127                         (PluginClient::end - PluginClient::start);
128                 intercept = sample1;
129 //printf("InterpolateAllEffect::process_loop 3\n");
130         }
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++)
137         {
138                 buffer[i] = intercept2 + slope * i;
139         }
140         current_position += fragment_len;
141         write_length = fragment_len;
142         result = progress->update(PluginClient::end - 
143                 PluginClient::start + 
144                 current_position - 
145                 PluginClient::start);
146         if(current_position >= PluginClient::end) result = 1;
147 //printf("InterpolateAllEffect::process_loop 5\n");
150         return result;