X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Faudioscope%2Faudioscope.C;h=484b6cc9e2bc00eb390ff8c541329827a02fd580;hp=b80b102c003902dfcdfd1eafe348f14fbbd51716;hb=21c2e6b36d6a96c2f662a89459d607b5a387f4eb;hpb=5a1b2bb96f2bd6b7ef4f8031763683726c02219d diff --git a/cinelerra-5.1/plugins/audioscope/audioscope.C b/cinelerra-5.1/plugins/audioscope/audioscope.C index b80b102c..484b6cc9 100644 --- a/cinelerra-5.1/plugins/audioscope/audioscope.C +++ b/cinelerra-5.1/plugins/audioscope/audioscope.C @@ -2,21 +2,21 @@ /* * CINELERRA * Copyright (C) 1997-2011 Adam Williams - * + * * 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 "audioscope.h" @@ -66,10 +66,10 @@ void AudioScopeConfig::copy_from(AudioScopeConfig &that) trigger_level = that.trigger_level; } -void AudioScopeConfig::interpolate(AudioScopeConfig &prev, - AudioScopeConfig &next, - int64_t prev_frame, - int64_t next_frame, +void AudioScopeConfig::interpolate(AudioScopeConfig &prev, + AudioScopeConfig &next, + int64_t prev_frame, + int64_t next_frame, int64_t current_frame) { copy_from(prev); @@ -101,9 +101,9 @@ AudioScopeFrame::~AudioScopeFrame() AudioScopeHistory::AudioScopeHistory(AudioScope *plugin, - int x, + int x, int y) - : BC_IPot(x, + : BC_IPot(x, y, plugin->config.history_size, MIN_HISTORY, @@ -126,13 +126,13 @@ int AudioScopeHistory::handle_event() -AudioScopeWindowSize::AudioScopeWindowSize(AudioScope *plugin, - int x, +AudioScopeWindowSize::AudioScopeWindowSize(AudioScope *plugin, + int x, int y, char *text) - : BC_PopupMenu(x, - y, - 80, + : BC_PopupMenu(x, + y, + 80, text) { this->plugin = plugin; @@ -147,7 +147,7 @@ int AudioScopeWindowSize::handle_event() AudioScopeWindowSizeTumbler::AudioScopeWindowSizeTumbler(AudioScope *plugin, int x, int y) - : BC_Tumbler(x, + : BC_Tumbler(x, y) { this->plugin = plugin; @@ -181,10 +181,10 @@ int AudioScopeWindowSizeTumbler::handle_down_event() -AudioScopeCanvas::AudioScopeCanvas(AudioScope *plugin, - int x, - int y, - int w, +AudioScopeCanvas::AudioScopeCanvas(AudioScope *plugin, + int x, + int y, + int w, int h) : BC_SubWindow(x, y, w, h, BLACK) { @@ -231,9 +231,9 @@ void AudioScopeCanvas::calculate_point() int y = get_cursor_y(); CLAMP(x, 0, get_w() - 1); CLAMP(y, 0, get_h() - 1); - + ((AudioScopeWindow*)plugin->thread->window)->calculate_probe( - x, + x, y, 1); @@ -268,12 +268,12 @@ int AudioScopeTriggerLevel::handle_event() -AudioScopeMode::AudioScopeMode(AudioScope *plugin, - int x, +AudioScopeMode::AudioScopeMode(AudioScope *plugin, + int x, int y) - : BC_PopupMenu(x, - y, - 180, + : BC_PopupMenu(x, + y, + 180, mode_to_text(plugin->config.mode)) { this->plugin = plugin; @@ -338,10 +338,10 @@ int AudioScopeMode::text_to_mode(const char *text) AudioScopeWindow::AudioScopeWindow(AudioScope *plugin) - : PluginClientWindow(plugin, - plugin->w, - plugin->h, - 320, + : PluginClientWindow(plugin, + plugin->w, + plugin->h, + 320, 320, 1) { @@ -358,12 +358,12 @@ void AudioScopeWindow::create_objects() int y = 0; char string[BCTEXTLEN]; - add_subwindow(canvas = new AudioScopeCanvas(plugin, - 0, - 0, - get_w(), - get_h() - - plugin->get_theme()->widget_border * 4 - + add_subwindow(canvas = new AudioScopeCanvas(plugin, + 0, + 0, + get_w(), + get_h() - + plugin->get_theme()->widget_border * 4 - BC_Title::calculate_h(this, "X") * 3)); canvas->set_cursor(CROSS_CURSOR, 0, 0); draw_overlay(); @@ -373,7 +373,7 @@ void AudioScopeWindow::create_objects() add_subwindow(history_size_title = new BC_Title(x, y, _("History Size:"))); x += history_size_title->get_w() + plugin->get_theme()->widget_border; add_subwindow(history_size = new AudioScopeHistory(plugin, - x, + x, y)); x += history_size->get_w() + plugin->get_theme()->widget_border; @@ -386,7 +386,7 @@ void AudioScopeWindow::create_objects() add_subwindow(window_size = new AudioScopeWindowSize(plugin, x, y, string)); x += window_size->get_w(); add_subwindow(window_size_tumbler = new AudioScopeWindowSizeTumbler(plugin, x, y)); - + for(int i = MIN_WINDOW; i <= MAX_WINDOW; i *= 2) { sprintf(string, "%d", i); @@ -410,7 +410,7 @@ void AudioScopeWindow::create_objects() x += trigger_level_title->get_w() + plugin->get_theme()->widget_border; add_subwindow(trigger_level = new AudioScopeTriggerLevel(plugin, x, y)); - + x += trigger_level->get_w() + plugin->get_theme()->widget_border; y = y1; @@ -431,9 +431,9 @@ int AudioScopeWindow::resize_event(int w, int h) int y_diff = h - get_h(); int canvas_factor = get_h() - canvas->get_h(); - canvas->reposition_window(0, - 0, - w, + canvas->reposition_window(0, + 0, + w, h - canvas_factor); canvas->clear_box(0, 0, canvas->get_w(), canvas->get_h()); draw_overlay(); @@ -443,37 +443,37 @@ int AudioScopeWindow::resize_event(int w, int h) // Remove all columns which may be a different size. plugin->frame_buffer.remove_all_objects(); - window_size_title->reposition_window(window_size_title->get_x(), + window_size_title->reposition_window(window_size_title->get_x(), window_size_title->get_y() + y_diff); - window_size->reposition_window(window_size->get_x(), + window_size->reposition_window(window_size->get_x(), window_size->get_y() + y_diff); - window_size_tumbler->reposition_window(window_size_tumbler->get_x(), + window_size_tumbler->reposition_window(window_size_tumbler->get_x(), window_size_tumbler->get_y() + y_diff); - - history_size_title->reposition_window(history_size_title->get_x(), + + history_size_title->reposition_window(history_size_title->get_x(), history_size_title->get_y() + y_diff); - history_size->reposition_window(history_size->get_x(), + history_size->reposition_window(history_size->get_x(), history_size->get_y() + y_diff); - mode_title->reposition_window(mode_title->get_x(), + mode_title->reposition_window(mode_title->get_x(), mode_title->get_y() + y_diff); - mode->reposition_window(mode->get_x(), + mode->reposition_window(mode->get_x(), mode->get_y() + y_diff); - trigger_level_title->reposition_window(trigger_level_title->get_x(), + trigger_level_title->reposition_window(trigger_level_title->get_x(), trigger_level_title->get_y() + y_diff); - trigger_level->reposition_window(trigger_level->get_x(), + trigger_level->reposition_window(trigger_level->get_x(), trigger_level->get_y() + y_diff); - probe_sample->reposition_window(probe_sample->get_x(), + probe_sample->reposition_window(probe_sample->get_x(), probe_sample->get_y() + y_diff); - probe_level0->reposition_window(probe_level0->get_x(), + probe_level0->reposition_window(probe_level0->get_x(), probe_level0->get_y() + y_diff); - probe_level1->reposition_window(probe_level1->get_x(), + probe_level1->reposition_window(probe_level1->get_x(), probe_level1->get_y() + y_diff); flush(); @@ -486,10 +486,10 @@ int AudioScopeWindow::resize_event(int w, int h) void AudioScopeWindow::draw_overlay() { canvas->set_color(GREEN); - - canvas->draw_line(0, - canvas->get_h() / 2, - canvas->get_w(), + + canvas->draw_line(0, + canvas->get_h() / 2, + canvas->get_w(), canvas->get_h() / 2); if(plugin->config.mode == XY_MODE) { @@ -509,8 +509,8 @@ void AudioScopeWindow::draw_trigger() if(plugin->config.mode == WAVEFORM_RISING_TRIGGER || plugin->config.mode == WAVEFORM_FALLING_TRIGGER) { - int y = (int)(-plugin->config.trigger_level * - canvas->get_h() / 2 + + int y = (int)(-plugin->config.trigger_level * + canvas->get_h() / 2 + canvas->get_h() / 2); CLAMP(y, 0, canvas->get_h() - 1); canvas->set_inverse(); @@ -583,8 +583,8 @@ void AudioScopeWindow::calculate_probe(int x, int y, int do_overlay) sprintf(string, _("Level 1: %.2f"), channel1); probe_level1->update(string); - - if(do_overlay) + + if(do_overlay) { draw_probe(); canvas->flash(); @@ -665,7 +665,7 @@ const char* AudioScope::plugin_title() { return _("AudioScope"); } int AudioScope::is_realtime() { return 1; } int AudioScope::is_multichannel() { return 1; } -int AudioScope::process_buffer(int64_t size, +int AudioScope::process_buffer(int64_t size, Samples **buffer, int64_t start_position, int sample_rate) @@ -712,8 +712,8 @@ int AudioScope::process_buffer(int64_t size, for(int i = 0; i < CHANNELS; i++) { Samples *new_samples = new Samples(needed); - memcpy(new_samples->get_data(), - audio_buffer[i]->get_data(), + memcpy(new_samples->get_data(), + audio_buffer[i]->get_data(), sizeof(double) * buffer_size); delete audio_buffer[i]; audio_buffer[i] = new_samples; @@ -722,7 +722,7 @@ int AudioScope::process_buffer(int64_t size, for(int i = 0; i < CHANNELS; i++) { - memcpy(audio_buffer[i]->get_data() + buffer_size, + memcpy(audio_buffer[i]->get_data() + buffer_size, buffer[MIN(i, channels - 1)]->get_data(), sizeof(double) * size); } @@ -735,15 +735,15 @@ int AudioScope::process_buffer(int64_t size, { if(allocated_data < (total_windows + 1) * window_size * CHANNELS) { - int new_allocation = (total_windows + 1) * - window_size * + int new_allocation = (total_windows + 1) * + window_size * CHANNELS; unsigned char *new_data = new unsigned char[sizeof(data_header_t) + sizeof(float) * new_allocation]; data_header_t *new_header = (data_header_t*)new_data; data_header_t *old_header = (data_header_t*)data; - memcpy(new_header->samples, - old_header->samples, + memcpy(new_header->samples, + old_header->samples, sizeof(float) * allocated_data); delete [] data; data = new_data; @@ -795,7 +795,7 @@ int AudioScope::process_buffer(int64_t size, for(int j = 0; j < CHANNELS; j++) { double *sample_input = audio_buffer[j]->get_data(); - memcpy(sample_input, + memcpy(sample_input, sample_input + buffer_size - window_size, sizeof(double) * window_size); } @@ -810,8 +810,8 @@ int AudioScope::process_buffer(int64_t size, //printf("AudioScope::process_buffer %d\n", __LINE__); for(int j = 0; j < CHANNELS; j++) { - float *sample_output = header->samples + - total_windows * CHANNELS * window_size + + float *sample_output = header->samples + + total_windows * CHANNELS * window_size + window_size * j; double *sample_input = audio_buffer[j]->get_data(); for(int i = 0; i < window_size; i++) @@ -821,8 +821,8 @@ int AudioScope::process_buffer(int64_t size, // Shift accumulation buffer //printf("AudioScope::process_buffer %d\n", __LINE__); - memcpy(sample_input, - sample_input + trigger_sample + window_size, + memcpy(sample_input, + sample_input + trigger_sample + window_size, sizeof(double) * (buffer_size - trigger_sample - window_size)); //printf("AudioScope::process_buffer %d\n", __LINE__); } @@ -841,8 +841,8 @@ int AudioScope::process_buffer(int64_t size, header->channels = channels; header->total_windows = total_windows; - send_render_gui(data, - sizeof(data_header_t) + + send_render_gui(data, + sizeof(data_header_t) + sizeof(float) * total_windows * window_size * CHANNELS); return 0; @@ -873,13 +873,13 @@ void AudioScope::update_gui() { BC_SubWindow *canvas = window->canvas; // Frames to draw in this iteration - int total_frames = timer->get_difference() * - header.sample_rate / - header.window_size / + int total_frames = timer->get_difference() * + header.sample_rate / + header.window_size / 1000; - if(total_frames) timer->subtract(total_frames * - header.window_size * - 1000 / + if(total_frames) timer->subtract(total_frames * + header.window_size * + 1000 / header.sample_rate); // Add forced frame drawing @@ -895,7 +895,7 @@ void AudioScope::update_gui() { if(frame_history.size() >= config.history_size) frame_history.remove_object_number(0); - + frame_history.append(frame_buffer.get(0)); frame_buffer.remove_number(0); } @@ -1030,7 +1030,7 @@ void AudioScope::update_gui() } } } - + canvas->set_line_width(1); } @@ -1066,14 +1066,14 @@ void AudioScope::render_gui(void *data, int size) for(int i = 0; i < frame_buffer.size(); i++) frame_buffer.get(i)->force = 1; - for(int current_fragment = 0; + for(int current_fragment = 0; current_fragment < header->total_windows; current_fragment++) { - float *in_frame = header->samples + + float *in_frame = header->samples + current_fragment * header->window_size * CHANNELS; AudioScopeFrame *out_frame = new AudioScopeFrame( - header->window_size, + header->window_size, header->channels); // Copy the window to the frame @@ -1122,7 +1122,7 @@ void AudioScope::read_data(KeyFrame *keyframe) w = input.tag.get_property("W", w); h = input.tag.get_property("H", h); } - + config.history_size = input.tag.get_property("HISTORY_SIZE", config.history_size); config.window_size = input.tag.get_property("WINDOW_SIZE", config.window_size); config.mode = input.tag.get_property("MODE", config.mode);