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 class SpectrogramFrame : public PluginClientFrame
245 SpectrogramFrame(int data_size);
252 // Linearized user level
256 class Spectrogram : public PluginAClient
259 Spectrogram(PluginServer *server);
262 PLUGIN_CLASS_MEMBERS2(SpectrogramConfig)
264 int process_buffer(int64_t size,
266 int64_t start_position,
268 void read_data(KeyFrame *keyframe);
269 void save_data(KeyFrame *keyframe);
272 void fix_gui_frame(SpectrogramFrame *frame);
277 int need_reconfigure;
278 int64_t last_position;
280 // Data buffer for frequency & magnitude
281 // unsigned char *data;
282 // Accumulate data for windowing
283 Samples *audio_buffer;
284 // Total samples in the buffer
286 // Last window size rendered
288 // Temporaries for the FFT
291 // Starting sample in audio_buffer.
292 int64_t audio_buffer_start;
293 // Total floats allocated in data buffer
295 // Accumulates canvas pixels until the next update_gui
296 // ArrayList<SpectrogramFrame*> frame_buffer;
297 // Layers for vertical mode
298 // Probing data for horizontal mode
299 ArrayList<SpectrogramFrame*> frame_history;
300 // Header from last data buffer
301 // data_header_t header;
302 // Time of last GUI update