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 #include "transportque.h"
00010
00011 #include <string.h>
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 class InterpolateAudioEffect : public PluginAClient
00025 {
00026 public:
00027 InterpolateAudioEffect(PluginServer *server);
00028 ~InterpolateAudioEffect();
00029
00030 VFrame* new_picon();
00031 char* plugin_title();
00032
00033 int process_buffer(int64_t size,
00034 double *buffer,
00035 int64_t start_position,
00036 int sample_rate);
00037 int is_realtime();
00038
00039 #define FRAGMENT_SIZE 4096
00040 double *start_fragment;
00041 double *end_fragment;
00042 double start_sample;
00043 double end_sample;
00044 int64_t range_start;
00045 int64_t range_end;
00046 };
00047
00048
00049
00050
00051 REGISTER_PLUGIN(InterpolateAudioEffect)
00052
00053
00054
00055
00056
00057
00058
00059 InterpolateAudioEffect::InterpolateAudioEffect(PluginServer *server)
00060 : PluginAClient(server)
00061 {
00062 start_fragment = 0;
00063 end_fragment = 0;
00064 }
00065
00066 InterpolateAudioEffect::~InterpolateAudioEffect()
00067 {
00068 if(start_fragment) delete [] start_fragment;
00069 if(end_fragment) delete [] end_fragment;
00070 }
00071
00072
00073
00074
00075 char* InterpolateAudioEffect::plugin_title()
00076 {
00077 return N_("Interpolate");
00078 }
00079
00080
00081 int InterpolateAudioEffect::is_realtime()
00082 {
00083 return 1;
00084 }
00085
00086
00087 #include "picon_png.h"
00088 NEW_PICON_MACRO(InterpolateAudioEffect)
00089
00090
00091
00092 int InterpolateAudioEffect::process_buffer(int64_t size,
00093 double *buffer,
00094 int64_t start_position,
00095 int sample_rate)
00096 {
00097 double slope;
00098 double intercept;
00099
00100 if(!start_fragment) start_fragment = new double[FRAGMENT_SIZE];
00101 if(!end_fragment) end_fragment = new double[FRAGMENT_SIZE];
00102
00103 if(get_direction() == PLAY_FORWARD)
00104 {
00105
00106 if(get_source_position() == get_source_start())
00107 {
00108
00109
00110 range_start = get_source_start();
00111 range_end = get_source_start() + get_total_len();
00112
00113 read_samples(start_fragment,
00114 0,
00115 sample_rate,
00116 range_start - FRAGMENT_SIZE,
00117 FRAGMENT_SIZE);
00118 start_sample = start_fragment[FRAGMENT_SIZE - 1];
00119 read_samples(end_fragment,
00120 0,
00121 sample_rate,
00122 range_end - FRAGMENT_SIZE,
00123 FRAGMENT_SIZE);
00124 end_sample = end_fragment[FRAGMENT_SIZE - 1];
00125 }
00126
00127
00128 for(int i = 0; i < size; i++)
00129 {
00130 double end_fraction = (double)(i + start_position - range_start) /
00131 (range_end - range_start);
00132 double start_fraction = 1.0 - end_fraction;
00133 double out_sample = start_sample * start_fraction +
00134 end_sample * end_fraction;
00135 buffer[i] = out_sample;
00136 }
00137 }
00138 else
00139 {
00140
00141 if(get_source_position() == get_source_start() + get_total_len())
00142 {
00143
00144
00145 range_start = get_source_start() + get_total_len();
00146 range_end = get_source_start();
00147 read_samples(start_fragment,
00148 0,
00149 sample_rate,
00150 range_start,
00151 FRAGMENT_SIZE);
00152 start_sample = start_fragment[0];
00153 read_samples(end_fragment,
00154 0,
00155 sample_rate,
00156 range_end,
00157 FRAGMENT_SIZE);
00158 end_sample = end_fragment[0];
00159 }
00160
00161
00162 for(int i = 0; i < size; i++)
00163 {
00164 double start_fraction = (double)(start_position - i - range_end) /
00165 (range_start - range_end);
00166 double end_fraction = 1.0 - start_fraction;
00167 double out_sample = start_sample * start_fraction +
00168 end_sample * end_fraction;
00169 buffer[i] = out_sample;
00170 }
00171 }
00172 return 0;
00173 }
00174
00175