4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "bctimer.inc"
35 #include "pluginaclient.h"
45 #define MIN_WINDOW 1024
46 #define MAX_WINDOW 65536
50 #define MAX_COLUMNS 1024
51 #define MAX_HISTORY 32
54 #define MAX_FREQ 30000
61 class SpectrogramLevel : public BC_FPot
64 SpectrogramLevel(Spectrogram *plugin, int x, int y);
69 class SpectrogramMode : public BC_PopupMenu
72 SpectrogramMode(Spectrogram *plugin,
76 static const char* mode_to_text(int mode);
77 static int text_to_mode(const char *text);
78 void create_objects();
82 class SpectrogramHistory : public BC_IPot
85 SpectrogramHistory(Spectrogram *plugin,
92 class SpectrogramWindowSize : public BC_PopupMenu
95 SpectrogramWindowSize(Spectrogram *plugin,
103 class SpectrogramWindowSizeTumbler : public BC_Tumbler
106 SpectrogramWindowSizeTumbler(Spectrogram *plugin, int x, int y);
107 int handle_up_event();
108 int handle_down_event();
112 class SpectrogramFragmentSize : public BC_PopupMenu
115 SpectrogramFragmentSize(Spectrogram *plugin,
123 class SpectrogramFragmentSizeTumbler : public BC_Tumbler
126 SpectrogramFragmentSizeTumbler(Spectrogram *plugin, int x, int y);
127 int handle_up_event();
128 int handle_down_event();
132 class SpectrogramNormalize : public BC_CheckBox
135 SpectrogramNormalize(Spectrogram *plugin, int x, int y);
140 class SpectrogramFreq : public BC_TextBox
143 SpectrogramFreq(Spectrogram *plugin, int x, int y);
148 class SpectrogramXZoom : public BC_IPot
151 SpectrogramXZoom(Spectrogram *plugin, int x, int y);
156 class SpectrogramCanvas : public BC_SubWindow
159 SpectrogramCanvas(Spectrogram *plugin, int x, int y, int w, int h);
160 int button_press_event();
161 int button_release_event();
162 int cursor_motion_event();
163 void calculate_point();
172 int current_operation;
177 class SpectrogramWindow : public PluginClientWindow
180 SpectrogramWindow(Spectrogram *plugin);
181 ~SpectrogramWindow();
183 void create_objects();
185 int resize_event(int w, int h);
186 void calculate_frequency(int x, int y, int do_overlay);
188 SpectrogramCanvas *canvas;
190 BC_Title *level_title;
191 SpectrogramLevel *level;
192 BC_Title *window_size_title;
193 SpectrogramWindowSize *window_size;
194 SpectrogramWindowSizeTumbler *window_size_tumbler;
196 BC_Title *mode_title;
197 SpectrogramMode *mode;
198 BC_Title *history_title;
199 SpectrogramHistory *history;
201 BC_Title *freq_title;
202 // SpectrogramFreq *freq;
203 BC_Title *amplitude_title;
206 BC_Title *xzoom_title;
207 SpectrogramXZoom *xzoom;
208 // SpectrogramFragmentSizeTumbler *window_fragment_tumbler;
210 SpectrogramNormalize *normalize;
212 int probe_x, probe_y;
220 class SpectrogramConfig
224 int equivalent(SpectrogramConfig &that);
225 void copy_from(SpectrogramConfig &that);
226 void interpolate(SpectrogramConfig &prev,
227 SpectrogramConfig &next,
230 int64_t current_frame);
233 // Generate this many columns for each window
242 // Header for data buffer
246 // Total windows in this buffer
248 // Samples per fragment
252 // Linearized user level
254 // Nothing goes after this
255 // 1st sample in each window is the max
259 class SpectrogramFrame
262 SpectrogramFrame(int data_size);
271 class Spectrogram : public PluginAClient
274 Spectrogram(PluginServer *server);
277 PLUGIN_CLASS_MEMBERS2(SpectrogramConfig)
279 int process_buffer(int64_t size,
281 int64_t start_position,
283 void read_data(KeyFrame *keyframe);
284 void save_data(KeyFrame *keyframe);
286 void render_gui(void *data, int size);
292 int need_reconfigure;
294 // Data buffer for frequency & magnitude
296 // Accumulate data for windowing
297 Samples *audio_buffer;
298 // Total samples in the buffer
300 // Last window size rendered
302 // Temporaries for the FFT
305 // Total windows sent to current GUI
307 // Starting sample in audio_buffer.
308 int64_t audio_buffer_start;
309 // Total floats allocated in data buffer
311 // Accumulates canvas pixels until the next update_gui
312 ArrayList<SpectrogramFrame*> frame_buffer;
313 // History for vertical mode
314 // Probing data for horizontal mode
315 ArrayList<SpectrogramFrame*> frame_history;
316 // Header from last data buffer
317 data_header_t header;
318 // Time of last GUI update