/*
* CINELERRA
- * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
- *
+ * Copyright (C) 2010-2016 Adam Williams <broadcast at earthling dot net>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
#include "bcdisplayinfo.h"
ResampleRTConfig::ResampleRTConfig()
{
- scale = 1;
+ num = 1;
+ denom = 1;
}
int ResampleRTConfig::equivalent(ResampleRTConfig &src)
{
- return fabs(scale - src.scale) < 0.0001;
+ return fabs(num - src.num) < 0.0001 &&
+ fabs(denom - src.denom) < 0.0001;
}
void ResampleRTConfig::copy_from(ResampleRTConfig &src)
{
- this->scale = src.scale;
+ this->num = src.num;
+ this->denom = src.denom;
}
-void ResampleRTConfig::interpolate(ResampleRTConfig &prev,
- ResampleRTConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+void ResampleRTConfig::interpolate(ResampleRTConfig &prev,
+ ResampleRTConfig &next,
+ int64_t prev_frame,
+ int64_t next_frame,
int64_t current_frame)
{
- this->scale = prev.scale;
+ this->num = prev.num;
+ this->denom = prev.denom;
}
void ResampleRTConfig::boundaries()
{
- if(fabs(scale) < 0.0001) scale = 0.0001;
+ if(num < 0.0001) num = 0.0001;
+ if(denom < 0.0001) denom = 0.0001;
}
ResampleRTWindow::ResampleRTWindow(ResampleRT *plugin)
- : PluginClientWindow(plugin,
- 210,
- 160,
- 200,
- 160,
+ : PluginClientWindow(plugin,
+ 210,
+ 160,
+ 200,
+ 160,
0)
{
this->plugin = plugin;
void ResampleRTWindow::create_objects()
{
- int x = 10, y = 10;
+ int x = plugin->get_theme()->window_border;
+ int y = plugin->get_theme()->window_border;
BC_Title *title;
- add_subwindow(title = new BC_Title(x, y, _("Scale by amount:")));
+ add_subwindow(title = new BC_Title(x, y, _("Input samples:")));
y += title->get_h() + plugin->get_theme()->widget_border;
+ num = new ResampleRTNum(this, plugin, x, y);
+ num->create_objects();
+
+ y += num->get_h() + plugin->get_theme()->widget_border;
+ add_subwindow(title = new BC_Title(x, y, _("Output samples:")));
+ y += title->get_h() + plugin->get_theme()->widget_border;
+ denom = new ResampleRTDenom(this, plugin, x, y);
+ denom->create_objects();
- scale = new ResampleRTScale(this,
- plugin,
- x,
- y);
- scale->create_objects();
show_window();
}
-ResampleRTScale::ResampleRTScale(ResampleRTWindow *window,
- ResampleRT *plugin,
- int x,
+ResampleRTNum::ResampleRTNum(ResampleRTWindow *window,
+ ResampleRT *plugin,
+ int x,
int y)
: BC_TumbleTextBox(window,
- plugin->config.scale,
+ plugin->config.num,
(float)0.0001,
(float)1000,
- x,
- y,
+ x,
+ y,
100)
{
this->plugin = plugin;
set_increment(0.001);
}
-int ResampleRTScale::handle_event()
+int ResampleRTNum::handle_event()
{
- plugin->config.scale = atof(get_text());
+ plugin->config.num = atof(get_text());
+ plugin->config.boundaries();
+ plugin->send_configure_change();
+ return 1;
+}
+
+
+
+
+ResampleRTDenom::ResampleRTDenom(ResampleRTWindow *window,
+ ResampleRT *plugin,
+ int x,
+ int y)
+ : BC_TumbleTextBox(window,
+ plugin->config.denom,
+ (float)0.0001,
+ (float)1000,
+ x,
+ y,
+ 100)
+{
+ this->plugin = plugin;
+ set_increment(0.001);
+}
+
+int ResampleRTDenom::handle_event()
+{
+ plugin->config.denom = atof(get_text());
+ plugin->config.boundaries();
plugin->send_configure_change();
return 1;
}
// To get the keyframes to work, resampling is always done in the forward
// direction with the plugin converting to reverse.
-int ResampleRTResample::read_samples(Samples *buffer,
- int64_t start,
+int ResampleRTResample::read_samples(Samples *buffer,
+ int64_t start,
int64_t len)
{
int result = plugin->read_samples(buffer,
plugin->source_start += len;
else
plugin->source_start -= len;
-
+
return result;
}
LOAD_CONFIGURATION_MACRO(ResampleRT, ResampleRTConfig)
-int ResampleRT::process_buffer(int64_t size,
+int ResampleRT::process_buffer(int64_t size,
Samples *buffer,
int64_t start_position,
int sample_rate)
if(!resample) resample = new ResampleRTResample(this);
need_reconfigure |= load_configuration();
-
-
+
+
if(start_position != dest_start) need_reconfigure = 1;
dest_start = start_position;
prev_position = get_source_start();
}
- source_start = (int64_t)((start_position - prev_position) *
- config.scale) + prev_position;
+ source_start = (int64_t)((start_position - prev_position) *
+ config.num / config.denom) + prev_position;
resample->reset();
need_reconfigure = 0;
resample->resample(buffer,
size,
- (int)1000000,
- (int)(1000000 / config.scale),
+ (int)(65536 * config.num),
+ (int)(65536 * config.denom),
start_position,
- get_direction());
+ get_direction());
if(get_direction() == PLAY_FORWARD)
dest_start += size;
// cause data to be stored directly in text
output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
output.tag.set_title("RESAMPLERT");
- output.tag.set_property("SCALE", config.scale);
+ output.tag.set_property("SCALE", config.num);
+ output.tag.set_property("DENOM", config.denom);
output.append_tag();
output.tag.set_title("/RESAMPLERT");
output.append_tag();
{
if(input.tag.title_is("RESAMPLERT"))
{
- config.scale = input.tag.get_property("SCALE", config.scale);
+ config.num = input.tag.get_property("SCALE", config.num);
+ config.denom = input.tag.get_property("DENOM", config.denom);
}
}
}
if(load_configuration())
{
thread->window->lock_window("ResampleRT::update_gui");
- ((ResampleRTWindow*)thread->window)->scale->update((float)config.scale);
+ ((ResampleRTWindow*)thread->window)->num->update((float)config.num);
+ ((ResampleRTWindow*)thread->window)->denom->update((float)config.denom);
thread->window->unlock_window();
}
}