foo-plugins-1.0/0000755000175000017500000000000010552473726011267 5ustar v2v2foo-plugins-1.0/makestub.pl0000755000175000017500000003476610552473725013461 0ustar v2v2#!/usr/bin/perl -w use XML::Parser; $xml_line = 1; if (@ARGV != 1) { die "Usage: $0 "; } $filename = $ARGV[0]; $run_adding_broken = 0; $xmlp = new XML::Parser(Style => 'Tree', ParseParamEnt => 1, ErrorContext => 3, NoLWP => 1); @tree = $xmlp -> parsefile($filename); open(XML, $filename); @xml_source = ; @required_calls = ('instantiate', 'connect_port', 'cleanup'); $root = $tree[0]; if ($$root[0] ne "ladspa") { die "This doesn't look like a valid ladspa description file"; } # Pointer to element $ladspa = $root->[1]; if ($ladspa->[3] ne "global") { die "Can't find global section. Should be immediatly after ladspa\n"; } @globtags = @{ $ladspa->[4] }; for ($i=3; $i<@globtags; $i+=4) { $foo = $globtags[$i]; unless (ref($foo)) { if ($foo eq "meta") { $global{$globtags[$i+1]->[0]->{'name'}} = $globtags[$i+1]->[0]->{'value'}; } if ($foo eq "include") { push(@includes, $globtags[$i+1]->[0]->{'file'}); } if ($foo eq "code") { $g_code = $globtags[$i+1]->[2]; $g_code =~ s/^\s*\n//; $g_code =~ s/\t/ /g; $g_code =~ /^( *)/; $xml_indent = " " x length($1); $g_code =~ s/(^|\n)$xml_indent/$1/g; $g_code =~ s/\s+$//; $global_code .= $g_code."\n\n"; } } } for (my $i=7; $i<@{$ladspa}; $i+=4) { $foo = $ladspa->[$i]; if ($foo eq "plugin") { &process_plugin($ladspa->[$i+1]); push(@allports, @ports); @ports = (); } } # General headers print < \#include \#ifdef ENABLE_NLS \#include \#endif \#define _ISOC9X_SOURCE 1 \#define _ISOC99_SOURCE 1 \#define __USE_ISOC99 1 \#define __USE_ISOC9X 1 \#include \#include "utils.h" \#include "ladspa.h" EOB for $inc (@includes) { print "#include \"$inc\"\n"; } unless ($global_code) { $global_code = ""; } my $glob_code_start = find_el_line("code"); print "#line $glob_code_start \"$filename\"\n" if $glob_code_start && $xml_line; print "\n$global_code"; my $n = 0; $last_plugin = ""; for $port (@allports) { if ($port->{'plugin'} ne $last_plugin) { $n = 0; $last_plugin = $port->{'plugin'}; } $pl = uc($port->{'plugin'}.'_'.$port->{'label'}); printf("#define %-30s $n\n", $pl); $n++; } print $globals; print <[0]->{'id'}; $label = $tree->[0]->{'label'}; if (!$id) { die "Plugin '$label' has no id"; } if (!$label) { die "Plugin #$id has no label"; } push(@plugins, $label); %i_data = (); for ($i=3; $i<@{$tree}; $i+=4) { $foo = $tree->[$i]; if ($foo eq "name") { $name = $tree->[$i+1]->[2]; } if ($foo eq "callback") { push(@callbacks, $tree->[$i+1]->[0]->{'event'}); $callback_code{$label.'_'.$tree->[$i+1]->[0]->{'event'}} = $tree->[$i+1]->[2]; } if ($foo eq "port") { push(@ports, &process_port($tree->[$i+1])); } if ($foo eq "instance-data") { $i_data{$tree->[$i+1]->[0]->{'label'}} = $tree->[$i+1]->[0]->{'type'}; } } my @calls = (); my %MARK = (); grep($MARK{$_}++, @callbacks, @required_calls); @calls = sort keys %MARK; for $call (@calls) { my $call_start = find_el_line("callback", "event" => $call); if ($call_start) { $call_start++; if ($xml_line ) { $cc_marker = "#line $call_start \"$filename\"\n"; } else { $cc_marker = ""; } } else { $cc_marker = ""; } if ($call eq "instantiate") { $c = ""; if ($callback_code{"${label}_instantiate"}) { $c .= "\t\u$label *plugin_data = (\u$label *)malloc(sizeof(\u$label));\n"; for $var (sort keys %i_data) { if ($i_data{$var} =~ /\*/) { $c .= "\t$i_data{$var}$var = NULL;\n"; } else { #$c .= "\t$i_data{$var} $var = 0;\n"; $c .= "\t$i_data{$var} $var;\n"; } } $c .= "\n".$cc_marker; $c .= reindent_callback($callback_code{"${label}_instantiate"})."\n\n"; for $var (sort keys %i_data) { $c .= "\tplugin_data->$var = $var;\n"; } $c .= "\n\treturn (LADSPA_Handle)plugin_data;" } else { $c .= "\t\u$label *plugin_data = (\u$label *)malloc(sizeof(\u$label));\n"; $c .= "\tplugin_data->run_adding_gain = 1.0f;\n"; $c .= "\n\treturn (LADSPA_Handle)plugin_data;" } $code .= <{'label'}); if ($port->{'watch'}) { $watch = "\n plugin->$port->{'watch'} = 1;"; } else { $watch = ""; } $code .= <$port->{label} = data;$watch break; EOB } $code .= <{'dir'} eq "input") { $const = "const "; } else { $const = ""; } if ($port->{'type'} eq "audio") { $run_code .= "\n /* $port->{name} (array of floats of length sample_count) */\n"; $run_code .= " ${const}LADSPA_Data * const ".$port->{'label'}." = plugin_data->".$port->{'label'}.";\n"; } elsif ($port->{'dir'} eq "input") { $run_code .= "\n /* $port->{name} (float value) */\n"; $run_code .= " const LADSPA_Data ".$port->{'label'}." = *(plugin_data->".$port->{'label'}.");\n"; } } for $var (sort keys %i_data) { $run_code .= " $i_data{$var} $var = plugin_data->$var;\n"; } if ($callback_code{"${label}_run"}) { $cb_code = $callback_code{"${label}_run"}; $cb_code =~ s/^\n//; $cb_code =~ s/\t/ /g; $cb_code =~ /^( *)/; $xml_indent = " " x length($1); $cb_code =~ s/(^|\n)$xml_indent/$1\t/g; $cb_code =~ s/\s+$//; } else { $cb_code = <run_adding_gain = gain; } static void runAdding\u$label(LADSPA_Handle instance, unsigned long sample_count) { \u$label *plugin_data = (\u$label *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; $run_code EOB } } $run_code = ""; $globals .= " static LADSPA_Descriptor *${label}Descriptor = NULL;\n"; $num_ports = @ports; $init_code .= <UniqueID = $id; ${label}Descriptor->Label = "$label"; ${label}Descriptor->Properties = $properties; ${label}Descriptor->Name = D_("$name"); ${label}Descriptor->Maker = "$maker"; ${label}Descriptor->Copyright = "$copyright"; ${label}Descriptor->PortCount = $num_ports; port_descriptors = (LADSPA_PortDescriptor *)calloc($num_ports, sizeof(LADSPA_PortDescriptor)); ${label}Descriptor->PortDescriptors = (const LADSPA_PortDescriptor *)port_descriptors; port_range_hints = (LADSPA_PortRangeHint *)calloc($num_ports, sizeof(LADSPA_PortRangeHint)); ${label}Descriptor->PortRangeHints = (const LADSPA_PortRangeHint *)port_range_hints; port_names = (char **)calloc($num_ports, sizeof(char*)); ${label}Descriptor->PortNames = (const char **)port_names; EOB $fini_code .= <PortDescriptors); free((char **)${label}Descriptor->PortNames); free((LADSPA_PortRangeHint *)${label}Descriptor->PortRangeHints); free(${label}Descriptor); } EOB $globals .= "\ntypedef struct {\n"; for $port (@ports) { my $min = ""; my $max = ""; $l = uc($port->{'label'}); $d = uc($port->{'dir'}); $t = uc($port->{'type'}); $n = $port->{'name'}; $p = uc($label); $min = $port->{'min'} if defined $port->{'min'}; $max = $port->{'max'} if defined $port->{'max'}; if (defined $port->{'hints'}) { $hints = $port->{'hints'}; } else { $hints = ""; } $init_code .= <[0]->{'label'}; $$pname{'watch'} = $tree->[0]->{'watch'}; $$pname{'dir'} = $tree->[0]->{'dir'}; $$pname{'type'} = $tree->[0]->{'type'}; if (!$$pname{'label'} || !$$pname{'dir'} || !$$pname{'type'}) { die "Ports must have a label, dir(ection) and type"; } my $hints = ""; if ($tree->[0]->{'hint'}) { for $h (split(/[ ,]+/, $tree->[0]->{'hint'})) { $hints .= " | LADSPA_HINT_\U$h"; } } $$pname{'hints'} = $hints; for (my $el=3; $el<@{$tree}; $el+=4) { $foo = $tree->[$el]; if ($foo eq "name") { $$pname{'name'} = $tree->[$el+1]->[2]; } if ($foo eq "range") { $$pname{'min'} = $tree->[$el+1]->[0]->{'min'}; $$pname{'max'} = $tree->[$el+1]->[0]->{'max'}; } } return \%$pname; } sub reindent_callback { local ($cb_code) = @_; $cb_code =~ s/^\n//; $cb_code =~ s/\t/ /g; $cb_code =~ /^( *)/; $xml_indent = " " x length($1); $cb_code =~ s/(^|\n)$xml_indent/$1\t/g; $cb_code =~ s/\s+$//; return $cb_code; } sub find_el_line { local ($el, @rest) = @_; my $cnt = 0; my %attrs = (); while (@rest) { my $key = shift @rest; $attrs{$key} = shift @rest; } if (%attrs) { my $in_el = 0; my $num_attrs = length keys %attrs; my $matched = 0; for $line (@xml_source) { $cnt++; $in_el = 1 if $line =~ /<\s*$el[ \n>]/; if ($in_el) { for $attr (keys %attrs) { my $val = $attrs{$attr}; $matched++ if $line =~ /$attr\s*=\s*"$val"/; } } if ($matched >= $num_attrs) { return $cnt; } if ($line =~ />/) { $in_el = 0; $matched = 0; } } } else { for $line (@xml_source) { $cnt++; return $cnt if $line =~ /<\s*$el\s*>/; } } return 0; } foo-plugins-1.0/rms.c0000644000175000017500000000271310552473725012236 0ustar v2v2/* * Copyright (C) 2006 Steve Harris * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * $Id: rms.c $ */ #include #include #include "rms.h" #define NEAR_ZERO 0.0001f struct _rms { double rm; double coef; double fs; }; rms *rms_new(float fs, float time) { rms *r = calloc(1, sizeof(rms)); r->fs = fs; r->rm = NEAR_ZERO; r->coef = 0.5 * (1.0 - exp(-1.0 / (r->fs * time))); return r; } void rms_set_time(rms *r, float time) { r->coef = 0.5 * (1.0 - exp(-1.0 / (r->fs * time))); } float rms_run(rms *r, float x) { if (r->rm < NEAR_ZERO) r->rm = NEAR_ZERO; r->rm += r->coef * (( (x * x) / r->rm) - r->rm); return r->rm; } float rms_run_buffer(rms *r, float *x, int length) { int i; for (i=0; irm < NEAR_ZERO) r->rm = NEAR_ZERO; r->rm += r->coef * ((x[i] * x[i] / r->rm) - r->rm); } return r->rm; } void rms_free(rms *r) { if (r) free(r); } /* vi:set expandtab sts=4 sw=4: */ foo-plugins-1.0/LICENSE0000644000175000017500000003542310552473725012302 0ustar v2v2 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS foo-plugins-1.0/utils.h0000644000175000017500000000224310552473725012600 0ustar v2v2/* This header file is part of foo-plugins, a package of ladspa plugins Copyright (C) 2006 Sampo Savolainen (except where credited otherwise) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _FOO_UTILS_H #define _FOO_UTILS_H #include #include "rms.h" /* Convert a value in dB's to a coefficent, from swh-plugins Copyright (C) 2000 Steve Harris */ #define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f) #define CO_DB(v) (20.0f * log10f(v)) #endif /* _FOO_UTILS_H */ foo-plugins-1.0/foo_transients_mono.xml0000644000175000017500000001076610552473725016107 0ustar v2v2 Foo Transient Architect (mono) fast_rms); rms_free (plugin_data->slow_rms); ]]> slow) { // Attack tmp = (fast - slow) * attack_gain_db * FOO_ARCHITECT_GAIN_SCALE; if ( ( attack_gain_db < 0.0f && tmp < relevant_attack_gain) || ( attack_gain_db > 0.0f && tmp > relevant_attack_gain) ) relevant_attack_gain = tmp; } else { // Release tmp = (slow - fast) * release_gain_db * FOO_ARCHITECT_GAIN_SCALE; if ( ( release_gain_db < 0.0f && tmp < relevant_release_gain) || ( release_gain_db > 0.0f && tmp > relevant_release_gain) ) relevant_release_gain = tmp; //printf("Release gain: %f, envelope difference = %f\n", tmp, slow - fast); } buffer_write(output[i], input[i] * DB_CO(tmp)); #ifdef FOO_TESTER //buffer_write(output[i], fast); #endif } *(plugin_data->actual_attack_gain) = relevant_attack_gain; *(plugin_data->actual_release_gain) = relevant_release_gain; ]]> Averaging difference (s)

Controls the averaging time difference between the controlling envelopes

Attack gain (dB)

Attack gain range control

Release gain (dB)

Release gain range control

Current attack gain (dB)

The amount of gain applied at the moment

Current release gain (dB)

The amount of gain applied at the moment

latency Input L Output L
foo-plugins-1.0/rms.h0000644000175000017500000000174310552473725012245 0ustar v2v2#ifndef RMS_H #define RMS_H typedef struct _rms rms; /* * rms_new: return an object ecapsulating the RMS state. * params: fs, the same rate, in Hz * time, averaging time */ rms *rms_new(float fs, float time); /* * rms_set_time: change averaging time. * params: r, an RMS object allocated by rms_new * time, averaging time */ void rms_set_time(rms *r, float time); /* * rms_run: push one sample into the RMS object, returns the current RMS value. * params: r, an RMS object allocated by rms_new * x, the input sample */ float rms_run(rms *r, float x); /* rms_run_buffer: push an array of samples through the RMS object, returning * the RMS value after processing the whole buffer. * params: r, an RMS object allocated by rms_new * x, and array of input samples * length, length of x in value */ float rms_run_buffer(rms *r, float *x, int length); /* * free the space allocated by the rms object. */ void rms_free(rms *r); #endif foo-plugins-1.0/tester.c0000644000175000017500000001545010552473725012745 0ustar v2v2/* This file contains a part of a testing suite for foo-plugins Copyright (C) 2006 Sampo Savolainen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define FOO_TESTER //#define TEST_TRANSIENT_ARCHITECT #define TEST_LIMITER #ifdef TEST_LIMITER #include "foo_limiter.c" #endif #ifdef TEST_TRANSIENT_ARCHITECT #include "foo_transients.c" #endif #include #include #include #include #include #include void write_file_constant(char *file, float value, int size) { int i; FILE *fd = fopen(file, "w+"); for (i = 0; i < size; i++) { fprintf(fd, "%f\n", value); } fclose(fd); } void write_file(char *file, float *buf, int size) { int i; FILE *fd = fopen(file, "w+"); for (i = 0; i < size; i++) { fprintf(fd, "%f\n", buf[i]); } fclose(fd); } void create_ABCD(float *data, int buffer_size) { int m = buffer_size / 4; int start_offset = m / 10; data[0 * m + start_offset] = 1.2f; data[0 * m + start_offset + 33 ] = 2.0f; data[1 * m + start_offset] = 1.2f; data[1 * m + start_offset + 33 ] = 1.3f; data[2 * m + start_offset] = 1.2f; data[2 * m + start_offset + 33 ] = 1.3f; data[3 * m + start_offset] = 1.2f; data[3 * m + start_offset + 33 ] = 0.9f; } void create_random(float *data, int buffer_size, float scale, float offset) { int i; for (i = 0; i < buffer_size; i++) { data[i] = (float)rand()/(float)RAND_MAX * scale + offset; } } #ifdef TEST_LIMITER int test_limiter(int argc, char **argv) { float input_gain = 0.0f; float max_peak = 0.0f; float release_time = 0.05f; // seconds float release_scale = 0.75f; float attenuation; float latency; int buffer_size = 1024 * 4; float *input_left = (float*) malloc(buffer_size * sizeof(float)); float *input_right = (float*) malloc(buffer_size * sizeof(float)); float *output_left = (float*) malloc(buffer_size * sizeof(float)); float *output_right = (float*) malloc(buffer_size * sizeof(float)); int seed; fake_init(); LADSPA_Handle limiter = foo_limiterDescriptor->instantiate( foo_limiterDescriptor, 44100); connectPortFoo_limiter(limiter, FOO_LIMITER_INPUT_GAIN_DB, &input_gain); connectPortFoo_limiter(limiter, FOO_LIMITER_MAX_PEAK_DB, &max_peak); connectPortFoo_limiter(limiter, FOO_LIMITER_RELEASE_TIME, &release_time); connectPortFoo_limiter(limiter, FOO_LIMITER_ATTENUATION, &attenuation); connectPortFoo_limiter(limiter, FOO_LIMITER_LATENCY, &latency); connectPortFoo_limiter(limiter, FOO_LIMITER_RELEASE_SCALE, &release_scale); connectPortFoo_limiter(limiter, FOO_LIMITER_INPUT_LEFT, input_left); connectPortFoo_limiter(limiter, FOO_LIMITER_INPUT_RIGHT, input_right); connectPortFoo_limiter(limiter, FOO_LIMITER_OUTPUT_LEFT, output_left); connectPortFoo_limiter(limiter, FOO_LIMITER_OUTPUT_RIGHT, output_right); memset(input_left, 0, buffer_size * sizeof(float)); memset(input_right, 0, buffer_size * sizeof(float)); seed = time(NULL); printf("using seed %d\n",seed); srand(seed); //create_random(input_left, buffer_size, 1.05f, 0.0f); create_ABCD(input_left, buffer_size); runFoo_limiter(limiter, buffer_size); printf("output[2216] = %f\n", output_left[2216]); write_file_constant("plot/max_peak.txt", max_peak, buffer_size); write_file("plot/input.txt", input_left, buffer_size); write_file("plot/output.txt", output_left, buffer_size); write_file("plot/envelope.txt", output_right, buffer_size); fake_fini(); return 0; } #endif void load_file(float *buffer, char *file, int samples) { int fd = open(file, O_RDONLY); read(fd, buffer, samples * sizeof(float)); close(fd); } #ifdef TEST_TRANSIENT_ARCHITECT int test_architect(int argc, char **argv) { int i; int buffer_size = 18238; float *input_left = (float*) malloc(buffer_size * sizeof(float)); float *input_right = (float*) malloc(buffer_size * sizeof(float)); float *output_left = (float*) malloc(buffer_size * sizeof(float)); float *output_right = (float*) malloc(buffer_size * sizeof(float)); float latency; float atten_attack; float atten_release; float attack_gain_db = 9.897f; float release_gain_db = 0.0f; float average_difference = 0.078f; int seed; seed = time(NULL); printf("using seed %d\n",seed); srand(seed); fake_init(); LADSPA_Handle transients = foo_transientsDescriptor->instantiate( foo_transientsDescriptor, 44100); connectPortFoo_transients(transients, FOO_TRANSIENTS_LATENCY, &latency); connectPortFoo_transients(transients, FOO_TRANSIENTS_ACTUAL_ATTACK_GAIN, &atten_attack); connectPortFoo_transients(transients, FOO_TRANSIENTS_ACTUAL_RELEASE_GAIN, &atten_release); connectPortFoo_transients(transients, FOO_TRANSIENTS_ATTACK_GAIN_DB, &attack_gain_db); connectPortFoo_transients(transients, FOO_TRANSIENTS_RELEASE_GAIN_DB, &release_gain_db); connectPortFoo_transients(transients, FOO_TRANSIENTS_AVERAGE_DIFFERENCE, &average_difference); connectPortFoo_transients(transients, FOO_TRANSIENTS_INPUT_LEFT, input_left); connectPortFoo_transients(transients, FOO_TRANSIENTS_INPUT_RIGHT, input_right); connectPortFoo_transients(transients, FOO_TRANSIENTS_OUTPUT_LEFT, output_left); connectPortFoo_transients(transients, FOO_TRANSIENTS_OUTPUT_RIGHT, output_right); //create_random(input_left, buffer_size, 0.8f, -0.4f); load_file(input_left, "snare.raw", buffer_size); memset(input_left, 0, sizeof(float) * 2048); // 2048 samples of zero at the start memset(input_right, 0, sizeof(float) * buffer_size); printf("input_left[%d] = %f\n", 2047, input_left[2047]); printf("input_left[%d] = %f\n", 2048, input_left[2048]); runFoo_transients(transients, buffer_size); write_file("plot/architect_input.txt", input_left, buffer_size); write_file("plot/architect_fast_avg.txt", output_left, buffer_size); write_file("plot/architect_slow_avg.txt", output_right, buffer_size); for (i = 0; i < buffer_size; i++) { output_left[i] = fabsf(output_left[i] - output_right[i]); } write_file("plot/architect_complete_env.txt", output_left, buffer_size); fake_fini(); return 0; } #endif int main(int argc, char **argv) { #ifdef TEST_LIMITER return test_limiter(argc, argv); #endif #ifdef TEST_TRANSIENT_ARCHITECT return test_architect(argc, argv); #endif } foo-plugins-1.0/foo_driver.xml0000644000175000017500000000566610552473725014163 0ustar v2v2 Foo Driver latency) = 0.0f; ]]> latency) = 0.0f; for (i = 0; i < sample_count; i++) { wet = tanh(input[i] * input_gain_coef * drive + offset) - tanh(offset); buffer_write(output[i], wet * (1.0f - balance) + input[i] * input_gain_coef * balance); } ]]> Input gain (dB)

Input gain before drive circuit

Drive

Controls the drive of the plugin

Drive offset

Controls the symmetry of the distortion

Web/dry balance

Controls the balance of wet vs dry signal

latency Input Output
foo-plugins-1.0/foo_transients.xml0000644000175000017500000001207510552473725015052 0ustar v2v2 Foo Transient Architect fast_rms); rms_free (plugin_data->slow_rms); ]]> fabsf(input_right[i])) tmp = input_left[i]; else tmp = input_right[i]; slow = rms_run(slow_rms, tmp); fast = rms_run(fast_rms, tmp); if (fast > slow) { // Attack tmp = (fast - slow) * attack_gain_db * FOO_ARCHITECT_GAIN_SCALE; if ( ( attack_gain_db < 0.0f && tmp < relevant_attack_gain) || ( attack_gain_db > 0.0f && tmp > relevant_attack_gain) ) relevant_attack_gain = tmp; } else { // Release tmp = (slow - fast) * release_gain_db * FOO_ARCHITECT_GAIN_SCALE; if ( ( release_gain_db < 0.0f && tmp < relevant_release_gain) || ( release_gain_db > 0.0f && tmp > relevant_release_gain) ) relevant_release_gain = tmp; //printf("Release gain: %f, envelope difference = %f\n", tmp, slow - fast); } buffer_write(output_left[i], input_left[i] * DB_CO(tmp)); buffer_write(output_right[i], input_right[i] * DB_CO(tmp)); #ifdef FOO_TESTER //buffer_write(output_right[i], tmp); //buffer_write(output_right[i], DB_CO(tmp) - 1.0f); // Default tester operations, suitable for architect_graph.sh buffer_write(output_left[i], fast); buffer_write(output_right[i], slow); #endif } *(plugin_data->actual_attack_gain) = relevant_attack_gain; *(plugin_data->actual_release_gain) = relevant_release_gain; ]]> Averaging difference (s)

Controls the averaging time difference between the controlling envelopes

Attack gain (dB)

Attack gain range control

Release gain (dB)

Release gain range control

Current attack gain (dB)

The amount of gain applied at the moment

Current release gain (dB)

The amount of gain applied at the moment

latency Input L Input R Output L Output R
foo-plugins-1.0/README0000644000175000017500000000374210552473725012154 0ustar v2v2foo-plugins ^^^^^^^^^^^ This is a small set of LADSPA plugins. Currently it consists of two plugins: Foo Lookahead Limiter (stereo) A lookahead peak limiter with an attack / release envelope. Parameters: - Input gain (dB) - Maximum peak level (dB) - Release time (seconds) Foo Transient Architect (stereo and mono version) Transient sound design. This is a dynamics control independent of the volume level. It gives separate control for transient attack and release gain. The plugin works by using two RMS envelopes. The first envelope reacts fast to changes in the signal and the other one more slowly. Attack and release is defined by the difference between the envelopes. Parameters: - Averaging time difference (seconds) This parameter controls how far apart are the envelope averaging times. The smaller the value, the closer together the envelopes are. With larger values the envelopes drift apart further and produce a less smooth sound. - Attack gain (dB) - Release gain (dB) Note that the gain values are not guarantees. The parametrized gain is scaled according to the envelope difference. Because of this the effectual gain would be a lot less than the user wants. To make the control more meaningful, the plugin scales the gain up. This might and will cause the plugin to sometimes "overshot" the gain. Note that these plugins are not finished products yet and the effect of the parameters might change with new versions. This is especially true for the transient designer as it hasn't been tuned yet. Thanks to Steve Harris for providing the tools to generate LADSPA plugins out of XML definitions and the RMS envelope code. ----------------------------------------------------------------------------- foo-plugins ladspa identifier range: 3181-3220 3181: Foo Lookahead Limiter 3182: Foo Transient Architect 3183: Foo Transient Architect (mono) 3184: Foo Driver foo-plugins-1.0/foo_limiter.xml0000644000175000017500000002633210552473725014326 0ustar v2v2 #include #include #define FOO_LIMITER_RAMP_UP_MILLISECONDS 2.5f #define FOO_LIMITER_MAX_LOGSCALE 10.0f typedef struct _Envelope { int ramp_samples; //int sustain_samples; int release_samples; int length_samples; // ramp_samples + sustain_samples + release_samples float start_gain; float limit_gain; // ramp_delta = (env->limit_gain - env->start_gain)/(float)env->ramp_samples float ramp_delta; // release_delta = (1.0f - env->limit_gain)/(float)env->release_samples float release_delta; int at_sample; // Logarithmic release envelope float logscale; } Envelope; // logscale parameter is given in 0.0f .. 1.0f, NOT in real scale values, this function sets the right scale void inline FooLimiter_triggerEnvelope(Envelope *env, int ramp_samples, int release_samples, float current_gain, float new_limit_gain, float logscale) { float new_ramp_delta = (new_limit_gain - current_gain)/(float)ramp_samples; // New envelopes are of suspect if previous envelope is still ramping up if (env->at_sample < env->ramp_samples) { // the new ramp delta is not as steep as the old one if (new_ramp_delta > env->ramp_delta) { // instead of creating a new envelope, we extend the current one env->at_sample = 0; env->start_gain = current_gain; env->limit_gain = current_gain + env->ramp_delta * (float)env->ramp_samples; env->release_delta = (1.0f - env->limit_gain)/(float)env->release_samples; // Logscale parameter will not be changed during ramp-up as it could // cause peaks to escape return; } } env->ramp_samples = ramp_samples; env->release_samples = release_samples; env->length_samples = env->ramp_samples + env->release_samples; env->start_gain = current_gain; env->limit_gain = new_limit_gain; env->ramp_delta = (env->limit_gain - env->start_gain)/(float)env->ramp_samples; env->release_delta = (1.0f - env->limit_gain)/(float)env->release_samples; env->logscale = 1 / expf(1.0f) + logscale * (FOO_LIMITER_MAX_LOGSCALE - 1/expf(1.0f)); #ifdef FOO_TESTER printf("envelope logscale = %f (parameter %f)\n",env->logscale, logscale); #endif env->at_sample = 0; } #define LOGSCALE(position, scale) ( logf( (position) * exp(scale) + 1.0f - (position)) / (scale)) float FooLimiter_calculateEnvelope(Envelope *env, int offset) { int at = env->at_sample + offset; if (at >= env->length_samples) return 1.0f; if (at < 0) return env->start_gain; // RAMP if (at < env->ramp_samples) { return env->start_gain + (float)at * env->ramp_delta; } // RELEASE return env->limit_gain + ( (1.0f - env->limit_gain) * LOGSCALE( ((float) (at - env->ramp_samples))/(float)(env->release_samples), env->logscale)); //return env->limit_gain + (float)(at - env->ramp_samples) * env->release_delta; } ]]> Foo Lookahead Limiter workbuffer_left); free(plugin_data->workbuffer_right); ]]> 0) { n = sample_count; // Make sure we process in slices where "lookahead + slice" fit in the work buffer if (n > workbuffer_size - ramp_up_time_samples) n = workbuffer_size - ramp_up_time_samples; // The start of the workbuffer contains the "latent" samples from the previous run memcpy(workbuffer_left + ramp_up_time_samples, input_left + buffer_offset, sizeof(float) * n); memcpy(workbuffer_right + ramp_up_time_samples, input_right + buffer_offset, sizeof(float) * n); lookahead = ramp_up_time_samples; for (i = 0; i < n; i++, lookahead++) { workbuffer_left [lookahead] *= input_gain; workbuffer_right[lookahead] *= input_gain; current_gain = FooLimiter_calculateEnvelope(&envelope, 0); // Peak detection peak_left = fabsf(workbuffer_left [lookahead]); peak_right = fabsf(workbuffer_right[lookahead]); tmp = fmaxf(peak_left, peak_right) * FooLimiter_calculateEnvelope(&envelope, ramp_up_time_samples); if (tmp > max_peak) { // calculate needed_limit_gain float needed_limit_gain = max_peak / fmaxf(peak_left, peak_right); int release_samples = (int)floor( release_time * (float)samplerate); #ifdef FOO_TESTER printf("new envelope! release samples = %d, max_peak = %f, current_gain = %f, peak = %f, limit_gain = %f\n", release_samples, max_peak, current_gain, tmp, needed_limit_gain); #endif FooLimiter_triggerEnvelope(&envelope, ramp_up_time_samples, release_samples, current_gain, needed_limit_gain, release_scale); } if (current_gain < min_gain) min_gain = current_gain; if (envelope.at_sample <= envelope.length_samples) envelope.at_sample++; buffer_write(output_left [i+buffer_offset], workbuffer_left [i] * current_gain); #ifndef FOO_TESTER buffer_write(output_right[i+buffer_offset], workbuffer_right[i] * current_gain); #else buffer_write(output_right[i+buffer_offset], current_gain); if (fabsf(output_left[i+buffer_offset]) > max_peak) { printf("######### Limiter failed at %ld, max_peak = %f and peaked at %f\n", i+buffer_offset, max_peak, output_left[i+buffer_offset]); printf("## Envelope: @%d, ramp_delta = %f, release_delta = %f, ramp_samples = %d, release_samples = %d, start_gain = %f, limit_gain = %f\n", envelope.at_sample, envelope.ramp_delta, envelope.release_delta, envelope.ramp_samples, envelope.release_samples, envelope.start_gain, envelope.limit_gain); } #endif } // copy the "end" of input data to the lookahead buffer // copy input[ (n-ramp_up_time_samples] .. n ] => lookahead if (n < ramp_up_time_samples) { memmove(workbuffer_left, workbuffer_left + n , sizeof(float) * ramp_up_time_samples); memmove(workbuffer_right, workbuffer_right + n , sizeof(float) * ramp_up_time_samples); } else { memcpy (workbuffer_left, workbuffer_left + n , sizeof(float) * ramp_up_time_samples); memcpy (workbuffer_right, workbuffer_right + n , sizeof(float) * ramp_up_time_samples); } sample_count -= n; buffer_offset += n; } *(plugin_data->attenuation) = -CO_DB(min_gain); *(plugin_data->latency) = ramp_up_time_samples; plugin_data->current_gain = current_gain; plugin_data->envelope = envelope; ]]> Input gain (dB)

Maximum peak level to limit

Max level (dB)

Maximum peak level to limit

Release time (s)

Limiter release time in milliseconds

Attenuation (dB)

The amount of attenuation at the moment

Input L Input R Output L Output R latency Linear/log release

Limiter release time in milliseconds

foo-plugins-1.0/ladspa-swh.dtd0000644000175000017500000000171410552473725014031 0ustar v2v2 foo-plugins-1.0/Makefile0000644000175000017500000000143510552473725012731 0ustar v2v2CC=gcc CFLAGS=-O3 -Wall -fomit-frame-pointer -fstrength-reduce -funroll-loops -ffast-math -fPIC -DPIC -g -msse -mfpmath=sse LIBFLAGS=-nostartfiles -shared -Wl,-Bsymbolic PLUGIN_LIBS=foo_limiter.so foo_transients.so foo_transients_mono.so foo_driver.so PLUGIN_SOURCES=foo_limiter.c foo_transients.c foo_transients_mono.c foo_driver.so all: plugins tester %.so : %.o rms.o $(CC) $(LIBFLAGS) rms.o $< -o $@ %.c : %.xml makestub.pl ./makestub.pl $< > $@ plugins: $(PLUGIN_LIBS) tester.o: foo_limiter.xml foo_transients.xml tester: tester.o rms.o $(PLUGIN_SOURCES) gcc tester.o rms.o -o tester -lm tester.o: $(PLUGIN_SOURCES) $(PLUGIN_SOURCES): utils.h rms.h rms.o: rms.h install: plugins cp $(PLUGIN_LIBS) /usr/lib/ladspa/ clean: rm -f *.o *.so $(PLUGIN_SOURCES) tester plot/* #