summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-01-02 12:24:03 +0100
committerGravatar waker <wakeroid@gmail.com>2011-01-02 12:24:03 +0100
commit4c90be31a1be29701c3fcca0cd67cb2114e18e15 (patch)
tree3351347735b93706e58b5da8358514415d41f34c
parentbe0631a8bbf54616547a54121efa1d7c7cf606bb (diff)
slightly updater decoder_template; added dsp_template; moved plugin templates to examples folder
-rw-r--r--examples/decoder_template.c (renamed from decoder_template.c)47
-rw-r--r--examples/dsp_template.c133
2 files changed, 147 insertions, 33 deletions
diff --git a/decoder_template.c b/examples/decoder_template.c
index fa1f0765..b6e6585b 100644
--- a/decoder_template.c
+++ b/examples/decoder_template.c
@@ -1,26 +1,11 @@
-/*
- 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.
-*/
-
// this is a decoder plugin skeleton
// use to create new decoder plugins
-#include "../../deadbeef.h"
+#include <stdlib.h>
+#include <string.h>
+#include <deadbeef/deadbeef.h>
+
+#define trace(...) { fprintf(stderr, __VA_ARGS__); }
static DB_decoder_t plugin;
static DB_functions_t *deadbeef;
@@ -50,9 +35,11 @@ static int
example_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
example_info_t *info = (example_info_t *)_info;
- _info->fmt.bps = ;
- _info->fmt.channels = ;
- _info->fmt.samplerate = ;
+ // take this parameters from your input file
+ // we set constants for clarity sake
+ _info->fmt.bps = 16;
+ _info->fmt.channels = 2;
+ _info->fmt.samplerate = 44100;
for (int i = 0; i < _info->fmt.channels; i++) {
_info->fmt.channelmask |= 1 << i;
}
@@ -66,6 +53,7 @@ example_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
}
else {
info->startsample = 0;
+ int TOTALSAMPLES = 1000; // calculate from file
info->endsample = TOTALSAMPLES-1;
}
return 0;
@@ -99,7 +87,7 @@ example_seek_sample (DB_fileinfo_t *_info, int sample) {
example_info_t *info = (example_info_t *)_info;
info->currentsample = sample + info->startsample;
- _info->readpos = (float)sample / _info->samplerate;
+ _info->readpos = (float)sample / _info->fmt.samplerate;
return 0;
}
@@ -108,7 +96,7 @@ example_seek_sample (DB_fileinfo_t *_info, int sample) {
// return -1 on failure
static int
example_seek (DB_fileinfo_t *_info, float time) {
- return example_seek_sample (_info, time * _info->samplerate);
+ return example_seek_sample (_info, time * _info->fmt.samplerate);
}
// read information from the track
@@ -119,20 +107,13 @@ example_seek (DB_fileinfo_t *_info, float time) {
static DB_playItem_t *
example_insert (DB_playItem_t *after, const char *fname) {
-// example code (won't compile):
-
// open file
DB_FILE *fp = deadbeef->fopen (fname);
if (!fp) {
trace ("example: failed to fopen %s\n", fname);
return NULL;
}
- // setup decoder to use vfs
- decoder_callbacks_t cb = {
- open = vfs_open_wrapper,
- .... etc ....
- }
- decoder_info_t *di = decoder_open_callbacks (&cb);
+ decoder_info_t *di = decoder_open ();
if (!di) {
trace ("example: failed to init decoder\n");
return NULL;
diff --git a/examples/dsp_template.c b/examples/dsp_template.c
new file mode 100644
index 00000000..24b53759
--- /dev/null
+++ b/examples/dsp_template.c
@@ -0,0 +1,133 @@
+// this is a dsp plugin skeleton/example
+// use to create new dsp plugins
+
+// usage:
+// 1. copy to your plugin folder
+// 2. s/example/plugname/g
+// 3. s/EXAMPLE/PLUGNAME/g
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <deadbeef/deadbeef.h>
+
+enum {
+ EXAMPLE_PARAM_LEVEL,
+ EXAMPLE_PARAM_COUNT
+};
+
+static DB_functions_t *deadbeef;
+static DB_dsp_t plugin;
+
+typedef struct {
+ ddb_dsp_context_t ctx;
+ // instance-specific variables here
+ float level; // this is example
+} ddb_example_t;
+
+ddb_dsp_context_t*
+example_open (void) {
+ ddb_example_t *example = malloc (sizeof (ddb_example_t));
+ DDB_INIT_DSP_CONTEXT (example,ddb_example_t,&plugin);
+
+ // initialize
+ example->level = 0.5;
+
+ return (ddb_dsp_context_t *)example;
+}
+
+void
+example_close (ddb_dsp_context_t *ctx) {
+ ddb_example_t *example = (ddb_example_t *)ctx;
+
+ // free instance-specific allocations
+
+ free (example);
+}
+
+void
+example_reset (ddb_dsp_context_t *ctx) {
+ // use this method to flush dsp buffers, reset filters, etc
+}
+
+int
+example_process (ddb_dsp_context_t *ctx, float *samples, int nframes, ddb_waveformat_t *fmt) {
+ ddb_example_t *example = (ddb_example_t *)ctx;
+ for (int i = 0; i < nframes*fmt->channels; i++) {
+ samples[i] *= example->level;
+ }
+ return nframes;
+}
+
+const char *
+example_get_param_name (int p) {
+ switch (p) {
+ case EXAMPLE_PARAM_LEVEL:
+ return "Volume level";
+ default:
+ fprintf (stderr, "example_param_name: invalid param index (%d)\n", p);
+ }
+ return NULL;
+}
+
+int
+example_num_params (void) {
+ return EXAMPLE_PARAM_COUNT;
+}
+
+void
+example_set_param (ddb_dsp_context_t *ctx, int p, const char *val) {
+ ddb_example_t *example = (ddb_example_t *)ctx;
+ switch (p) {
+ case EXAMPLE_PARAM_LEVEL:
+ example->level = atof (val);
+ break;
+ default:
+ fprintf (stderr, "example_param: invalid param index (%d)\n", p);
+ }
+}
+
+void
+example_get_param (ddb_dsp_context_t *ctx, int p, char *val, int sz) {
+ ddb_example_t *example = (ddb_example_t *)ctx;
+ switch (p) {
+ case EXAMPLE_PARAM_LEVEL:
+ snprintf (val, sz, "%f", example->level);
+ break;
+ default:
+ fprintf (stderr, "example_get_param: invalid param index (%d)\n", p);
+ }
+}
+
+static const char settings_dlg[] =
+ "property \"Volume Level\" spinbtn[0,2,0.1] 0 0.5;\n"
+;
+
+static DB_dsp_t plugin = {
+ .plugin.api_vmajor = DB_API_VERSION_MAJOR,
+ .plugin.api_vminor = DB_API_VERSION_MINOR,
+ .open = example_open,
+ .close = example_close,
+ .process = example_process,
+ .plugin.version_major = 0,
+ .plugin.version_minor = 1,
+ .plugin.type = DB_PLUGIN_DSP,
+ .plugin.id = "example",
+ .plugin.name = "example",
+ .plugin.descr = "example DSP Plugin",
+ .plugin.author = "",
+ .plugin.email = "",
+ .plugin.website = "",
+ .num_params = example_num_params,
+ .get_param_name = example_get_param_name,
+ .set_param = example_set_param,
+ .get_param = example_get_param,
+ .reset = example_reset,
+ .configdialog = settings_dlg,
+};
+
+DB_plugin_t *
+example_load (DB_functions_t *f) {
+ deadbeef = f;
+ return &plugin.plugin;
+}