Skip to content

Commit

Permalink
Release 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed May 20, 2022
1 parent 2703482 commit c6608ad
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 169 deletions.
10 changes: 10 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version=0.19.0
profile = 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
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.5.1 (20-05-2022)
=====
* Switch to `pkg-config` for library detection.
* Cleanup warnings

0.5.0 (07-10-2020)
=====
* Convert to Unix.read style API.
Expand Down
9 changes: 6 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
(lang dune 2.0)
(version 0.5.0)
(lang dune 2.8)
(version 0.5.1)
(name faad)
(source (github savonet/ocaml-faad))
(license GPL-2.0)
(authors "The Savonet Team <savonet-users@lists.sourceforge.net>")
(maintainers "Romain Beauxis <toots@rastageeks.org>")

(generate_opam_files true)
(use_standard_c_and_cxx_flags false)

(package
(name faad)
(synopsis "Bindings for the faad library which provides functions for decoding AAC audio files")
(depends
(dune (> 2.0))
conf-faad
conf-pkg-config
dune
dune-configurator)
)
88 changes: 47 additions & 41 deletions example/aac2wav.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*)

let bufsize = 16 * 1024

let src = ref ""
let dst = ref ""

Expand All @@ -42,21 +41,20 @@ let output_short chan n =
let usage = "usage: aac2wav [options] source destination"

let () =
Arg.parse
[]
(
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
);
Arg.parse []
(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 buflen = 1024 in
let buf = Bytes.create buflen in
Expand All @@ -71,11 +69,13 @@ let () =
for c = 0 to channels - 1 do
let n = a.(c).(i) *. 32767. in
let n = int_of_float n in
Bytes.set tmp (2 * (i * channels + c)) (char_of_int (n land 0xff));
Bytes.set tmp (2 * (i * channels + c) + 1) (char_of_int ((n lsr 8) land 0xff));
Bytes.set tmp (2 * ((i * channels) + c)) (char_of_int (n land 0xff));
Bytes.set tmp
((2 * ((i * channels) + c)) + 1)
(char_of_int ((n lsr 8) land 0xff))
done
done;
outbuf := !outbuf ^ (Bytes.to_string tmp)
outbuf := !outbuf ^ Bytes.to_string tmp
in

let decode_mp4 () =
Expand All @@ -85,22 +85,25 @@ let () =
let fill_out = fill_out channels in
let samples = Faad.Mp4.samples mp4 track in
Printf.printf "Input file: %d channels at %d Hz.\n%!" channels samplerate;
Array.iter (fun (i,t) -> Printf.printf "%s: %s\n%!" i t) (Faad.Mp4.metadata mp4);
Array.iter
(fun (i, t) -> Printf.printf "%s: %s\n%!" i t)
(Faad.Mp4.metadata mp4);
Printf.printf "%d tracks (AAC track: %d).\n%!" (Faad.Mp4.tracks mp4) track;
Printf.printf "%d samples.\n" samples;
for i = 0 to samples - 1 do
Printf.printf "Decoding sample: %d / %d (%d bytes).\r%!" i samples (String.length !outbuf);
Printf.printf "Decoding sample: %d / %d (%d bytes).\r%!" i samples
(String.length !outbuf);
let a = Faad.Mp4.decode mp4 track i dec in
fill_out a
done;
Printf.printf "\n%!";
channels, samplerate, !outbuf
(channels, samplerate, !outbuf)
in

let decode_aac () =
let len = Unix.read f buf 0 buflen in
let offset, samplerate, channels = Faad.init dec buf 0 len in
let buflen = Faad.min_bytes_per_channel * channels in
let buflen = Faad.min_bytes_per_channel * channels in
let consumed = ref buflen in
let aacbuf = Bytes.create buflen in

Expand All @@ -109,7 +112,7 @@ let () =
while !consumed <> 0 do
let n = Unix.read f aacbuf (buflen - !consumed) !consumed in
if n = 0 then raise End_of_file;
consumed := !consumed - n;
consumed := !consumed - n
done
in

Expand All @@ -126,21 +129,18 @@ let () =
consumed := c;
fill_out a
done;
channels, samplerate, !outbuf
(channels, samplerate, !outbuf)
with
| End_of_file
| Faad.Failed ->
channels, samplerate, !outbuf
| Faad.Error n as e ->
Printf.printf "Faad error %d: %s\n%!" n (Faad.error_message n);
raise e
| End_of_file | Faad.Failed -> (channels, samplerate, !outbuf)
| Faad.Error n as e ->
Printf.printf "Faad error %d: %s\n%!" n (Faad.error_message n);
raise e
in

let channels, samplerate, outbuf =
if Filename.check_suffix !src ".aac" || Filename.check_suffix !src ".AAC" then
decode_aac ()
else
decode_mp4 ()
if Filename.check_suffix !src ".aac" || Filename.check_suffix !src ".AAC"
then decode_aac ()
else decode_mp4 ()
in

(* Do the wav stuff. *)
Expand All @@ -151,12 +151,18 @@ let () =
output_string oc "WAVE";
output_string oc "fmt ";
output_int oc 16;
output_short oc 1; (* WAVE_FORMAT_PCM *)
output_short oc channels; (* channels *)
output_int oc samplerate; (* freq *)
output_int oc (samplerate * channels * 2); (* bytes / s *)
output_short oc (channels * 2); (* block alignment *)
output_short oc 16; (* bits per sample *)
output_short oc 1;
(* WAVE_FORMAT_PCM *)
output_short oc channels;
(* channels *)
output_int oc samplerate;
(* freq *)
output_int oc (samplerate * channels * 2);
(* bytes / s *)
output_short oc (channels * 2);
(* block alignment *)
output_short oc 16;
(* bits per sample *)
output_string oc "data";
output_int oc datalen;
output_string oc outbuf;
Expand Down
18 changes: 6 additions & 12 deletions faad.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.5.0"
version: "0.5.1"
synopsis:
"Bindings for the faad library which provides functions for decoding AAC audio files"
maintainer: ["Romain Beauxis <toots@rastageeks.org>"]
Expand All @@ -9,11 +9,14 @@ license: "GPL-2.0"
homepage: "https://github.com/savonet/ocaml-faad"
bug-reports: "https://github.com/savonet/ocaml-faad/issues"
depends: [
"dune" {> "2.0"}
"conf-faad"
"conf-pkg-config"
"dune" {>= "2.8"}
"dune-configurator"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {pinned}
["dune" "subst"] {dev}
[
"dune"
"build"
Expand All @@ -27,12 +30,3 @@ build: [
]
]
dev-repo: "git+https://github.com/savonet/ocaml-faad.git"
depexts: [
["faad2-dev"] {os-distribution = "alpine"}
["faad2"] {os-distribution = "arch"}
["faad2-devel"] {os-distribution = "centos"}
["faad2-devel"] {os-distribution = "fedora"}
["faad2-devel"] {os-family = "suse"}
["libfaad-dev"] {os-family = "debian"}
["faad2"] {os = "macos" & os-distribution = "homebrew"}
]
9 changes: 0 additions & 9 deletions faad.opam.template

This file was deleted.

38 changes: 16 additions & 22 deletions src/config/discover.ml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
module C = Configurator.V1

let faad_test_code = {|
#include <neaacdec.h>

int main()
{
NeAACDecHandle hAac = NeAACDecOpen();
unsigned char input[1024];
size_t input_size = 0;
unsigned long samplerate;
unsigned char channels;

char err = NeAACDecInit(hAac, input, input_size, &samplerate, &channels);

return 0;
}
|}

let () =
C.main ~name:"has_faad" (fun c ->
let has_faad = C.c_test c faad_test_code ~link_flags:["-lfaad -lm"] in

C.C_define.gen_header_file c ~fname:"config.h"
[ "HAS_FAAD", Switch has_faad ]);
C.main ~name:"faad2-pkg-config" (fun c ->
let default : C.Pkg_config.package_conf =
{ libs = ["-lfaad2"]; cflags = [] }
in
let conf =
match C.Pkg_config.get c with
| None -> default
| Some pc -> (
match
C.Pkg_config.query_expr_err pc ~package:"faad2" ~expr:"mad"
with
| Error msg -> failwith msg
| Ok deps -> deps)
in
C.Flags.write_sexp "c_flags.sexp" conf.cflags;
C.Flags.write_sexp "c_library_flags.sexp" conf.libs)
22 changes: 9 additions & 13 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
(synopsis "Ocaml bindings to libfaad")
(foreign_stubs
(language c)
(extra_deps config.h)
(names
faad_stubs
mp4atom
mp4ff
mp4meta
mp4sample
mp4tagupdate
mp4util)
(flags -DUSE_TAGGING))
(c_library_flags "-lfaad -lm"))
(names faad_stubs mp4atom mp4ff mp4meta mp4sample mp4tagupdate mp4util)
(flags
-DUSE_TAGGING
(:include c_flags.sexp)))
(c_library_flags
(:include c_library_flags.sexp)))

(rule
(targets config.h)
(action (run ./config/discover.exe)))
(targets c_flags.sexp c_library_flags.sexp)
(action
(run ./config/discover.exe)))
Loading

0 comments on commit c6608ad

Please sign in to comment.