Hi all !

While discussing the fact that dtools doesn't close stdout, we discovered 
that, while it's recommended for a proper daemon fork to close stdin, stdout 
and stderr, with a minimal test, it seems that writing to stdout while 
previously closed might crash the process..

Than I guess, we should take care of not using Print.printf in liquidsoap..

I've greped for Printf.printf, and found some use that are legal, such as in 
lang.ml, main.ml and dynliq.ml, and some that do not seem..

I've written quick and dirty patch to convert them to log#f, but perhaps you'd 
like to have it another way ?

Also, we should take care of process output from system() calls and co.. ?
I've tested closing stdout while liq uses scripts that output to stdout, seems 
it works, but needs to be confirmed...



Romain
Index: protocols/mpd.ml
===================================================================
--- protocols/mpd.ml	(révision 4934)
+++ protocols/mpd.ml	(copie de travail)
@@ -24,6 +24,8 @@
 
 module Conf = Dtools.Conf
 
+let log = Dtools.Log.make ["mpd"]
+
 let conf =
   Conf.void ~p:(Configure.conf#plug "mpd")
     "Parameters for the mpd protocol."
@@ -65,12 +67,12 @@
         n := Unix.recv socket buf 0 buflen [];
         ans := !ans ^ String.sub buf 0 !n
       done;
-      if debug then Printf.printf "R: %s%!" !ans;
+      if debug then log#f 4 "R: %s%!" !ans;
       !ans
   in
   let write s =
     let len = String.length s in
-      if debug then Printf.printf "W: %s%!" s;
+      if debug then log#f 4 "W: %s%!" s;
       assert (Unix.send socket s 0 len [] = len)
   in
     Unix.connect socket sockaddr;
@@ -113,7 +115,7 @@
              let f = Str.matched_group 1 s in
              let prefix = conf_path_prefix#get in
              let f = prefix ^ "/" ^ f in
-               if debug then Printf.printf "Found: %s\n%!" f;
+               if debug then log#f 4 "Found: %s\n%!" f;
                add ();
                file := f
            )
Index: visualization/vumeter.ml
===================================================================
--- visualization/vumeter.ml	(révision 4934)
+++ visualization/vumeter.ml	(copie de travail)
@@ -24,6 +24,8 @@
 
 open Source
 
+let log = Dtools.Log.make ["vumeter"]
+
 let screen_width = 80
 let rms_max = -5.
 let rms_min = -25.
@@ -54,9 +56,9 @@
     let vol = Array.fold_left (fun ans s -> ans ^ "  " ^ s) "" vol in
     let vol = String.sub vol 2 (String.length vol - 2) in
       if scroll then
-        Printf.printf "%s\n%!" vol
+        log#f 4 "%s\n%!" vol
       else
-        Printf.printf "\r%s%!" vol
+        log#f 4 "\r%s%!" vol
 end
 
 let () =
Index: operators/biquad_filter.ml
===================================================================
--- operators/biquad_filter.ml	(révision 4934)
+++ operators/biquad_filter.ml	(copie de travail)
@@ -24,6 +24,8 @@
 
 let pi = 3.14159265358979323846
 
+let dlog = Dtools.Log.make ["biquad-filter"]
+
 type filter_type = All_pass | Band_pass | High_pass | Low_pass
                    | Notch | Peak | High_shelf | Low_shelf
 
@@ -41,7 +43,7 @@
   initializer
     if debug then
       (
-        Printf.printf "================== BEG INIT FILTER %s ==================\n" self#id
+        dlog#f 4 "================== BEG INIT FILTER %s ==================\n" self#id
       ) ;
     let a =
       (match filter_type with
@@ -52,7 +54,7 @@
           (
             if debug then
               (
-                Printf.printf "A = 10 ^ (db_gain / 40) = %+.013f\n" (10. ** (db_gain /. 40.))
+                dlog#f 4 "A = 10 ^ (db_gain / 40) = %+.013f\n" (10. ** (db_gain /. 40.))
               ) ;
             10. ** (db_gain /. 40.)
           )
@@ -62,7 +64,7 @@
     let w0 = 2. *. pi *. freq /. float_of_int (Fmt.samples_per_second ()) in
     if debug then
       (
-        Printf.printf "ω0 = 2π f0 / Fs = %+.013f.\n" w0
+        dlog#f 4 "ω0 = 2π f0 / Fs = %+.013f.\n" w0
       ) ;
     let alpha =
       (match filter_type with
@@ -74,8 +76,8 @@
           (
             if debug then
               (
-                Printf.printf "BW = %+.013f\n" fparam ;
-                Printf.printf "α = sin(w0)*sinh(ln(2)/2 * BW * (w0/sin(w0)))\n"
+                dlog#f 4 "BW = %+.013f\n" fparam ;
+                dlog#f 4 "α = sin(w0)*sinh(ln(2)/2 * BW * (w0/sin(w0)))\n"
               ) ;
             (sin w0) *. sinh (fparam *. (w0 /. sin w0) *. ((log 2.) /. 2.))
           )
@@ -85,8 +87,8 @@
           (
             if debug then
               (
-                Printf.printf "S = %+.013f\n" fparam ;
-                Printf.printf "α = sin(w0)/2 * √ ((A + 1/A) * (1/S - 1) + 2)\n"
+                dlog#f 4 "S = %+.013f\n" fparam ;
+                dlog#f 4 "α = sin(w0)/2 * √ ((A + 1/A) * (1/S - 1) + 2)\n"
               ) ;
             ((sin w0) /. 2.)
               *. sqrt ((a +. 1. /. a) *. ((1. /. fparam) -. 1.) +. 2.)
@@ -96,21 +98,21 @@
           (
             if debug then
               (
-                Printf.printf "Q = %+.013f\n" fparam ;
-                Printf.printf "α = sin(w0) / 2Q\n";
+                dlog#f 4 "Q = %+.013f\n" fparam ;
+                dlog#f 4 "α = sin(w0) / 2Q\n";
               ) ;
             (sin w0) /. (2. *. fparam))
           )
     in
       if debug then
         (
-          Printf.printf "α = %+.013f\n" alpha
+          dlog#f 4 "α = %+.013f\n" alpha
         ) ;
       let c0 = cos w0 in
         coeffs <-
           (match filter_type with
             | Low_pass ->
-              if debug then (Printf.printf "This is a low-pass filter.\n") ;
+              if debug then (dlog#f 4 "This is a low-pass filter.\n") ;
               let a0 = 1. +. alpha in
                 [| (1. -. c0) /. (2. *. a0) ;    (* b0/a0 *)
                    (1. -. c0) /. a0 ;            (* b1/a0 *)
@@ -118,7 +120,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. alpha) /. a0 |]        (* a2/a0 *)
             | High_pass ->
-              if debug then (Printf.printf "This is a high-pass filter.\n") ;
+              if debug then (dlog#f 4 "This is a high-pass filter.\n") ;
               let a0 = 1. +. alpha in
                 [| (1. +. c0) /. (2. *. a0) ;    (* b0/a0 *)
                    -. (1. +. c0) /. a0 ;         (* b1/a0 *)
@@ -126,7 +128,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. alpha) /. a0 |]        (* a2/a0 *)
             | Band_pass ->
-              if debug then (Printf.printf "This is a band-pass filter.\n") ;
+              if debug then (dlog#f 4 "This is a band-pass filter.\n") ;
               let a0 = 1. +. alpha in
                 [| alpha /. a0 ;                 (* b0/a0 *)
                    0. ;                          (* b1/a0 *)
@@ -134,7 +136,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. alpha) /. a0 |]        (* a2/a0 *)
             | Notch ->
-              if debug then (Printf.printf "This is a notch filter.\n") ;
+              if debug then (dlog#f 4 "This is a notch filter.\n") ;
               let a0 = 1. +. alpha in
                 [| 1. /. a0 ;                    (* b0/a0 *)
                    (-. 2. *. c0) /. a0 ;         (* b1/a0 *)
@@ -142,7 +144,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. alpha) /. a0 |]        (* a2/a0 *)
             | All_pass ->
-              if debug then (Printf.printf "This is an all-pass filter.\n") ;
+              if debug then (dlog#f 4 "This is an all-pass filter.\n") ;
               let a0 = 1. +. alpha in
                 [| (1. -. alpha) /. a0 ;         (* b0/a0 *)
                    (-. 2. *. c0) /. a0 ;         (* b1/a0 *)
@@ -150,7 +152,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. alpha) /. a0 |]        (* a2/a0 *)
             | Peak ->
-              if debug then (Printf.printf "This is a peak filter.\n") ;
+              if debug then (dlog#f 4 "This is a peak filter.\n") ;
               let a0 = 1. +. (alpha /. a) in
                 [| (1. +. (alpha *. a)) /. a0 ;  (* b0/a0 *)
                    (-. 2. *. c0) /. a0 ;         (* b1/a0 *)
@@ -158,7 +160,7 @@
                    (-. 2. *. c0) /. a0 ;         (* a1/a0 *)
                    (1. -. (alpha /. a)) /. a0 |] (* a2/a0 *)
             | Low_shelf ->
-              if debug then (Printf.printf "This is a low-shelf filter.\n") ;
+              if debug then (dlog#f 4 "This is a low-shelf filter.\n") ;
               let s = 2. *. (sqrt a) *. alpha in
               let a0 = (a +. 1.) +. (a -. 1.) *. c0 +. s in
                 [| (a *. ((a +. 1.) -. (a -. 1.) *. c0 +. s)) /. a0 ;     (* b0/a0 *)
@@ -167,7 +169,7 @@
                    (-. 2. *. ((a -. 1.) +. (a +. 1.) *. c0)) /. a0 ;      (* a1/a0 *)
                    ((a +. 1.) +. (a -. 1.) *. c0 -. s) /. a0 |]           (* a2/a0 *)
             | High_shelf ->
-              if debug then (Printf.printf "This is an high-shelf filter.\n") ;
+              if debug then (dlog#f 4 "This is an high-shelf filter.\n") ;
               let s = 2. *. (sqrt a) *. alpha in
               let a0 = (a +. 1.) -. (a -. 1.) *. c0 +. s in
                 [| (a *. ((a +. 1.) +. (a -. 1.) *. c0 +. s)) /. a0 ;     (* b0/a0 *)
@@ -177,8 +179,8 @@
                    ((a +. 1.) -. (a -. 1.) *. c0 -. s) /. a0 |]           (* a2/a0 *)) ;
         if debug then
           (
-            Printf.printf "Coefficients:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) coeffs)))) ;
-            Printf.printf "================== END INIT FILTER %s ==================\n" self#id
+            dlog#f 4 "Coefficients:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) coeffs)))) ;
+            dlog#f 4 "================== END INIT FILTER %s ==================\n" self#id
           )
   
   (* Digital filter based on "Cookbook formulae for audio EQ biquad filter
Index: operators/st_bpm.ml
===================================================================
--- operators/st_bpm.ml	(révision 4934)
+++ operators/st_bpm.ml	(copie de travail)
@@ -22,6 +22,8 @@
 
 open Source
 
+let log = Dtools.Log.make ["bpm"]
+
 class bpm (source:source) every =
 object (self)
   inherit operator [source] as super
@@ -43,7 +45,7 @@
       if n >= every then
         (
           n <- 0;
-          Printf.printf "BPM: %.02f\n%!" (Soundtouch.BPM.get_bpm bpm)
+          log#f 4 "BPM: %.02f\n%!" (Soundtouch.BPM.get_bpm bpm)
         )
 
 end
Index: operators/normalize.ml
===================================================================
--- operators/normalize.ml	(révision 4934)
+++ operators/normalize.ml	(copie de travail)
@@ -22,6 +22,8 @@
 
 open Source
 
+let log = Dtools.Log.make ["normalize"]
+
 class normalize (source:source)
            rmst  (** RMS target. *)
            window  (** Number of samples for computing rms. *)
@@ -76,7 +78,7 @@
                 (
                   let rmsl = sqrt (rms.(0) /. (float_of_int rmsi)) in
                   let rmsr = sqrt (rms.(1) /. (float_of_int rmsi)) in
-                    Printf.printf "%6.02f  *  %4.02f  ->  %6.02f    |    %6.02f  *  %4.02f  ->  %6.02f\n%!"
+                    log#f 4 "%6.02f  *  %4.02f  ->  %6.02f    |    %6.02f  *  %4.02f  ->  %6.02f\n%!"
                       (Sutils.dB_of_lin rmsl)
                       v.(0)
                       (Sutils.dB_of_lin (rmsl *. v.(0)))
Index: operators/fir_filter.ml
===================================================================
--- operators/fir_filter.ml	(révision 4934)
+++ operators/fir_filter.ml	(copie de travail)
@@ -25,6 +25,8 @@
 
 let pi = 3.14159265358979323846
 
+let log = Dtools.Log.make ["fir-filter"]
+
 class fir (source:source) freq beta numcoeffs debug =
 object (self)
   inherit operator [source] as super
@@ -48,8 +50,8 @@
   initializer
     if debug then
       (
-        Printf.printf "================== BEG INIT FILTER %s ==================\n" self#id ;
-        Printf.printf "Alpha: %+.013f.\nBeta: %+.013f.\nF1: %+.013f.\nF2: %+.013f.\nTau: %+.013f.\n# zeros: %d.\n" (freq /. (float_of_int (Fmt.samples_per_second ()))) beta f1 f2 tau nzeros
+        log#f 4 "================== BEG INIT FILTER %s ==================\n" self#id ;
+        log#f 4 "Alpha: %+.013f.\nBeta: %+.013f.\nF1: %+.013f.\nF2: %+.013f.\nTau: %+.013f.\n# zeros: %d.\n" (freq /. (float_of_int (Fmt.samples_per_second ()))) beta f1 f2 tau nzeros
       ) ;
     (* Init circle *)
     let circle =
@@ -106,12 +108,12 @@
                      (fun i x -> vec.((2048 - h + i) mod 2048).re /. 2048.)
                      xcoeffs;
         if debug then
-          Printf.printf "Xcoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) xcoeffs)))) ;
+          log#f 4 "Xcoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) xcoeffs)))) ;
         gain <- Array.fold_left (+.) 0. xcoeffs ;
         if debug then
           (
-            Printf.printf "Gain: %+.013f.\n" gain ;
-            Printf.printf "================== END INIT FILTER %s ==================\n" self#id
+            log#f 4 "Gain: %+.013f.\n" gain ;
+            log#f 4 "================== END INIT FILTER %s ==================\n" self#id
           )
   
   (* Digital filter based on mkfilter/mkshape/gencode by A.J. Fisher *)
Index: operators/iir_filter.ml
===================================================================
--- operators/iir_filter.ml	(révision 4934)
+++ operators/iir_filter.ml	(copie de travail)
@@ -25,6 +25,8 @@
 
 let pi = 3.14159265358979323846
 
+let log = Dtools.Log.make ["iir-filter"]
+
 type filter_type = Band_stop | Band_pass | High_pass | Low_pass | All_pass
 type filter_family = Butterworth | Resonator
 
@@ -71,10 +73,10 @@
   initializer
     if debug then
       (
-        Printf.printf "================== BEG INIT FILTER %s ==================\n" self#id ;
-        Printf.printf "Alpha 1: %.013f (warped: %.013f)\n" raw_alpha1 warped_alpha1 ;
-        Printf.printf "Alpha 2: %.013f (warped: %.013f)\n" raw_alpha2 warped_alpha2 ;
-        Printf.printf "Q: %.013f\n" qfactor
+        log#f 4 "================== BEG INIT FILTER %s ==================\n" self#id ;
+        log#f 4 "Alpha 1: %.013f (warped: %.013f)\n" raw_alpha1 warped_alpha1 ;
+        log#f 4 "Alpha 2: %.013f (warped: %.013f)\n" raw_alpha2 warped_alpha2 ;
+        log#f 4 "Q: %.013f\n" qfactor
       ) ;
     let cor a = {re = a ; im = 0.}
       and ( +~ ), ( -~ ), ( *~ ), ( /~ ) =
@@ -117,12 +119,12 @@
         | Butterworth ->
             (* Compute S-plane poles (Butterworth) *)
             if debug then
-              Printf.printf "This is a Butterworth filter.\n" ;
+              log#f 4 "This is a Butterworth filter.\n" ;
             let choosepole z =
               if (z.re < 0.) then
                 (
                   if debug then
-                    Printf.printf "z = %+.013f %+.013f i.\n" z.re z.im ;
+                    log#f 4 "z = %+.013f %+.013f i.\n" z.re z.im ;
                   if (polemask mod 2 == 0) then
                     (
                       splane_poles <- Array.append splane_poles [|z|] ;
@@ -132,7 +134,7 @@
                 ) ;
             in
               if debug then
-                Printf.printf "Theta:\n" ;
+                log#f 4 "Theta:\n" ;
               for i = 0 to (2 * order) - 1 do
                 let theta =
                   match (order mod 2) with
@@ -142,7 +144,7 @@
                     | _ -> assert false
                 in
                   if debug then
-                    Printf.printf "%d: %+.013f --> %+.013f %+.013f i.\n" i theta (cos theta) (sin theta) ;
+                    log#f 4 "%d: %+.013f --> %+.013f %+.013f i.\n" i theta (cos theta) (sin theta) ;
                   choosepole ({re = cos(theta) ; im = sin(theta)})
               done;
             (* Normalize *)
@@ -153,7 +155,7 @@
                 | Band_stop ->
                     (* Band-stop filter *)
                     if debug then
-                      Printf.printf "This is a band-stop filter.\n" ;
+                      log#f 4 "This is a band-stop filter.\n" ;
                     let w0 = sqrt (w1 *~ w2)
                       and bw = w2 -~ w1
                     in
@@ -181,7 +183,7 @@
                 | Band_pass ->
                     (* Band-pass filter *)
                     if debug then
-                      Printf.printf "This is a band-pass filter.\n" ;
+                      log#f 4 "This is a band-pass filter.\n" ;
                     let w0 = sqrt (w1 *~ w2)
                       and bw = w2 -~ w1
                     in
@@ -207,7 +209,7 @@
                 | High_pass ->
                     (* Hi-pass filter *)
                     if debug then
-                      Printf.printf "This is a hi-pass filter.\n" ;
+                      log#f 4 "This is a hi-pass filter.\n" ;
                     for i = 0 to splane_numpoles - 1 do
                       splane_poles.(i) <- w1 /~ splane_poles.(i) ;
                     done;
@@ -221,7 +223,7 @@
                 | Low_pass ->
                     (* Lo-pass filter *)
                     if debug then
-                      Printf.printf "This is a lo-pass filter.\n" ;
+                      log#f 4 "This is a lo-pass filter.\n" ;
                     for i = 0 to splane_numpoles - 1 do
                       splane_poles.(i) <- splane_poles.(i) *~ w1 ;
                     done;
@@ -232,8 +234,8 @@
             (* Compute Z-plane zeros & poles using bilinear transform *)
             if debug then
               (
-                Printf.printf "S-Plane zeros:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) splane_zeros)))) ;
-                Printf.printf "S-Plane poles:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) splane_poles))))
+                log#f 4 "S-Plane zeros:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) splane_zeros)))) ;
+                log#f 4 "S-Plane poles:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) splane_poles))))
               ) ;
             zplane_numpoles <- splane_numpoles ;
             zplane_numzeros <- splane_numzeros ;
@@ -255,14 +257,14 @@
               done;
             if debug then
               (
-                Printf.printf "Z-Plane zeros:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) zplane_zeros)))) ;
-                Printf.printf "Z-Plane poles:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) zplane_poles))))
+                log#f 4 "Z-Plane zeros:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) zplane_zeros)))) ;
+                log#f 4 "Z-Plane poles:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) zplane_poles))))
               )
         | Resonator ->
             (* Compute Z-plane zeros and poles (Resonator). Let's admit we're
             creating a bandpass filter, we'll transform later if needed. *)
             if debug then
-              Printf.printf "This is a Resonator filter.\n" ;
+              log#f 4 "This is a Resonator filter.\n" ;
             zplane_numpoles <- 2 ;
             zplane_numzeros <- 2 ;
             zplane_zeros <- [|cor 1. ; cor (-1.)|] ;
@@ -271,7 +273,7 @@
               if (qfactor == infinity) then
                 (
                   if debug then
-                    Printf.printf "Infinite Q factor!\n" ;
+                    log#f 4 "Infinite Q factor!\n" ;
                   (* oscillator *)
                   let zp = {re = cos theta ; im = sin theta } in
                     zplane_poles <- [|zp ; Complex.conj zp|]
@@ -313,7 +315,7 @@
                   | Band_stop ->
                       (* Band-stop filter *)
                       if debug then
-                        Printf.printf "This is a band-stop filter.\n" ;
+                        log#f 4 "This is a band-stop filter.\n" ;
                       (* compute Z-plane pole & zero positions for bandstop
                       resonator (notch filter) *)
                       (* place zeros exactly *)
@@ -322,7 +324,7 @@
                   | All_pass ->
                       (* All-pass filter *)
                       if debug then
-                        Printf.printf "This is an all-pass filter.\n" ;
+                        log#f 4 "This is an all-pass filter.\n" ;
                       (* compute Z-plane pole & zero positions for allpass
                       resonator *)
                       zplane_zeros.(0) <- zplane_poles.(0) /~
@@ -332,13 +334,13 @@
                   | Band_pass -> () ;
                   | _ -> assert false ) ) ;
       (* Now expand the polynomials *)
-      Printf.printf "Expanding polynomials...\n" ;
+      log#f 4 "Expanding polynomials...\n" ;
       topcoeffs <- expand zplane_zeros zplane_numzeros ;
       botcoeffs <- expand zplane_poles zplane_numpoles ;
       if debug then
         (
-          Printf.printf "Top coeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) topcoeffs)))) ;
-          Printf.printf "Bottom coeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) botcoeffs))))
+          log#f 4 "Top coeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) topcoeffs)))) ;
+          log#f 4 "Bottom coeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f %+.013f i." i a.re a.im) botcoeffs))))
         ) ;
       (* Gain *)
       dc_gain <- evaluate topcoeffs zplane_numzeros botcoeffs
@@ -357,14 +359,14 @@
                 | High_pass -> Complex.norm hf_gain
                 | Low_pass -> Complex.norm dc_gain ) ;
       if debug then
-        Printf.printf "Gains:\nDC:     %+.013f.\nCentre: %+.013f.\nHF:     %+.013f.\nFinal:  %+.013f.\n" (Complex.norm dc_gain) (Complex.norm fc_gain) (Complex.norm hf_gain) gain ;
+        log#f 4 "Gains:\nDC:     %+.013f.\nCentre: %+.013f.\nHF:     %+.013f.\nFinal:  %+.013f.\n" (Complex.norm dc_gain) (Complex.norm fc_gain) (Complex.norm hf_gain) gain ;
       (* X-coeffs *)
       for i = 0 to zplane_numzeros do
         xcoeffs <- Array.append xcoeffs
                      [|topcoeffs.(i).re /. botcoeffs.(zplane_numpoles).re|] ;
       done;
       if debug then
-        Printf.printf "Xcoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) xcoeffs)))) ;
+        log#f 4 "Xcoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) xcoeffs)))) ;
       (* Y-coeffs *)
       for i = 0 to zplane_numpoles do
         ycoeffs <- Array.append ycoeffs
@@ -372,8 +374,8 @@
       done;
       if debug then
         (
-          Printf.printf "Ycoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) ycoeffs)))) ;
-          Printf.printf "================== END INIT FILTER %s ==================\n" self#id
+          log#f 4 "Ycoeffs:\n%s\n" (String.concat "\n" (Array.to_list ((Array.mapi (fun i a -> Printf.sprintf "%d: %+.013f." i a) ycoeffs)))) ;
+          log#f 4 "================== END INIT FILTER %s ==================\n" self#id
         ) 
   
   (* Digital filter based on mkfilter/mkshape/gencode by A.J. Fisher *)
Index: operators/compress.ml
===================================================================
--- operators/compress.ml	(révision 4934)
+++ operators/compress.ml	(copie de travail)
@@ -24,6 +24,8 @@
 
 (** See http://www.musicdsp.org/archive.php?classid=4#169 *)
 
+let log = Dtools.Log.make ["compress"]
+
 class compress (source:source) attack release threshold ratio knee rmsw gn debug =
   (** Number of samples for computing rms. *)
   let rmsn = Fmt.samples_of_seconds rmsw in
@@ -140,7 +142,7 @@
                 (* Debug messages. *)
                 count <- count + 1;
                 if debug && count mod 10000 = 0 then
-                  Printf.printf "RMS:%7.02f     Env:%7.02f     Gain: %4.02f\r%!" (Sutils.dB_of_lin amp) (Sutils.dB_of_lin env) gain
+                  log#f 4 "RMS:%7.02f     Env:%7.02f     Gain: %4.02f\r%!" (Sutils.dB_of_lin amp) (Sutils.dB_of_lin env) gain
 
         done;
         (* Reset values if it is the end of the track. *)
Index: operators/pitch.ml
===================================================================
--- operators/pitch.ml	(révision 4934)
+++ operators/pitch.ml	(copie de travail)
@@ -22,6 +22,8 @@
 
 open Source
 
+let dlog = Dtools.Log.make ["pitch"]
+
 let average_diff delta buf ofs len =
   let s = ref 0. in
     for i = 0 to len - delta - 1 do
@@ -93,14 +95,14 @@
             let d = average_diff l databuf 0 length in
               if d < !d_opt then
                 (
-                  (* Printf.printf "d: %.02f      l: %d\n%!" d l; *)
+                  (* dlog#f 4 "d: %.02f      l: %d\n%!" d l; *)
                   d_opt := d;
                   wl_opt := l
                 )
           done;
           let f = samples_per_second /. float !wl_opt in
           let f = if f > freq_max then 0. else f in
-            Printf.printf "Found frequency: %.02f (%s)\n%!" f (string_of_note (note_of_freq f))
+            dlog#f 4 "Found frequency: %.02f (%s)\n%!" f (string_of_note (note_of_freq f))
 end
 
 let () =

Répondre à