1 #include "bcdisplayinfo.h"
3 #include "mainprogress.h"
5 #include "normalizewindow.h"
14 #define _(String) gettext(String)
15 #define gettext_noop(String) String
16 #define N_(String) gettext_noop (String)
18 REGISTER_PLUGIN(NormalizeMain)
25 NormalizeMain::NormalizeMain(PluginServer *server)
26 : PluginAClient(server)
31 NormalizeMain::~NormalizeMain()
37 char* NormalizeMain::plugin_title() { return _("Normalize"); }
39 int NormalizeMain::is_realtime() { return 0; }
41 int NormalizeMain::is_multichannel() { return 1; }
43 VFrame* NormalizeMain::new_picon()
45 return new VFrame(picon_png);
49 int NormalizeMain::load_defaults()
51 char directory[BCTEXTLEN];
53 // set the default directory
54 sprintf(directory, "%snormalize.rc", BCASTDIR);
58 defaults = new Defaults(directory);
62 db_over = defaults->get("DBOVER", 0);
63 separate_tracks = defaults->get("SEPERATE_TRACKS", 1);
67 int NormalizeMain::save_defaults()
69 defaults->update("DBOVER", db_over);
70 defaults->update("SEPERATE_TRACKS", separate_tracks);
75 int NormalizeMain::get_parameters()
78 //printf("NormalizeMain::get_parameters 1\n");
79 NormalizeWindow window(info.get_abs_cursor_x(), info.get_abs_cursor_y());
80 //printf("NormalizeMain::get_parameters 2\n");
81 window.create_objects(&db_over, &separate_tracks);
82 //printf("NormalizeMain::get_parameters 3\n");
83 int result = window.run_window();
84 //printf("NormalizeMain::get_parameters 4\n");
88 int NormalizeMain::start_loop()
90 char string[BCTEXTLEN];
91 sprintf(string, "%s...", plugin_title());
92 progress = start_progress(string, (PluginClient::end - PluginClient::start) * 2);
95 current_position = PluginClient::start;
96 peak = new double[PluginClient::total_in_buffers];
97 scale = new double[PluginClient::total_in_buffers];
98 bzero(peak, sizeof(double) * PluginClient::total_in_buffers);
103 int NormalizeMain::process_loop(double **buffer, int64_t &write_length)
106 int64_t fragment_len;
108 //printf("NormalizeMain::process_loop 1\n");
111 fragment_len = PluginClient::in_buffer_size;
112 if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
113 //printf("NormalizeMain::process_loop 2 %d %f\n", current_position, scale[0]);
115 for(int i = 0; i < PluginClient::total_in_buffers; i++)
117 read_samples(buffer[i], i, current_position, fragment_len);
118 for(int j = 0; j < fragment_len; j++)
119 buffer[i][j] *= scale[i];
122 //printf("NormalizeMain::process_loop 1 %d %f\n", current_position, scale[0]);
123 current_position += fragment_len;
124 write_length = fragment_len;
125 result = progress->update(PluginClient::end -
126 PluginClient::start +
128 PluginClient::start);
129 if(current_position >= PluginClient::end) result = 1;
134 //printf("NormalizeMain::process_loop 4\n");
135 for(int i = PluginClient::start;
136 i < PluginClient::end && !result;
139 fragment_len = PluginClient::in_buffer_size;
140 if(i + fragment_len > PluginClient::end) fragment_len = PluginClient::end - i;
141 //printf("NormalizeMain::process_loop 5\n");
143 for(int j = 0; j < PluginClient::total_in_buffers; j++)
145 //printf("NormalizeMain::process_loop 6 %p\n", buffer);
146 read_samples(buffer[j], j, i, fragment_len);
147 //printf("NormalizeMain::process_loop 7\n");
149 for(int k = 0; k < fragment_len; k++)
151 if(peak[j] < fabs(buffer[j][k])) peak[j] = fabs(buffer[j][k]);
154 //printf("NormalizeMain::process_loop 8\n");
155 result = progress->update(i - PluginClient::start);
156 //printf("NormalizeMain::process_loop 9\n");
159 // Normalize all tracks
161 for(int i = 0; i < PluginClient::total_in_buffers; i++)
163 if(peak[i] > max) max = peak[i];
167 for(int i = 0; i < PluginClient::total_in_buffers; i++)
173 for(int i = 0; i < PluginClient::total_in_buffers; i++)
175 scale[i] = DB::fromdb(db_over) / peak[i];
177 //printf("NormalizeMain::process_loop 10\n");
179 char string[BCTEXTLEN];
180 sprintf(string, "%s %.0f%%...", plugin_title(), (DB::fromdb(db_over) / max) * 100);
181 progress->update_title(string);
182 // Start writing on next iteration
189 int NormalizeMain::stop_loop()
191 progress->stop_progress();