1 // this is a dsp plugin skeleton/example
2 // use to create new dsp plugins
3
4 // usage:
5 // 1. copy to your plugin folder
6 // 2. s/example/plugname/g
7 // 3. s/EXAMPLE/PLUGNAME/g
8
9 #include <stdlib.h>
10 #include <string.h>
11 #include <assert.h>
12 #include <deadbeef/deadbeef.h>
13
14 enum {
15 EXAMPLE_PARAM_LEVEL,
16 EXAMPLE_PARAM_COUNT
17 };
18
19 static DB_functions_t *deadbeef;
20 static DB_dsp_t plugin;
21
22 typedef struct {
23 ddb_dsp_context_t ctx;
24 // instance-specific variables here
25 float level; // this is example
26 } ddb_example_t;
27
28 ddb_dsp_context_t*
example_open(void)29 example_open (void) {
30 ddb_example_t *example = malloc (sizeof (ddb_example_t));
31 DDB_INIT_DSP_CONTEXT (example,ddb_example_t,&plugin);
32
33 // initialize
34 example->level = 0.5;
35
36 return (ddb_dsp_context_t *)example;
37 }
38
39 void
example_close(ddb_dsp_context_t * ctx)40 example_close (ddb_dsp_context_t *ctx) {
41 ddb_example_t *example = (ddb_example_t *)ctx;
42
43 // free instance-specific allocations
44
45 free (example);
46 }
47
48 void
example_reset(ddb_dsp_context_t * ctx)49 example_reset (ddb_dsp_context_t *ctx) {
50 // use this method to flush dsp buffers, reset filters, etc
51 }
52
53 int
example_process(ddb_dsp_context_t * ctx,float * samples,int nframes,int maxframes,ddb_waveformat_t * fmt,float * r)54 example_process (ddb_dsp_context_t *ctx, float *samples, int nframes, int maxframes, ddb_waveformat_t *fmt, float *r) {
55 ddb_example_t *example = (ddb_example_t *)ctx;
56 for (int i = 0; i < nframes*fmt->channels; i++) {
57 samples[i] *= example->level;
58 }
59 return nframes;
60 }
61
62 const char *
example_get_param_name(int p)63 example_get_param_name (int p) {
64 switch (p) {
65 case EXAMPLE_PARAM_LEVEL:
66 return "Volume level";
67 default:
68 fprintf (stderr, "example_param_name: invalid param index (%d)\n", p);
69 }
70 return NULL;
71 }
72
73 int
example_num_params(void)74 example_num_params (void) {
75 return EXAMPLE_PARAM_COUNT;
76 }
77
78 void
example_set_param(ddb_dsp_context_t * ctx,int p,const char * val)79 example_set_param (ddb_dsp_context_t *ctx, int p, const char *val) {
80 ddb_example_t *example = (ddb_example_t *)ctx;
81 switch (p) {
82 case EXAMPLE_PARAM_LEVEL:
83 example->level = atof (val);
84 break;
85 default:
86 fprintf (stderr, "example_param: invalid param index (%d)\n", p);
87 }
88 }
89
90 void
example_get_param(ddb_dsp_context_t * ctx,int p,char * val,int sz)91 example_get_param (ddb_dsp_context_t *ctx, int p, char *val, int sz) {
92 ddb_example_t *example = (ddb_example_t *)ctx;
93 switch (p) {
94 case EXAMPLE_PARAM_LEVEL:
95 snprintf (val, sz, "%f", example->level);
96 break;
97 default:
98 fprintf (stderr, "example_get_param: invalid param index (%d)\n", p);
99 }
100 }
101
102 static const char settings_dlg[] =
103 "property \"Volume Level\" spinbtn[0,2,0.1] 0 0.5;\n"
104 ;
105
106 static DB_dsp_t plugin = {
107 .plugin.api_vmajor = DB_API_VERSION_MAJOR,
108 .plugin.api_vminor = DB_API_VERSION_MINOR,
109 .open = example_open,
110 .close = example_close,
111 .process = example_process,
112 .plugin.version_major = 0,
113 .plugin.version_minor = 1,
114 .plugin.type = DB_PLUGIN_DSP,
115 .plugin.id = "example",
116 .plugin.name = "example",
117 .plugin.descr = "example DSP Plugin",
118 .plugin.copyright = "copyright message - author(s), license, etc",
119 .plugin.website = "http://example.com",
120 .num_params = example_num_params,
121 .get_param_name = example_get_param_name,
122 .set_param = example_set_param,
123 .get_param = example_get_param,
124 .reset = example_reset,
125 .configdialog = settings_dlg,
126 };
127
128 DB_plugin_t *
example_load(DB_functions_t * f)129 example_load (DB_functions_t *f) {
130 deadbeef = f;
131 return &plugin.plugin;
132 }
133