annotate src/echo_plugin/echo.c @ 3200:8da9787de69d

alsa-ng: More paranoid debugging.
author John Lindgren <john.lindgren@tds.net>
date Tue, 11 Aug 2009 10:34:26 -0400
parents 3134a0987162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2499
4d6045c20cc5 Include cleanups, part #4.
Matti Hamalainen <ccr@tnsp.org>
parents: 2124
diff changeset
1 #include "config.h"
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2575
diff changeset
2 #include <audlegacy/plugin.h>
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
3 #include <stdlib.h>
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
4 #include <stdio.h>
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
5 #include <string.h>
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
6 #include <gtk/gtk.h>
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2575
diff changeset
7 #include <audlegacy/i18n.h>
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
8 #include "echo.h"
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
9
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
10
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
11 static void init(void);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
12 static void cleanup(void);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
13 static int mod_samples(gpointer * d, gint length, AFormat afmt, gint srate, gint nch);
2575
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
14 static void query_format(AFormat * fmt, gint * rate, gint * nch);
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
15
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
16 #define MAX_SRATE 50000
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
17 #define MAX_CHANNELS 2
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
18 #define BYTES_PS 2
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
19 #define BUFFER_SAMPLES (MAX_SRATE * MAX_DELAY / 1000)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
20 #define BUFFER_SHORTS (BUFFER_SAMPLES * MAX_CHANNELS)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
21 #define BUFFER_BYTES (BUFFER_SHORTS * BYTES_PS)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
22
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
23 EffectPlugin echo_ep =
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
24 {
1640
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
25 .description = "Echo Plugin", /* Description */
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
26 .init = init,
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
27 .cleanup = cleanup,
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
28 .about = echo_about,
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
29 .configure = echo_configure,
a5045f10f80c echo_plugin: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
30 .mod_samples = mod_samples,
2575
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
31 .query_format = query_format,
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
32 };
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
33
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
34 static gint16 *buffer = NULL;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
35 gint echo_delay = 500, echo_feedback = 50, echo_volume = 50;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
36 gboolean echo_surround_enable = FALSE;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
37 static int w_ofs;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
38
1106
8ca72224786a [svn] - echo: convert to plugin API v2
nenolod
parents: 527
diff changeset
39 EffectPlugin *echo_eplist[] = { &echo_ep, NULL };
8ca72224786a [svn] - echo: convert to plugin API v2
nenolod
parents: 527
diff changeset
40
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1106
diff changeset
41 DECLARE_PLUGIN(echo, NULL, NULL, NULL, NULL, echo_eplist, NULL, NULL, NULL);
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
42
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
43 static void init(void)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
44 {
2523
769e17da93dd Replaced s/ConfigDb/mcs_handle_t/g, as per changes in the core.
Matti Hamalainen <ccr@tnsp.org>
parents: 2499
diff changeset
45 mcs_handle_t *cfg;
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
46
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
47 if (sizeof(short) != sizeof(gint16))
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
48 abort();
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
49
2124
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
50 cfg = aud_cfg_db_open();
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
51 aud_cfg_db_get_int(cfg, "echo_plugin", "delay", &echo_delay);
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
52 aud_cfg_db_get_int(cfg, "echo_plugin", "feedback", &echo_feedback);
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
53 aud_cfg_db_get_int(cfg, "echo_plugin", "volume", &echo_volume);
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
54 aud_cfg_db_get_bool(cfg, "echo_plugin", "enable_surround", &echo_surround_enable);
b8da6a0b0da2 s/bmp_cfg_/aud_cfg_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
55 aud_cfg_db_close(cfg);
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
56 }
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
57
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
58 static void cleanup(void)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
59 {
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
60 g_free(buffer);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
61 buffer = NULL;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
62 }
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
63
2575
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
64 static void query_format(AFormat * fmt, gint * rate, gint * nch)
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
65 {
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
66 if (!(*fmt == FMT_S16_NE ||
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
67 (*fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) ||
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
68 (*fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)))
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
69 *fmt = FMT_S16_NE;
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
70 }
1e67df1a1edc Implemented query_format() callback in all effect plugins
Stefano D'Angelo <zanga.mail@gmail.com>
parents: 2523
diff changeset
71
127
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
72 static int mod_samples(gpointer * d, gint length, AFormat afmt, gint srate, gint nch)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
73 {
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
74 gint i, in, out, buf, r_ofs, fb_div;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
75 gint16 *data = (gint16 *) * d;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
76 static gint old_srate, old_nch;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
77
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
78 if (!(afmt == FMT_S16_NE ||
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
79 (afmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) ||
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
80 (afmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)))
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
81 return length;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
82
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
83 if (!buffer)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
84 buffer = g_malloc0(BUFFER_BYTES + 2);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
85
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
86 if (nch != old_nch || srate != old_srate)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
87 {
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
88 memset(buffer, 0, BUFFER_BYTES);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
89 w_ofs = 0;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
90 old_nch = nch;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
91 old_srate = srate;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
92 }
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
93
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
94 if (echo_surround_enable && nch == 2)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
95 fb_div = 200;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
96 else
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
97 fb_div = 100;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
98
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
99 r_ofs = w_ofs - (srate * echo_delay / 1000) * nch;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
100 if (r_ofs < 0)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
101 r_ofs += BUFFER_SHORTS;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
102
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
103 for (i = 0; i < length / BYTES_PS; i++)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
104 {
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
105 in = data[i];
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
106 buf = buffer[r_ofs];
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
107 if (echo_surround_enable && nch == 2)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
108 {
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
109 if (i & 1)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
110 buf -= buffer[r_ofs - 1];
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
111 else
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
112 buf -= buffer[r_ofs + 1];
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
113 }
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
114 out = in + buf * echo_volume / 100;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
115 buf = in + buf * echo_feedback / fb_div;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
116 out = CLAMP(out, -32768, 32767);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
117 buf = CLAMP(buf, -32768, 32767);
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
118 buffer[w_ofs] = buf;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
119 data[i] = out;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
120 if (++r_ofs >= BUFFER_SHORTS)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
121 r_ofs -= BUFFER_SHORTS;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
122 if (++w_ofs >= BUFFER_SHORTS)
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
123 w_ofs -= BUFFER_SHORTS;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
124 }
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
125
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
126 return length;
46730e83b1e2 [svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff changeset
127 }