Codebase list rev-plugins / upstream/0.3.1
Imported Upstream version 0.3.1 Alessio Treglia 13 years ago
13 changed file(s) with 1739 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Fons Adriaensen <fons.adriaensen@alcatel.be>
0 GNU GENERAL PUBLIC LICENSE
1 Version 2, June 1991
2
3 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
4 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8 Preamble
9
10 The licenses for most software are designed to take away your
11 freedom to share and change it. By contrast, the GNU General Public
12 License is intended to guarantee your freedom to share and change free
13 software--to make sure the software is free for all its users. This
14 General Public License applies to most of the Free Software
15 Foundation's software and to any other program whose authors commit to
16 using it. (Some other Free Software Foundation software is covered by
17 the GNU Library General Public License instead.) You can apply it to
18 your programs, too.
19
20 When we speak of free software, we are referring to freedom, not
21 price. Our General Public Licenses are designed to make sure that you
22 have the freedom to distribute copies of free software (and charge for
23 this service if you wish), that you receive source code or can get it
24 if you want it, that you can change the software or use pieces of it
25 in new free programs; and that you know you can do these things.
26
27 To protect your rights, we need to make restrictions that forbid
28 anyone to deny you these rights or to ask you to surrender the rights.
29 These restrictions translate to certain responsibilities for you if you
30 distribute copies of the software, or if you modify it.
31
32 For example, if you distribute copies of such a program, whether
33 gratis or for a fee, you must give the recipients all the rights that
34 you have. You must make sure that they, too, receive or can get the
35 source code. And you must show them these terms so they know their
36 rights.
37
38 We protect your rights with two steps: (1) copyright the software, and
39 (2) offer you this license which gives you legal permission to copy,
40 distribute and/or modify the software.
41
42 Also, for each author's protection and ours, we want to make certain
43 that everyone understands that there is no warranty for this free
44 software. If the software is modified by someone else and passed on, we
45 want its recipients to know that what they have is not the original, so
46 that any problems introduced by others will not reflect on the original
47 authors' reputations.
48
49 Finally, any free program is threatened constantly by software
50 patents. We wish to avoid the danger that redistributors of a free
51 program will individually obtain patent licenses, in effect making the
52 program proprietary. To prevent this, we have made it clear that any
53 patent must be licensed for everyone's free use or not licensed at all.
54
55 The precise terms and conditions for copying, distribution and
56 modification follow.
57
58 GNU GENERAL PUBLIC LICENSE
59 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
60
61 0. This License applies to any program or other work which contains
62 a notice placed by the copyright holder saying it may be distributed
63 under the terms of this General Public License. The "Program", below,
64 refers to any such program or work, and a "work based on the Program"
65 means either the Program or any derivative work under copyright law:
66 that is to say, a work containing the Program or a portion of it,
67 either verbatim or with modifications and/or translated into another
68 language. (Hereinafter, translation is included without limitation in
69 the term "modification".) Each licensee is addressed as "you".
70
71 Activities other than copying, distribution and modification are not
72 covered by this License; they are outside its scope. The act of
73 running the Program is not restricted, and the output from the Program
74 is covered only if its contents constitute a work based on the
75 Program (independent of having been made by running the Program).
76 Whether that is true depends on what the Program does.
77
78 1. You may copy and distribute verbatim copies of the Program's
79 source code as you receive it, in any medium, provided that you
80 conspicuously and appropriately publish on each copy an appropriate
81 copyright notice and disclaimer of warranty; keep intact all the
82 notices that refer to this License and to the absence of any warranty;
83 and give any other recipients of the Program a copy of this License
84 along with the Program.
85
86 You may charge a fee for the physical act of transferring a copy, and
87 you may at your option offer warranty protection in exchange for a fee.
88
89 2. You may modify your copy or copies of the Program or any portion
90 of it, thus forming a work based on the Program, and copy and
91 distribute such modifications or work under the terms of Section 1
92 above, provided that you also meet all of these conditions:
93
94 a) You must cause the modified files to carry prominent notices
95 stating that you changed the files and the date of any change.
96
97 b) You must cause any work that you distribute or publish, that in
98 whole or in part contains or is derived from the Program or any
99 part thereof, to be licensed as a whole at no charge to all third
100 parties under the terms of this License.
101
102 c) If the modified program normally reads commands interactively
103 when run, you must cause it, when started running for such
104 interactive use in the most ordinary way, to print or display an
105 announcement including an appropriate copyright notice and a
106 notice that there is no warranty (or else, saying that you provide
107 a warranty) and that users may redistribute the program under
108 these conditions, and telling the user how to view a copy of this
109 License. (Exception: if the Program itself is interactive but
110 does not normally print such an announcement, your work based on
111 the Program is not required to print an announcement.)
112
113 These requirements apply to the modified work as a whole. If
114 identifiable sections of that work are not derived from the Program,
115 and can be reasonably considered independent and separate works in
116 themselves, then this License, and its terms, do not apply to those
117 sections when you distribute them as separate works. But when you
118 distribute the same sections as part of a whole which is a work based
119 on the Program, the distribution of the whole must be on the terms of
120 this License, whose permissions for other licensees extend to the
121 entire whole, and thus to each and every part regardless of who wrote it.
122
123 Thus, it is not the intent of this section to claim rights or contest
124 your rights to work written entirely by you; rather, the intent is to
125 exercise the right to control the distribution of derivative or
126 collective works based on the Program.
127
128 In addition, mere aggregation of another work not based on the Program
129 with the Program (or with a work based on the Program) on a volume of
130 a storage or distribution medium does not bring the other work under
131 the scope of this License.
132
133 3. You may copy and distribute the Program (or a work based on it,
134 under Section 2) in object code or executable form under the terms of
135 Sections 1 and 2 above provided that you also do one of the following:
136
137 a) Accompany it with the complete corresponding machine-readable
138 source code, which must be distributed under the terms of Sections
139 1 and 2 above on a medium customarily used for software interchange; or,
140
141 b) Accompany it with a written offer, valid for at least three
142 years, to give any third party, for a charge no more than your
143 cost of physically performing source distribution, a complete
144 machine-readable copy of the corresponding source code, to be
145 distributed under the terms of Sections 1 and 2 above on a medium
146 customarily used for software interchange; or,
147
148 c) Accompany it with the information you received as to the offer
149 to distribute corresponding source code. (This alternative is
150 allowed only for noncommercial distribution and only if you
151 received the program in object code or executable form with such
152 an offer, in accord with Subsection b above.)
153
154 The source code for a work means the preferred form of the work for
155 making modifications to it. For an executable work, complete source
156 code means all the source code for all modules it contains, plus any
157 associated interface definition files, plus the scripts used to
158 control compilation and installation of the executable. However, as a
159 special exception, the source code distributed need not include
160 anything that is normally distributed (in either source or binary
161 form) with the major components (compiler, kernel, and so on) of the
162 operating system on which the executable runs, unless that component
163 itself accompanies the executable.
164
165 If distribution of executable or object code is made by offering
166 access to copy from a designated place, then offering equivalent
167 access to copy the source code from the same place counts as
168 distribution of the source code, even though third parties are not
169 compelled to copy the source along with the object code.
170
171 4. You may not copy, modify, sublicense, or distribute the Program
172 except as expressly provided under this License. Any attempt
173 otherwise to copy, modify, sublicense or distribute the Program is
174 void, and will automatically terminate your rights under this License.
175 However, parties who have received copies, or rights, from you under
176 this License will not have their licenses terminated so long as such
177 parties remain in full compliance.
178
179 5. You are not required to accept this License, since you have not
180 signed it. However, nothing else grants you permission to modify or
181 distribute the Program or its derivative works. These actions are
182 prohibited by law if you do not accept this License. Therefore, by
183 modifying or distributing the Program (or any work based on the
184 Program), you indicate your acceptance of this License to do so, and
185 all its terms and conditions for copying, distributing or modifying
186 the Program or works based on it.
187
188 6. Each time you redistribute the Program (or any work based on the
189 Program), the recipient automatically receives a license from the
190 original licensor to copy, distribute or modify the Program subject to
191 these terms and conditions. You may not impose any further
192 restrictions on the recipients' exercise of the rights granted herein.
193 You are not responsible for enforcing compliance by third parties to
194 this License.
195
196 7. If, as a consequence of a court judgment or allegation of patent
197 infringement or for any other reason (not limited to patent issues),
198 conditions are imposed on you (whether by court order, agreement or
199 otherwise) that contradict the conditions of this License, they do not
200 excuse you from the conditions of this License. If you cannot
201 distribute so as to satisfy simultaneously your obligations under this
202 License and any other pertinent obligations, then as a consequence you
203 may not distribute the Program at all. For example, if a patent
204 license would not permit royalty-free redistribution of the Program by
205 all those who receive copies directly or indirectly through you, then
206 the only way you could satisfy both it and this License would be to
207 refrain entirely from distribution of the Program.
208
209 If any portion of this section is held invalid or unenforceable under
210 any particular circumstance, the balance of the section is intended to
211 apply and the section as a whole is intended to apply in other
212 circumstances.
213
214 It is not the purpose of this section to induce you to infringe any
215 patents or other property right claims or to contest validity of any
216 such claims; this section has the sole purpose of protecting the
217 integrity of the free software distribution system, which is
218 implemented by public license practices. Many people have made
219 generous contributions to the wide range of software distributed
220 through that system in reliance on consistent application of that
221 system; it is up to the author/donor to decide if he or she is willing
222 to distribute software through any other system and a licensee cannot
223 impose that choice.
224
225 This section is intended to make thoroughly clear what is believed to
226 be a consequence of the rest of this License.
227
228 8. If the distribution and/or use of the Program is restricted in
229 certain countries either by patents or by copyrighted interfaces, the
230 original copyright holder who places the Program under this License
231 may add an explicit geographical distribution limitation excluding
232 those countries, so that distribution is permitted only in or among
233 countries not thus excluded. In such case, this License incorporates
234 the limitation as if written in the body of this License.
235
236 9. The Free Software Foundation may publish revised and/or new versions
237 of the General Public License from time to time. Such new versions will
238 be similar in spirit to the present version, but may differ in detail to
239 address new problems or concerns.
240
241 Each version is given a distinguishing version number. If the Program
242 specifies a version number of this License which applies to it and "any
243 later version", you have the option of following the terms and conditions
244 either of that version or of any later version published by the Free
245 Software Foundation. If the Program does not specify a version number of
246 this License, you may choose any version ever published by the Free Software
247 Foundation.
248
249 10. If you wish to incorporate parts of the Program into other free
250 programs whose distribution conditions are different, write to the author
251 to ask for permission. For software which is copyrighted by the Free
252 Software Foundation, write to the Free Software Foundation; we sometimes
253 make exceptions for this. Our decision will be guided by the two goals
254 of preserving the free status of all derivatives of our free software and
255 of promoting the sharing and reuse of software generally.
256
257 NO WARRANTY
258
259 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
260 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
261 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
262 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
263 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
264 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
265 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
266 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
267 REPAIR OR CORRECTION.
268
269 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
270 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
271 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
272 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
273 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
274 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
275 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
276 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
277 POSSIBILITY OF SUCH DAMAGES.
278
279 END OF TERMS AND CONDITIONS
280
281 How to Apply These Terms to Your New Programs
282
283 If you develop a new program, and you want it to be of the greatest
284 possible use to the public, the best way to achieve this is to make it
285 free software which everyone can redistribute and change under these terms.
286
287 To do so, attach the following notices to the program. It is safest
288 to attach them to the start of each source file to most effectively
289 convey the exclusion of warranty; and each file should have at least
290 the "copyright" line and a pointer to where the full notice is found.
291
292 <one line to give the program's name and a brief idea of what it does.>
293 Copyright (C) <year> <name of author>
294
295 This program is free software; you can redistribute it and/or modify
296 it under the terms of the GNU General Public License as published by
297 the Free Software Foundation; either version 2 of the License, or
298 (at your option) any later version.
299
300 This program is distributed in the hope that it will be useful,
301 but WITHOUT ANY WARRANTY; without even the implied warranty of
302 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303 GNU General Public License for more details.
304
305 You should have received a copy of the GNU General Public License
306 along with this program; if not, write to the Free Software
307 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
308
309
310 Also add information on how to contact you by electronic and paper mail.
311
312 If the program is interactive, make it output a short notice like this
313 when it starts in an interactive mode:
314
315 Gnomovision version 69, Copyright (C) year name of author
316 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 This is free software, and you are welcome to redistribute it
318 under certain conditions; type `show c' for details.
319
320 The hypothetical commands `show w' and `show c' should show the appropriate
321 parts of the General Public License. Of course, the commands you use may
322 be called something other than `show w' and `show c'; they could even be
323 mouse-clicks or menu items--whatever suits your program.
324
325 You should also get your employer (if you work as a programmer) or your
326 school, if any, to sign a "copyright disclaimer" for the program, if
327 necessary. Here is a sample; alter the names:
328
329 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
332 <signature of Ty Coon>, 1 April 1989
333 Ty Coon, President of Vice
334
335 This General Public License does not permit incorporating your program into
336 proprietary programs. If your program is a subroutine library, you may
337 consider it more useful to permit linking proprietary applications with the
338 library. If this is what you want to do, use the GNU Library General
339 Public License instead of this License.
0 To install:
1
2 make
3
4 will make the plugins, then as root:
5
6 make install
7
8 installs them in /usr/lib/ladspa.
9
10 That's all there is to it...
0
1 CPPFLAGS += -I. -fPIC -D_REENTRANT -Wall -O2
2
3
4 all: g2reverb.so
5
6
7 g2reverb.so: greverb.o g2reverb.o g2reverb_if.o exp2ap.o
8 g++ -shared greverb.o g2reverb.o g2reverb_if.o exp2ap.o -o g2reverb.so
9
10 g2reverb.o: ladspaplugin.h g2reverb.h greverb.o
11 g2reverb_if.o: ladspaplugin.h g2reverb.h
12
13
14 install:
15 cp *.so /usr/lib/ladspa
16
17
18 DIR := $(shell basename `pwd`)
19
20 archive: clean
21 cd ..; /bin/rm -f $(DIR).tar.bz2; tar cvf $(DIR).tar $(DIR); bzip2 $(DIR).tar
22
23
24 clean:
25 /bin/rm -f *~ *.o *.so
26
0 -----------------------------------------------------------------------------------
1
2 Copyright (C) 2003 Fons Adriaensen
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 -----------------------------------------------------------------------------------
19
20
21 --------------------------------------------
22 Version 0.3.1
23 --------------------------------------------
24
25 Added code to reset all audio upon deactivate(). Parameters
26 are preserved across deactivate()/activate().
27
28 Many thanks to Chris Cannam for pointing out the problem and
29 for providing patches to solve it.
30
31
32 --------------------------------------------
33 g2reverb.so -- First release - 22/8/2003
34 --------------------------------------------
35
36 This reverb is based on gverb by Juhana Sadeharju, but the code
37 (now C++) is entirely original. I added a second input for stereo
38 operation, and some code to prevent FP denormalisation.
39 This is a preliminary release, and this plugin will probably change
40 a lot in future versions.
41
42
43
44
0 #include <math.h>
1
2
3 float exp2ap (float x)
4 {
5 int i;
6
7 i = (int)(floor (x));
8 x -= i;
9 // return ldexp (1 + x * (0.66 + 0.34 * x), i);
10 return ldexp (1 + x * (0.6930 + x * (0.2416 + x * (0.0517 + x * 0.0137))), i);
11 }
12
13
0 /*
1 Copyright (C) 2003 Fons Adriaensen
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18
19 #include <stdio.h>
20 #include <math.h>
21 #include "g2reverb.h"
22
23
24 extern float exp2ap (float x);
25
26
27 void Ladspa_G2reverb::setport (unsigned long port, LADSPA_Data *data)
28 {
29 _port [port] = data;
30 }
31
32
33 void Ladspa_G2reverb::active (bool act)
34 {
35 if (! act) _grev->reset ();
36 }
37
38
39 void Ladspa_G2reverb::runproc (unsigned long len, bool add)
40 {
41 _grev->set_roomsize (_port [4][0]);
42 _grev->set_revbtime (_port [5][0]);
43 _grev->set_ipbandw (0.1 + 0.9 * _port [6][0]);
44 _grev->set_damping (0.9 * _port [7][0]);
45 _grev->set_dryslev (exp2ap (0.1661 * _port [8][0]));
46 _grev->set_refllev (exp2ap (0.1661 * _port [9][0]));
47 _grev->set_taillev (exp2ap (0.1661 * _port [10][0]));
48 _grev->process (len, _port [0], _port[1], _port [2], _port [3]);
49 }
50
51
52
0 /*
1 Copyright (C) 2003 Fons Adriaensen
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18
19 #ifndef __G2REVERB_H
20 #define __G2REVERB_H
21
22 #include "ladspaplugin.h"
23 #include "greverb.h"
24
25
26 class Ladspa_G2reverb : public LadspaPlugin
27 {
28 public:
29
30 enum { NPORT = 11 };
31
32 Ladspa_G2reverb (unsigned long fsam) : LadspaPlugin (fsam) { _grev = new Greverb (fsam); }
33 virtual void setport (unsigned long port, LADSPA_Data *data);
34 virtual void active (bool act);
35 virtual void runproc (unsigned long len, bool add);
36 virtual ~Ladspa_G2reverb (void) { delete _grev; }
37
38 private:
39
40 float *_port [NPORT];
41 Greverb *_grev;
42
43 };
44
45
46 #endif
0 /*
1 Copyright (C) 2003 Fons Adriaensen
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18 //-----------------------------------------------------------------------------------
19 // Common definitions
20
21
22 #include "g2reverb.h"
23
24 #define NMODS 1
25 #define VERSION "0.3.1"
26
27
28 static const char* maker = "Fons Adriaensen <fons.adriaensen@alcatel.be>";
29 static const char* copyr = "GPL";
30
31
32 static void pconnect (LADSPA_Handle H, unsigned long port, LADSPA_Data *data)
33 {
34 ((LadspaPlugin *)H)->setport (port, data);
35 }
36
37 static void activate (LADSPA_Handle H)
38 {
39 ((LadspaPlugin *)H)->active (true);
40 }
41
42 static void runplugin (LADSPA_Handle H, unsigned long k)
43 {
44 ((LadspaPlugin *)H)->runproc (k, false);
45 }
46 /*
47 static void runadding (LADSPA_Handle H, unsigned long k)
48 {
49 ((LadspaPlugin *)H)->runproc (k, true);
50 }
51
52 static void setadding (LADSPA_Handle H, LADSPA_Data gain)
53 {
54 ((LadspaPlugin *)H)->setgain (gain);
55 }
56 */
57 static void deactivate (LADSPA_Handle H)
58 {
59 ((LadspaPlugin *)H)->active (false);
60 }
61
62 static void cleanup (LADSPA_Handle H)
63 {
64 delete (LadspaPlugin *) H;
65 }
66
67 //-----------------------------------------------------------------------------------
68 // Plugin definitions
69
70
71 static const char* label0 = "G2reverb";
72 static const char* name0 = "Stereo reverb";
73
74
75 static LADSPA_Handle instant0 (const struct _LADSPA_Descriptor *desc, unsigned long rate)
76 {
77 return new Ladspa_G2reverb (rate);
78 }
79
80
81 static const LADSPA_PortDescriptor pdesc0 [Ladspa_G2reverb::NPORT] =
82 {
83 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO,
84 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO,
85 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO,
86 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO,
87 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
88 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
89 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
90 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
91 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
92 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
93 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL
94 };
95
96 static const char * const pname0 [Ladspa_G2reverb::NPORT] =
97 {
98 "In L",
99 "In R",
100 "Out L",
101 "Out R",
102 "Room size",
103 "Reverb time",
104 "Input BW",
105 "Damping",
106 "Dry sound",
107 "Reflections",
108 "Reverb tail"
109 };
110
111 static const LADSPA_PortRangeHint phint0 [Ladspa_G2reverb::NPORT] =
112 {
113 { 0, 0, 0 },
114 { 0, 0, 0 },
115 { 0, 0, 0 },
116 { 0, 0, 0 },
117 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 10, 150 },
118 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 1, 20 },
119 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
120 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
121 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, -80, 0 },
122 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, -80, 0 },
123 { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, -80, 0 }
124 };
125
126
127 static const LADSPA_Descriptor moddescr [NMODS] =
128 {
129 {
130 1950,
131 label0,
132 LADSPA_PROPERTY_REALTIME | LADSPA_PROPERTY_HARD_RT_CAPABLE,
133 name0,
134 maker,
135 copyr,
136 Ladspa_G2reverb::NPORT,
137 pdesc0,
138 pname0,
139 phint0,
140 0,
141 instant0,
142 pconnect,
143 activate,
144 runplugin,
145 0,
146 0,
147 deactivate,
148 cleanup
149 }
150 };
151
152 extern "C" const LADSPA_Descriptor *ladspa_descriptor (unsigned long i)
153 {
154 if (i >= NMODS) return 0;
155 return moddescr + i;
156 }
157
158 //-----------------------------------------------------------------------------------
0 #include <math.h>
1 #include <string.h>
2 #include "greverb.h"
3
4
5 void Diffuser::init (unsigned long size, float c)
6 {
7 _size = size;
8 _data = new float [size];
9 _c = c;
10 reset ();
11 }
12
13
14 void Diffuser::reset (void)
15 {
16 memset (_data, 0, _size * sizeof (float));
17 _i = 0;
18 }
19
20
21 void Diffuser::fini (void)
22 {
23 delete[] _data;
24 }
25
26
27 void QuadFDN::init (unsigned long size)
28 {
29 _size = size;
30 for (int j = 0; j < 4; j++)
31 {
32 _data [j] = new float [size];
33 _g [j] = 0;
34 _d [j] = 0;
35 }
36 _c = 1;
37 reset ();
38 }
39
40
41 void QuadFDN::reset (void)
42 {
43 for (int j = 0; j < 4; j++)
44 {
45 memset (_data [j], 0, _size * sizeof (float));
46 _y [j] = 0;
47 }
48 _i = 0;
49 }
50
51
52 void QuadFDN::fini (void)
53 {
54 for (int j = 0; j < 4; j++) delete[] _data [j];
55 }
56
57
58 void MTDelay::init (unsigned long size)
59 {
60 _size = size;
61 _data = new float [size];
62 for (int j = 0; j < 4; j++) _d [j] = 0;
63 _c = 1;
64 reset ();
65 }
66
67
68 void MTDelay::reset (void)
69 {
70 memset (_data, 0, _size * sizeof (float));
71 for (int j = 0; j < 4; j++) _y [j] = 0;
72 _z = 0;
73 _i = 0;
74 }
75
76
77 void MTDelay::fini (void)
78 {
79 delete[] _data;
80 }
81
82
83 Greverb::Greverb (unsigned long rate) :
84 _rate (rate),
85 _roomsize (0.0),
86 _revbtime (0.0),
87 _ipbandw (0.8),
88 _damping (0.2),
89 _refllev (0.3),
90 _taillev (0.3)
91 {
92 unsigned long n;
93
94 n = (unsigned long)(rate * 0.015);
95 _dif0.init (n, 0.450);
96 _dif1.init (n, 0.450);
97 _qfdn.init ((unsigned long)(rate * MAX_ROOMSIZE / 340));
98 n = (unsigned long)(_qfdn._size * 0.450);
99 _del0.init (n);
100 _del1.init (n);
101 n = (unsigned long)(rate * 0.124);
102 _dif1L.init ((unsigned long)(n * 0.2137), 0.5);
103 _dif2L.init ((unsigned long)(n * 0.3753), 0.5);
104 _dif3L.init (n - _dif1L._size - _dif2L._size, 0.5);
105 _dif1R.init ((unsigned long)(n * 0.1974), 0.5);
106 _dif2R.init ((unsigned long)(n * 0.3526), 0.5);
107 _dif3R.init (n - _dif1R._size - _dif2R._size, 0.5);
108
109 set_ipbandw (0.8);
110 set_damping (0.2);
111 set_roomsize (50.0);
112 set_revbtime (3.0);
113 }
114
115
116 Greverb::~Greverb (void)
117 {
118 _dif0.fini ();
119 _dif1.fini ();
120 _qfdn.fini ();
121 _del0.fini ();;
122 _del1.fini ();;
123 _dif1L.fini ();
124 _dif2L.fini ();
125 _dif3L.fini ();
126 _dif1R.fini ();
127 _dif2R.fini ();
128 _dif3R.fini ();
129 }
130
131
132 void Greverb::reset (void)
133 {
134 // Clear all delay lines and filter states.
135 // Current parameters are preserved.
136 _dif0.reset ();
137 _dif1.reset ();
138 _qfdn.reset ();
139 _del0.reset ();
140 _del1.reset ();
141 _dif1L.reset ();
142 _dif2L.reset ();
143 _dif3L.reset ();
144 _dif1R.reset ();
145 _dif2R.reset ();
146 _dif3R.reset ();
147 }
148
149
150 void Greverb::set_roomsize (float R)
151 {
152 if (R > MAX_ROOMSIZE) R = MAX_ROOMSIZE;
153 if (R < MIN_ROOMSIZE) R = MIN_ROOMSIZE;
154 if (fabs (_roomsize - R) < 0.5) return;
155 _roomsize = R;
156 _qfdn._d [0] = (unsigned long)(_rate * R / 340.0);
157 _qfdn._d [1] = (unsigned long)(_qfdn._d [0] * 0.816490);
158 _qfdn._d [2] = (unsigned long)(_qfdn._d [0] * 0.707100);
159 _qfdn._d [3] = (unsigned long)(_qfdn._d [0] * 0.632450);
160
161 _del0._d [0] = (unsigned long)(_qfdn._d [0] * 0.100);
162 _del0._d [1] = (unsigned long)(_qfdn._d [0] * 0.164);
163 _del0._d [2] = (unsigned long)(_qfdn._d [0] * 0.270);
164 _del0._d [3] = (unsigned long)(_qfdn._d [0] * 0.443);
165
166 _del1._d [0] = (unsigned long)(_qfdn._d [0] * 0.087);
167 _del1._d [1] = (unsigned long)(_qfdn._d [0] * 0.149);
168 _del1._d [2] = (unsigned long)(_qfdn._d [0] * 0.256);
169 _del1._d [3] = (unsigned long)(_qfdn._d [0] * 0.440);
170 set_params ();
171 }
172
173
174 void Greverb::set_revbtime (float T)
175 {
176 if (T > MAX_REVBTIME) T = MAX_REVBTIME;
177 if (T < MIN_REVBTIME) T = MIN_REVBTIME;
178 if (fabs (_revbtime - T) < 0.05) return;
179 _revbtime = T;
180 set_params ();
181 }
182
183
184 void Greverb::set_ipbandw (float B)
185 {
186 if (B < 0.1) B = 0.1;
187 if (B > 1.0) B = 1.0;
188 _del1._c = _del0._c = _ipbandw = B;
189 }
190
191
192 void Greverb::set_damping (float D)
193 {
194 if (D < 0.0) D = 0.0;
195 if (D > 0.9) D = 0.9;
196 _damping = D;
197 _qfdn._c = 1.0 - _damping;
198 }
199
200
201 void Greverb::set_params (void)
202 {
203 double a;
204
205 a = pow (0.001, 1.0 / (_rate * _revbtime));
206 for (int j = 0; j < 4; j++)
207 {
208 _qfdn._g [j] = pow (a, (double)(_qfdn._d [j]));
209 }
210 }
211
212
213 void Greverb::process (unsigned long n, float *x0, float *x1, float *y0, float *y1)
214 {
215 float z, z0, z1;
216
217 while (n--)
218 {
219 _del0.process (_dif0.process (*x0 + 1e-20));
220 _del1.process (_dif1.process (*x1 + 1e-20));
221 _qfdn.process (_del0._y, _del1._y);
222 z = _taillev * (_qfdn._y [0] + _qfdn._y [1] + _qfdn._y [2] + _qfdn._y [3]);
223 z0 = _refllev * (_del0._y [0] - _del0._y [1] + _del0._y [2] - _del0._y [3]);
224 z1 = _refllev * (_del1._y [0] - _del1._y [1] + _del1._y [2] - _del1._y [3]);
225 *y0++ = _dif3L.process (_dif2L.process (_dif1L.process (z + z0))) + _dryslev * *x0++;
226 *y1++ = _dif3R.process (_dif2R.process (_dif1R.process (z + z1))) + _dryslev * *x1++;
227 }
228 }
0 #ifndef __GREVERB_H
1 #define __GREVERB_H
2
3
4 class Diffuser
5 {
6 private:
7
8 friend class Greverb;
9
10 void init (unsigned long size, float c);
11 void reset (void);
12 void fini (void);
13
14 float process (float x)
15 {
16 float w;
17
18 w = x - _c * _data [_i];
19 x = _data [_i] + _c * w;
20 _data [_i] = w;
21 if (++_i == _size) _i = 0;
22 return x;
23 }
24
25 float *_data;
26 unsigned long _size;
27 unsigned long _i; // sample index
28 float _c; // feedback
29 };
30
31
32 class QuadFDN
33 {
34 private:
35
36 friend class Greverb;
37
38 void init (unsigned long size);
39 void reset (void);
40 void fini (void);
41
42 void process (float *x0, float *x1)
43 {
44 int j;
45 long k;
46
47 for (j = 0; j < 4; j++)
48 {
49 k = _i - _d [j];
50 if (k < 0) k += _size;
51 _y [j] += _c * (_g [j] * _data [j][k] - _y [j]);
52 }
53 _data [0][_i] = x0 [0] + x1 [0] + 0.5 * ( _y [0] + _y [1] - _y [2] - _y [3]);
54 _data [1][_i] = x0 [1] + x1 [1] + 0.5 * ( _y [0] - _y [1] - _y [2] + _y [3]);
55 _data [2][_i] = x0 [2] + x1 [2] + 0.5 * (-_y [0] + _y [1] - _y [2] + _y [3]);
56 _data [3][_i] = x0 [3] + x1 [3] + 0.5 * ( _y [0] + _y [1] + _y [2] + _y [3]);
57 if (++_i == _size) _i = 0;
58 }
59
60 float *_data [4];
61 unsigned long _size;
62 float _g [4]; // gain
63 float _y [4]; // filtered output
64 unsigned long _d [4]; // delay
65 unsigned long _i; // input index
66 float _c; // damping
67 };
68
69
70 class MTDelay
71 {
72 private:
73
74 friend class Greverb;
75
76 void init (unsigned long size);
77 void reset (void);
78 void fini (void);
79
80 void process (float x)
81 {
82 int j;
83 long k;
84
85 for (j = 0; j < 4; j++)
86 {
87 k = _i - _d [j];
88 if (k < 0) k += _size;
89 _y [j] = _data [k];
90 }
91 _z += _c * (x - _z);
92 _data [_i] = _z;
93 if (++_i == _size) _i = 0;
94 }
95
96 float *_data;
97 unsigned long _size;
98 float _y [4]; // output
99 unsigned long _d [4]; // delay
100 unsigned long _i; // input index
101 float _c; // damping;
102 float _z; // filter state
103 } ;
104
105
106
107 class Greverb
108 {
109 public:
110
111 enum
112 {
113 MIN_ROOMSIZE = 5,
114 MAX_ROOMSIZE = 150,
115 MIN_REVBTIME = 1,
116 MAX_REVBTIME = 20
117 };
118
119 Greverb (unsigned long rate);
120 ~Greverb (void);
121
122 void reset (void);
123 void set_roomsize (float roomsize);
124 void set_revbtime (float revbtime);
125 void set_ipbandw (float ipbandw);
126 void set_damping (float damping);
127 void set_dryslev (float refllev) { _dryslev = refllev; }
128 void set_refllev (float refllev) { _refllev = refllev; }
129 void set_taillev (float taillev) { _taillev = taillev; }
130 void process (unsigned long n, float *x0, float *x1, float *y0, float *y1);
131
132 private:
133
134 void set_params (void);
135
136 unsigned long _rate;
137
138 float _roomsize;
139 float _revbtime;
140 float _ipbandw;
141 float _damping;
142 float _dryslev;
143 float _refllev;
144 float _taillev;
145
146 Diffuser _dif0;
147 Diffuser _dif1;
148 MTDelay _del0;
149 MTDelay _del1;
150 QuadFDN _qfdn;
151 Diffuser _dif1L;
152 Diffuser _dif2L;
153 Diffuser _dif3L;
154 Diffuser _dif1R;
155 Diffuser _dif2R;
156 Diffuser _dif3R;
157 };
158
159
160 #endif
0 /* ladspa.h
1
2 Linux Audio Developer's Simple Plugin API Version 1.1[LGPL].
3 Copyright (C) 2000-2002 Richard W.E. Furse, Paul Barton-Davis,
4 Stefan Westerfeld.
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License
8 as published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA. */
20
21 #ifndef LADSPA_INCLUDED
22 #define LADSPA_INCLUDED
23
24 #define LADSPA_VERSION "1.1"
25 #define LADSPA_VERSION_MAJOR 1
26 #define LADSPA_VERSION_MINOR 1
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /*****************************************************************************/
33
34 /* Overview:
35
36 There is a large number of synthesis packages in use or development
37 on the Linux platform at this time. This API (`The Linux Audio
38 Developer's Simple Plugin API') attempts to give programmers the
39 ability to write simple `plugin' audio processors in C/C++ and link
40 them dynamically (`plug') into a range of these packages (`hosts').
41 It should be possible for any host and any plugin to communicate
42 completely through this interface.
43
44 This API is deliberately short and simple. To achieve compatibility
45 with a range of promising Linux sound synthesis packages it
46 attempts to find the `greatest common divisor' in their logical
47 behaviour. Having said this, certain limiting decisions are
48 implicit, notably the use of a fixed type (LADSPA_Data) for all
49 data transfer and absence of a parameterised `initialisation'
50 phase. See below for the LADSPA_Data typedef.
51
52 Plugins are expected to distinguish between control and audio
53 data. Plugins have `ports' that are inputs or outputs for audio or
54 control data and each plugin is `run' for a `block' corresponding
55 to a short time interval measured in samples. Audio data is
56 communicated using arrays of LADSPA_Data, allowing a block of audio
57 to be processed by the plugin in a single pass. Control data is
58 communicated using single LADSPA_Data values. Control data has a
59 single value at the start of a call to the `run()' or `run_adding()'
60 function, and may be considered to remain this value for its
61 duration. The plugin may assume that all its input and output ports
62 have been connected to the relevant data location (see the
63 `connect_port()' function below) before it is asked to run.
64
65 Plugins will reside in shared object files suitable for dynamic
66 linking by dlopen() and family. The file will provide a number of
67 `plugin types' that can be used to instantiate actual plugins
68 (sometimes known as `plugin instances') that can be connected
69 together to perform tasks.
70
71 This API contains very limited error-handling. */
72
73 /*****************************************************************************/
74
75 /* Fundamental data type passed in and out of plugin. This data type
76 is used to communicate audio samples and control values. It is
77 assumed that the plugin will work sensibly given any numeric input
78 value although it may have a preferred range (see hints below).
79
80 For audio it is generally assumed that 1.0f is the `0dB' reference
81 amplitude and is a `normal' signal level. */
82
83 typedef float LADSPA_Data;
84
85 /*****************************************************************************/
86
87 /* Special Plugin Properties:
88
89 Optional features of the plugin type are encapsulated in the
90 LADSPA_Properties type. This is assembled by ORing individual
91 properties together. */
92
93 typedef int LADSPA_Properties;
94
95 /* Property LADSPA_PROPERTY_REALTIME indicates that the plugin has a
96 real-time dependency (e.g. listens to a MIDI device) and so its
97 output must not be cached or subject to significant latency. */
98 #define LADSPA_PROPERTY_REALTIME 0x1
99
100 /* Property LADSPA_PROPERTY_INPLACE_BROKEN indicates that the plugin
101 may cease to work correctly if the host elects to use the same data
102 location for both input and output (see connect_port()). This
103 should be avoided as enabling this flag makes it impossible for
104 hosts to use the plugin to process audio `in-place.' */
105 #define LADSPA_PROPERTY_INPLACE_BROKEN 0x2
106
107 /* Property LADSPA_PROPERTY_HARD_RT_CAPABLE indicates that the plugin
108 is capable of running not only in a conventional host but also in a
109 `hard real-time' environment. To qualify for this the plugin must
110 satisfy all of the following:
111
112 (1) The plugin must not use malloc(), free() or other heap memory
113 management within its run() or run_adding() functions. All new
114 memory used in run() must be managed via the stack. These
115 restrictions only apply to the run() function.
116
117 (2) The plugin will not attempt to make use of any library
118 functions with the exceptions of functions in the ANSI standard C
119 and C maths libraries, which the host is expected to provide.
120
121 (3) The plugin will not access files, devices, pipes, sockets, IPC
122 or any other mechanism that might result in process or thread
123 blocking.
124
125 (4) The plugin will take an amount of time to execute a run() or
126 run_adding() call approximately of form (A+B*SampleCount) where A
127 and B depend on the machine and host in use. This amount of time
128 may not depend on input signals or plugin state. The host is left
129 the responsibility to perform timings to estimate upper bounds for
130 A and B. */
131 #define LADSPA_PROPERTY_HARD_RT_CAPABLE 0x4
132
133 #define LADSPA_IS_REALTIME(x) ((x) & LADSPA_PROPERTY_REALTIME)
134 #define LADSPA_IS_INPLACE_BROKEN(x) ((x) & LADSPA_PROPERTY_INPLACE_BROKEN)
135 #define LADSPA_IS_HARD_RT_CAPABLE(x) ((x) & LADSPA_PROPERTY_HARD_RT_CAPABLE)
136
137 /*****************************************************************************/
138
139 /* Plugin Ports:
140
141 Plugins have `ports' that are inputs or outputs for audio or
142 data. Ports can communicate arrays of LADSPA_Data (for audio
143 inputs/outputs) or single LADSPA_Data values (for control
144 input/outputs). This information is encapsulated in the
145 LADSPA_PortDescriptor type which is assembled by ORing individual
146 properties together.
147
148 Note that a port must be an input or an output port but not both
149 and that a port must be a control or audio port but not both. */
150
151 typedef int LADSPA_PortDescriptor;
152
153 /* Property LADSPA_PORT_INPUT indicates that the port is an input. */
154 #define LADSPA_PORT_INPUT 0x1
155
156 /* Property LADSPA_PORT_OUTPUT indicates that the port is an output. */
157 #define LADSPA_PORT_OUTPUT 0x2
158
159 /* Property LADSPA_PORT_CONTROL indicates that the port is a control
160 port. */
161 #define LADSPA_PORT_CONTROL 0x4
162
163 /* Property LADSPA_PORT_AUDIO indicates that the port is a audio
164 port. */
165 #define LADSPA_PORT_AUDIO 0x8
166
167 #define LADSPA_IS_PORT_INPUT(x) ((x) & LADSPA_PORT_INPUT)
168 #define LADSPA_IS_PORT_OUTPUT(x) ((x) & LADSPA_PORT_OUTPUT)
169 #define LADSPA_IS_PORT_CONTROL(x) ((x) & LADSPA_PORT_CONTROL)
170 #define LADSPA_IS_PORT_AUDIO(x) ((x) & LADSPA_PORT_AUDIO)
171
172 /*****************************************************************************/
173
174 /* Plugin Port Range Hints:
175
176 The host may wish to provide a representation of data entering or
177 leaving a plugin (e.g. to generate a GUI automatically). To make
178 this more meaningful, the plugin should provide `hints' to the host
179 describing the usual values taken by the data.
180
181 Note that these are only hints. The host may ignore them and the
182 plugin must not assume that data supplied to it is meaningful. If
183 the plugin receives invalid input data it is expected to continue
184 to run without failure and, where possible, produce a sensible
185 output (e.g. a high-pass filter given a negative cutoff frequency
186 might switch to an all-pass mode).
187
188 Hints are meaningful for all input and output ports but hints for
189 input control ports are expected to be particularly useful.
190
191 More hint information is encapsulated in the
192 LADSPA_PortRangeHintDescriptor type which is assembled by ORing
193 individual hint types together. Hints may require further
194 LowerBound and UpperBound information.
195
196 All the hint information for a particular port is aggregated in the
197 LADSPA_PortRangeHint structure. */
198
199 typedef int LADSPA_PortRangeHintDescriptor;
200
201 /* Hint LADSPA_HINT_BOUNDED_BELOW indicates that the LowerBound field
202 of the LADSPA_PortRangeHint should be considered meaningful. The
203 value in this field should be considered the (inclusive) lower
204 bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also
205 specified then the value of LowerBound should be multiplied by the
206 sample rate. */
207 #define LADSPA_HINT_BOUNDED_BELOW 0x1
208
209 /* Hint LADSPA_HINT_BOUNDED_ABOVE indicates that the UpperBound field
210 of the LADSPA_PortRangeHint should be considered meaningful. The
211 value in this field should be considered the (inclusive) upper
212 bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also
213 specified then the value of UpperBound should be multiplied by the
214 sample rate. */
215 #define LADSPA_HINT_BOUNDED_ABOVE 0x2
216
217 /* Hint LADSPA_HINT_TOGGLED indicates that the data item should be
218 considered a Boolean toggle. Data less than or equal to zero should
219 be considered `off' or `false,' and data above zero should be
220 considered `on' or `true.' LADSPA_HINT_TOGGLED may not be used in
221 conjunction with any other hint except LADSPA_HINT_DEFAULT_0 or
222 LADSPA_HINT_DEFAULT_1. */
223 #define LADSPA_HINT_TOGGLED 0x4
224
225 /* Hint LADSPA_HINT_SAMPLE_RATE indicates that any bounds specified
226 should be interpreted as multiples of the sample rate. For
227 instance, a frequency range from 0Hz to the Nyquist frequency (half
228 the sample rate) could be requested by this hint in conjunction
229 with LowerBound = 0 and UpperBound = 0.5. Hosts that support bounds
230 at all must support this hint to retain meaning. */
231 #define LADSPA_HINT_SAMPLE_RATE 0x8
232
233 /* Hint LADSPA_HINT_LOGARITHMIC indicates that it is likely that the
234 user will find it more intuitive to view values using a logarithmic
235 scale. This is particularly useful for frequencies and gains. */
236 #define LADSPA_HINT_LOGARITHMIC 0x10
237
238 /* Hint LADSPA_HINT_INTEGER indicates that a user interface would
239 probably wish to provide a stepped control taking only integer
240 values. Any bounds set should be slightly wider than the actual
241 integer range required to avoid floating point rounding errors. For
242 instance, the integer set {0,1,2,3} might be described as [-0.1,
243 3.1]. */
244 #define LADSPA_HINT_INTEGER 0x20
245
246 /* The various LADSPA_HINT_HAS_DEFAULT_* hints indicate a `normal'
247 value for the port that is sensible as a default. For instance,
248 this value is suitable for use as an initial value in a user
249 interface or as a value the host might assign to a control port
250 when the user has not provided one. Defaults are encoded using a
251 mask so only one default may be specified for a port. Some of the
252 hints make use of lower and upper bounds, in which case the
253 relevant bound or bounds must be available and
254 LADSPA_HINT_SAMPLE_RATE must be applied as usual. The resulting
255 default must be rounded if LADSPA_HINT_INTEGER is present. Default
256 values were introduced in LADSPA v1.1. */
257 #define LADSPA_HINT_DEFAULT_MASK 0x3C0
258
259 /* This default values indicates that no default is provided. */
260 #define LADSPA_HINT_DEFAULT_NONE 0x0
261
262 /* This default hint indicates that the suggested lower bound for the
263 port should be used. */
264 #define LADSPA_HINT_DEFAULT_MINIMUM 0x40
265
266 /* This default hint indicates that a low value between the suggested
267 lower and upper bounds should be chosen. For ports with
268 LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.75 +
269 log(upper) * 0.25). Otherwise, this should be (lower * 0.75 + upper
270 * 0.25). */
271 #define LADSPA_HINT_DEFAULT_LOW 0x80
272
273 /* This default hint indicates that a middle value between the
274 suggested lower and upper bounds should be chosen. For ports with
275 LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.5 +
276 log(upper) * 0.5). Otherwise, this should be (lower * 0.5 + upper *
277 0.5). */
278 #define LADSPA_HINT_DEFAULT_MIDDLE 0xC0
279
280 /* This default hint indicates that a high value between the suggested
281 lower and upper bounds should be chosen. For ports with
282 LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.25 +
283 log(upper) * 0.75). Otherwise, this should be (lower * 0.25 + upper
284 * 0.75). */
285 #define LADSPA_HINT_DEFAULT_HIGH 0x100
286
287 /* This default hint indicates that the suggested upper bound for the
288 port should be used. */
289 #define LADSPA_HINT_DEFAULT_MAXIMUM 0x140
290
291 /* This default hint indicates that the number 0 should be used. Note
292 that this default may be used in conjunction with
293 LADSPA_HINT_TOGGLED. */
294 #define LADSPA_HINT_DEFAULT_0 0x200
295
296 /* This default hint indicates that the number 1 should be used. Note
297 that this default may be used in conjunction with
298 LADSPA_HINT_TOGGLED. */
299 #define LADSPA_HINT_DEFAULT_1 0x240
300
301 /* This default hint indicates that the number 100 should be used. */
302 #define LADSPA_HINT_DEFAULT_100 0x280
303
304 /* This default hint indicates that the Hz frequency of `concert A'
305 should be used. This will be 440 unless the host uses an unusual
306 tuning convention, in which case it may be within a few Hz. */
307 #define LADSPA_HINT_DEFAULT_440 0x2C0
308
309 #define LADSPA_IS_HINT_BOUNDED_BELOW(x) ((x) & LADSPA_HINT_BOUNDED_BELOW)
310 #define LADSPA_IS_HINT_BOUNDED_ABOVE(x) ((x) & LADSPA_HINT_BOUNDED_ABOVE)
311 #define LADSPA_IS_HINT_TOGGLED(x) ((x) & LADSPA_HINT_TOGGLED)
312 #define LADSPA_IS_HINT_SAMPLE_RATE(x) ((x) & LADSPA_HINT_SAMPLE_RATE)
313 #define LADSPA_IS_HINT_LOGARITHMIC(x) ((x) & LADSPA_HINT_LOGARITHMIC)
314 #define LADSPA_IS_HINT_INTEGER(x) ((x) & LADSPA_HINT_INTEGER)
315
316 #define LADSPA_IS_HINT_HAS_DEFAULT(x) ((x) & LADSPA_HINT_DEFAULT_MASK)
317 #define LADSPA_IS_HINT_DEFAULT_MINIMUM(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
318 == LADSPA_HINT_DEFAULT_MINIMUM)
319 #define LADSPA_IS_HINT_DEFAULT_LOW(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
320 == LADSPA_HINT_DEFAULT_LOW)
321 #define LADSPA_IS_HINT_DEFAULT_MIDDLE(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
322 == LADSPA_HINT_DEFAULT_MIDDLE)
323 #define LADSPA_IS_HINT_DEFAULT_HIGH(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
324 == LADSPA_HINT_DEFAULT_HIGH)
325 #define LADSPA_IS_HINT_DEFAULT_MAXIMUM(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
326 == LADSPA_HINT_DEFAULT_MAXIMUM)
327 #define LADSPA_IS_HINT_DEFAULT_0(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
328 == LADSPA_HINT_DEFAULT_0)
329 #define LADSPA_IS_HINT_DEFAULT_1(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
330 == LADSPA_HINT_DEFAULT_1)
331 #define LADSPA_IS_HINT_DEFAULT_100(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
332 == LADSPA_HINT_DEFAULT_100)
333 #define LADSPA_IS_HINT_DEFAULT_440(x) (((x) & LADSPA_HINT_DEFAULT_MASK) \
334 == LADSPA_HINT_DEFAULT_440)
335
336 typedef struct _LADSPA_PortRangeHint {
337
338 /* Hints about the port. */
339 LADSPA_PortRangeHintDescriptor HintDescriptor;
340
341 /* Meaningful when hint LADSPA_HINT_BOUNDED_BELOW is active. When
342 LADSPA_HINT_SAMPLE_RATE is also active then this value should be
343 multiplied by the relevant sample rate. */
344 LADSPA_Data LowerBound;
345
346 /* Meaningful when hint LADSPA_HINT_BOUNDED_ABOVE is active. When
347 LADSPA_HINT_SAMPLE_RATE is also active then this value should be
348 multiplied by the relevant sample rate. */
349 LADSPA_Data UpperBound;
350
351 } LADSPA_PortRangeHint;
352
353 /*****************************************************************************/
354
355 /* Plugin Handles:
356
357 This plugin handle indicates a particular instance of the plugin
358 concerned. It is valid to compare this to NULL (0 for C++) but
359 otherwise the host should not attempt to interpret it. The plugin
360 may use it to reference internal instance data. */
361
362 typedef void * LADSPA_Handle;
363
364 /*****************************************************************************/
365
366 /* Descriptor for a Type of Plugin:
367
368 This structure is used to describe a plugin type. It provides a
369 number of functions to examine the type, instantiate it, link it to
370 buffers and workspaces and to run it. */
371
372 typedef struct _LADSPA_Descriptor {
373
374 /* This numeric identifier indicates the plugin type
375 uniquely. Plugin programmers may reserve ranges of IDs from a
376 central body to avoid clashes. Hosts may assume that IDs are
377 below 0x1000000. */
378 unsigned long UniqueID;
379
380 /* This identifier can be used as a unique, case-sensitive
381 identifier for the plugin type within the plugin file. Plugin
382 types should be identified by file and label rather than by index
383 or plugin name, which may be changed in new plugin
384 versions. Labels must not contain white-space characters. */
385 const char * Label;
386
387 /* This indicates a number of properties of the plugin. */
388 LADSPA_Properties Properties;
389
390 /* This member points to the null-terminated name of the plugin
391 (e.g. "Sine Oscillator"). */
392 const char * Name;
393
394 /* This member points to the null-terminated string indicating the
395 maker of the plugin. This can be an empty string but not NULL. */
396 const char * Maker;
397
398 /* This member points to the null-terminated string indicating any
399 copyright applying to the plugin. If no Copyright applies the
400 string "None" should be used. */
401 const char * Copyright;
402
403 /* This indicates the number of ports (input AND output) present on
404 the plugin. */
405 unsigned long PortCount;
406
407 /* This member indicates an array of port descriptors. Valid indices
408 vary from 0 to PortCount-1. */
409 const LADSPA_PortDescriptor * PortDescriptors;
410
411 /* This member indicates an array of null-terminated strings
412 describing ports (e.g. "Frequency (Hz)"). Valid indices vary from
413 0 to PortCount-1. */
414 const char * const * PortNames;
415
416 /* This member indicates an array of range hints for each port (see
417 above). Valid indices vary from 0 to PortCount-1. */
418 const LADSPA_PortRangeHint * PortRangeHints;
419
420 /* This may be used by the plugin developer to pass any custom
421 implementation data into an instantiate call. It must not be used
422 or interpreted by the host. It is expected that most plugin
423 writers will not use this facility as LADSPA_Handle should be
424 used to hold instance data. */
425 void * ImplementationData;
426
427 /* This member is a function pointer that instantiates a plugin. A
428 handle is returned indicating the new plugin instance. The
429 instantiation function accepts a sample rate as a parameter. The
430 plugin descriptor from which this instantiate function was found
431 must also be passed. This function must return NULL if
432 instantiation fails.
433
434 Note that instance initialisation should generally occur in
435 activate() rather than here. */
436 LADSPA_Handle (*instantiate)(const struct _LADSPA_Descriptor * Descriptor,
437 unsigned long SampleRate);
438
439 /* This member is a function pointer that connects a port on an
440 instantiated plugin to a memory location at which a block of data
441 for the port will be read/written. The data location is expected
442 to be an array of LADSPA_Data for audio ports or a single
443 LADSPA_Data value for control ports. Memory issues will be
444 managed by the host. The plugin must read/write the data at these
445 locations every time run() or run_adding() is called and the data
446 present at the time of this connection call should not be
447 considered meaningful.
448
449 connect_port() may be called more than once for a plugin instance
450 to allow the host to change the buffers that the plugin is
451 reading or writing. These calls may be made before or after
452 activate() or deactivate() calls.
453
454 connect_port() must be called at least once for each port before
455 run() or run_adding() is called. When working with blocks of
456 LADSPA_Data the plugin should pay careful attention to the block
457 size passed to the run function as the block allocated may only
458 just be large enough to contain the block of samples.
459
460 Plugin writers should be aware that the host may elect to use the
461 same buffer for more than one port and even use the same buffer
462 for both input and output (see LADSPA_PROPERTY_INPLACE_BROKEN).
463 However, overlapped buffers or use of a single buffer for both
464 audio and control data may result in unexpected behaviour. */
465 void (*connect_port)(LADSPA_Handle Instance,
466 unsigned long Port,
467 LADSPA_Data * DataLocation);
468
469 /* This member is a function pointer that initialises a plugin
470 instance and activates it for use. This is separated from
471 instantiate() to aid real-time support and so that hosts can
472 reinitialise a plugin instance by calling deactivate() and then
473 activate(). In this case the plugin instance must reset all state
474 information dependent on the history of the plugin instance
475 except for any data locations provided by connect_port() and any
476 gain set by set_run_adding_gain(). If there is nothing for
477 activate() to do then the plugin writer may provide a NULL rather
478 than an empty function.
479
480 When present, hosts must call this function once before run() (or
481 run_adding()) is called for the first time. This call should be
482 made as close to the run() call as possible and indicates to
483 real-time plugins that they are now live. Plugins should not rely
484 on a prompt call to run() after activate(). activate() may not be
485 called again unless deactivate() is called first. Note that
486 connect_port() may be called before or after a call to
487 activate(). */
488 void (*activate)(LADSPA_Handle Instance);
489
490 /* This method is a function pointer that runs an instance of a
491 plugin for a block. Two parameters are required: the first is a
492 handle to the particular instance to be run and the second
493 indicates the block size (in samples) for which the plugin
494 instance may run.
495
496 Note that if an activate() function exists then it must be called
497 before run() or run_adding(). If deactivate() is called for a
498 plugin instance then the plugin instance may not be reused until
499 activate() has been called again.
500
501 If the plugin has the property LADSPA_PROPERTY_HARD_RT_CAPABLE
502 then there are various things that the plugin should not do
503 within the run() or run_adding() functions (see above). */
504 void (*run)(LADSPA_Handle Instance,
505 unsigned long SampleCount);
506
507 /* This method is a function pointer that runs an instance of a
508 plugin for a block. This has identical behaviour to run() except
509 in the way data is output from the plugin. When run() is used,
510 values are written directly to the memory areas associated with
511 the output ports. However when run_adding() is called, values
512 must be added to the values already present in the memory
513 areas. Furthermore, output values written must be scaled by the
514 current gain set by set_run_adding_gain() (see below) before
515 addition.
516
517 run_adding() is optional. When it is not provided by a plugin,
518 this function pointer must be set to NULL. When it is provided,
519 the function set_run_adding_gain() must be provided also. */
520 void (*run_adding)(LADSPA_Handle Instance,
521 unsigned long SampleCount);
522
523 /* This method is a function pointer that sets the output gain for
524 use when run_adding() is called (see above). If this function is
525 never called the gain is assumed to default to 1. Gain
526 information should be retained when activate() or deactivate()
527 are called.
528
529 This function should be provided by the plugin if and only if the
530 run_adding() function is provided. When it is absent this
531 function pointer must be set to NULL. */
532 void (*set_run_adding_gain)(LADSPA_Handle Instance,
533 LADSPA_Data Gain);
534
535 /* This is the counterpart to activate() (see above). If there is
536 nothing for deactivate() to do then the plugin writer may provide
537 a NULL rather than an empty function.
538
539 Hosts must deactivate all activated units after they have been
540 run() (or run_adding()) for the last time. This call should be
541 made as close to the last run() call as possible and indicates to
542 real-time plugins that they are no longer live. Plugins should
543 not rely on prompt deactivation. Note that connect_port() may be
544 called before or after a call to deactivate().
545
546 Deactivation is not similar to pausing as the plugin instance
547 will be reinitialised when activate() is called to reuse it. */
548 void (*deactivate)(LADSPA_Handle Instance);
549
550 /* Once an instance of a plugin has been finished with it can be
551 deleted using the following function. The instance handle passed
552 ceases to be valid after this call.
553
554 If activate() was called for a plugin instance then a
555 corresponding call to deactivate() must be made before cleanup()
556 is called. */
557 void (*cleanup)(LADSPA_Handle Instance);
558
559 } LADSPA_Descriptor;
560
561 /**********************************************************************/
562
563 /* Accessing a Plugin: */
564
565 /* The exact mechanism by which plugins are loaded is host-dependent,
566 however all most hosts will need to know is the name of shared
567 object file containing the plugin types. To allow multiple hosts to
568 share plugin types, hosts may wish to check for environment
569 variable LADSPA_PATH. If present, this should contain a
570 colon-separated path indicating directories that should be searched
571 (in order) when loading plugin types.
572
573 A plugin programmer must include a function called
574 "ladspa_descriptor" with the following function prototype within
575 the shared object file. This function will have C-style linkage (if
576 you are using C++ this is taken care of by the `extern "C"' clause
577 at the top of the file).
578
579 A host will find the plugin shared object file by one means or
580 another, find the ladspa_descriptor() function, call it, and
581 proceed from there.
582
583 Plugin types are accessed by index (not ID) using values from 0
584 upwards. Out of range indexes must result in this function
585 returning NULL, so the plugin count can be determined by checking
586 for the least index that results in NULL being returned. */
587
588 const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index);
589
590 /* Datatype corresponding to the ladspa_descriptor() function. */
591 typedef const LADSPA_Descriptor *
592 (*LADSPA_Descriptor_Function)(unsigned long Index);
593
594 /**********************************************************************/
595
596 #ifdef __cplusplus
597 }
598 #endif
599
600 #endif /* LADSPA_INCLUDED */
601
602 /* EOF */
0 /*
1 Copyright (C) 2003 Fons Adriaensen
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18
19 #ifndef __LADSPAPLUGIN_H
20 #define __LADSPAPLUGIN_H
21
22
23 #include "ladspa.h" // use local version
24
25
26
27 class LadspaPlugin
28 {
29 public:
30
31 LadspaPlugin (unsigned long fsam) : _gain (1.0), _fsam (fsam) {}
32
33 virtual void setport (unsigned long port, LADSPA_Data *data) = 0;
34 virtual void active (bool act) = 0;
35 virtual void runproc (unsigned long len, bool add) = 0;
36 virtual ~LadspaPlugin (void) {}
37
38 void setgain (LADSPA_Data gain) { _gain = gain; }
39
40 protected:
41
42 float _gain;
43 float _fsam;
44 };
45
46
47
48 #endif