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 N_("Normalize"); }
38 int NormalizeMain::is_realtime() { return 0; }
39 int NormalizeMain::is_multichannel() { return 1; }
42 VFrame* NormalizeMain::new_picon()
44 return new VFrame(picon_png);
48 int NormalizeMain::load_defaults()
50 char directory[BCTEXTLEN];
52 // set the default directory
53 sprintf(directory, "%snormalize.rc", BCASTDIR);
57 defaults = new Defaults(directory);
61 db_over = defaults->get("DBOVER", 0);
62 separate_tracks = defaults->get("SEPERATE_TRACKS", 1);
66 int NormalizeMain::save_defaults()
68 defaults->update("DBOVER", db_over);
69 defaults->update("SEPERATE_TRACKS", separate_tracks);
74 int NormalizeMain::get_parameters()
77 NormalizeWindow window(info.get_abs_cursor_x(), info.get_abs_cursor_y());
78 window.create_objects(&db_over, &separate_tracks);
79 int result = window.run_window();
83 int NormalizeMain::start_loop()
85 char string[BCTEXTLEN];
86 sprintf(string, "%s...", plugin_title());
87 progress = start_progress(string, (PluginClient::end - PluginClient::start) * 2);
90 current_position = PluginClient::start;
91 peak = new double[PluginClient::total_in_buffers];
92 scale = new double[PluginClient::total_in_buffers];
93 bzero(peak, sizeof(double) * PluginClient::total_in_buffers);
98 int NormalizeMain::process_loop(double **buffer, int64_t &write_length)
101 int64_t fragment_len;
103 //printf("NormalizeMain::process_loop 1\n");
106 fragment_len = PluginClient::in_buffer_size;
107 if(current_position + fragment_len > PluginClient::end) fragment_len = PluginClient::end - current_position;
108 //printf("NormalizeMain::process_loop 2 %d %f\n", current_position, scale[0]);
110 for(int i = 0; i < PluginClient::total_in_buffers; i++)
112 read_samples(buffer[i], i, current_position, fragment_len);
113 for(int j = 0; j < fragment_len; j++)
114 buffer[i][j] *= scale[i];
117 //printf("NormalizeMain::process_loop 1 %d %f\n", current_position, scale[0]);
118 current_position += fragment_len;
119 write_length = fragment_len;
120 result = progress->update(PluginClient::end -
121 PluginClient::start +
123 PluginClient::start);
124 if(current_position >= PluginClient::end) result = 1;
129 //printf("NormalizeMain::process_loop 4\n");
130 for(int i = PluginClient::start;
131 i < PluginClient::end && !result;
134 fragment_len = PluginClient::in_buffer_size;
135 if(i + fragment_len > PluginClient::end) fragment_len = PluginClient::end - i;
136 //printf("NormalizeMain::process_loop 5\n");
138 for(int j = 0; j < PluginClient::total_in_buffers; j++)
140 //printf("NormalizeMain::process_loop 6 %p\n", buffer);
141 read_samples(buffer[j], j, i, fragment_len);
142 //printf("NormalizeMain::process_loop 7\n");
144 for(int k = 0; k < fragment_len; k++)
146 if(peak[j] < fabs(buffer[j][k])) peak[j] = fabs(buffer[j][k]);
149 //printf("NormalizeMain::process_loop 8\n");
150 result = progress->update(i - PluginClient::start);
151 //printf("NormalizeMain::process_loop 9\n");
154 // Normalize all tracks
156 for(int i = 0; i < PluginClient::total_in_buffers; i++)
158 if(peak[i] > max) max = peak[i];
162 for(int i = 0; i < PluginClient::total_in_buffers; i++)
168 for(int i = 0; i < PluginClient::total_in_buffers; i++)
170 scale[i] = DB::fromdb(db_over) / peak[i];
172 //printf("NormalizeMain::process_loop 10\n");
174 char string[BCTEXTLEN];
175 sprintf(string, "%s %.0f%%...", plugin_title(), (DB::fromdb(db_over) / max) * 100);
176 progress->update_title(string);
177 // Start writing on next iteration
184 int NormalizeMain::stop_loop()
186 progress->stop_progress();