pax_global_header00006660000000000000000000000064143121176310014511gustar00rootroot0000000000000052 comment=b3822116187cac75f848c8fc6605a217ef89c6f9 ocaml-fdkaac-0.3.3~gitd3393eb/000077500000000000000000000000001431211763100157155ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/.github/000077500000000000000000000000001431211763100172555ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/.github/workflows/000077500000000000000000000000001431211763100213125ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/.github/workflows/ci.yml000066400000000000000000000005351431211763100224330ustar00rootroot00000000000000name: CI on: [push] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macos-latest, ubuntu-latest] steps: - name: Build and test module uses: savonet/build-and-test-ocaml-module@main ocaml-fdkaac-0.3.3~gitd3393eb/.gitignore000066400000000000000000000000721431211763100177040ustar00rootroot00000000000000*~ _build *.byte *.native _tests .merlin *.install .*.sw* ocaml-fdkaac-0.3.3~gitd3393eb/.ocamlformat000066400000000000000000000003201431211763100202150ustar00rootroot00000000000000profile = 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-fdkaac-0.3.3~gitd3393eb/CHANGES000066400000000000000000000006511431211763100167120ustar00rootroot000000000000000.3.3 (unreleased) ===== * Bring back dynamic loader (#5) 0.3.2 (27-03-2020) ===== * Compatibility with version 2.0.0. * Switch to dune for building. 0.3.1 (22-09-2019) ===== * Check for fdk-aac version <= 0.1.6 0.3.0 (02-08-2019) ===== * Fixed type for `Bandwidth param. 0.2.1 (03-08-2015) ===== * Added variable bitrate mode. 0.2.0 (18-05-2013) ===== * Added dynamic loader 0.1.0 (08-05-2013) ===== * Initial release ocaml-fdkaac-0.3.3~gitd3393eb/COPYING000066400000000000000000000431311431211763100167520ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 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. 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 Library 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 How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ocaml-fdkaac-0.3.3~gitd3393eb/README.md000066400000000000000000000013161431211763100171750ustar00rootroot00000000000000ocaml-fdkaac This package contains an OCaml interface for the fdk-aac library. Please read the COPYING file before using this software. Prerequisites: ============== - ocaml >= 4.00.1 (haven't tried earlier versions) - fdk-aac >= 0.1.1 - findlib >= 0.8.1 (haven't tried earlier versions) - dune >= 2.0 Compilation: ============ ``` $ dune build ``` This should build both the native and the byte-code version of the extension library. Installation: ============= Via `opam`: ``` $ opam install fdkaac ``` Via `dune` (for developers): ``` $ dune install ``` Author: ======= This author of this software may be contacted by electronic mail at the following address: savonet-users@lists.sourceforge.net. ocaml-fdkaac-0.3.3~gitd3393eb/dune-project000066400000000000000000000010541431211763100202370ustar00rootroot00000000000000(lang dune 2.9) (version 0.3.2) (name fdkaac) (source (github savonet/ocaml-fdkaac)) (license GPL-2.0) (authors "The Savonet Team ") (maintainers "The Savonet Team ") (generate_opam_files true) (use_standard_c_and_cxx_flags false) (package (name fdkaac) (synopsis "Fraunhofer FDK AAC Codec Library") (description "The FDK AAC Codec Library For Android contains an encoder implementation of the Advanced Audio Coding (AAC) audio codec.") (depends dune dune-configurator) ) ocaml-fdkaac-0.3.3~gitd3393eb/examples/000077500000000000000000000000001431211763100175335ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/examples/dune000066400000000000000000000000661431211763100204130ustar00rootroot00000000000000(executable (name wav2aac) (libraries unix fdkaac)) ocaml-fdkaac-0.3.3~gitd3393eb/examples/wav2aac.ml000066400000000000000000000134571431211763100214230ustar00rootroot00000000000000(* * Copyright 2013 Savonet team * * This file is part of OCaml-Vorbis. * * OCaml-Vorbis 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. * * OCaml-Vorbis 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 OCaml-Vorbis; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) let src = ref "" let dst = ref "" let input_string chan len = let ans = Bytes.create len in (* TODO: check length *) ignore (input chan ans 0 len); Bytes.to_string ans let input_int chan = let buf = input_string chan 4 in int_of_char buf.[0] + (int_of_char buf.[1] lsl 8) + (int_of_char buf.[2] lsl 16) + (int_of_char buf.[3] lsl 24) let input_short chan = let buf = input_string chan 2 in int_of_char buf.[0] + (int_of_char buf.[1] lsl 8) let vbr = ref 0 let bitrate = ref 64000 let aot_of_string = function | "MPEG4 AAC-LC" -> `Mpeg_4 `AAC_LC | "MPEG4 HE-AAC" -> `Mpeg_4 `HE_AAC | "MPEG4 HE-AAC v2" -> `Mpeg_4 `HE_AAC_v2 | "MPEG4 AAC-LD" -> `Mpeg_4 `AAC_LD | "MPEG4 AAC-ELD" -> `Mpeg_4 `AAC_ELD | "MPEG2 AAC-LC" -> `Mpeg_2 `AAC_LC | "MPEG2 HE-AAC" -> `Mpeg_2 `HE_AAC | "MPEG2 HE-AAC v2" -> `Mpeg_2 `HE_AAC_v2 | _ -> raise Fdkaac.Encoder.Unsupported_parameter let string_of_aot = function | `Mpeg_4 `AAC_LC -> "MPEG4 AAC-LC" | `Mpeg_4 `HE_AAC -> "MPEG4 HE-AAC" | `Mpeg_4 `HE_AAC_v2 -> "MPEG4 HE-AAC v2" | `Mpeg_4 `AAC_LD -> "MPEG4 AAC-LD" | `Mpeg_4 `AAC_ELD -> "MPEG4 AAC-ELD" | `Mpeg_2 `AAC_LC -> "MPEG2 AAC-LC" | `Mpeg_2 `HE_AAC -> "MPEG2 HE-AAC" | `Mpeg_2 `HE_AAC_v2 -> "MPEG2 HE-AAC v2" let aots = [ "MPEG4 AAC-LC"; "MPEG4 HE-AAC"; "MPEG4 HE-AAC v2"; "MPEG4 AAC-LD"; "MPEG4 AAC-ELD"; "MPEG2 AAC-LC"; "MPEG2 HE-AAC"; "MPEG42 HE-AAC v2"; ] let aot = ref (`Mpeg_4 `HE_AAC_v2) let afterburner = ref true let sbr = ref true let usage = "usage: wav2aac [options] source destination" let _ = let aots = List.map (Printf.sprintf "%S") aots in Arg.parse [ ("--vbr", Arg.Int (fun i -> vbr := i), "Encode in variable bitrate."); ( "--bitrate", Arg.Int (fun b -> bitrate := b * 1000), "Bitrate, in kilobits per second, defaults to 64kbps" ); ("--afterburner", Arg.Set afterburner, "Enable afterburner effect."); ( "--aot", Arg.String (fun x -> aot := aot_of_string x), Printf.sprintf "Audio object type. Possible values:\n %s" (String.concat ",\n " aots) ); ("--no-sbr", Arg.Clear sbr, "Disable spectral band replication."); ] (let pnum = ref (-1) in fun s -> incr pnum; match !pnum with | 0 -> src := s | 1 -> dst := s | _ -> Printf.eprintf "Error: too many arguments\n"; exit 1) usage; if !src = "" || !dst = "" then ( Printf.printf "%s\n" usage; exit 1); let ic = open_in_bin !src in let oc = open_out_bin !dst in (* TODO: improve! *) if input_string ic 4 <> "RIFF" then invalid_arg "No RIFF tag"; ignore (input_string ic 4); if input_string ic 4 <> "WAVE" then invalid_arg "No WAVE tag"; if input_string ic 4 <> "fmt " then invalid_arg "No fmt tag"; let _ = input_int ic in let _ = input_short ic in (* TODO: should be 1 *) let channels = input_short ic in let infreq = input_int ic in let _ = input_int ic in (* bytes / s *) let _ = input_short ic in (* block align *) let bits = input_short ic in let enc = Fdkaac.Encoder.create channels in Fdkaac.Encoder.set enc (`Aot !aot); if !vbr <> 0 then Fdkaac.Encoder.set enc (`Bitrate_mode (`Variable !vbr)) else begin Fdkaac.Encoder.set enc (`Bitrate_mode `Constant); Fdkaac.Encoder.set enc (`Bitrate !bitrate) end; Fdkaac.Encoder.set enc (`Transmux `Adts); Fdkaac.Encoder.set enc (`Samplerate infreq); Fdkaac.Encoder.set enc (`Afterburner !afterburner); Fdkaac.Encoder.set enc (`Sbr_mode !sbr); let buflen = 1024 in let data = Bytes.create buflen in let start = Unix.time () in Printf.printf "Input detected: PCM WAVE %d channels, %d Hz, %d bits\n%!" channels infreq bits; let br_info = if !vbr <> 0 then Printf.sprintf "VBR %d" !vbr else Printf.sprintf "%d kbps" (!bitrate / 1000) in Printf.printf "Encoding to: %s, %d channels, %d Hz, %s, afterburner: %b, sbr: %b\n\ Please wait...\n\ %!" (string_of_aot !aot) channels infreq br_info !afterburner !sbr; (* skip headers *) let rec aux () = let tag = input_string ic 4 in match tag with | "LIST" -> let n = input_int ic in let _ = input_string ic n in aux () | "data" -> () | _ -> invalid_arg "No data tag" in aux (); begin try while true do let len = input ic data 0 buflen in let data = Bytes.to_string data in if len = 0 then raise End_of_file; let ret = Fdkaac.Encoder.encode enc data 0 len in output_string oc ret done with | End_of_file -> () | Fdkaac.Encoder.Error _ as e -> failwith (match Fdkaac.Encoder.string_of_exception e with | Some s -> s | None -> "Unknown error.") end; let ret = try Fdkaac.Encoder.flush enc with Fdkaac.Encoder.Unsupported_parameter -> Printf.printf "Could not flush.\n"; "" in output_string oc ret; close_in ic; close_out oc; Printf.printf "Finished in %.0f seconds.\n" (Unix.time () -. start); Gc.full_major () ocaml-fdkaac-0.3.3~gitd3393eb/fdkaac.opam000066400000000000000000000024221431211763100200040ustar00rootroot00000000000000# This file is generated by dune, edit dune-project instead opam-version: "2.0" version: "0.3.2" synopsis: "Fraunhofer FDK AAC Codec Library" description: "The FDK AAC Codec Library For Android contains an encoder implementation of the Advanced Audio Coding (AAC) audio codec." maintainer: ["The Savonet Team "] authors: ["The Savonet Team "] license: "GPL-2.0" homepage: "https://github.com/savonet/ocaml-fdkaac" bug-reports: "https://github.com/savonet/ocaml-fdkaac/issues" depends: [ "dune" {>= "2.9"} "dune-configurator" "odoc" {with-doc} ] build: [ ["dune" "subst"] {dev} [ "dune" "build" "-p" name "-j" jobs "--promote-install-files=false" "@install" "@runtest" {with-test} "@doc" {with-doc} ] ["dune" "install" "-p" name "--create-install-files" name] ] dev-repo: "git+https://github.com/savonet/ocaml-fdkaac.git" depexts: [ ["fdk-aac-dev"] {os-distribution = "alpine"} ["libfdk-aac"] {os-distribution = "arch"} ["fdk-aac-devel"] {os-distribution = "centos"} ["fdk-aac-devel"] {os-distribution = "fedora"} ["fdk-aac-devel"] {os-family = "suse"} ["libfdk-aac-dev"] {os-family = "debian"} ["fdk-aac"] {os = "macos" & os-distribution = "homebrew"} ] ocaml-fdkaac-0.3.3~gitd3393eb/fdkaac.opam.template000066400000000000000000000005331431211763100216170ustar00rootroot00000000000000depexts: [ ["fdk-aac-dev"] {os-distribution = "alpine"} ["libfdk-aac"] {os-distribution = "arch"} ["fdk-aac-devel"] {os-distribution = "centos"} ["fdk-aac-devel"] {os-distribution = "fedora"} ["fdk-aac-devel"] {os-family = "suse"} ["libfdk-aac-dev"] {os-family = "debian"} ["fdk-aac"] {os = "macos" & os-distribution = "homebrew"} ] ocaml-fdkaac-0.3.3~gitd3393eb/src/000077500000000000000000000000001431211763100165045ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/src/config/000077500000000000000000000000001431211763100177515ustar00rootroot00000000000000ocaml-fdkaac-0.3.3~gitd3393eb/src/config/discover.ml000066400000000000000000000012161431211763100221210ustar00rootroot00000000000000module C = Configurator.V1 let () = C.main ~name:"fdkaac-pkg-config" (fun c -> let default : C.Pkg_config.package_conf = { libs = ["-lfdk-aac"]; cflags = [] } in let conf = match C.Pkg_config.get c with | None -> default | Some pc -> ( match C.Pkg_config.query_expr_err pc ~package:"fdk-aac" ~expr:"fdk-aac >= 0.1.1" with | Error msg -> failwith msg | Ok deps -> deps) in C.Flags.write_sexp "c_flags.sexp" ("-fPIC" :: conf.cflags); C.Flags.write_sexp "c_library_flags.sexp" conf.libs) ocaml-fdkaac-0.3.3~gitd3393eb/src/config/dune000066400000000000000000000000751431211763100206310ustar00rootroot00000000000000(executable (name discover) (libraries dune.configurator)) ocaml-fdkaac-0.3.3~gitd3393eb/src/dune000066400000000000000000000016431431211763100173660ustar00rootroot00000000000000(library (name fdkaac) (public_name fdkaac) (synopsis "OCaml bindings for fdkaac") (modules fdkaac) (foreign_stubs (language c) (names fdkaac_stubs) (flags (:include c_flags.sexp))) (c_library_flags (:include c_library_flags.sexp))) (rule (targets c_flags.sexp c_library_flags.sexp) (action (run ./config/discover.exe))) (rule (deps (:fdkaac fdkaac.mli)) (target fdkaac.cmi) (action (run %{ocamlc} -c %{fdkaac}))) (rule (deps (:fdkaac_cmi fdkaac.cmi) (:fdkaac_dynlink_in fdkaac_dynlink.mli.in)) (target fdkaac_dynlink.mli) (action (with-stdout-to %{target} (run %{ocamlc} -i -intf %{fdkaac_dynlink_in})))) (rule (deps (:fdkaac_loader fdkaac_loader.ml) (:fdkaac_dynkink fdkaac_dynlink.mli)) (target fdkaac_loader.cmxs) (action (run %{ocamlopt} -shared %{fdkaac_dynkink} %{fdkaac_loader} -o %{target}))) (install (files fdkaac_loader.cmxs fdkaac_dynlink.mli) (section lib)) ocaml-fdkaac-0.3.3~gitd3393eb/src/fdkaac.ml000066400000000000000000000174331431211763100202570ustar00rootroot00000000000000(* * Copyright 2013 Savonet team * * This file is part of ocaml-fdkaac. * * ocaml-fdkaac 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. * * ocaml-fdkaac 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 ocaml-fdkaac; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) (** OCaml bindings for the libfdk-aac. *) module Encoder = struct exception Invalid_handle exception Unsupported_parameter exception Invalid_config exception Invalid_data exception Error of int exception End_of_file exception Unknown of int let () = Callback.register_exception "fdkaac_exn_invalid_handle" Invalid_handle; Callback.register_exception "fdkaac_exn_unsupported_parameter" Unsupported_parameter; Callback.register_exception "fdkaac_exn_invalid_config" Invalid_config; Callback.register_exception "fdkaac_exn_error" (Error 0); Callback.register_exception "fdkaac_exn_encode_eof" End_of_file; Callback.register_exception "aacplus_exn_unknown_error" (Unknown 0) let string_of_exception = function | Invalid_handle -> Some "Handle passed to function call was invalid" | Unsupported_parameter -> Some "Parameter not available" | Invalid_config -> Some "Invalid configuration" | Invalid_data -> Some "Invalid input data" | Error 0 -> Some "General initialization error" | Error 1 -> Some "AAC library initialization error" | Error 2 -> Some "SBR library initialization error" | Error 3 -> Some "Transport library initialization error" | Error 4 -> Some "Meta data library initialization error" | Error 5 -> Some "The encoding process was interrupted by an unexpected error" | End_of_file -> Some "End of file reached" | _ -> None let () = Printexc.register_printer string_of_exception type enc type info = { input_channels : int; frame_length : int } external info : enc -> info = "ocaml_fdkaac_info" type t = { enc : enc; mutable info : info option; buffer : Buffer.t; chans : int; } external create : int -> enc = "ocaml_fdkaac_init_enc" let create chans = { enc = create chans; info = None; buffer = Buffer.create 1024; chans } type mpeg2_aac = [ `AAC_LC | `HE_AAC | `HE_AAC_v2 ] type mpeg4_aac = [ mpeg2_aac | `AAC_LD | `AAC_ELD ] type aot = [ `Mpeg_4 of mpeg4_aac | `Mpeg_2 of mpeg2_aac ] let int_of_aot = function | `Mpeg_4 `AAC_LC -> 2 | `Mpeg_4 `HE_AAC -> 5 | `Mpeg_4 `HE_AAC_v2 -> 29 | `Mpeg_4 `AAC_LD -> 23 | `Mpeg_4 `AAC_ELD -> 39 | `Mpeg_2 `AAC_LC -> 129 | `Mpeg_2 `HE_AAC -> 132 | `Mpeg_2 `HE_AAC_v2 -> 156 let aot_of_int = function | 2 -> `Mpeg_4 `AAC_LC | 5 -> `Mpeg_4 `HE_AAC | 29 -> `Mpeg_4 `HE_AAC_v2 | 23 -> `Mpeg_4 `AAC_LD | 39 -> `Mpeg_4 `AAC_ELD | 129 -> `Mpeg_2 `AAC_LC | 132 -> `Mpeg_2 `HE_AAC | 156 -> `Mpeg_2 `HE_AAC_v2 | _ -> raise Unsupported_parameter type bitrate_mode = [ `Constant | `Full_bitreservoir | `Variable of int ] let int_of_bitrate_mode = function | `Constant -> 0 | `Variable vbr -> vbr | `Full_bitreservoir -> 8 let bitrate_mode_of_int = function | 0 -> `Constant | 8 -> `Full_bitreservoir | vbr -> `Variable vbr type transmux = [ `Raw | `Adif | `Adts | `Latm | `Latm_out_of_band | `Loas ] let int_of_transmux = function | `Raw -> 0 | `Adif -> 1 | `Adts -> 2 | `Latm -> 6 | `Latm_out_of_band -> 7 | `Loas -> 10 let transmux_of_int = function | 0 -> `Raw | 1 -> `Adif | 2 -> `Adts | 6 -> `Latm | 7 -> `Latm_out_of_band | 10 -> `Loas | _ -> raise Unsupported_parameter type param = [ `Aot of aot | `Bitrate of int | `Bitrate_mode of bitrate_mode | `Samplerate of int | `Sbr_mode of bool | `Granule_length of int | `Afterburner of bool | `Bandwidth of int | `Transmux of transmux ] type param_name = [ `Aot | `Bitrate | `Bitrate_mode | `Samplerate | `Sbr_mode | `Granule_length | `Afterburner | `Bandwidth | `Transmux ] let int_of_param_name = function | `Aot -> 0x0100 | `Bitrate -> 0x0101 | `Bitrate_mode -> 0x0102 | `Samplerate -> 0x0103 | `Sbr_mode -> 0x0104 | `Granule_length -> 0x0105 | `Afterburner -> 0x0200 | `Bandwidth -> 0x0203 | `Transmux -> 0x0300 let extract_param = function | `Aot x -> (int_of_param_name `Aot, int_of_aot x) | `Bitrate x -> (int_of_param_name `Bitrate, x) | `Bitrate_mode x -> (int_of_param_name `Bitrate_mode, int_of_bitrate_mode x) | `Samplerate x -> (int_of_param_name `Samplerate, x) | `Sbr_mode x -> (int_of_param_name `Sbr_mode, if x then 1 else 0) | `Granule_length x -> (int_of_param_name `Granule_length, x) | `Afterburner x -> (int_of_param_name `Afterburner, if x then 1 else 0) | `Bandwidth x -> (int_of_param_name `Bandwidth, x) | `Transmux x -> (int_of_param_name `Transmux, int_of_transmux x) external set : enc -> int -> int -> unit = "ocaml_fdkaac_set_param" let set enc param = let p, v = extract_param param in set enc.enc p v let pack_param = function | `Aot, x -> `Aot (aot_of_int x) | `Bitrate, x -> `Bitrate x | `Bitrate_mode, x -> `Bitrate_mode (bitrate_mode_of_int x) | `Samplerate, x -> `Samplerate x | `Sbr_mode, x -> `Sbr_mode (x == 1) | `Granule_length, x -> `Granule_length x | `Afterburner, x -> `Afterburner (x == 1) | `Bandwidth, x -> `Bandwidth x | `Transmux, x -> `Transmux (transmux_of_int x) external get : enc -> int -> int = "ocaml_fdkaac_get_param" let get enc param = let x = get enc.enc (int_of_param_name param) in pack_param (param, x) external encode : enc -> string -> int -> int -> string = "ocaml_fdkaac_encode" (* Drop the first [len] bytes. *) let buffer_drop buffer len = let size = Buffer.length buffer in if len = size then Buffer.clear buffer else begin let tmp = Buffer.sub buffer len (size - len) in Buffer.clear buffer; Buffer.add_string buffer tmp end let rec encode_frames enc len pos out = if len <= Buffer.length enc.buffer - pos then begin let data = Buffer.sub enc.buffer pos len in Buffer.add_string out (encode enc.enc data 0 len); encode_frames enc len (pos + len) out end else if 0 < pos then buffer_drop enc.buffer pos let get_info enc = match enc.info with | Some info -> info | None -> let info = info enc.enc in enc.info <- Some info; info let chunk_length enc = let info = get_info enc in 2 * info.input_channels * info.frame_length let encode enc data ofs len = if String.length data - ofs < len then raise Invalid_data; Buffer.add_substring enc.buffer data ofs len; let ret = Buffer.create 1024 in encode_frames enc (chunk_length enc) 0 ret; Buffer.contents ret external flush : enc -> string = "ocaml_fdkaac_flush" let flush enc = let buf = Buffer.create 1024 in let len = chunk_length enc in encode_frames enc len 0 buf; let rem = Buffer.length enc.buffer in if 0 < rem then begin Buffer.add_string enc.buffer (String.make (len - rem) (Char.chr 0)); encode_frames enc len 0 buf end; try while true do Buffer.add_string buf (flush enc.enc) done; assert false with Unsupported_parameter | End_of_file -> Buffer.contents buf end ocaml-fdkaac-0.3.3~gitd3393eb/src/fdkaac.mli000066400000000000000000000046111431211763100204220ustar00rootroot00000000000000(* * Copyright 2013 Savonet team * * This file is part of ocaml-fdkaac. * * ocaml-fdkaac 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. * * ocaml-fdkaac 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 ocaml-fdkaac; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) module Encoder : sig (** {1 AAC encoding module for OCaml} *) (** {2 Exceptions} *) exception Invalid_handle exception Unsupported_parameter exception Invalid_config exception Error of int exception End_of_file exception Unknown of int val string_of_exception : exn -> string option (** {2 Types} *) type t type mpeg2_aac = [ `AAC_LC | `HE_AAC | `HE_AAC_v2 ] type mpeg4_aac = [ mpeg2_aac | `AAC_LD | `AAC_ELD ] type aot = [ `Mpeg_4 of mpeg4_aac | `Mpeg_2 of mpeg2_aac ] (** VBR modes gives roughly the following bit rates per channel: * * VBR | kbps/channel | AOTs * ------------------------- * 1 | 20-32 | LC,HE,HEv2 * 2 | 32-40 | LC,HE,HEv2 * 3 | 48-56 | LC,HE,HEv2 * 4 | 64-72 | LC * 5 | 96-112 | LC * * HE bit rates will be much lower. *) type bitrate_mode = [ `Constant | `Full_bitreservoir | `Variable of int ] type transmux = [ `Raw | `Adif | `Adts | `Latm | `Latm_out_of_band | `Loas ] type param_name = [ `Aot | `Bitrate | `Bitrate_mode | `Samplerate | `Sbr_mode | `Granule_length | `Afterburner | `Bandwidth | `Transmux ] type param = [ `Aot of aot | `Bitrate of int | `Bitrate_mode of bitrate_mode | `Samplerate of int | `Sbr_mode of bool | `Granule_length of int | `Afterburner of bool | `Bandwidth of int | `Transmux of transmux ] (** {2 Functions} *) val create : int -> t val set : t -> param -> unit val get : t -> param_name -> param val encode : t -> string -> int -> int -> string val flush : t -> string end ocaml-fdkaac-0.3.3~gitd3393eb/src/fdkaac_dynlink.mli.in000066400000000000000000000022021431211763100225510ustar00rootroot00000000000000(* * Copyright 2013 Savonet team * * This file is part of ocaml-fdkaac. * * ocaml-fdkaac 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. * * ocaml-fdkaac 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 ocaml-fdkaac; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) (* $Id$ *) (** * Bindings to the fdkaac AAC library. * Dynamic loading module. * * @author Romain Beauxis *) (** Type for dynamically loded module. * See main module for documentation. *) module type Fdkaac_t = sig include module type of Fdkaac end type handler = { mutable fdkaac_module : (module Fdkaac_t) option } val handler : handler ocaml-fdkaac-0.3.3~gitd3393eb/src/fdkaac_loader.ml000066400000000000000000000017541431211763100216040ustar00rootroot00000000000000(* * Copyright 2013 Savonet team * * This file is part of ocaml-fdkaac. * * ocaml-fdkaac 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. * * ocaml-fdkaac 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 ocaml-fdkaac; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) (* $Id$ *) (** * Bindings to the fdkaac AAC library. * Dynamic loading module. * * @author Romain Beauxis *) open Fdkaac_dynlink let () = handler.fdkaac_module <- Some (module Fdkaac : Fdkaac_t) ocaml-fdkaac-0.3.3~gitd3393eb/src/fdkaac_stubs.c000066400000000000000000000162231431211763100213050ustar00rootroot00000000000000/* * OCaml bindings for libfdk-aac * * Copyright 2013 Savonet team * * This file is part of ocaml-fdk-aac. * * ocaml-fdk-aac 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. * * ocaml-fdk-aac 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 ocaml-fdk-aac; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* OCaml bindings for the libfdk-aac library. */ #include #include #include #include #include #include #include #include #include #include /* Not all errors seem to be used * so we only check the one that * appear relevant.. */ static void check_for_err(int ret) { switch (ret) { case AACENC_OK: return; case AACENC_INVALID_HANDLE: caml_raise_constant(*caml_named_value("fdkaac_exn_invalid_handle")); break; case AACENC_MEMORY_ERROR: caml_raise_out_of_memory(); break; case AACENC_UNSUPPORTED_PARAMETER: caml_raise_constant(*caml_named_value("fdkaac_exn_unsupported_parameter")); break; case AACENC_INVALID_CONFIG: caml_raise_constant(*caml_named_value("fdkaac_exn_invalid_config")); break; case AACENC_INIT_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(0)); break; case AACENC_INIT_AAC_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(1)); break; case AACENC_INIT_SBR_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(2)); break; case AACENC_INIT_TP_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(3)); break; case AACENC_INIT_META_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(4)); break; case AACENC_ENCODE_ERROR: caml_raise_with_arg(*caml_named_value("fdkaac_exn_error"), Val_int(5)); break; case AACENC_ENCODE_EOF: caml_raise_constant(*caml_named_value("fdkaac_exn_encode_eof")); break; default: caml_raise_with_arg(*caml_named_value("fdkaac_exn_unknown_error"), Val_int(ret)); break; } } #define Encoder_val(v) (*((HANDLE_AACENCODER *)Data_custom_val(v))) static void finalize_encoder(value e) { HANDLE_AACENCODER enc = Encoder_val(e); aacEncClose(&enc); } static struct custom_operations encoder_ops = { "ocaml_fdkaac_encoder", finalize_encoder, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default}; #include CAMLprim value ocaml_fdkaac_init_enc(value chans) { CAMLparam0(); CAMLlocal1(ans); int channels = Int_val(chans); int mode; HANDLE_AACENCODER enc; int ret = aacEncOpen(&enc, 0x0, channels); if (ret != AACENC_OK) { free(enc); check_for_err(ret); } switch (channels) { case 1: mode = MODE_1; break; case 2: mode = MODE_2; break; case 3: mode = MODE_1_2; break; case 4: mode = MODE_1_2_1; break; case 5: mode = MODE_1_2_2; break; case 6: mode = MODE_1_2_2_1; break; default: free(enc); caml_raise_constant(*caml_named_value("fdkaac_exn_unsupported_parameter")); } ret = aacEncoder_SetParam(enc, AACENC_CHANNELMODE, mode); if (ret != AACENC_OK) { free(enc); check_for_err(ret); } ret = aacEncoder_SetParam(enc, AACENC_CHANNELORDER, 1); if (ret != AACENC_OK) { free(enc); check_for_err(ret); } ans = caml_alloc_custom(&encoder_ops, sizeof(HANDLE_AACENCODER), 1, 0); Encoder_val(ans) = enc; CAMLreturn(ans); } CAMLprim value ocaml_fdkaac_encode(value e, value buf, value ofs, value len) { CAMLparam2(e, buf); CAMLlocal1(ret); HANDLE_AACENCODER enc = Encoder_val(e); AACENC_BufDesc inBuf = {0}; AACENC_BufDesc outBuf = {0}; AACENC_InArgs inArgs = {0}; AACENC_OutArgs outArgs = {0}; // Input buffer int bufid = IN_AUDIO_DATA; int buflen = Int_val(len); int bufelsize = 2; // S16LE int offset = Int_val(ofs); void *bufs; inBuf.numBufs = 1; inBuf.bufferIdentifiers = &bufid; inBuf.bufSizes = &buflen; inBuf.bufElSizes = &bufelsize; bufs = malloc(buflen); if (bufs == NULL) caml_raise_out_of_memory(); memcpy(bufs, String_val(buf) + offset, buflen); inBuf.bufs = &bufs; inArgs.numInSamples = buflen / bufelsize; // Output buffer uint8_t outbuf[20480]; int outid = OUT_BITSTREAM_DATA; int outlen = sizeof(outbuf); int outelsize = 1; void *outptr = &outbuf; outBuf.numBufs = 1; outBuf.bufferIdentifiers = &outid; outBuf.bufSizes = &outlen; outBuf.bufElSizes = &outelsize; outBuf.bufs = &outptr; caml_enter_blocking_section(); int err = aacEncEncode(enc, &inBuf, &outBuf, &inArgs, &outArgs); caml_leave_blocking_section(); free(bufs); check_for_err(err); ret = caml_alloc_string(outArgs.numOutBytes); memcpy(Bp_val(ret), outbuf, outArgs.numOutBytes); CAMLreturn(ret); } CAMLprim value ocaml_fdkaac_flush(value e) { CAMLparam1(e); CAMLlocal1(ret); HANDLE_AACENCODER enc = Encoder_val(e); AACENC_BufDesc inBuf = {0}; AACENC_BufDesc outBuf = {0}; AACENC_InArgs inArgs = {0}; AACENC_OutArgs outArgs = {0}; inArgs.numInSamples = -1; // Output buffer uint8_t outbuf[20480]; int outid = OUT_BITSTREAM_DATA; int outlen = sizeof(outbuf); int outelsize = 1; void *outptr = &outbuf; outBuf.bufferIdentifiers = &outid; outBuf.bufSizes = &outlen; outBuf.bufElSizes = &outelsize; outBuf.bufs = &outptr; caml_enter_blocking_section(); int err = aacEncEncode(enc, &inBuf, &outBuf, &inArgs, &outArgs); caml_leave_blocking_section(); check_for_err(err); ret = caml_alloc_string(outArgs.numOutBytes); memcpy(Bp_val(ret), outbuf, outArgs.numOutBytes); CAMLreturn(ret); } CAMLprim value ocaml_fdkaac_set_param(value e, value p, value v) { CAMLparam3(e, p, v); HANDLE_AACENCODER enc = Encoder_val(e); AACENC_PARAM param = Int_val(p); check_for_err(aacEncoder_SetParam(enc, param, Int_val(v))); CAMLreturn(Val_unit); } CAMLprim value ocaml_fdkaac_get_param(value e, value p) { CAMLparam2(e, p); int ans; HANDLE_AACENCODER enc = Encoder_val(e); AACENC_PARAM param = Int_val(p); ans = aacEncoder_GetParam(enc, param); CAMLreturn(Val_int(ans)); } CAMLprim value ocaml_fdkaac_info(value e) { CAMLparam1(e); CAMLlocal1(ans); HANDLE_AACENCODER enc = Encoder_val(e); AACENC_InfoStruct info = {0}; // Apparently we need to do this before being able to access info... check_for_err(aacEncEncode(enc, NULL, NULL, NULL, NULL)); check_for_err(aacEncInfo(enc, &info)); ans = caml_alloc_tuple(2); Store_field(ans, 0, Val_int(info.inputChannels)); Store_field(ans, 1, Val_int(info.frameLength)); CAMLreturn(ans); }