Show
Ignore:
Timestamp:
07/02/09 13:37:13 (14 months ago)
Author:
smimram
Message:

Warning for non-existent channels + more modular code.

Files:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/liquidsoap/src/tools/mutils.ml

    r6344 r6716  
    2121 *****************************************************************************) 
    2222 
    23 let lin_of_dB x = 10. ** (x /. 20.) 
     23(** Convert a value into a channel number, checking that it actually exists. *) 
     24let to_chan v = 
     25  let n = Lang.to_int v in 
     26    if n >= Fmt.midi_channels () then 
     27      raise (Lang.Invalid_value (v, "channel number too big (try increasing lang.midi.channels)")) 
     28    else 
     29      n 
    2430 
    25 let dB_of_lin x = 20. *. log x /. log 10. 
    26  
    27 let clip x = min 1. (max (-.1.) x) 
     31(** Convert delta-times to ticks. *) 
     32let ticks_of_delta division tempo delta = 
     33  match division with 
     34    | Midi.Ticks_per_quarter tpq -> 
     35        (* These computations sometimes overflow on 32 bits. *) 
     36        let tpq = Int64.of_int tpq in 
     37        let tempo = Int64.of_int tempo in 
     38        let tps = Int64.of_int (Fmt.ticks_per_second ()) in 
     39        let ten = Int64.of_int 1000000 in 
     40        let delta = Int64.of_int delta in 
     41        let ( * ) = Int64.mul in 
     42        let ( / ) = Int64.div in 
     43          Int64.to_int ((((delta * tempo) / tpq) * tps) / ten) 
     44    | Midi.SMPTE (fps,res) -> 
     45        (delta * Fmt.ticks_per_second ()) / (fps * res)