1 /*
2     Musical Spectrum plugin for the DeaDBeeF audio player
3 
4     Copyright (C) 2015 Christian Boxdörfer <christian.boxdoerfer@posteo.de>
5 
6     Based on DeaDBeeFs stock spectrum.
7     Copyright (c) 2009-2015 Alexey Yakovenko <waker@users.sourceforge.net>
8     Copyright (c) 2011 William Pitcock <nenolod@dereferenced.org>
9 
10     This program is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     as published by the Free Software Foundation; either version 2
13     of the License, or (at your option) any later version.
14 
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 */
24 
25 #ifndef SPECTRUM_HEADER
26 #define SPECTRUM_HEADER
27 
28 #include <gtk/gtk.h>
29 #include <stdint.h>
30 #include <fftw3.h>
31 
32 #include <deadbeef/deadbeef.h>
33 #include <deadbeef/gtkui_api.h>
34 
35 #define MAX_BARS 2000
36 #define REFRESH_INTERVAL 25
37 #define GRADIENT_TABLE_SIZE 1024
38 #define MAX_FFT_SIZE 32768
39 
40 /* Global variables */
41 extern DB_misc_t plugin;
42 extern DB_functions_t *deadbeef;
43 extern ddb_gtkui_t *gtkui_plugin;
44 
45 typedef struct {
46     ddb_gtkui_widget_t base;
47     GtkWidget *drawarea;
48     GtkWidget *popup;
49     GtkWidget *popup_item;
50     cairo_surface_t *surf;
51     unsigned char *surf_data;
52     guint drawtimer;
53     // spectrum_data: holds amplitude of frequency bins (result of fft)
54     double *spectrum_data;
55     double window[MAX_FFT_SIZE];
56     // keys: index of frequencies of musical notes (c0;d0;...;f10) in data
57     int keys[MAX_BARS + 1];
58     // freq: hold frequency values
59     float freq[MAX_BARS + 1];
60     uint32_t colors[GRADIENT_TABLE_SIZE];
61     int samplerate;
62     double *samples;
63     double *fft_in;
64     fftw_complex *fft_out;
65     fftw_plan p_r2c;
66     int buffered;
67     int low_res_end;
68     float bars[MAX_BARS + 1];
69     float peaks[MAX_BARS + 1];
70     int delay_bars[MAX_BARS + 1];
71     int delay_peaks[MAX_BARS + 1];
72     intptr_t mutex;
73 } w_spectrum_t;
74 
75 #endif
76