pax_global_header00006660000000000000000000000064141566706250014526gustar00rootroot0000000000000052 comment=140dd657fc30c82e9281c0f63225101dbbe95563 ocaml-lame-0.3.5/000077500000000000000000000000001415667062500135425ustar00rootroot00000000000000ocaml-lame-0.3.5/.github/000077500000000000000000000000001415667062500151025ustar00rootroot00000000000000ocaml-lame-0.3.5/.github/workflows/000077500000000000000000000000001415667062500171375ustar00rootroot00000000000000ocaml-lame-0.3.5/.github/workflows/main.yml000066400000000000000000000006601415667062500206100ustar00rootroot00000000000000name: Build on: [push] jobs: build: runs-on: ${{ matrix.operating-system }} strategy: matrix: operating-system: [ubuntu-latest, macos-latest] ocaml-version: ['4.09.0'] steps: - uses: actions/checkout@v1 - uses: avsm/setup-ocaml@master with: ocaml-version: ${{ matrix.ocaml-version }} - run: opam pin add -n . - run: opam depext -yt lame - run: opam install -t . ocaml-lame-0.3.5/.gitignore000066400000000000000000000000631415667062500155310ustar00rootroot00000000000000*~ _build *.byte *.native _tests .merlin *.install ocaml-lame-0.3.5/.ocamlformat000066400000000000000000000003201415667062500160420ustar00rootroot00000000000000profile = 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-lame-0.3.5/CHANGES000066400000000000000000000025531415667062500145420ustar00rootroot000000000000000.3.5 (12-16-2021) ===== * Better endianess detection. * Avoid race condition between the GC and `encode_buffer_float_ba` 0.3.4 (05-09-2020) ===== * Add encode_buffer_float_ba. * Drop dynlink API * Switched to dune * Use stack-allocated buffers. 0.3.3 (03-08-2015) ===== * Dummy github release. 0.3.2 (06-05-2013) ===== * Correct binding for flush_nogap. 0.3.1 (04-10-2011) ===== * Support for setting special bits in MP3 frames: original, copyright and private. 0.3.0 (14-06-2011) ===== * Added dynamic Lame module and dynamic loading module. 0.2.4 (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.2.3 (05-01-2009) ===== * Fixed compilation error when using big endian machine * Fixed bswap_16 to make sure it operates on signed integers 0.2.2 (2008-04-16) ===== * More portable make invokation * Install .cmx file 0.2.1 (2007-10-17) ===== * Avoid a double-free at finalize. 0.2.0 (2007-06-05) ===== * Added encode_buffer_float{,_part}. 0.1.2 (2006-03-02) ===== * Fixed endianness bug 0.1.1 (2006-11-11) ===== * Fixed some syntax errors in configure script. 0.1.0 (2006-04-09) ===== * Initial release. ocaml-lame-0.3.5/COPYING000066400000000000000000000431311415667062500145770ustar00rootroot00000000000000 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-lame-0.3.5/README.md000066400000000000000000000012721415667062500150230ustar00rootroot00000000000000ocaml-lame This package contains an OCaml interface for the lame library. Please read the COPYING file before using this software. Prerequisites: ============== - ocaml >= 4.00.1 (haven't tried earlier versions) - lame - 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 lame ``` 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-lame-0.3.5/dune-project000066400000000000000000000007241415667062500160670ustar00rootroot00000000000000(lang dune 2.0) (version 0.3.5) (name lame) (source (github savonet/ocaml-lame)) (license GPL-2.0) (authors "The Savonet Team ") (maintainers "The Savonet Team ") (generate_opam_files true) (package (name lame) (synopsis "MP3 encoding library") (description "Bindings for the lame library which provides functions for encoding mp3 files") (depends (dune (> 2.0)) dune-configurator) ) ocaml-lame-0.3.5/examples/000077500000000000000000000000001415667062500153605ustar00rootroot00000000000000ocaml-lame-0.3.5/examples/dune000066400000000000000000000000641415667062500162360ustar00rootroot00000000000000(executable (name wav2mp3) (libraries unix lame)) ocaml-lame-0.3.5/examples/wav2mp3.ml000066400000000000000000000112771415667062500172210ustar00rootroot00000000000000(* Copyright 2003 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 *) (** An wav to mp3 converter using OCaml-Lame. @author Samuel Mimram *) let src = ref "" let dst = ref "" let buflen = ref 1024 let input_string chan len = let ans = Bytes.create len in (* TODO: check length *) ignore (input chan ans 0 len); Bytes.unsafe_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 stereo = ref true let freq = ref 44100 let bitrate = ref 128 let bigarray = ref false let usage = "usage: wav2mp3 [options] source destination" let _ = Arg.parse [ ( "--sample-freq", Arg.Int (fun f -> freq := f), "Sample frequency, default to 44100Hz" ); ("--mono", Arg.Clear stereo, "Do not encode in stereo"); ("--bigarray", Arg.Set bigarray, "Use bigarrays."); ( "--bitrate", Arg.Int (fun b -> bitrate := b), "Bitrate, in bits per second, defaults to 128kbps" ); ( "--buflen", Arg.Int (fun i -> buflen := i), "Size of chunks successively encoded" ); ] (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 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 wav_type = input_short ic in assert (wav_type = 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 (* Skip to data part *) let rec skip () = match input_string ic 4 with | "data" -> () | "LIST" -> let n = input_int ic in ignore (input_string ic n); skip () | _ -> assert false in skip (); let enc = Lame.create_encoder () in Lame.set_brate enc !bitrate; let start = Unix.time () in Lame.init_params enc; Printf.printf "Input detected: PCM WAVE %d channels, %d Hz, %d bits\n%!" channels infreq bits; Printf.printf "Encoding to: MP3 %d channels, %d Hz, %d kbps\nPlease wait...\n%!" (if !stereo then 2 else 1) !freq !bitrate; (* output oc header 0 (String.length header); *) let buflen = !buflen in let buf = Bytes.create buflen in let babufl = Bigarray.Array1.create Bigarray.Float32 Bigarray.c_layout (buflen / 4) in let babufr = Bigarray.Array1.create Bigarray.Float32 Bigarray.c_layout (buflen / 4) in begin try while true do really_input ic buf 0 buflen; let buf = Bytes.unsafe_to_string buf in let outbuf = if not !bigarray then Lame.encode_buffer enc buf (buflen / 4) else ( let f i = let n = (int_of_char buf.[(2 * i) + 1] * 0x100) + int_of_char buf.[(2 * i) + 0] in if n <= 0x7fff then n else n - 0xffff in for i = 0 to (buflen / 4) - 1 do babufl.{i} <- float_of_int (f (2 * i)); babufr.{i} <- float_of_int (f ((2 * i) + 1)) done; Lame.encode_buffer_float_ba enc babufl babufr ) in output oc (Bytes.of_string outbuf) 0 (String.length outbuf) done with End_of_file -> () end; let outbuf = Lame.encode_flush enc in output oc (Bytes.of_string outbuf) 0 (String.length outbuf); Printf.printf "Finished in %.0f seconds.\n" (Unix.time () -. start); Gc.full_major () ocaml-lame-0.3.5/lame.opam000066400000000000000000000021031415667062500153320ustar00rootroot00000000000000# This file is generated by dune, edit dune-project instead opam-version: "2.0" version: "0.3.5" synopsis: "MP3 encoding library" description: "Bindings for the lame library which provides functions for encoding mp3 files" maintainer: ["The Savonet Team "] authors: ["The Savonet Team "] license: "GPL-2.0" homepage: "https://github.com/savonet/ocaml-lame" bug-reports: "https://github.com/savonet/ocaml-lame/issues" depends: [ "dune" {> "2.0"} "dune-configurator" ] build: [ ["dune" "subst"] {pinned} [ "dune" "build" "-p" name "-j" jobs "@install" "@runtest" {with-test} "@doc" {with-doc} ] ] dev-repo: "git+https://github.com/savonet/ocaml-lame.git" depexts: [ ["lame-dev"] {os-distribution = "alpine"} ["lame-devel"] {os-distribution = "centos"} ["lame-devel"] {os-distribution = "fedora"} ["lame-devel"] {os-family = "suse"} ["libmp3lame-dev"] {os-family = "debian"} ["lame"] {os = "macos" & os-distribution = "homebrew"} ["lame"] {os = "freebsd"} ] ocaml-lame-0.3.5/lame.opam.template000066400000000000000000000004741415667062500171550ustar00rootroot00000000000000depexts: [ ["lame-dev"] {os-distribution = "alpine"} ["lame-devel"] {os-distribution = "centos"} ["lame-devel"] {os-distribution = "fedora"} ["lame-devel"] {os-family = "suse"} ["libmp3lame-dev"] {os-family = "debian"} ["lame"] {os = "macos" & os-distribution = "homebrew"} ["lame"] {os = "freebsd"} ] ocaml-lame-0.3.5/src/000077500000000000000000000000001415667062500143315ustar00rootroot00000000000000ocaml-lame-0.3.5/src/config/000077500000000000000000000000001415667062500155765ustar00rootroot00000000000000ocaml-lame-0.3.5/src/config/discover.ml000066400000000000000000000010401415667062500177410ustar00rootroot00000000000000module C = Configurator.V1 external is_big_endian : unit -> bool = "ocaml_lame_is_big_endian" let has_lame_h_code = {| #include int main() { lame_init(); return 0; } |} let link_flags = ["-lmp3lame"; "-lm"] let () = C.main ~name:"ocaml-lame" (fun c -> C.C_define.gen_header_file c ~fname:"config.h" [("BIGENDIAN", Switch (is_big_endian ()))]; assert (C.c_test ~link_flags c has_lame_h_code); C.Flags.write_sexp "c_flags.sexp" []; C.Flags.write_sexp "c_library_flags.sexp" link_flags) ocaml-lame-0.3.5/src/config/dune000066400000000000000000000001611415667062500164520ustar00rootroot00000000000000(executable (name discover) (foreign_stubs (language c) (names endianess)) (libraries dune.configurator)) ocaml-lame-0.3.5/src/config/endianess.c000066400000000000000000000006261415667062500177170ustar00rootroot00000000000000#include #include enum { OCAML_LAME_LITTLE_ENDIAN = 0x0100, OCAML_LAME_BIG_ENDIAN = 0x0001, }; static const union { unsigned char bytes[2]; uint16_t value; } host_order = { { 0, 1 } }; CAMLprim value ocaml_lame_is_big_endian(value unit) { CAMLparam0(); if (host_order.value == OCAML_LAME_BIG_ENDIAN) CAMLreturn(Val_bool(1)); CAMLreturn(Val_bool(0)); } ocaml-lame-0.3.5/src/dune000066400000000000000000000004751415667062500152150ustar00rootroot00000000000000(library (name lame) (public_name lame) (synopsis "OCaml bindings for lame") (foreign_stubs (language c) (names lame_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))) ocaml-lame-0.3.5/src/lame.ml000066400000000000000000000136451415667062500156120ustar00rootroot00000000000000(* * Copyright 2005-2006 Savonet team * * This file is part of ocaml-lame. * * ocaml-lame 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-lame 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-lame; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) exception Init_params_failed exception Init_params_not_called exception Psychoacoustic_problem exception Unknown_error of int let _ = Callback.register_exception "lame_exn_init_params_failed" Init_params_failed; Callback.register_exception "lame_exn_init_params_not_called" Init_params_not_called; Callback.register_exception "lame_exn_psychoacoustic_problem" Psychoacoustic_problem; Callback.register_exception "lame_exn_unknown_error" (Unknown_error 0) type encoder external create_encoder : unit -> encoder = "ocaml_lame_init" external set_in_samplerate : encoder -> int -> unit = "ocaml_lame_set_in_samplerate" external set_num_channels : encoder -> int -> unit = "ocaml_lame_set_num_channels" external set_out_samplerate : encoder -> int -> unit = "ocaml_lame_set_out_samplerate" external set_quality : encoder -> int -> unit = "ocaml_lame_set_quality" let set_quality e q = if q < 0 || q > 9 then invalid_arg "quality"; set_quality e q type mode = Stereo | Joint_stereo | Dual_channel | Mono external set_mode : encoder -> mode -> unit = "ocaml_lame_set_mode" type vbr_mode = Vbr_off | Vbr_rh | Vbr_abr | Vbr_mtrh | Vbr_max_indicator external set_vbr_mode : encoder -> vbr_mode -> unit = "ocaml_lame_set_vbr" external set_vbr_quality : encoder -> int -> unit = "ocaml_lame_set_VBR_q" external set_vbr_mean_bitrate : encoder -> int -> unit = "ocaml_lame_set_VBR_mean_bitrate_kbps" external set_vbr_min_bitrate : encoder -> int -> unit = "ocaml_lame_set_VBR_min_bitrate_kbps" external set_vbr_max_bitrate : encoder -> int -> unit = "ocaml_lame_set_VBR_max_bitrate_kbps" external set_vbr_hard_min : encoder -> bool -> unit = "ocaml_lame_set_VBR_hard_min" external set_brate : encoder -> int -> unit = "ocaml_lame_set_brate" external set_compression_ratio : encoder -> float -> unit = "ocaml_lame_set_compression_ratio" external set_private : encoder -> bool -> unit = "ocaml_lame_set_extension" external get_private : encoder -> bool = "ocaml_lame_get_extension" external set_original : encoder -> bool -> unit = "ocaml_lame_set_original" external get_original : encoder -> bool = "ocaml_lame_get_original" external set_copyright : encoder -> bool -> unit = "ocaml_lame_set_copyright" external get_copyright : encoder -> bool = "ocaml_lame_get_copyright" external init_params : encoder -> unit = "ocaml_lame_init_params" external init_bitstream : encoder -> unit = "ocaml_lame_init_bitstream" external encode_buffer_part : encoder -> string -> int -> int -> string = "ocaml_lame_encode_buffer_interleaved" (** [encode_buffer_float_part enc left right offset samples] * encodes float samples, expected to be in [-1;1]. *) external encode_buffer_float_part : encoder -> float array -> float array -> int -> int -> string = "ocaml_lame_encode_buffer_float" (** Encode left and right buffers. Data are supposed to be scaled -/+32768. *) external encode_buffer_float_ba : encoder -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> string = "ocaml_lame_encode_buffer_float_ba" (** [encode_buffer enc buf smpl] encodes [smpl] samples of PCM audio into MP3. * Input samples are expected to be 16bits little-endian, other input/output * params are specified using [set_*] functions. *) let encode_buffer enc buf smpl = encode_buffer_part enc buf 0 smpl let encode_buffer_float enc left right smpl = encode_buffer_float_part enc left right 0 smpl external encode_flush : encoder -> string = "ocaml_lame_encode_flush" external encode_flush_nogap : encoder -> string = "ocaml_lame_encode_flush_nogap" module Id3tag = struct external init : encoder -> unit = "ocaml_lame_id3tag_init" external set_title : encoder -> string -> unit = "ocaml_lame_id3tag_set_title" external set_artist : encoder -> string -> unit = "ocaml_lame_id3tag_set_artist" external set_album : encoder -> string -> unit = "ocaml_lame_id3tag_set_album" external set_year : encoder -> string -> unit = "ocaml_lame_id3tag_set_year" external set_comment : encoder -> string -> unit = "ocaml_lame_id3tag_set_comment" external set_track : encoder -> string -> unit = "ocaml_lame_id3tag_set_track" external set_genre : encoder -> string -> unit = "ocaml_lame_id3tag_set_genre" end external get_lame_version : unit -> string = "ocaml_lame_get_lame_version" external get_lame_short_version : unit -> string = "ocaml_lame_get_lame_short_version" external get_lame_very_short_version : unit -> string = "ocaml_lame_get_lame_very_short_version" external get_psy_version : unit -> string = "ocaml_lame_get_psy_version" external get_lame_url : unit -> string = "ocaml_lame_get_lame_url" type mpeg_version = Mpeg_1 | Mpeg_2 | Mpeg_2_5 external get_version : encoder -> mpeg_version = "ocaml_lame_get_version" external get_encoder_delay : encoder -> int = "ocaml_lame_get_encoder_delay" external get_framesize : encoder -> int = "ocaml_lame_get_framesize" external get_nb_samples_to_encode : encoder -> int = "ocaml_lame_get_mf_samples_to_encode" external get_nb_encoded_frames : encoder -> int = "ocaml_lame_get_frameNum" external get_nb_frames : encoder -> int = "ocaml_lame_get_totalframes" ocaml-lame-0.3.5/src/lame.mli000066400000000000000000000172601415667062500157600ustar00rootroot00000000000000(* * Copyright 2005-2006 Savonet team * * This file is part of ocaml-lame. * * ocaml-lame 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-lame 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-lame; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) (** * Bindings to the lame library to encode mp3 files. * * @author Samuel Mimram *) (** {1 General informations} *) (** Get the lame version number. *) val get_lame_version : unit -> string (** Get the lame version number (shorter than [get_lame_version]). *) val get_lame_short_version : unit -> string (** Get the lame version number (shorter than [get_lame_short_version]). *) val get_lame_very_short_version : unit -> string (** Get the url of the lame website. *) val get_lame_url : unit -> string (** Get the version of the psy model. *) val get_psy_version : unit -> string (** {1 Encoders} *) (** Type for lame encoders. *) type encoder (** Create a new lame encoder. *) val create_encoder : unit -> encoder (** {2 Parameters} *) (** Input sample rate in Hz (default: 44100). *) val set_in_samplerate : encoder -> int -> unit (** Number of channels in input stream (default: 2). *) val set_num_channels : encoder -> int -> unit (** * Output sample rate in Hz (default: 0, which means LAME picks best value * based on the amount of compression). MPEG only allows: * - MPEG1 (32, 44.1, 48 kHz) * - MPEG2 (16, 22.05, 24 kHz) * - MPEG2.5 (8, 11.025, 12 kHz) *) val set_out_samplerate : encoder -> int -> unit (** * Internal algorithm selection. True quality is determined by the bitrate * but this variable will effect quality by selecting expensive or cheap * algorithms. The quality is an integer between 0 and 9, where 0=best (very * slow) and 9=worst. More precisely: * - 2: near-best quality, not too slow (recommended) * - 5: good quality, fast * - 7: ok quality, really fast *) val set_quality : encoder -> int -> unit (** Compression mode. *) type mode = | Stereo (** stereo, channels encoded independely *) | Joint_stereo (** stereo, channels encoded together *) | Dual_channel (** not supported *) | Mono (** mono *) (** Set the compression mode. *) val set_mode : encoder -> mode -> unit (** VBR (Variable BitRate) mode. *) type vbr_mode = | Vbr_off (** constant bitrate *) | Vbr_rh | Vbr_abr | Vbr_mtrh | Vbr_max_indicator (* don't use this (it's for sanity checks) *) (** Set the VBR mode. *) val set_vbr_mode : encoder -> vbr_mode -> unit (** Set the VBR quality level (0:highest, 9: lowest). *) val set_vbr_quality : encoder -> int -> unit (** Set the VBR mean birate in kbps. Only used by [Vbr_abr] mode. *) val set_vbr_mean_bitrate : encoder -> int -> unit (** Set the minimal VBR bitrate in kbps. *) val set_vbr_min_bitrate : encoder -> int -> unit (** Set the maximal VBR bitrate in kbps. *) val set_vbr_max_bitrate : encoder -> int -> unit (** If [true], enforce the minimal VBR bitrate. Normally it will be violated * for analog silence. *) val set_vbr_hard_min : encoder -> bool -> unit (** Set the bitrate of compressed data. You can either set this or use * [set_compression_ratio]. *) val set_brate : encoder -> int -> unit (** Set the compression ratio (default: 11). *) val set_compression_ratio : encoder -> float -> unit (** Get/set private bit. *) val set_private : encoder -> bool -> unit val get_private : encoder -> bool (** Get/set copyright bit. *) val set_copyright : encoder -> bool -> unit val get_copyright : encoder -> bool (** Get/set original bit. *) val set_original : encoder -> bool -> unit val get_original : encoder -> bool (** A call to [init_params] failed for some reason. *) exception Init_params_failed (** Initialize lame's parameters. Should be called before encoding (and after * having set the parameters). Raises [Init_params_failed] on error. *) val init_params : encoder -> unit (** Write id3v2 and Xing headers into the front of the bitstream, and set * frame counters and bitrate histogram data to 0. Normally, this is called by * [init_params]. You can call this after [encode_flush_nogap]. *) val init_bitstream : encoder -> unit (** {2 Encoding} *) (** You should have called [init_params]. *) exception Init_params_not_called (** A problem occured with psychoacoustics. *) exception Psychoacoustic_problem (** This should not have happened. Please report. *) exception Unknown_error of int (** [encode_buffer_part enc buf ofs smpl] encodes [samples] * samples (per channel) of [buf] starting at position [ofs]. *) val encode_buffer_part : encoder -> string -> int -> int -> string (** Same as [encode_buffer_part] but with [ofs = 0]. *) val encode_buffer : encoder -> string -> int -> string (** [encode_buffer_float_part enc left right ofs smpl] encodes [samples] * samples of [left] and [right] channels starting at position [ofs]. * Floats are expected to range over [-1;1]. *) val encode_buffer_float_part : encoder -> float array -> float array -> int -> int -> string (** Same as [encode_buffer_float_part] but with [ofs = 0]. *) val encode_buffer_float : encoder -> float array -> float array -> int -> string (** Encode a buffer of samples. The samples follow here lame's convention of having floats in the range [-32768.,32768.] (yes, this is crazy but that's the way things are). *) val encode_buffer_float_ba : encoder -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t -> string (** Flush the PCM buffers, padding with zeros if needed to make a complete * frame. Will also write id3v1 tags (if any) into the bitstream. *) val encode_flush : encoder -> string (** Flush the PCM buffers, padding with zeros if needed to make a complete * frame. This function will not write id3v1 tags into the bitstream. *) val encode_flush_nogap : encoder -> string (** {2 Id3 tags} *) module Id3tag : sig (** This function should be called before any other in the [Id3tag] module. *) val init : encoder -> unit (** Set the title. *) val set_title : encoder -> string -> unit (** Set the artist. *) val set_artist : encoder -> string -> unit (** Set the album. *) val set_album : encoder -> string -> unit (** Set the year. *) val set_year : encoder -> string -> unit (** Set the comment. *) val set_comment : encoder -> string -> unit (** Set the track number. *) val set_track : encoder -> string -> unit (** Set the genre. *) val set_genre : encoder -> string -> unit end (** {2 Informations about encoding} *) (** MPEG version. *) type mpeg_version = | Mpeg_1 (** MPEG v1 *) | Mpeg_2 (** MPEG v2 *) | Mpeg_2_5 (** MPEG v2.5 *) (** The MPEG version used by the encoder. *) val get_version : encoder -> mpeg_version (** Get the encoder delay. *) val get_encoder_delay : encoder -> int (** Size of an mpeg frame in bytes. *) val get_framesize : encoder -> int (** Number of PCM samples buffered, but not yet encoded to mp3 data. *) val get_nb_samples_to_encode : encoder -> int (** Number of frames encoded so far. *) val get_nb_encoded_frames : encoder -> int (** Estimate of the total number of frames to be encoded * (only valid if [set_nb_samples] was called). *) val get_nb_frames : encoder -> int ocaml-lame-0.3.5/src/lame_stubs.c000066400000000000000000000262231415667062500166400ustar00rootroot00000000000000/* * OCaml bindings for liblame * * Copyright 2005-2006 Savonet team * * This file is part of ocaml-lame. * * ocaml-lame 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-lame 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-lame; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" #ifndef Bytes_val #define Bytes_val String_val #endif #define Lame_val(v) (*(lame_global_flags **)Data_custom_val(v)) static inline int16_t bswap_16(int16_t x) { return ((((x) >> 8) & 0xff) | (((x)&0xff) << 8)); } static void finalize_lame_t(value l) { lame_global_flags *lgf = Lame_val(l); lame_close(lgf); } static struct custom_operations lame_ops = { "ocaml_lame_t", finalize_lame_t, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default}; CAMLprim value ocaml_lame_init(value unit) { CAMLparam1(unit); CAMLlocal1(l); lame_global_flags *lgf; lgf = lame_init(); #ifdef DEBUG printf("New encoder: %p.\n", lgf); #endif l = caml_alloc_custom(&lame_ops, sizeof(lame_global_flags *), 0, 1); Lame_val(l) = lgf; CAMLreturn(l); } /***** Parameters *****/ #define BIND_SET_INT_PARAM(p) \ CAMLprim value ocaml_lame_set_##p(value l, value v) { \ CAMLparam1(l); \ lame_set_##p(Lame_val(l), Int_val(v)); \ CAMLreturn(Val_unit); \ } #define BIND_GET_INT_PARAM(p) \ CAMLprim value ocaml_lame_get_##p(value l) { \ CAMLparam1(l); \ CAMLreturn(Val_int(lame_get_##p(Lame_val(l)))); \ } #define BIND_INT_PARAM(p) BIND_GET_INT_PARAM(p) BIND_SET_INT_PARAM(p) BIND_INT_PARAM(num_samples); BIND_INT_PARAM(in_samplerate); BIND_INT_PARAM(num_channels); BIND_INT_PARAM(out_samplerate); BIND_INT_PARAM(quality); BIND_INT_PARAM(mode); BIND_INT_PARAM(brate); #define BIND_FLOAT_PARAM(p) \ CAMLprim value ocaml_lame_set_##p(value l, value v) { \ CAMLparam2(l, v); \ lame_set_##p(Lame_val(l), Double_val(v)); \ CAMLreturn(Val_unit); \ } \ CAMLprim value ocaml_lame_get_##p(value l) { \ CAMLparam1(l); \ CAMLreturn(caml_copy_double(lame_get_##p(Lame_val(l)))); \ } BIND_FLOAT_PARAM(compression_ratio); CAMLprim value ocaml_lame_init_params(value l) { CAMLparam1(l); int ans = lame_init_params(Lame_val(l)); if (ans < 0) { fprintf(stderr, "init_params error: %d\n", ans); caml_raise_constant(*caml_named_value("lame_exn_init_params_failed")); } CAMLreturn(Val_unit); } CAMLprim value ocaml_lame_init_bitstream(value l) { CAMLparam1(l); lame_init_bitstream(Lame_val(l)); CAMLreturn(Val_unit); } static vbr_mode vbr_mode_val[] = {vbr_off, vbr_rh, vbr_abr, vbr_mtrh, vbr_max_indicator}; CAMLprim value ocaml_lame_set_vbr(value l, value m) { CAMLparam2(l, m); lame_set_VBR(Lame_val(l), vbr_mode_val[Int_val(m)]); CAMLreturn(Val_unit); } BIND_INT_PARAM(VBR_q); BIND_INT_PARAM(VBR_mean_bitrate_kbps); BIND_INT_PARAM(VBR_min_bitrate_kbps); BIND_INT_PARAM(VBR_max_bitrate_kbps); BIND_INT_PARAM(VBR_hard_min); #define BIND_SET_BOOL_PARAM(p) \ CAMLprim value ocaml_lame_set_##p(value l, value v) { \ CAMLparam1(l); \ lame_set_##p(Lame_val(l), Int_val(v)); \ CAMLreturn(Val_unit); \ } #define BIND_GET_BOOL_PARAM(p) \ CAMLprim value ocaml_lame_get_##p(value l) { \ CAMLparam1(l); \ CAMLreturn(Val_bool(lame_get_##p(Lame_val(l)))); \ } #define BIND_BOOL_PARAM(p) BIND_GET_BOOL_PARAM(p) BIND_SET_BOOL_PARAM(p) BIND_BOOL_PARAM(copyright) BIND_BOOL_PARAM(original) BIND_BOOL_PARAM(extension) /****** Encoding ******/ static void raise_enc_err(int n) { switch (n) { case -3: caml_raise_constant(*caml_named_value("lame_exn_init_params_not_called")); case -4: caml_raise_constant(*caml_named_value("lame_exn_psychoacoustic_problem")); default: /* TODO: be more precise. */ caml_raise_with_arg(*caml_named_value("lame_exn_unknown_error"), Val_int(n)); } } CAMLprim value ocaml_lame_encode_buffer_interleaved(value l, value _buf, value _ofs, value _samples) { CAMLparam4(l, _buf, _ofs, _samples); CAMLlocal1(ret); lame_global_flags *lgf = Lame_val(l); int samples = Int_val(_samples); int inbuf_len = caml_string_length(_buf); short int *inbuf = malloc(inbuf_len); unsigned char outbuf[LAME_MAXMP3BUFFER]; int ans; memcpy(inbuf, String_val(_buf), inbuf_len); caml_release_runtime_system(); #ifdef BIGENDIAN int i; for (i = 0; i < inbuf_len / 2; i++) inbuf[i] = bswap_16(inbuf[i]); #endif ans = lame_encode_buffer_interleaved(lgf, inbuf, samples, outbuf, sizeof(outbuf)); caml_acquire_runtime_system(); free(inbuf); if (ans < 0) raise_enc_err(ans); ret = caml_alloc_string(ans); memcpy(Bytes_val(ret), outbuf, ans); CAMLreturn(ret); } /* Input: float arrays, floats in [-1..1] * Output: MP3 frames. * Lame wants floats in +/- SHRTMAX, we renormalize when copying to C heap. * TODO Figure out how to proceed when encoding mono data. */ CAMLprim value ocaml_lame_encode_buffer_float(value l, value _bufl, value _bufr, value _ofs, value _samples) { CAMLparam5(l, _bufl, _bufr, _ofs, _samples); CAMLlocal1(ret); lame_global_flags *lgf = Lame_val(l); int ofs = Int_val(_ofs); int samples = Int_val(_samples); float *inbufl = malloc(sizeof(float) * samples); float *inbufr = malloc(sizeof(float) * samples); unsigned char outbuf[LAME_MAXMP3BUFFER]; int i, ans; for (i = 0; i < samples; i++) { inbufl[i] = 32768. * Double_field(_bufl, ofs + i); inbufr[i] = 32768. * Double_field(_bufr, ofs + i); } caml_release_runtime_system(); ans = lame_encode_buffer_float(lgf, inbufl, inbufr, samples, outbuf, sizeof(outbuf)); caml_acquire_runtime_system(); free(inbufl); free(inbufr); if (ans < 0) raise_enc_err(ans); ret = caml_alloc_string(ans); memcpy(Bytes_val(ret), outbuf, ans); CAMLreturn(ret); } CAMLprim value ocaml_lame_encode_buffer_float_ba(value l, value _bufl, value _bufr) { CAMLparam3(l, _bufl, _bufr); CAMLlocal1(ret); lame_global_flags *lgf = Lame_val(l); struct caml_ba_array *bal = Caml_ba_array_val(_bufl); struct caml_ba_array *bar = Caml_ba_array_val(_bufr); const float *bufl = bal->data; const float *bufr = bar->data; int samples = bal->dim[0]; if (bar->dim[0] != samples) caml_failwith("Invalid argument: buffers must be of same length"); caml_release_runtime_system(); unsigned char outbuf[LAME_MAXMP3BUFFER]; int ans; ans = lame_encode_buffer_float(lgf, bufl, bufr, samples, outbuf, sizeof(outbuf)); caml_acquire_runtime_system(); if (ans < 0) raise_enc_err(ans); ret = caml_alloc_string(ans); memcpy(Bytes_val(ret), outbuf, ans); CAMLreturn(ret); } CAMLprim value ocaml_lame_encode_flush(value l) { CAMLparam1(l); CAMLlocal1(ret); lame_global_flags *lgf = Lame_val(l); int ans; unsigned char outbuf[LAME_MAXMP3BUFFER]; caml_release_runtime_system(); ans = lame_encode_flush(lgf, outbuf, sizeof(outbuf)); caml_acquire_runtime_system(); if (ans < 0) raise_enc_err(ans); ret = caml_alloc_string(ans); memcpy(Bytes_val(ret), outbuf, ans); CAMLreturn(ret); } CAMLprim value ocaml_lame_encode_flush_nogap(value l) { CAMLparam1(l); CAMLlocal1(ret); lame_global_flags *lgf = Lame_val(l); int ans; unsigned char outbuf[LAME_MAXMP3BUFFER]; caml_release_runtime_system(); ans = lame_encode_flush_nogap(lgf, outbuf, sizeof(outbuf)); caml_acquire_runtime_system(); if (ans < 0) raise_enc_err(ans); ret = caml_alloc_string(ans); memcpy(Bytes_val(ret), outbuf, ans); CAMLreturn(ret); } /***** Id3 tags *****/ CAMLprim value ocaml_lame_id3tag_init(value l) { CAMLparam1(l); id3tag_init(Lame_val(l)); CAMLreturn(Val_unit); } #define BIND_TAG_PARAM(p) \ CAMLprim value ocaml_lame_id3tag_set_##p(value l, value v) { \ CAMLparam2(l, v); \ id3tag_set_##p(Lame_val(l), String_val(v)); \ CAMLreturn(Val_unit); \ } BIND_TAG_PARAM(title); BIND_TAG_PARAM(artist); BIND_TAG_PARAM(album); BIND_TAG_PARAM(year); BIND_TAG_PARAM(comment); BIND_TAG_PARAM(track); /* TODO: check for errors. */ BIND_TAG_PARAM(genre); /***** Informations *****/ BIND_GET_INT_PARAM(version); BIND_GET_INT_PARAM(encoder_delay); BIND_GET_INT_PARAM(framesize); BIND_GET_INT_PARAM(mf_samples_to_encode); BIND_GET_INT_PARAM(frameNum); BIND_GET_INT_PARAM(totalframes); #define BIND_GET_STRING_PARAM(p) \ CAMLprim value ocaml_lame_get_##p(value unit) { \ CAMLparam1(unit); \ CAMLreturn(caml_copy_string(get_##p())); \ } BIND_GET_STRING_PARAM(lame_version); BIND_GET_STRING_PARAM(lame_short_version); BIND_GET_STRING_PARAM(lame_very_short_version); BIND_GET_STRING_PARAM(psy_version); BIND_GET_STRING_PARAM(lame_url);