pax_global_header00006660000000000000000000000064141672034610014516gustar00rootroot0000000000000052 comment=ebb7e80233f076ca703a939f0e5a04e9cb16b818 ocaml-ladspa-0.2.2/000077500000000000000000000000001416720346100140545ustar00rootroot00000000000000ocaml-ladspa-0.2.2/.github/000077500000000000000000000000001416720346100154145ustar00rootroot00000000000000ocaml-ladspa-0.2.2/.github/workflows/000077500000000000000000000000001416720346100174515ustar00rootroot00000000000000ocaml-ladspa-0.2.2/.github/workflows/main.yml000066400000000000000000000011631416720346100211210ustar00rootroot00000000000000name: CI on: [push] jobs: cancel_previous_run: runs-on: ubuntu-latest steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.4.0 with: access_token: ${{ github.token }} build: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] steps: - name: Install some plugins if: ${{ matrix.os == 'ubuntu-latest' }} run: | sudo apt-get update sudo apt-get -y install amb-plugins - name: Build and test module uses: savonet/build-and-test-ocaml-module@main ocaml-ladspa-0.2.2/.gitignore000066400000000000000000000000631416720346100160430ustar00rootroot00000000000000*~ _build *.byte *.native _tests .merlin *.install ocaml-ladspa-0.2.2/.merlin000066400000000000000000000000221416720346100153350ustar00rootroot00000000000000S src/** B src/** ocaml-ladspa-0.2.2/.ocamlformat000066400000000000000000000003201416720346100163540ustar00rootroot00000000000000profile = conventional break-separators = after space-around-lists = false doc-comments = before match-indent = 2 match-indent-nested = always parens-ite exp-grouping = preserve module-item-spacing = compact ocaml-ladspa-0.2.2/CHANGES000066400000000000000000000016101416720346100150450ustar00rootroot000000000000000.2.2 (10-01-2022) ===== * Fix GC issues introduced in previous release. 0.2.1 (07-01-2022) ====== * Get rid of naked pointers. 0.2.0 (03-12-2020) ===== * Use bigarrays for audio buffers. * Use generational global roots for global OCaml values in C. * Switch to dune 0.1.5 (03-08-2015) ===== * Dummy github release. 0.1.4 (04-10-2011) ===== * Updated autoconf. * Distribute examples. 0.1.3 (04-07-2011) ===== * Export definitions shared with ocaml-dssi in ocaml_ladspa.h. 0.1.2 (12-10-2009) ===== * Added support for --enable-debugging configure option * Added NO_CUSTOM to build in standard mode. * Added prefix to main compilation variables if passed to configure. * Makefile now honnors LIBDIRS variable for linking against libraries located in other places than then standard ones. 0.1.1 (16-04-2008) ===== * Install .cmx file with others 0.1.0 (14-11-2007) ===== * Initial release ocaml-ladspa-0.2.2/COPYING000066400000000000000000000655731416720346100151270ustar00rootroot00000000000000The software distributed in this tarball is licenced under the GNU Lesser General Public License, with a special exception: As a special exception to the GNU Library General Public License, you may link, statically or dynamically, a "work that uses the Library" with a publicly distributed version of the Library to produce an executable file containing portions of the Library, and distribute that executable file under terms of your choice, without any of the additional requirements listed in clause 6 of the GNU Library General Public License. By "a publicly distributed version of the Library", we mean either the unmodified Library as distributed by The Savonet Team, or a modified version of the Library that is distributed under the conditions defined in clause 3 of the GNU Library General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Library General Public License. The GNU Lesser General Public Licence text is: <---------------------------------------------------------------------- GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, 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 and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, 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 library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete 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 distribute a copy of this License along with the Library. 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 Library or any portion of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, 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 Library, 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 Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you 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. If distribution of 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 satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be 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. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library 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. 9. 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 Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library 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 with this License. 11. 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 Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library 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 Library. 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. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library 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. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library 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 Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, 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 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. 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 LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ocaml-ladspa-0.2.2/README.md000066400000000000000000000013501416720346100153320ustar00rootroot00000000000000ocaml-ladspa ============ This package contains an OCaml interface for LADSPA audio plugins library. Please read the COPYING file before using this software. Prerequisites ------------- - ocaml >= 3.0.6 - LADSPA sdk >= 1.1 - findlib >= 0.8.1 - dune >= 2.0 Compilation ----------- ```sh dune build ``` This should build both the native and the byte-code version of the extension library. Installation ------------ Via `opam`: ```sh opam install ladspa ``` Via `dune` (for developers): ```sh dune install ``` This should install the library file (using ocamlfind) in the appropriate place. Author ------ This author of this software may be contacted by electronic mail at the following address: savonet-users@lists.sourceforge.net. ocaml-ladspa-0.2.2/dune-project000066400000000000000000000007351416720346100164030ustar00rootroot00000000000000(lang dune 2.8) (version 0.2.2) (name ladspa) (source (github savonet/ocaml-ladspa)) (license LGPL-2.1) (authors "The Savonet Team ") (maintainers "The Savonet Team ") (generate_opam_files true) (use_standard_c_and_cxx_flags false) (package (name ladspa) (synopsis "Bindings for the LADSPA API which provides audio effects") (depends dune dune-configurator (ocaml (>= 4.08)) conf-ladspa) ) ocaml-ladspa-0.2.2/examples/000077500000000000000000000000001416720346100156725ustar00rootroot00000000000000ocaml-ladspa-0.2.2/examples/amp.ml000066400000000000000000000023241416720346100170020ustar00rootroot00000000000000open Ladspa let p = Plugin.load "/usr/lib/ladspa/amp.so" let d = Descriptor.descriptor p 0 let print_port n = Printf.printf " * %s: %s %s\n%!" (Descriptor.port_name d n) (if Descriptor.port_is_input d n then "input" else "output") (if Descriptor.port_is_control d n then "control" else "audio") let () = Printf.printf "LADSPA %s\n\n%!" (Ladspa.version ()); Printf.printf "Using plugin %s (%s) by %s, %s.\n\n%!" (Descriptor.label d) (Descriptor.name d) (Descriptor.maker d) (match Descriptor.copyright d with Some c -> c | None -> ""); Printf.printf "Found %d descriptors.\n%!" (Array.length (Descriptor.descriptors p)); Printf.printf "Found %d ports:\n%!" (Descriptor.port_count d); for i = 0 to Descriptor.port_count d - 1 do print_port i done let samples_len = 1024 let samples = Bigarray.Array1.create Bigarray.float32 Bigarray.c_layout samples_len let inst = Descriptor.instantiate d 44100 let () = Descriptor.set_control_port inst 0 0.5; Descriptor.connect_port inst 1 samples; Descriptor.connect_port inst 2 samples; Descriptor.activate inst; Descriptor.run inst samples_len; Descriptor.deactivate inst let () = Gc.full_major (); Plugin.unload p; Gc.full_major () ocaml-ladspa-0.2.2/examples/dune000066400000000000000000000003721416720346100165520ustar00rootroot00000000000000(executable (name amp) (modules amp) (libraries ladspa)) (executable (name inspect) (modules inspect) (libraries unix ladspa)) (executable (name sc4) (modules sc4) (libraries ladspa)) (rule (alias runtest) (action (run ./inspect.exe))) ocaml-ladspa-0.2.2/examples/inspect.ml000066400000000000000000000031711416720346100176730ustar00rootroot00000000000000open Ladspa let plugins_dir = "/usr/lib/ladspa" let plugins = if Array.length Sys.argv > 1 then [Sys.argv.(1)] else ( if Sys.file_exists plugins_dir && Sys.is_directory plugins_dir then ( let dir = Unix.opendir plugins_dir in let ans = ref [] in (try while true do let f = Unix.readdir dir in if f <> "." && f <> ".." then ans := (plugins_dir ^ "/" ^ f) :: !ans done with End_of_file -> ()); Unix.closedir dir; List.rev !ans) else []) let () = Printf.printf "LADSPA %s\n\n%!" (Ladspa.version ()) let print_port d n = Printf.printf ". %s: %s %s\n%!" (Descriptor.port_name d n) (if Descriptor.port_is_input d n then "input" else "output") (if Descriptor.port_is_control d n then "control" else "audio") let print_descr d = for i = 0 to Descriptor.port_count d - 1 do print_port d i done; Printf.printf "\n%!" let print_plugin pname = Printf.printf "* Loading plugin %s... %!" pname; try let p = Plugin.load pname in Printf.printf "done.\n\n%!"; let descr = Descriptor.descriptors p in Printf.printf "- Found %d descriptors.\n%!" (Array.length descr); Array.iteri (fun i d -> Printf.printf "- Descriptor %d (%d ports): %s (%s) by %s, %s.\n%!" i (Descriptor.port_count d) (Descriptor.label d) (Descriptor.name d) (Descriptor.maker d) (match Descriptor.copyright d with Some c -> c | None -> ""); print_descr d) descr; Printf.printf "\n%!"; Plugin.unload p with Plugin.Not_a_plugin -> Printf.printf "failed.\n\n%!" let () = List.iter print_plugin plugins; Gc.full_major () ocaml-ladspa-0.2.2/examples/sc4.ml000066400000000000000000000034421416720346100167200ustar00rootroot00000000000000open Ladspa let p = try Plugin.load "/usr/lib/ladspa/sc4_1882x.so" with Plugin.Not_a_plugin -> print_endline "Could not load plugin, exiting."; exit 0 let d = Descriptor.descriptor p 0 let print_port n = Printf.printf " %02d. %s: %s %s\n%!" n (Descriptor.port_name d n) (if Descriptor.port_is_input d n then "input" else "output") (if Descriptor.port_is_control d n then "control" else "audio") let () = Printf.printf "LADSPA %s\n\n%!" (Ladspa.version ()); Printf.printf "Using plugin %s (%s) by %s, %s.\n\n%!" (Descriptor.label d) (Descriptor.name d) (Descriptor.maker d) (match Descriptor.copyright d with Some c -> c | None -> ""); Printf.printf "Found %d descriptors.\n%!" (Array.length (Descriptor.descriptors p)); Printf.printf "Found %d ports:\n%!" (Descriptor.port_count d); for i = 0 to Descriptor.port_count d - 1 do print_port i done let samples_len = 1024 let samples = Bigarray.Array1.create Bigarray.float32 Bigarray.c_layout samples_len let inst = Descriptor.instantiate d 44100 let () = let c = Bigarray.Array1.create Bigarray.float32 Bigarray.c_layout 1 in Descriptor.set_control_port inst 0 0.; Descriptor.set_control_port inst 1 0.; Descriptor.set_control_port inst 2 0.; Descriptor.set_control_port inst 3 0.; Descriptor.set_control_port inst 4 0.; Descriptor.set_control_port inst 5 0.; Descriptor.set_control_port inst 6 0.; Descriptor.connect_port inst 7 c; Descriptor.connect_port inst 8 c; Descriptor.connect_port inst 9 samples; Descriptor.connect_port inst 10 samples; Descriptor.connect_port inst 11 samples; Descriptor.connect_port inst 12 samples; Descriptor.activate inst; Descriptor.run inst samples_len; Descriptor.deactivate inst let () = Gc.full_major (); Plugin.unload p; Gc.full_major () ocaml-ladspa-0.2.2/ladspa.opam000066400000000000000000000014131416720346100161750ustar00rootroot00000000000000# This file is generated by dune, edit dune-project instead opam-version: "2.0" version: "0.2.2" synopsis: "Bindings for the LADSPA API which provides audio effects" maintainer: ["The Savonet Team "] authors: ["The Savonet Team "] license: "LGPL-2.1" homepage: "https://github.com/savonet/ocaml-ladspa" bug-reports: "https://github.com/savonet/ocaml-ladspa/issues" depends: [ "dune" {>= "2.8"} "dune-configurator" "ocaml" {>= "4.08"} "conf-ladspa" "odoc" {with-doc} ] build: [ ["dune" "subst"] {dev} [ "dune" "build" "-p" name "-j" jobs "@install" "@runtest" {with-test} "@doc" {with-doc} ] ] dev-repo: "git+https://github.com/savonet/ocaml-ladspa.git" ocaml-ladspa-0.2.2/src/000077500000000000000000000000001416720346100146435ustar00rootroot00000000000000ocaml-ladspa-0.2.2/src/config/000077500000000000000000000000001416720346100161105ustar00rootroot00000000000000ocaml-ladspa-0.2.2/src/config/discover.ml000066400000000000000000000010451416720346100202600ustar00rootroot00000000000000module C = Configurator.V1 let () = C.main ~name:"ladspa-header" (fun c -> let has_ladspa = try let defined = C.C_define.import c ~includes:["ladspa.h"] [("LADSPA_VERSION", C.C_define.Type.String)] in match defined with | [("LADSPA_VERSION", C.C_define.Value.String _)] -> true | _ -> false with _ -> false in C.C_define.gen_header_file c ~fname:"ocaml_ladspa_config.h" [("HAS_LADSPA", C.C_define.Value.Switch has_ladspa)]) ocaml-ladspa-0.2.2/src/config/dune000066400000000000000000000000751416720346100167700ustar00rootroot00000000000000(executable (name discover) (libraries dune.configurator)) ocaml-ladspa-0.2.2/src/dune000066400000000000000000000005011416720346100155150ustar00rootroot00000000000000(library (name ladspa) (public_name ladspa) (synopsis "OCaml bindings for ladspa") (install_c_headers ladspa ocaml_ladspa_config ocaml_ladspa) (foreign_stubs (language c) (names ladspa_stubs) (extra_deps ocaml_ladspa_config.h))) (rule (targets ocaml_ladspa_config.h) (action (run ./config/discover.exe))) ocaml-ladspa-0.2.2/src/ladspa.h000066400000000000000000000651141416720346100162670ustar00rootroot00000000000000/* ladspa.h Linux Audio Developer's Simple Plugin API Version 1.1[LGPL]. Copyright (C) 2000-2002 Richard W.E. Furse, Paul Barton-Davis, Stefan Westerfeld. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef LADSPA_INCLUDED #define LADSPA_INCLUDED #define LADSPA_VERSION "1.1" #define LADSPA_VERSION_MAJOR 1 #define LADSPA_VERSION_MINOR 1 #ifdef __cplusplus extern "C" { #endif /*****************************************************************************/ /* Overview: There is a large number of synthesis packages in use or development on the Linux platform at this time. This API (`The Linux Audio Developer's Simple Plugin API') attempts to give programmers the ability to write simple `plugin' audio processors in C/C++ and link them dynamically (`plug') into a range of these packages (`hosts'). It should be possible for any host and any plugin to communicate completely through this interface. This API is deliberately short and simple. To achieve compatibility with a range of promising Linux sound synthesis packages it attempts to find the `greatest common divisor' in their logical behaviour. Having said this, certain limiting decisions are implicit, notably the use of a fixed type (LADSPA_Data) for all data transfer and absence of a parameterised `initialisation' phase. See below for the LADSPA_Data typedef. Plugins are expected to distinguish between control and audio data. Plugins have `ports' that are inputs or outputs for audio or control data and each plugin is `run' for a `block' corresponding to a short time interval measured in samples. Audio data is communicated using arrays of LADSPA_Data, allowing a block of audio to be processed by the plugin in a single pass. Control data is communicated using single LADSPA_Data values. Control data has a single value at the start of a call to the `run()' or `run_adding()' function, and may be considered to remain this value for its duration. The plugin may assume that all its input and output ports have been connected to the relevant data location (see the `connect_port()' function below) before it is asked to run. Plugins will reside in shared object files suitable for dynamic linking by dlopen() and family. The file will provide a number of `plugin types' that can be used to instantiate actual plugins (sometimes known as `plugin instances') that can be connected together to perform tasks. This API contains very limited error-handling. */ /*****************************************************************************/ /* Fundamental data type passed in and out of plugin. This data type is used to communicate audio samples and control values. It is assumed that the plugin will work sensibly given any numeric input value although it may have a preferred range (see hints below). For audio it is generally assumed that 1.0f is the `0dB' reference amplitude and is a `normal' signal level. */ typedef float LADSPA_Data; /*****************************************************************************/ /* Special Plugin Properties: Optional features of the plugin type are encapsulated in the LADSPA_Properties type. This is assembled by ORing individual properties together. */ typedef int LADSPA_Properties; /* Property LADSPA_PROPERTY_REALTIME indicates that the plugin has a real-time dependency (e.g. listens to a MIDI device) and so its output must not be cached or subject to significant latency. */ #define LADSPA_PROPERTY_REALTIME 0x1 /* Property LADSPA_PROPERTY_INPLACE_BROKEN indicates that the plugin may cease to work correctly if the host elects to use the same data location for both input and output (see connect_port()). This should be avoided as enabling this flag makes it impossible for hosts to use the plugin to process audio `in-place.' */ #define LADSPA_PROPERTY_INPLACE_BROKEN 0x2 /* Property LADSPA_PROPERTY_HARD_RT_CAPABLE indicates that the plugin is capable of running not only in a conventional host but also in a `hard real-time' environment. To qualify for this the plugin must satisfy all of the following: (1) The plugin must not use malloc(), free() or other heap memory management within its run() or run_adding() functions. All new memory used in run() must be managed via the stack. These restrictions only apply to the run() function. (2) The plugin will not attempt to make use of any library functions with the exceptions of functions in the ANSI standard C and C maths libraries, which the host is expected to provide. (3) The plugin will not access files, devices, pipes, sockets, IPC or any other mechanism that might result in process or thread blocking. (4) The plugin will take an amount of time to execute a run() or run_adding() call approximately of form (A+B*SampleCount) where A and B depend on the machine and host in use. This amount of time may not depend on input signals or plugin state. The host is left the responsibility to perform timings to estimate upper bounds for A and B. */ #define LADSPA_PROPERTY_HARD_RT_CAPABLE 0x4 #define LADSPA_IS_REALTIME(x) ((x)&LADSPA_PROPERTY_REALTIME) #define LADSPA_IS_INPLACE_BROKEN(x) ((x)&LADSPA_PROPERTY_INPLACE_BROKEN) #define LADSPA_IS_HARD_RT_CAPABLE(x) ((x)&LADSPA_PROPERTY_HARD_RT_CAPABLE) /*****************************************************************************/ /* Plugin Ports: Plugins have `ports' that are inputs or outputs for audio or data. Ports can communicate arrays of LADSPA_Data (for audio inputs/outputs) or single LADSPA_Data values (for control input/outputs). This information is encapsulated in the LADSPA_PortDescriptor type which is assembled by ORing individual properties together. Note that a port must be an input or an output port but not both and that a port must be a control or audio port but not both. */ typedef int LADSPA_PortDescriptor; /* Property LADSPA_PORT_INPUT indicates that the port is an input. */ #define LADSPA_PORT_INPUT 0x1 /* Property LADSPA_PORT_OUTPUT indicates that the port is an output. */ #define LADSPA_PORT_OUTPUT 0x2 /* Property LADSPA_PORT_CONTROL indicates that the port is a control port. */ #define LADSPA_PORT_CONTROL 0x4 /* Property LADSPA_PORT_AUDIO indicates that the port is a audio port. */ #define LADSPA_PORT_AUDIO 0x8 #define LADSPA_IS_PORT_INPUT(x) ((x)&LADSPA_PORT_INPUT) #define LADSPA_IS_PORT_OUTPUT(x) ((x)&LADSPA_PORT_OUTPUT) #define LADSPA_IS_PORT_CONTROL(x) ((x)&LADSPA_PORT_CONTROL) #define LADSPA_IS_PORT_AUDIO(x) ((x)&LADSPA_PORT_AUDIO) /*****************************************************************************/ /* Plugin Port Range Hints: The host may wish to provide a representation of data entering or leaving a plugin (e.g. to generate a GUI automatically). To make this more meaningful, the plugin should provide `hints' to the host describing the usual values taken by the data. Note that these are only hints. The host may ignore them and the plugin must not assume that data supplied to it is meaningful. If the plugin receives invalid input data it is expected to continue to run without failure and, where possible, produce a sensible output (e.g. a high-pass filter given a negative cutoff frequency might switch to an all-pass mode). Hints are meaningful for all input and output ports but hints for input control ports are expected to be particularly useful. More hint information is encapsulated in the LADSPA_PortRangeHintDescriptor type which is assembled by ORing individual hint types together. Hints may require further LowerBound and UpperBound information. All the hint information for a particular port is aggregated in the LADSPA_PortRangeHint structure. */ typedef int LADSPA_PortRangeHintDescriptor; /* Hint LADSPA_HINT_BOUNDED_BELOW indicates that the LowerBound field of the LADSPA_PortRangeHint should be considered meaningful. The value in this field should be considered the (inclusive) lower bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also specified then the value of LowerBound should be multiplied by the sample rate. */ #define LADSPA_HINT_BOUNDED_BELOW 0x1 /* Hint LADSPA_HINT_BOUNDED_ABOVE indicates that the UpperBound field of the LADSPA_PortRangeHint should be considered meaningful. The value in this field should be considered the (inclusive) upper bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also specified then the value of UpperBound should be multiplied by the sample rate. */ #define LADSPA_HINT_BOUNDED_ABOVE 0x2 /* Hint LADSPA_HINT_TOGGLED indicates that the data item should be considered a Boolean toggle. Data less than or equal to zero should be considered `off' or `false,' and data above zero should be considered `on' or `true.' LADSPA_HINT_TOGGLED may not be used in conjunction with any other hint except LADSPA_HINT_DEFAULT_0 or LADSPA_HINT_DEFAULT_1. */ #define LADSPA_HINT_TOGGLED 0x4 /* Hint LADSPA_HINT_SAMPLE_RATE indicates that any bounds specified should be interpreted as multiples of the sample rate. For instance, a frequency range from 0Hz to the Nyquist frequency (half the sample rate) could be requested by this hint in conjunction with LowerBound = 0 and UpperBound = 0.5. Hosts that support bounds at all must support this hint to retain meaning. */ #define LADSPA_HINT_SAMPLE_RATE 0x8 /* Hint LADSPA_HINT_LOGARITHMIC indicates that it is likely that the user will find it more intuitive to view values using a logarithmic scale. This is particularly useful for frequencies and gains. */ #define LADSPA_HINT_LOGARITHMIC 0x10 /* Hint LADSPA_HINT_INTEGER indicates that a user interface would probably wish to provide a stepped control taking only integer values. Any bounds set should be slightly wider than the actual integer range required to avoid floating point rounding errors. For instance, the integer set {0,1,2,3} might be described as [-0.1, 3.1]. */ #define LADSPA_HINT_INTEGER 0x20 /* The various LADSPA_HINT_HAS_DEFAULT_* hints indicate a `normal' value for the port that is sensible as a default. For instance, this value is suitable for use as an initial value in a user interface or as a value the host might assign to a control port when the user has not provided one. Defaults are encoded using a mask so only one default may be specified for a port. Some of the hints make use of lower and upper bounds, in which case the relevant bound or bounds must be available and LADSPA_HINT_SAMPLE_RATE must be applied as usual. The resulting default must be rounded if LADSPA_HINT_INTEGER is present. Default values were introduced in LADSPA v1.1. */ #define LADSPA_HINT_DEFAULT_MASK 0x3C0 /* This default values indicates that no default is provided. */ #define LADSPA_HINT_DEFAULT_NONE 0x0 /* This default hint indicates that the suggested lower bound for the port should be used. */ #define LADSPA_HINT_DEFAULT_MINIMUM 0x40 /* This default hint indicates that a low value between the suggested lower and upper bounds should be chosen. For ports with LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.75 + log(upper) * 0.25). Otherwise, this should be (lower * 0.75 + upper * 0.25). */ #define LADSPA_HINT_DEFAULT_LOW 0x80 /* This default hint indicates that a middle value between the suggested lower and upper bounds should be chosen. For ports with LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.5 + log(upper) * 0.5). Otherwise, this should be (lower * 0.5 + upper * 0.5). */ #define LADSPA_HINT_DEFAULT_MIDDLE 0xC0 /* This default hint indicates that a high value between the suggested lower and upper bounds should be chosen. For ports with LADSPA_HINT_LOGARITHMIC, this should be exp(log(lower) * 0.25 + log(upper) * 0.75). Otherwise, this should be (lower * 0.25 + upper * 0.75). */ #define LADSPA_HINT_DEFAULT_HIGH 0x100 /* This default hint indicates that the suggested upper bound for the port should be used. */ #define LADSPA_HINT_DEFAULT_MAXIMUM 0x140 /* This default hint indicates that the number 0 should be used. Note that this default may be used in conjunction with LADSPA_HINT_TOGGLED. */ #define LADSPA_HINT_DEFAULT_0 0x200 /* This default hint indicates that the number 1 should be used. Note that this default may be used in conjunction with LADSPA_HINT_TOGGLED. */ #define LADSPA_HINT_DEFAULT_1 0x240 /* This default hint indicates that the number 100 should be used. */ #define LADSPA_HINT_DEFAULT_100 0x280 /* This default hint indicates that the Hz frequency of `concert A' should be used. This will be 440 unless the host uses an unusual tuning convention, in which case it may be within a few Hz. */ #define LADSPA_HINT_DEFAULT_440 0x2C0 #define LADSPA_IS_HINT_BOUNDED_BELOW(x) ((x)&LADSPA_HINT_BOUNDED_BELOW) #define LADSPA_IS_HINT_BOUNDED_ABOVE(x) ((x)&LADSPA_HINT_BOUNDED_ABOVE) #define LADSPA_IS_HINT_TOGGLED(x) ((x)&LADSPA_HINT_TOGGLED) #define LADSPA_IS_HINT_SAMPLE_RATE(x) ((x)&LADSPA_HINT_SAMPLE_RATE) #define LADSPA_IS_HINT_LOGARITHMIC(x) ((x)&LADSPA_HINT_LOGARITHMIC) #define LADSPA_IS_HINT_INTEGER(x) ((x)&LADSPA_HINT_INTEGER) #define LADSPA_IS_HINT_HAS_DEFAULT(x) ((x)&LADSPA_HINT_DEFAULT_MASK) #define LADSPA_IS_HINT_DEFAULT_MINIMUM(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_MINIMUM) #define LADSPA_IS_HINT_DEFAULT_LOW(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_LOW) #define LADSPA_IS_HINT_DEFAULT_MIDDLE(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_MIDDLE) #define LADSPA_IS_HINT_DEFAULT_HIGH(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_HIGH) #define LADSPA_IS_HINT_DEFAULT_MAXIMUM(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_MAXIMUM) #define LADSPA_IS_HINT_DEFAULT_0(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_0) #define LADSPA_IS_HINT_DEFAULT_1(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_1) #define LADSPA_IS_HINT_DEFAULT_100(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_100) #define LADSPA_IS_HINT_DEFAULT_440(x) \ (((x)&LADSPA_HINT_DEFAULT_MASK) == LADSPA_HINT_DEFAULT_440) typedef struct _LADSPA_PortRangeHint { /* Hints about the port. */ LADSPA_PortRangeHintDescriptor HintDescriptor; /* Meaningful when hint LADSPA_HINT_BOUNDED_BELOW is active. When LADSPA_HINT_SAMPLE_RATE is also active then this value should be multiplied by the relevant sample rate. */ LADSPA_Data LowerBound; /* Meaningful when hint LADSPA_HINT_BOUNDED_ABOVE is active. When LADSPA_HINT_SAMPLE_RATE is also active then this value should be multiplied by the relevant sample rate. */ LADSPA_Data UpperBound; } LADSPA_PortRangeHint; /*****************************************************************************/ /* Plugin Handles: This plugin handle indicates a particular instance of the plugin concerned. It is valid to compare this to NULL (0 for C++) but otherwise the host should not attempt to interpret it. The plugin may use it to reference internal instance data. */ typedef void *LADSPA_Handle; /*****************************************************************************/ /* Descriptor for a Type of Plugin: This structure is used to describe a plugin type. It provides a number of functions to examine the type, instantiate it, link it to buffers and workspaces and to run it. */ typedef struct _LADSPA_Descriptor { /* This numeric identifier indicates the plugin type uniquely. Plugin programmers may reserve ranges of IDs from a central body to avoid clashes. Hosts may assume that IDs are below 0x1000000. */ unsigned long UniqueID; /* This identifier can be used as a unique, case-sensitive identifier for the plugin type within the plugin file. Plugin types should be identified by file and label rather than by index or plugin name, which may be changed in new plugin versions. Labels must not contain white-space characters. */ const char *Label; /* This indicates a number of properties of the plugin. */ LADSPA_Properties Properties; /* This member points to the null-terminated name of the plugin (e.g. "Sine Oscillator"). */ const char *Name; /* This member points to the null-terminated string indicating the maker of the plugin. This can be an empty string but not NULL. */ const char *Maker; /* This member points to the null-terminated string indicating any copyright applying to the plugin. If no Copyright applies the string "None" should be used. */ const char *Copyright; /* This indicates the number of ports (input AND output) present on the plugin. */ unsigned long PortCount; /* This member indicates an array of port descriptors. Valid indices vary from 0 to PortCount-1. */ const LADSPA_PortDescriptor *PortDescriptors; /* This member indicates an array of null-terminated strings describing ports (e.g. "Frequency (Hz)"). Valid indices vary from 0 to PortCount-1. */ const char *const *PortNames; /* This member indicates an array of range hints for each port (see above). Valid indices vary from 0 to PortCount-1. */ const LADSPA_PortRangeHint *PortRangeHints; /* This may be used by the plugin developer to pass any custom implementation data into an instantiate call. It must not be used or interpreted by the host. It is expected that most plugin writers will not use this facility as LADSPA_Handle should be used to hold instance data. */ void *ImplementationData; /* This member is a function pointer that instantiates a plugin. A handle is returned indicating the new plugin instance. The instantiation function accepts a sample rate as a parameter. The plugin descriptor from which this instantiate function was found must also be passed. This function must return NULL if instantiation fails. Note that instance initialisation should generally occur in activate() rather than here. */ LADSPA_Handle (*instantiate)(const struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); /* This member is a function pointer that connects a port on an instantiated plugin to a memory location at which a block of data for the port will be read/written. The data location is expected to be an array of LADSPA_Data for audio ports or a single LADSPA_Data value for control ports. Memory issues will be managed by the host. The plugin must read/write the data at these locations every time run() or run_adding() is called and the data present at the time of this connection call should not be considered meaningful. connect_port() may be called more than once for a plugin instance to allow the host to change the buffers that the plugin is reading or writing. These calls may be made before or after activate() or deactivate() calls. connect_port() must be called at least once for each port before run() or run_adding() is called. When working with blocks of LADSPA_Data the plugin should pay careful attention to the block size passed to the run function as the block allocated may only just be large enough to contain the block of samples. Plugin writers should be aware that the host may elect to use the same buffer for more than one port and even use the same buffer for both input and output (see LADSPA_PROPERTY_INPLACE_BROKEN). However, overlapped buffers or use of a single buffer for both audio and control data may result in unexpected behaviour. */ void (*connect_port)(LADSPA_Handle Instance, unsigned long Port, LADSPA_Data *DataLocation); /* This member is a function pointer that initialises a plugin instance and activates it for use. This is separated from instantiate() to aid real-time support and so that hosts can reinitialise a plugin instance by calling deactivate() and then activate(). In this case the plugin instance must reset all state information dependent on the history of the plugin instance except for any data locations provided by connect_port() and any gain set by set_run_adding_gain(). If there is nothing for activate() to do then the plugin writer may provide a NULL rather than an empty function. When present, hosts must call this function once before run() (or run_adding()) is called for the first time. This call should be made as close to the run() call as possible and indicates to real-time plugins that they are now live. Plugins should not rely on a prompt call to run() after activate(). activate() may not be called again unless deactivate() is called first. Note that connect_port() may be called before or after a call to activate(). */ void (*activate)(LADSPA_Handle Instance); /* This method is a function pointer that runs an instance of a plugin for a block. Two parameters are required: the first is a handle to the particular instance to be run and the second indicates the block size (in samples) for which the plugin instance may run. Note that if an activate() function exists then it must be called before run() or run_adding(). If deactivate() is called for a plugin instance then the plugin instance may not be reused until activate() has been called again. If the plugin has the property LADSPA_PROPERTY_HARD_RT_CAPABLE then there are various things that the plugin should not do within the run() or run_adding() functions (see above). */ void (*run)(LADSPA_Handle Instance, unsigned long SampleCount); /* This method is a function pointer that runs an instance of a plugin for a block. This has identical behaviour to run() except in the way data is output from the plugin. When run() is used, values are written directly to the memory areas associated with the output ports. However when run_adding() is called, values must be added to the values already present in the memory areas. Furthermore, output values written must be scaled by the current gain set by set_run_adding_gain() (see below) before addition. run_adding() is optional. When it is not provided by a plugin, this function pointer must be set to NULL. When it is provided, the function set_run_adding_gain() must be provided also. */ void (*run_adding)(LADSPA_Handle Instance, unsigned long SampleCount); /* This method is a function pointer that sets the output gain for use when run_adding() is called (see above). If this function is never called the gain is assumed to default to 1. Gain information should be retained when activate() or deactivate() are called. This function should be provided by the plugin if and only if the run_adding() function is provided. When it is absent this function pointer must be set to NULL. */ void (*set_run_adding_gain)(LADSPA_Handle Instance, LADSPA_Data Gain); /* This is the counterpart to activate() (see above). If there is nothing for deactivate() to do then the plugin writer may provide a NULL rather than an empty function. Hosts must deactivate all activated units after they have been run() (or run_adding()) for the last time. This call should be made as close to the last run() call as possible and indicates to real-time plugins that they are no longer live. Plugins should not rely on prompt deactivation. Note that connect_port() may be called before or after a call to deactivate(). Deactivation is not similar to pausing as the plugin instance will be reinitialised when activate() is called to reuse it. */ void (*deactivate)(LADSPA_Handle Instance); /* Once an instance of a plugin has been finished with it can be deleted using the following function. The instance handle passed ceases to be valid after this call. If activate() was called for a plugin instance then a corresponding call to deactivate() must be made before cleanup() is called. */ void (*cleanup)(LADSPA_Handle Instance); } LADSPA_Descriptor; /**********************************************************************/ /* Accessing a Plugin: */ /* The exact mechanism by which plugins are loaded is host-dependent, however all most hosts will need to know is the name of shared object file containing the plugin types. To allow multiple hosts to share plugin types, hosts may wish to check for environment variable LADSPA_PATH. If present, this should contain a colon-separated path indicating directories that should be searched (in order) when loading plugin types. A plugin programmer must include a function called "ladspa_descriptor" with the following function prototype within the shared object file. This function will have C-style linkage (if you are using C++ this is taken care of by the `extern "C"' clause at the top of the file). A host will find the plugin shared object file by one means or another, find the ladspa_descriptor() function, call it, and proceed from there. Plugin types are accessed by index (not ID) using values from 0 upwards. Out of range indexes must result in this function returning NULL, so the plugin count can be determined by checking for the least index that results in NULL being returned. */ const LADSPA_Descriptor *ladspa_descriptor(unsigned long Index); /* Datatype corresponding to the ladspa_descriptor() function. */ typedef const LADSPA_Descriptor *(*LADSPA_Descriptor_Function)( unsigned long Index); /**********************************************************************/ #ifdef __cplusplus } #endif #endif /* LADSPA_INCLUDED */ /* EOF */ ocaml-ladspa-0.2.2/src/ladspa.ml000066400000000000000000000115601416720346100164440ustar00rootroot00000000000000(* * Copyright 2007-2010 Samuel Mimram * * This file is part of ocaml-ladspa. * * ocaml-ladspa is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-ladspa 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 Lesser General Public License * along with ocaml-ladspa; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a publicly * distributed version of the Library to produce an executable file containing * portions of the Library, and distribute that executable file under terms of * your choice, without any of the additional requirements listed in clause 6 * of the GNU Library General Public License. * By "a publicly distributed version of the Library", we mean either the unmodified * Library as distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library General * Public License. This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU Library General Public License. * *) let () = Callback.register_exception "ocaml_ladspa_exn_not_found" Not_found external version : unit -> string = "ocaml_ladspa_version" external version_major : unit -> int = "ocaml_ladspa_version_major" external version_minor : unit -> int = "ocaml_ladspa_version_minor" module Plugin = struct type t exception Not_a_plugin external load : string -> t = "ocaml_ladspa_open" external unload : t -> unit = "ocaml_ladspa_close" end let () = Callback.register_exception "ocaml_ladspa_exn_not_a_plugin" Plugin.Not_a_plugin module Descriptor = struct type t external descriptor : Plugin.t -> int -> t = "ocaml_ladspa_descriptor" let rec descriptors p n = try let d = descriptor p n in let dd = descriptors p (n + 1) in d :: dd with Not_found -> [] let descriptors p = Array.of_list (descriptors p 0) external unique_id : t -> int = "ocaml_ladspa_unique_id" external label : t -> string = "ocaml_ladspa_label" external name : t -> string = "ocaml_ladspa_name" external maker : t -> string = "ocaml_ladspa_maker" external copyright : t -> string = "ocaml_ladspa_copyright" let copyright d = let c = copyright d in (* "None" is the standard answer when there is no copyright. *) if c = "None" then None else Some c external port_count : t -> int = "ocaml_ladspa_port_count" external port_names : t -> string array = "ocaml_ladspa_port_names" let port_name d n = (port_names d).(n) external port_is_input : t -> int -> bool = "ocaml_ladspa_port_is_input" external port_is_output : t -> int -> bool = "ocaml_ladspa_port_is_output" external port_is_control : t -> int -> bool = "ocaml_ladspa_port_is_control" external port_is_audio : t -> int -> bool = "ocaml_ladspa_port_is_audio" external port_is_integer : t -> int -> bool = "ocaml_ladspa_port_is_integer" external port_is_boolean : t -> int -> bool = "ocaml_ladspa_port_is_boolean" external port_is_logarithmic : t -> int -> bool = "ocaml_ladspa_port_is_logarithmic" external port_get_default : t -> int -> int -> float option = "ocaml_ladspa_port_get_default" let port_get_default d ?(samplerate = 44100) p = port_get_default d samplerate p external port_get_min : t -> int -> int -> float option = "ocaml_ladspa_port_get_min" let port_get_min d ?(samplerate = 44100) p = port_get_min d samplerate p external port_get_max : t -> int -> int -> float option = "ocaml_ladspa_port_get_max" let port_get_max d ?(samplerate = 44100) p = port_get_max d samplerate p type instance external get_descriptor : instance -> t = "ocaml_ladspa_get_descriptor" external instantiate : t -> int -> instance = "ocaml_ladspa_instantiate" external connect_port : instance -> int -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> unit = "ocaml_ladspa_connect_port" let set_control_port i n v = assert (port_is_control (get_descriptor i) n); let buf = Bigarray.Array1.create Bigarray.float32 Bigarray.c_layout 1 in buf.{0} <- v; connect_port i n buf external activate : instance -> unit = "ocaml_ladspa_activate" external deactivate : instance -> unit = "ocaml_ladspa_deactivate" external run : instance -> int -> unit = "ocaml_ladspa_run" end ocaml-ladspa-0.2.2/src/ladspa.mli000066400000000000000000000120561416720346100166160ustar00rootroot00000000000000(* * Copyright 2007-2010 Savonet team * * This file is part of ocaml-ladspa. * * ocaml-ladspa is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-ladspa 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 Lesser General Public License * along with ocaml-ladspa; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a publicly * distributed version of the Library to produce an executable file containing * portions of the Library, and distribute that executable file under terms of * your choice, without any of the additional requirements listed in clause 6 * of the GNU Library General Public License. * By "a publicly distributed version of the Library", we mean either the unmodified * Library as distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library General * Public License. This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU Library General Public License. * *) (** * Functions for using LADSPA plugins. * * @author Samuel Mimram *) (** Version number. *) val version : unit -> string (** Major version. *) val version_major : unit -> int (** Minor version. *) val version_minor : unit -> int (** Plugins. *) module Plugin : sig (** A plugin. *) type t (** The file being loaded is not a LADSPA plugin. *) exception Not_a_plugin (** Load a LADSPA plugin. The argument is the path of a .so file. *) val load : string -> t (** Unload a LADSPA plugin. *) val unload : t -> unit end (** Descriptors. *) module Descriptor : sig (** A descriptor. *) type t (** Retrieve the [n]-th descriptor of a plugin. *) val descriptor : Plugin.t -> int -> t (** Retrieve all the descriptors of a plugin. *) val descriptors : Plugin.t -> t array (** This numeric identifier indicates the plugin type uniquely. Plugin * programmers may reserve ranges of IDs from a central body to avoid * clashes. Hosts may assume that IDs are below 0x1000000. *) val unique_id : t -> int (** This identifier can be used as a unique, case-sensitive identifier for the * plugin type within the plugin file. Plugin types should be identified by * file and label rather than by index or plugin name, which may be changed * in new plugin versions. Labels must not contain white-space characters. *) val label : t -> string (** Name of the plugin (e.g. "Sine Oscillator"). *) val name : t -> string (** String indicating the maker of the plugin. *) val maker : t -> string (** String indicating any copyright applying to the plugin. *) val copyright : t -> string option (** This indicates the number of ports (input AND output) present on the plugin. *) val port_count : t -> int (** Name of the [n]-th port. *) val port_name : t -> int -> string (** Is the [n]-th port an input? *) val port_is_input : t -> int -> bool (** Is the [n]-th port an output? *) val port_is_output : t -> int -> bool (** Is the [n]-th port an audio port? *) val port_is_audio : t -> int -> bool (** Is the [n]-th port a control port? *) val port_is_control : t -> int -> bool val port_is_integer : t -> int -> bool val port_is_boolean : t -> int -> bool val port_is_logarithmic : t -> int -> bool (** Get a sensible default value for a control port. *) val port_get_default : t -> ?samplerate:int -> int -> float option val port_get_min : t -> ?samplerate:int -> int -> float option val port_get_max : t -> ?samplerate:int -> int -> float option (** Instance of a descriptor. *) type instance (** [instantiate descr freq] instantiates the descriptor [descr] with a sampling frequency [freq]. *) val instantiate : t -> int -> instance (** [connect_audio_port inst p buf] connects the port [p] of instance [inst] to the buffer [buf]. For control ports only the first value is relevant (the bigarray can be of length 1). *) val connect_port : instance -> int -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> unit val set_control_port : instance -> int -> float -> unit (** Activate (i.e. initialize) a plugin. *) val activate : instance -> unit (** Deactivate a plugin. *) val deactivate : instance -> unit (** Process a given number of samples (which should be smaller than all the buffers given through [connect_port]. *) val run : instance -> int -> unit end ocaml-ladspa-0.2.2/src/ladspa_stubs.c000066400000000000000000000267161416720346100175070ustar00rootroot00000000000000/* * Copyright 2007-2010 Savonet team * * This file is part of ocaml-ladspa. * * ocaml-ladspa is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-ladspa 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 Lesser General Public License * along with ocaml-ladspa; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a * publicly distributed version of the Library to produce an executable file * containing portions of the Library, and distribute that executable file under * terms of your choice, without any of the additional requirements listed in * clause 6 of the GNU Library General Public License. By "a publicly * distributed version of the Library", we mean either the unmodified Library as * distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library * General Public License. This exception does not however invalidate any other * reasons why the executable file might be covered by the GNU Library General * Public License. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include "ocaml_ladspa.h" #include "ocaml_ladspa_config.h" #ifdef HAS_LADSPA #include #else #include "ladspa.h" #endif #define Descr_val(v) (*(void **)Data_abstract_val(v)) static inline value value_of_descr(value ret, void *d) { ret = caml_alloc(1, Abstract_tag); Descr_val(ret) = d; return ret; } CAMLprim value ocaml_ladspa_version(value unit) { return caml_copy_string(LADSPA_VERSION); } CAMLprim value ocaml_ladspa_version_major(value unit) { return Val_int(LADSPA_VERSION_MAJOR); } CAMLprim value ocaml_ladspa_version_minor(value unit) { return Val_int(LADSPA_VERSION_MINOR); } CAMLprim value ocaml_ladspa_open(value fname) { CAMLparam0(); CAMLlocal1(tmp); void *handle = dlopen(String_val(fname), RTLD_LAZY); LADSPA_Descriptor_Function ladspa_descriptor; if (!handle) caml_raise_constant(*caml_named_value("ocaml_ladspa_exn_not_a_plugin")); ladspa_descriptor = (LADSPA_Descriptor_Function)dlsym((void *)handle, "ladspa_descriptor"); if (dlerror() != NULL || !ladspa_descriptor) { dlclose(handle); caml_raise_constant(*caml_named_value("ocaml_ladspa_exn_not_a_plugin")); } CAMLreturn(value_of_descr(tmp, handle)); } CAMLprim value ocaml_ladspa_close(value handle) { CAMLparam1(handle); dlclose(Descr_val(handle)); CAMLreturn(Val_unit); } CAMLprim value ocaml_ladspa_descriptor(value handle, value n) { CAMLparam1(handle); CAMLlocal1(ret); LADSPA_Descriptor_Function ladspa_descriptor = (LADSPA_Descriptor_Function)dlsym(Descr_val(handle), "ladspa_descriptor"); const LADSPA_Descriptor *d = ladspa_descriptor(Int_val(n)); if (!d) caml_raise_constant(*caml_named_value("ocaml_ladspa_exn_not_found")); CAMLreturn(value_of_ladspa_descr(ret, d)); } CAMLprim value ocaml_ladspa_unique_id(value d) { CAMLparam1(d); CAMLreturn(Val_int(LADSPA_descr_val(d)->UniqueID)); } CAMLprim value ocaml_ladspa_label(value d) { CAMLparam1(d); CAMLreturn(caml_copy_string(LADSPA_descr_val(d)->Label)); } CAMLprim value ocaml_ladspa_name(value d) { CAMLparam1(d); CAMLreturn(caml_copy_string(LADSPA_descr_val(d)->Name)); } CAMLprim value ocaml_ladspa_maker(value d) { CAMLparam1(d); CAMLreturn(caml_copy_string(LADSPA_descr_val(d)->Maker)); } CAMLprim value ocaml_ladspa_copyright(value d) { CAMLparam1(d); CAMLreturn(caml_copy_string(LADSPA_descr_val(d)->Copyright)); } CAMLprim value ocaml_ladspa_port_count(value d) { CAMLparam1(d); CAMLreturn(Val_int(LADSPA_descr_val(d)->PortCount)); } CAMLprim value ocaml_ladspa_port_names(value d) { CAMLparam1(d); CAMLlocal1(ans); const char *const *pn = LADSPA_descr_val(d)->PortNames; int i; int n = LADSPA_descr_val(d)->PortCount; ans = caml_alloc_tuple(n); for (i = 0; i < n; i++) Store_field(ans, i, caml_copy_string(pn[i])); CAMLreturn(ans); } CAMLprim value ocaml_ladspa_port_is_input(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool( LADSPA_IS_PORT_INPUT(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)]))); } CAMLprim value ocaml_ladspa_port_is_output(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool( LADSPA_IS_PORT_OUTPUT(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)]))); } CAMLprim value ocaml_ladspa_port_is_control(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool(LADSPA_IS_PORT_CONTROL( LADSPA_descr_val(d)->PortDescriptors[Int_val(n)]))); } CAMLprim value ocaml_ladspa_port_is_audio(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool( LADSPA_IS_PORT_AUDIO(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)]))); } CAMLprim value ocaml_ladspa_port_is_integer(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool(LADSPA_IS_HINT_INTEGER( LADSPA_descr_val(d)->PortRangeHints[Int_val(n)].HintDescriptor))); } CAMLprim value ocaml_ladspa_port_is_boolean(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool(LADSPA_IS_HINT_TOGGLED( LADSPA_descr_val(d)->PortRangeHints[Int_val(n)].HintDescriptor))); } CAMLprim value ocaml_ladspa_port_is_logarithmic(value d, value n) { CAMLparam1(d); CAMLreturn(Val_bool(LADSPA_IS_HINT_LOGARITHMIC( LADSPA_descr_val(d)->PortRangeHints[Int_val(n)].HintDescriptor))); } CAMLprim value ocaml_ladspa_port_get_default(value d, value samplerate, value n) { CAMLparam1(d); CAMLlocal1(ans); assert( LADSPA_IS_PORT_CONTROL(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)])); const LADSPA_PortRangeHint ri = LADSPA_descr_val(d)->PortRangeHints[Int_val(n)]; LADSPA_PortRangeHintDescriptor h = ri.HintDescriptor; float lower = ri.LowerBound; float upper = ri.UpperBound; float def = 0.; if (LADSPA_IS_HINT_SAMPLE_RATE(h)) { lower *= Int_val(samplerate); upper *= Int_val(samplerate); } if LADSPA_IS_HINT_HAS_DEFAULT (h) { if LADSPA_IS_HINT_DEFAULT_MINIMUM (h) def = lower; else if LADSPA_IS_HINT_DEFAULT_LOW (h) if LADSPA_IS_HINT_LOGARITHMIC (h) def = exp(log(lower) * 0.75 + log(upper) * 0.25); else def = lower * 0.75 + upper * 0.25; else if LADSPA_IS_HINT_DEFAULT_MIDDLE (h) if LADSPA_IS_HINT_LOGARITHMIC (h) def = exp(log(lower) * 0.5 + log(upper) * 0.5); else def = lower * 0.5 + upper * 0.5; else if LADSPA_IS_HINT_DEFAULT_HIGH (h) if LADSPA_IS_HINT_LOGARITHMIC (h) def = exp(log(lower) * 0.25 + log(upper) * 0.75); else def = lower * 0.25 + upper * 0.75; else if LADSPA_IS_HINT_DEFAULT_MAXIMUM (h) def = upper; else if LADSPA_IS_HINT_DEFAULT_0 (h) def = 0; else if LADSPA_IS_HINT_DEFAULT_1 (h) def = 1; else if LADSPA_IS_HINT_DEFAULT_100 (h) def = 100; else if LADSPA_IS_HINT_DEFAULT_440 (h) def = 440; ans = caml_alloc(1, 0); Store_field(ans, 0, caml_copy_double(def)); CAMLreturn(ans); } else CAMLreturn(Val_int(0)); } CAMLprim value ocaml_ladspa_port_get_min(value d, value samplerate, value n) { CAMLparam1(d); CAMLlocal1(ans); const LADSPA_PortRangeHint ri = LADSPA_descr_val(d)->PortRangeHints[Int_val(n)]; LADSPA_Data bound; assert( LADSPA_IS_PORT_CONTROL(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)])); if (!LADSPA_IS_HINT_BOUNDED_BELOW(ri.HintDescriptor)) CAMLreturn(Val_int(0)); bound = ri.LowerBound; if (LADSPA_IS_HINT_SAMPLE_RATE(ri.HintDescriptor)) bound *= Int_val(samplerate); ans = caml_alloc(1, 0); Store_field(ans, 0, caml_copy_double(bound)); CAMLreturn(ans); } CAMLprim value ocaml_ladspa_port_get_max(value d, value samplerate, value n) { CAMLparam1(d); CAMLlocal1(ans); const LADSPA_PortRangeHint ri = LADSPA_descr_val(d)->PortRangeHints[Int_val(n)]; LADSPA_Data bound; assert( LADSPA_IS_PORT_CONTROL(LADSPA_descr_val(d)->PortDescriptors[Int_val(n)])); if (!LADSPA_IS_HINT_BOUNDED_ABOVE(ri.HintDescriptor)) CAMLreturn(Val_int(0)); bound = ri.UpperBound; if (LADSPA_IS_HINT_SAMPLE_RATE(ri.HintDescriptor)) bound *= Int_val(samplerate); ans = caml_alloc(1, 0); Store_field(ans, 0, caml_copy_double(bound)); CAMLreturn(ans); } /***** Instances ****/ static void finalize_instance(value inst) { ladspa_instance *instance = Instance_val(inst); int i; instance->descr->cleanup(instance->handle); for (i = 0; i < instance->descr->PortCount; i++) { if (instance->vbuf[i]) caml_remove_generational_global_root(&instance->vbuf[i]); } free(instance->vbuf); free(instance); } static struct custom_operations instance_ops = { "ocaml_ladspa_instance", finalize_instance, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default}; CAMLprim value ocaml_ladspa_instantiate(value d, value rate) { CAMLparam2(d, rate); CAMLlocal1(ans); ladspa_instance *instance = malloc(sizeof(ladspa_instance)); int ports; int i; instance->descr = LADSPA_descr_val(d); ports = instance->descr->PortCount; instance->handle = instance->descr->instantiate(instance->descr, Int_val(rate)); instance->vbuf = malloc(ports * sizeof(value)); for (i = 0; i < ports; i++) instance->vbuf[i] = 0; ans = caml_alloc_custom(&instance_ops, sizeof(ladspa_instance *), 1, 0); Instance_val(ans) = instance; CAMLreturn(ans); } CAMLprim value ocaml_ladspa_get_descriptor(value i) { CAMLparam1(i); CAMLlocal1(ret); ladspa_instance *instance = Instance_val(i); CAMLreturn(value_of_ladspa_descr(ret, instance->descr)); } CAMLprim value ocaml_ladspa_connect_port(value i, value _n, value buf) { CAMLparam3(i, _n, buf); ladspa_instance *instance = Instance_val(i); int n = Int_val(_n); if (!instance->vbuf[n]) { instance->vbuf[n] = buf; caml_register_generational_global_root(&instance->vbuf[n]); } else caml_modify_generational_global_root(&instance->vbuf[n], buf); instance->descr->connect_port(instance->handle, n, Caml_ba_data_val(buf)); CAMLreturn(Val_unit); } CAMLprim value ocaml_ladspa_activate(value i) { CAMLparam1(i); ladspa_instance *instance = Instance_val(i); if (instance->descr->activate) instance->descr->activate(instance->handle); CAMLreturn(Val_unit); } CAMLprim value ocaml_ladspa_deactivate(value i) { CAMLparam1(i); ladspa_instance *instance = Instance_val(i); if (instance->descr->deactivate) instance->descr->deactivate(instance->handle); CAMLreturn(Val_unit); } CAMLprim value ocaml_ladspa_run(value inst, value _samples) { CAMLparam2(inst, _samples); ladspa_instance *instance = Instance_val(inst); int samples = Int_val(_samples); caml_release_runtime_system(); instance->descr->run(instance->handle, samples); caml_acquire_runtime_system(); CAMLreturn(Val_unit); } ocaml-ladspa-0.2.2/src/ocaml_ladspa.h000066400000000000000000000045431416720346100174410ustar00rootroot00000000000000/* * Copyright 2007-2010 Savonet team * * This file is part of ocaml-ladspa. * * ocaml-ladspa is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-ladspa 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 Lesser General Public License * along with ocaml-ladspa; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a * publicly distributed version of the Library to produce an executable file * containing portions of the Library, and distribute that executable file under * terms of your choice, without any of the additional requirements listed in * clause 6 of the GNU Library General Public License. By "a publicly * distributed version of the Library", we mean either the unmodified Library as * distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library * General Public License. This exception does not however invalidate any other * reasons why the executable file might be covered by the GNU Library General * Public License. * */ #include #include #include "ocaml_ladspa_config.h" #ifdef HAS_LADSPA #include #else #include "ladspa.h" #endif typedef struct { const LADSPA_Descriptor *descr; LADSPA_Handle handle; LADSPA_Data *control_data; value *vbuf; } ladspa_instance; #define Instance_val(v) (*((ladspa_instance **)Data_custom_val(v))) #define LADSPA_descr_val(v) \ (*((const LADSPA_Descriptor **)Data_abstract_val(v))) static inline value value_of_ladspa_descr(value ret, const LADSPA_Descriptor *d) { ret = caml_alloc(1, Abstract_tag); LADSPA_descr_val(ret) = d; return ret; }