summaryrefslogtreecommitdiff
path: root/plugins/supereq/supereq.c
blob: d35093128d382dea8375d0bb08b0be12bc77b642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
    DeaDBeeF - ultimate music player for GNU/Linux systems with X11
    Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net>

    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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
#include "../../deadbeef.h"
#include "supereq.h"

static DB_functions_t *deadbeef;

void *paramlist_alloc (void);
void paramlist_free (void *);
void equ_makeTable(float *lbc,float *rbc,void *param,float fs);
int equ_modifySamples(char *buf,int nsamples,int nch,int bps);
void equ_clearbuf(int bps,int srate);
void equ_init(int wb);
void equ_quit(void);

float last_srate = 0;
int last_nch = 0, last_bps = 0;
float lbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
float rbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
void *paramsroot;

int
supereq_plugin_start (void) {
    equ_init (14);
    paramsroot = paramlist_alloc ();
    return 0;
}

int
supereq_plugin_stop (void) {
    equ_quit ();
    paramlist_free (paramsroot);
    return 0;
}


int
supereq_process_int16 (int16_t *samples, int nsamples, int nch, int bps, int srate) {
	if ((nch != 1 && nch != 2) || (bps != 8 && bps != 16 && bps != 24)) return nsamples;
	if (last_srate != srate) {
        equ_makeTable (lbands, rbands, paramsroot, srate);
		last_srate = srate;
		last_nch = nch;
		last_bps = bps;
		equ_clearbuf(bps,srate);
    }
	else if (last_nch != nch || last_bps != bps) {
		last_nch = nch;
		last_bps = bps;
		equ_clearbuf(bps,srate);
    }
	equ_modifySamples((char *)samples,nsamples,nch,bps);
	return nsamples;
}

float
supereq_get_band (int band) {
    return lbands[band];
}

void
supereq_set_band (int band, float value) {
    last_srate = 0;
    lbands[band] = rbands[band] = value;
}

static DB_supereq_dsp_t plugin = {
    .dsp.plugin.api_vmajor = DB_API_VERSION_MAJOR,
    .dsp.plugin.api_vminor = DB_API_VERSION_MINOR,
    .dsp.plugin.type = DB_PLUGIN_DSP,
    .dsp.plugin.id = "supereq",
    .dsp.plugin.name = "SuperEQ",
    .dsp.plugin.descr = "equalizer plugin using SuperEQ library by Naoki Shibata",
    .dsp.plugin.author = "Alexey Yakovenko",
    .dsp.plugin.email = "waker@users.sourceforge.net",
    .dsp.plugin.website = "http://deadbeef.sf.net",
    .dsp.plugin.start = supereq_plugin_start,
    .dsp.plugin.stop = supereq_plugin_stop,
//  .dsp.plugin.configdialog = settings_dlg,
    .dsp.process_int16 = supereq_process_int16,
    .get_band = supereq_get_band,
    .set_band = supereq_set_band,
};

DB_plugin_t *
supereq_load (DB_functions_t *api) {
    deadbeef = api;
    return DB_PLUGIN (&plugin);
}