Mercurial > audlegacy-plugins
annotate src/echo_plugin/echo.c @ 1584:a6115d004ec3
Adapted plugins for internationalisation, update-po, German translation
author | mf0102 <0102@gmx.at> |
---|---|
date | Mon, 03 Sep 2007 23:43:38 +0200 |
parents | 761e17b23e0c |
children | a5045f10f80c |
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> |
527
d124034ebea3
[svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents:
127
diff
changeset
|
7 #include <audacious/i18n.h> |
127
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, |
1106 | 28 "Echo Plugin", /* Description */ |
127
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 |
1106 | 42 EffectPlugin *echo_eplist[] = { &echo_ep, NULL }; |
43 | |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1106
diff
changeset
|
44 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
|
45 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
46 static void init(void) |
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 ConfigDb *cfg; |
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 if (sizeof(short) != sizeof(gint16)) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
51 abort(); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
52 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
53 cfg = bmp_cfg_db_open(); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 bmp_cfg_db_close(cfg); |
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 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
61 static void cleanup(void) |
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 g_free(buffer); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
64 buffer = NULL; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
65 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
66 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
67 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
|
68 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
69 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
|
70 gint16 *data = (gint16 *) * d; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
71 static gint old_srate, old_nch; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
72 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
73 if (!(afmt == FMT_S16_NE || |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
74 (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
|
75 (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
|
76 return length; |
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 (!buffer) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
79 buffer = g_malloc0(BUFFER_BYTES + 2); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
80 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
81 if (nch != old_nch || srate != old_srate) |
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 memset(buffer, 0, BUFFER_BYTES); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
84 w_ofs = 0; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
85 old_nch = nch; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
86 old_srate = 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 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
89 if (echo_surround_enable && nch == 2) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
90 fb_div = 200; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
91 else |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
92 fb_div = 100; |
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 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
|
95 if (r_ofs < 0) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
96 r_ofs += BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
97 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
98 for (i = 0; i < length / BYTES_PS; i++) |
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 in = data[i]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
101 buf = buffer[r_ofs]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
102 if (echo_surround_enable && nch == 2) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
103 { |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
104 if (i & 1) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
105 buf -= buffer[r_ofs - 1]; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
106 else |
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 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
109 out = in + buf * echo_volume / 100; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
110 buf = in + buf * echo_feedback / fb_div; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
111 out = CLAMP(out, -32768, 32767); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
112 buf = CLAMP(buf, -32768, 32767); |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
113 buffer[w_ofs] = buf; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
114 data[i] = out; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
115 if (++r_ofs >= BUFFER_SHORTS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
116 r_ofs -= BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
117 if (++w_ofs >= BUFFER_SHORTS) |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
118 w_ofs -= BUFFER_SHORTS; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
119 } |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
120 |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
121 return length; |
46730e83b1e2
[svn] - echo plugin support by Christian Birchinger <joker -at- gentoo.org>
nenolod
parents:
diff
changeset
|
122 } |