/*
* CINELERRA
* Copyright (C) 2011 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"
int ParametricBand::equivalent(ParametricBand &that)
{
- if(freq == that.freq &&
- EQUIV(quality, that.quality) &&
+ if(freq == that.freq &&
+ EQUIV(quality, that.quality) &&
EQUIV(magnitude, that.magnitude) &&
mode == that.mode)
{
mode = that.mode;
}
-void ParametricBand::interpolate(ParametricBand &prev,
- ParametricBand &next,
- double prev_scale,
+void ParametricBand::interpolate(ParametricBand &prev,
+ ParametricBand &next,
+ double prev_scale,
double next_scale)
{
freq = (int)(prev.freq * prev_scale + next.freq * next_scale + 0.5);
band[i].copy_from(that.band[i]);
}
-void ParametricConfig::interpolate(ParametricConfig &prev,
- ParametricConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+void ParametricConfig::interpolate(ParametricConfig &prev,
+ ParametricConfig &next,
+ int64_t prev_frame,
+ int64_t next_frame,
int64_t current_frame)
{
double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
ParametricMode::ParametricMode(ParametricEQ *plugin, int x, int y, int band)
- : BC_PopupMenu(x,
- y,
- 150,
+ : BC_PopupMenu(x,
+ y,
+ 150,
mode_to_text(plugin->config.band[band].mode))
{
//printf("ParametricMode::ParametricMode %d %d\n", band, plugin->config.band[band].mode);
#define X3 110
#define X4 160
-
+
void ParametricBandGUI::create_objects()
{
window->add_subwindow(freq = new ParametricFreq(plugin, X1, y, band));
ParametricWindow::ParametricWindow(ParametricEQ *plugin)
- : PluginClientWindow(plugin,
- 350,
- 400,
- 350,
+ : PluginClientWindow(plugin,
+ 350,
+ 400,
+ 350,
400,
0)
{
void ParametricWindow::create_objects()
{
int y = 35;
-SET_TRACE
-
+SET_TRACE
+
add_subwindow(new BC_Title(X1, 10, _("Freq")));
add_subwindow(new BC_Title(X2, 10, _("Qual")));
add_subwindow(new BC_Title(X3, 10, _("Level")));
y += 50;
}
-SET_TRACE
+SET_TRACE
BC_Title *title;
int x = plugin->get_theme()->widget_border;
add_subwindow(title = new BC_Title(x, y + 10, _("Wetness:")));
x += title->get_w() + plugin->get_theme()->widget_border;
- add_subwindow(wetness = new ParametricWetness(plugin,
- x,
+ add_subwindow(wetness = new ParametricWetness(plugin,
+ x,
y));
x += wetness->get_w() + plugin->get_theme()->widget_border;
add_subwindow(title = new BC_Title(x, y + 10, _("Window:")));
x += title->get_w() + plugin->get_theme()->widget_border;
- add_subwindow(size = new ParametricSize(this,
- plugin,
- x,
+ add_subwindow(size = new ParametricSize(this,
+ plugin,
+ x,
y + 10));
size->create_objects();
size->update(plugin->config.window_size);
int canvas_y = y;
int canvas_w = get_w() - canvas_x - 10;
int canvas_h = get_h() - canvas_y - 30;
- add_subwindow(canvas = new BC_SubWindow(canvas_x,
- canvas_y,
- canvas_w,
- canvas_h,
+ add_subwindow(canvas = new BC_SubWindow(canvas_x,
+ canvas_y,
+ canvas_w,
+ canvas_h,
BLACK));
-SET_TRACE
+SET_TRACE
// Draw canvas titles
set_font(SMALLFONT);
#define MAJOR_DIVISIONS 4
}
}
-SET_TRACE
+SET_TRACE
#undef MAJOR_DIVISIONS
#define MAJOR_DIVISIONS 5
for(int i = 0; i <= MAJOR_DIVISIONS; i++)
int y2 = y1 - 10;
int y3 = y2 - 5;
int y4 = canvas_y + canvas_h;
-
+
set_color(BLACK);
draw_text(x2 + 1, y1 + 1, string);
draw_line(x1 + 1, y4 + 1, x1 + 1, y2 + 1);
#define MINOR_DIVISIONS 5
for(int j = 0; j < MINOR_DIVISIONS; j++)
{
- int x3 = (int)(x1 +
+ int x3 = (int)(x1 +
(canvas_w / MAJOR_DIVISIONS) -
- exp(-(double)j * 0.7) *
+ exp(-(double)j * 0.7) *
(canvas_w / MAJOR_DIVISIONS));
set_color(BLACK);
draw_line(x3 + 1, y4 + 1, x3 + 1, y3 + 1);
}
}
-SET_TRACE
+SET_TRACE
update_canvas();
show_window();
-SET_TRACE
+SET_TRACE
}
int index = (int64_t)freq * (int64_t)frame->window_size / 2 / niquist;
if(index < frame->window_size / 2)
{
- double magnitude = frame->data[index] /
- frame->freq_max *
+ double magnitude = frame->data[index] /
+ frame->freq_max *
frame->time_max;
- y2 = (int)(canvas->get_h() -
+ y2 = (int)(canvas->get_h() -
(DB::todb(magnitude) - INFINITYGAIN) *
- canvas->get_h() /
+ canvas->get_h() /
-INFINITYGAIN);
CLAMP(y2, 0, canvas->get_h() - 1);
if(i > 0)
if(frame) delete frame;
total_frames--;
}
-
+
// canvas->set_color(GREEN);
// canvas->draw_line(0, wetness, canvas->get_w(), wetness);
-// canvas->draw_line(0,
-// wetness,
-// canvas->get_w(),
+// canvas->draw_line(0,
+// wetness,
+// canvas->get_w(),
// wetness);
canvas->set_color(WHITE);
if(magnitude > 1)
{
- y2 -= (int)(DB::todb(magnitude) *
- canvas->get_h() *
- 3 /
- 4 /
+ y2 -= (int)(DB::todb(magnitude) *
+ canvas->get_h() *
+ 3 /
+ 4 /
15);
}
else
// int freq = Freq::tofreq((int)((float)i / canvas->get_w() * TOTALFREQS));
// int index = (int)((float)freq / niquist * plugin->config.window_size / 2);
// double magnitude = plugin->envelope[index];
-// int y2 = canvas->get_h() -
+// int y2 = canvas->get_h() -
// (int)((double)canvas->get_h() / normalize * magnitude);
// if(i > 0) canvas->draw_line(i - 1, y1, i, y2);
// y1 = y2;
int ParametricFFT::signal_process()
{
// Create new frame for updating GUI
- frame = new ParametricGUIFrame(window_size,
+ frame = new ParametricGUIFrame(window_size,
plugin->PluginAClient::project_sample_rate);
plugin->add_gui_frame(frame);
for(int i = 0; i < window_size / 2; i++)
{
-// if(i == 10) printf("ParametricFFT::signal_process %d %f\n",
-// __LINE__,
+// if(i == 10) printf("ParametricFFT::signal_process %d %f\n",
+// __LINE__,
// plugin->envelope[i]);
- double result = plugin->envelope[i] *
+ double result = plugin->envelope[i] *
sqrt(freq_real[i] * freq_real[i] + freq_imag[i] * freq_imag[i]);
double angle = atan2(freq_imag[i], freq_real[i]);
freq_real[i] = result * cos(angle);
freq_imag[i] = result * sin(angle);
-
+
frame->data[i] = result;
if(result > freq_max) freq_max = result;
}
-int ParametricFFT::read_samples(int64_t output_sample,
- int samples,
+int ParametricFFT::read_samples(int64_t output_sample,
+ int samples,
Samples *buffer)
{
return plugin->read_samples(buffer,
ParametricEQ::ParametricEQ(PluginServer *server)
: PluginAClient(server)
{
-
+
fft = 0;
need_reconfigure = 1;
envelope = 0;
int cutoff = (int)((double)config.band[band].freq / niquist * config.window_size / 2);
for(int i = 0; i < config.window_size / 2; i++)
{
- if(i < cutoff)
+ if(i < cutoff)
envelope[i] += magnitude;
}
}
int cutoff = (int)((double)config.band[band].freq / niquist * config.window_size / 2);
for(int i = 0; i < config.window_size / 2; i++)
{
- if(i > cutoff)
+ if(i > cutoff)
envelope[i] += magnitude;
}
}
case ParametricBand::BANDPASS:
if(pass == 0)
{
- double magnitude = (config.band[band].magnitude > 0) ?
- (DB::fromdb(config.band[band].magnitude) - 1) :
+ double magnitude = (config.band[band].magnitude > 0) ?
+ (DB::fromdb(config.band[band].magnitude) - 1) :
(-1 + DB::fromdb(config.band[band].magnitude));
double sigma = (config.band[band].quality < 1) ?
(1.0 - config.band[band].quality) :
0.01;
sigma /= 4;
- double center = (double)Freq::fromfreq(config.band[band].freq) /
+ double center = (double)Freq::fromfreq(config.band[band].freq) /
TOTALFREQS;
double normalize = gauss(sigma, 0, 0);
- if(config.band[band].magnitude <= -MAXMAGNITUDE)
+ if(config.band[band].magnitude <= -MAXMAGNITUDE)
magnitude = -1;
for(int i = 0; i < config.window_size / 2; i++)
{
int freq = i * niquist / (config.window_size / 2);
int current_slot = Freq::fromfreq(freq);
- envelope[i] += magnitude *
- gauss(sigma, center, (double)current_slot / TOTALFREQS) /
+ envelope[i] += magnitude *
+ gauss(sigma, center, (double)current_slot / TOTALFREQS) /
normalize;
// printf("freq=%d magnitude=%f gauss=%f normalize=%f envelope[i]=%f\n",
// freq,
{
if(EQUIV(sigma, 0)) sigma = 0.01;
- double result = 1.0 /
- sqrt(2 * M_PI * sigma * sigma) *
- exp(-(x - center) * (x - center) /
+ double result = 1.0 /
+ sqrt(2 * M_PI * sigma * sigma) *
+ exp(-(x - center) * (x - center) /
(2 * sigma * sigma));
-int ParametricEQ::process_buffer(int64_t size,
- Samples *buffer,
+int ParametricEQ::process_buffer(int64_t size,
+ Samples *buffer,
int64_t start_position,
int sample_rate)
{
need_reconfigure |= load_configuration();
if(need_reconfigure) reconfigure();
-
- fft->process_buffer(start_position,
- size,
- buffer,
+
+ fft->process_buffer(start_position,
+ size,
+ buffer,
get_direction());