Mercurial > audlegacy-plugins
annotate src/echo_plugin/echo.c @ 155:adf9f4b26039 trunk
[svn] - user-friendly names (UI side unimplemented still)
author | nenolod |
---|---|
date | Tue, 31 Oct 2006 12:07:32 -0800 |
parents | 46730e83b1e2 |
children | d124034ebea3 |
rev | line source |
---|---|
127
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
1 #include <audacious/plugin.h> |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
2 |
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> |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
7 #include <glib/gi18n.h> |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
8 #include "audacious/configdb.h" |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
9 #include "echo.h" |
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 #include "../../config.h" |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
12 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
13 static void init(void); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
14 static void cleanup(void); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
15 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
|
16 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
17 #define MAX_SRATE 50000 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
18 #define MAX_CHANNELS 2 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
19 #define BYTES_PS 2 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
20 #define BUFFER_SAMPLES (MAX_SRATE * MAX_DELAY / 1000) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
21 #define BUFFER_SHORTS (BUFFER_SAMPLES * MAX_CHANNELS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
22 #define BUFFER_BYTES (BUFFER_SHORTS * BYTES_PS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
23 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
24 EffectPlugin echo_ep = |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
25 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
26 NULL, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
27 NULL, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
28 NULL, /* Description */ |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
29 init, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
30 cleanup, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
31 echo_about, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
32 echo_configure, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
33 mod_samples, |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
34 NULL |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
35 }; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
36 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
37 static gint16 *buffer = NULL; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
38 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
|
39 gboolean echo_surround_enable = FALSE; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
40 static int w_ofs; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
41 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
42 EffectPlugin *get_eplugin_info(void) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
43 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
44 echo_ep.description = g_strdup_printf(_("Echo Plugin %s"), VERSION); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
45 return &echo_ep; |
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 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
48 static void init(void) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
49 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
50 ConfigDb *cfg; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
51 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
52 if (sizeof(short) != sizeof(gint16)) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
53 abort(); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
54 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
55 cfg = bmp_cfg_db_open(); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
56 bmp_cfg_db_get_int(cfg, "echo_plugin", "delay", &echo_delay); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
57 bmp_cfg_db_get_int(cfg, "echo_plugin", "feedback", &echo_feedback); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
58 bmp_cfg_db_get_int(cfg, "echo_plugin", "volume", &echo_volume); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
59 bmp_cfg_db_get_bool(cfg, "echo_plugin", "enable_surround", &echo_surround_enable); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
60 bmp_cfg_db_close(cfg); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
61 } |
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 static void cleanup(void) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
64 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
65 g_free(buffer); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
66 buffer = NULL; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
67 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
68 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
69 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
|
70 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
71 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
|
72 gint16 *data = (gint16 *) * d; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
73 static gint old_srate, old_nch; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
74 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
75 if (!(afmt == FMT_S16_NE || |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
76 (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
|
77 (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
|
78 return length; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
79 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
80 if (!buffer) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
81 buffer = g_malloc0(BUFFER_BYTES + 2); |
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 (nch != old_nch || srate != old_srate) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
84 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
85 memset(buffer, 0, BUFFER_BYTES); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
86 w_ofs = 0; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
87 old_nch = nch; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
88 old_srate = srate; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
89 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
90 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
91 if (echo_surround_enable && nch == 2) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
92 fb_div = 200; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
93 else |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
94 fb_div = 100; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
95 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
96 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
|
97 if (r_ofs < 0) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
98 r_ofs += BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
99 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
100 for (i = 0; i < length / BYTES_PS; i++) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
101 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
102 in = data[i]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
103 buf = buffer[r_ofs]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
104 if (echo_surround_enable && nch == 2) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
105 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
106 if (i & 1) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
107 buf -= buffer[r_ofs - 1]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
108 else |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
109 buf -= buffer[r_ofs + 1]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
110 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
111 out = in + buf * echo_volume / 100; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
112 buf = in + buf * echo_feedback / fb_div; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
113 out = CLAMP(out, -32768, 32767); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
114 buf = CLAMP(buf, -32768, 32767); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
115 buffer[w_ofs] = buf; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
116 data[i] = out; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
117 if (++r_ofs >= BUFFER_SHORTS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
118 r_ofs -= BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
119 if (++w_ofs >= BUFFER_SHORTS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
120 w_ofs -= BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
121 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
122 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
123 return length; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
124 } |