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"
31 #include "transportque.h"
46 class InterpolateAudioEffect : public PluginAClient
49 InterpolateAudioEffect(PluginServer *server);
50 ~InterpolateAudioEffect();
52 const char* plugin_title();
54 int process_buffer(int64_t size,
56 int64_t start_position,
60 #define FRAGMENT_SIZE 4096
61 Samples *start_fragment;
62 Samples *end_fragment;
72 REGISTER_PLUGIN(InterpolateAudioEffect)
80 InterpolateAudioEffect::InterpolateAudioEffect(PluginServer *server)
81 : PluginAClient(server)
87 InterpolateAudioEffect::~InterpolateAudioEffect()
89 if(start_fragment) delete start_fragment;
90 if(end_fragment) delete end_fragment;
96 const char* InterpolateAudioEffect::plugin_title()
98 return N_("Interpolate");
102 int InterpolateAudioEffect::is_realtime()
111 int InterpolateAudioEffect::process_buffer(int64_t size,
113 int64_t start_position,
116 if(!start_fragment) start_fragment = new Samples(FRAGMENT_SIZE);
117 if(!end_fragment) end_fragment = new Samples(FRAGMENT_SIZE);
118 double *buffer_samples = buffer->get_data();
119 double *start_samples = start_fragment->get_data();
120 double *end_samples = end_fragment->get_data();
122 if(get_direction() == PLAY_FORWARD)
124 // On first sample of range. Get boundary samples of effect.
125 if(get_source_position() == get_source_start())
127 // Need to read before desired sample to diffuse transients after audio
129 range_start = get_source_start();
130 range_end = get_source_start() + get_total_len();
131 //printf("InterpolateAudioEffect::process_buffer 1 %p\n", start_fragment);
132 read_samples(start_fragment,
135 range_start - FRAGMENT_SIZE,
137 start_sample = start_samples[FRAGMENT_SIZE - 1];
138 read_samples(end_fragment,
141 range_end - FRAGMENT_SIZE,
143 end_sample = end_samples[FRAGMENT_SIZE - 1];
147 for(int i = 0; i < size; i++)
149 double end_fraction = (double)(i + start_position - range_start) /
150 (range_end - range_start);
151 double start_fraction = 1.0 - end_fraction;
152 double out_sample = start_sample * start_fraction +
153 end_sample * end_fraction;
154 buffer_samples[i] = out_sample;
159 // On first sample of range. Get boundary samples of effect.
160 if(get_source_position() == get_source_start() + get_total_len())
162 // Need to read before desired sample to diffuse transients after audio
164 range_start = get_source_start() + get_total_len();
165 range_end = get_source_start();
166 read_samples(start_fragment,
171 start_sample = start_samples[0];
172 read_samples(end_fragment,
177 end_sample = end_samples[0];
181 for(int i = 0; i < size; i++)
183 double start_fraction = (double)(start_position - i - range_end) /
184 (range_start - range_end);
185 double end_fraction = 1.0 - start_fraction;
186 double out_sample = start_sample * start_fraction +
187 end_sample * end_fraction;
188 buffer_samples[i] = out_sample;