Changeset 512

Show
Ignore:
Timestamp:
10/23/07 08:07:12 (1 year ago)
Author:
shans
Message:

Moved "plugin" to "note" in line with original remix
Set up envelopes as notes
Started work on "continuous" (0, Forever) sounds and plugins
Added some repeat and shift utilities for notes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ocaml-remix/trunk/Makefile

    r510 r512  
    11ALL: all.opt 
    22 
    3 COMPONENTS = remix time volume sound plugin tone wave envelope transparency \ 
    4                         layer track instrument ladspa  
    5 TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test
    6                         ladspa_test 
     3COMPONENTS = remix time volume sound envelope note tone wave transparency \ 
     4                        layer track ladspa deck noteUtil 
     5TESTS = sound_test_sin layer_test_sins track_test_sins
     6                        ladspa_test continuous_sound_test 
    77INCLUDES=-I +extlib 
    88OBJECTS=extLib unix oss ladspa_raw 
  • ocaml-remix/trunk/envelope.ml

    r493 r512  
    55  let d = Time.time_to_raw_samples remix d in 
    66  let r = Time.time_to_raw_samples remix r in 
     7  if length = Time.Forever then 
     8    Printf.printf "can't create a non-terminating adsr envelope\n"; 
    79  let raw_length = Time.time_to_raw_samples remix length in 
    810  if pos <= a  
     
    1517 
    1618let apply envelope sound remix sound_extent render_extent = 
    17   let (ss, sl) = Time.extent_to_raw_samples remix sound_extent in 
     19  let ss = Time.time_to_raw_samples remix (fst sound_extent) in 
    1820  let (rs, rl) = Time.extent_to_raw_samples remix render_extent in 
    1921  let raw_envelope = envelope remix sound_extent in 
  • ocaml-remix/trunk/layer.ml

    r508 r512  
    11(** a layer consists of a list of sounds with start times and lengths, and 
    22    a transparency list (nb: default transparency is 0.0) *) 
    3 type layer = {mutable la_plugins:(Time.extent * Plugin.plugin) list; 
     3type layer = {mutable la_notes:(Time.extent * Note.note) list; 
    44              mutable la_transparency: 
    55              (Time.extent * Transparency.transparency) list};; 
     
    77exception OverlappingSounds;; 
    88 
    9 let empty () = {la_plugins=[]; la_transparency=[]};; 
     9let empty () = {la_notes=[]; la_transparency=[]};; 
    1010 
    11 let add_plugin layer plugin extent = 
    12   layer.la_plugins <- (extent, plugin)::layer.la_plugins;; 
     11let add_note layer plugin extent = 
     12  layer.la_notes <- (extent, plugin)::layer.la_notes;; 
    1313 
    1414let add_transparency layer trans extent = 
     
    3131    | [] -> () in 
    3232  Printf.printf "layer is:\n";  
    33   _print_sounds layer.la_plugins; 
     33  _print_sounds layer.la_notes; 
    3434  _print_transparencies layer.la_transparency;; 
    3535 
     
    5757 *          <----render----> 
    5858 *) 
    59 let to_sound layer undersound remix layer_extent (render_start, render_length)
    60   let raw_render_start = Time.time_to_raw_time remix render_start in 
    61   let raw_render_length = Time.time_to_raw_time remix render_length in 
     59let to_note layer undersound remix _ render_extent
     60  let (raw_render_start, raw_render_length) =  
     61      Time.extent_to_raw_time remix render_extent in 
    6262  let sound = Array.create (raw_render_length * Remix.channels remix) 0 in 
    6363  let rec _layer_to_sound laylist = match laylist with 
    6464    | []                    -> () 
    65     | ((start,length),s)::t   -> ( 
    66         let raw_start = Time.time_to_raw_time remix start in 
    67         let raw_length = Time.time_to_raw_time remix length in 
    68         if (raw_start + raw_length > raw_render_start) && 
    69            (raw_render_start + raw_render_length > raw_start) 
    70         then ( 
    71           let rs = max raw_start raw_render_start in 
    72           let rl = (min (raw_render_start + raw_render_length)  
    73                             (raw_start + raw_length)) - rs in 
    74           let raw_sound = (s undersound) remix (start,length)  
    75                                 (Time.Samples rs, Time.Samples rl) in 
     65    | ((start,length),ss)::t   -> ( 
     66        let (s, l) = Time.overlap remix render_extent (start, length) in 
     67        let (rs, rl) = Time.extent_to_raw_time remix (s, l) in 
     68        if rl > 0 then ( 
     69          let raw_sound = (ss undersound) remix (start, length) (s, l) in 
    7670          Array.blit raw_sound 0 sound 
    7771                         ((rs - raw_render_start) * Remix.channels remix)  
    7872                         (rl * Remix.channels remix)); 
    7973        _layer_to_sound t) in 
    80   _layer_to_sound layer.la_plugins; 
     74  _layer_to_sound layer.la_notes; 
    8175  sound;; 
    82  
    83  
  • ocaml-remix/trunk/layer.mli

    r508 r512  
    44 
    55(** add_sound remix layer sound start length *) 
    6 val add_plugin : layer -> Plugin.plugin -> Time.extent -> unit;; 
     6val add_note : layer -> Note.note -> Time.extent -> unit;; 
    77 
    8 val to_sound : layer -> Sound.sound -> Sound.sound;; 
     8val to_note : layer -> Sound.sound -> Sound.sound;; 
    99 
    1010val add_transparency : layer -> Transparency.transparency ->  
  • ocaml-remix/trunk/layer_test_sins.ml

    r508 r512  
    77                                                          (Time.Seconds 0.1);; 
    88 
    9 let a    = Plugin.from_sound  
     9let a    = Note.from_sound  
    1010                (Envelope.apply e (Wave.sin    (Volume.constant 30000.) 440.));; 
    11 let hi_a = Plugin.from_sound  
     11let hi_a = Note.from_sound  
    1212                (Envelope.apply e (Wave.square (Volume.constant 20000.) 880.));; 
    13 let e    = Plugin.from_sound 
     13let e    = Note.from_sound 
    1414                (Envelope.apply e (Wave.tri    (Volume.constant 20000.) 660.));; 
    1515 
    1616let layer = Layer.empty ();; 
    17 Layer.add_plugin layer a    (Time.Seconds 2.0, Time.Seconds 4.0);; 
    18 Layer.add_plugin layer hi_a (Time.Seconds 6.0, Time.Seconds 2.0);; 
    19 Layer.add_plugin layer e    (Time.Seconds 12.0, Time.Seconds 3.0);; 
     17Layer.add_note layer a    (Time.Seconds 2.0, Time.Seconds 4.0);; 
     18Layer.add_note layer hi_a (Time.Seconds 6.0, Time.Seconds 2.0);; 
     19Layer.add_note layer e    (Time.Seconds 12.0, Time.Seconds 3.0);; 
    2020 
    2121Layer.print layer;; 
    22 let sound = Layer.to_sound layer Sound.silence;; 
     22let sound = Layer.to_note layer Sound.silence;; 
    2323                                                             
    2424Sound.preview remix sound (Time.Seconds 0.0, Time.Seconds 15.0)  
  • ocaml-remix/trunk/sound.ml

    r508 r512  
    3535 
    3636let preview remix sound sound_extent (start,length) = 
     37  let raw_start = Time.time_to_raw_time remix start in 
     38  let raw_inc = Time.time_to_raw_time remix (Time.Seconds 0.2) in 
    3739  let dev = Oss.sound_open () in 
    3840  Oss.sound_set_parms dev (Remix.channels remix) (Remix.samplerate remix);  
    39   let raw_start = Time.time_to_raw_time remix start in 
    40   let raw_length = Time.time_to_raw_time remix length in 
    41   let raw_inc = Time.time_to_raw_time remix (Time.Seconds 0.2) in 
    4241  let t = ref raw_start in 
    43   while !t < raw_length do ( 
     42  let cond =  
     43    ( 
     44      if length = Time.Forever  
     45      then (fun a -> true) 
     46      else ( 
     47        let raw_length = Time.time_to_raw_time remix length in 
     48        fun a -> a < raw_length 
     49      ) 
     50    ) in 
     51  while cond !t do ( 
    4452    Oss.sound_write dev  
    4553        (sound remix sound_extent (Time.Samples !t, Time.Samples raw_inc)); 
  • ocaml-remix/trunk/time.ml

    r494 r512  
    66            | Samples of int  
    77            | Beats of float  
    8             | Hertz of float;; 
     8            | Hertz of float 
     9            | Forever ;; 
    910 
    1011type raw_extent = raw_time * raw_time;; 
     
    1213(* an extent is a start and a length *) 
    1314type extent = time * time;; 
     15 
     16exception ButHowLongIsForever;; 
    1417 
    1518let time_to_raw_time r t =  
     
    1922  | Samples i -> i 
    2023  | Beats   f -> sec_to_sam (f /. (Remix.bpm r) *. 60.) 
    21   | Hertz   f -> sec_to_sam (1. /. f);; 
     24  | Hertz   f -> sec_to_sam (1. /. f) 
     25  | Forever   -> raise ButHowLongIsForever;; 
    2226 
    2327let time_to_raw_samples r t = time_to_raw_time r t * Remix.channels r;; 
     
    2933  (time_to_raw_samples r s, time_to_raw_samples r l);; 
    3034 
     35let t_max r a b = Samples (max (time_to_raw_time r a) (time_to_raw_time r b));; 
     36let t_min r a b = Samples (min (time_to_raw_time r a) (time_to_raw_time r b));; 
     37let t_add r a b =  
     38  if a = Forever || b = Forever then Forever else  
     39  Samples ((time_to_raw_time r a) + (time_to_raw_time r b));; 
     40let t_sub r a b =  
     41  if a = Forever then Forever else 
     42  Samples ((time_to_raw_time r a) - (time_to_raw_time r b));; 
     43 
     44let overlap r (astart, alen) (bstart, blen) = 
     45  let (s, e) = 
     46    let start = t_max r astart bstart in  
     47    if alen = Forever then (start, t_add r bstart blen) 
     48    else if blen = Forever then (start, t_add r astart alen) 
     49    else (start, t_min r (t_add r astart alen) (t_add r bstart blen)) in 
     50  (s, t_sub r e s) 
     51 
    3152let to_string time = 
    3253  match time with 
     
    3556  | Beats   b -> Printf.sprintf "%f beats"   b 
    3657  | Hertz   h -> Printf.sprintf "%f Hz"      h 
     58  | Forever   -> Printf.sprintf "Forever!" 
  • ocaml-remix/trunk/time.mli

    r488 r512  
    66            | Samples of int  
    77            | Beats of float  
    8             | Hertz of float;; 
     8            | Hertz of float 
     9            | Forever;; 
    910 
    1011type raw_extent = raw_time * raw_time;; 
     
    1920val extent_to_raw_samples : Remix.remix -> extent -> (int * int);; 
    2021 
     22val overlap : Remix.remix -> extent -> extent -> extent;; 
     23 
    2124val to_string : time -> string;; 
  • ocaml-remix/trunk/track.ml

    r508 r512  
    8888 * case 3,4,5,6: length=min(trans.end, render.end)-start 
    8989 *) 
    90 let to_sound track remix extent (start, length)  = 
     90let to_note track undersound remix extent (start, length)  = 
    9191  let layers = track.tr_layers in 
    9292  let rec _render_at pos remix extent (start, length) = 
    9393    maybe_gen_tcache track pos remix; 
    9494    let olayer = Layer.empty () in 
    95     let _add_s_to_out sound raw_start raw_length = Layer.add_plugin olayer  
    96                             (Plugin.from_sound sound) 
     95    let _add_s_to_out sound raw_start raw_length = Layer.add_note olayer  
     96                            (Note.from_sound sound) 
    9797                          (Time.Samples raw_start, Time.Samples raw_length) in 
    98     (*let _add_l_to_out layer = _add_s_to_out (Layer.to_sound layer) in*) 
    9998    let (layer, pretrans) = layers.(pos) in 
    10099    let (translist, _) = strip pretrans in 
     
    103102      | [] -> ( 
    104103        let sound2 = _render_at (pos + 1) in 
    105         let sound1 = Layer.to_sound layer sound2 in 
     104        let sound1 = Layer.to_note layer sound2 in 
    106105        _add_s_to_out sound1 raw_start raw_length 
    107106        (*_add_l_to_out layer raw_start raw_length*) 
     
    112111            let diff = min (elem.tce_raw_start - raw_start) raw_length in 
    113112            let sound2 = _render_at (pos + 1) in 
    114             let sound1 = Layer.to_sound layer sound2 in 
     113            let sound1 = Layer.to_note layer sound2 in 
    115114            _add_s_to_out sound1 raw_start diff;  
    116115            (* _add_l_to_out layer raw_start diff; *) 
     
    122121            let l = (min trans_end render_end) - raw_start in  
    123122            let sound2 = _render_at (pos + 1) in 
    124             let sound1 = (Layer.to_sound layer sound2) in 
     123            let sound1 = (Layer.to_note layer sound2) in 
    125124            let trans = elem.tce_transparency in  
    126125            let ext = (Time.Samples raw_start, Time.Samples l) in 
     
    133132    let raw_length = Time.time_to_raw_time remix length in 
    134133    _render_at_2 raw_start raw_length translist; 
    135     Layer.to_sound olayer Sound.silence remix extent (start, length) in 
     134    Layer.to_note olayer undersound remix extent (start, length) in 
    136135  _render_at 0 remix extent (start,length);; 
    137136       
  • ocaml-remix/trunk/track.mli

    r488 r512  
    55val add_layer : track -> Layer.layer -> unit;; 
    66 
    7 val to_sound : track -> Sound.sound;; 
     7val to_note : track -> Sound.sound -> Sound.sound;; 
  • ocaml-remix/trunk/track_test_sins.ml

    r511 r512  
    22   a period of 100 samples *) 
    33 
    4 let remix = Remix.create 44000 2 120.;; 
    54let env = Envelope.adsr (Time.Seconds 0.2) (Time.Seconds 0.6) 0.7  
    65                                                           (Time.Seconds 0.1);; 
     
    87let e = Wave.sin (Volume.constant 20000.) (Tone.note Tone.e 1);; 
    98let [a; e] = List.map (Envelope.apply env) [a; e];; 
    10 let [a; e] = List.map Plugin.from_sound [a; e];; 
     9let [a; e] = List.map Note.from_sound [a; e];; 
    1110 
    1211 
     
    1817let trans1 = Transparency.linear_ramp 0.0 1.0;; 
    1918let trans2 = Transparency.linear_ramp 1.0 0.0;; 
    20 Layer.add_plugin layer1 a (Time.Seconds 0.0, Time.Seconds 4.0);; 
    21 Layer.add_plugin layer1 a (Time.Seconds 6.0, Time.Seconds 4.0);; 
    22 Layer.add_plugin layer1 e (Time.Seconds 11.0, Time.Seconds 4.0);; 
     19Layer.add_note layer1 a (Time.Seconds 0.0, Time.Seconds 4.0);; 
     20Layer.add_note layer1 a (Time.Seconds 6.0, Time.Seconds 4.0);; 
     21Layer.add_note layer1 e (Time.Seconds 11.0, Time.Seconds 4.0);; 
    2322 
    2423let noise = Ladspa_raw.open_plugin "noise:noise_white";; 
    2524let setup_noise _ = 1.0;; 
    26 let noise_p = Plugin.from_ladspa noise (Plugin.ladspa_init setup_noise);; 
    27 Layer.add_plugin layer1 noise_p (Time.Seconds 4.0, Time.Seconds 2.0);; 
     25let noise_p = Note.from_ladspa noise (Note.ladspa_init setup_noise);; 
     26Layer.add_note layer1 noise_p (Time.Seconds 4.0, Time.Seconds 2.0);; 
    2827 
    2928Layer.add_transparency layer1 trans1 (Time.Seconds 0.0, Time.Seconds 4.0);; 
     
    3231 
    3332let layer2 = Layer.empty ();; 
    34 Layer.add_plugin layer2 e (Time.Seconds 0.0, Time.Seconds 4.0);; 
    35 Layer.add_plugin layer2 e (Time.Seconds 5.0, Time.Seconds 6.0);; 
    36 Layer.add_plugin layer2 a (Time.Seconds 12.0, Time.Seconds 4.0);; 
     33Layer.add_note layer2 e (Time.Seconds 0.0, Time.Seconds 4.0);; 
     34Layer.add_note layer2 e (Time.Seconds 5.0, Time.Seconds 6.0);; 
     35Layer.add_note layer2 a (Time.Seconds 12.0, Time.Seconds 4.0);; 
    3736 
    3837let layer3 = Layer.empty();; 
     
    4342  | 2 -> -90.0 
    4443  | _ -> 0.0;; 
    45 let plugin = Plugin.from_ladspa ladspa (Plugin.ladspa_init setup_plugin);; 
    46 Layer.add_plugin layer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);; 
     44let plugin = Note.from_ladspa ladspa (Note.ladspa_init setup_plugin);; 
     45Layer.add_note layer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);; 
    4746let trans = Transparency.linear_ramp 1.0 1.0;; 
    4847Layer.add_transparency layer3 trans (Time.Seconds 0.0, Time.Seconds 2.0);; 
     
    5453Track.add_layer track layer2;; 
    5554 
    56 let sound = Track.to_sound track;; 
     55let sound = Track.to_note track Sound.silence;; 
    5756let extent = (Time.Seconds 0.0, Time.Seconds 16.0);; 
    5857 
     58let remix = Remix.create 44000 2 120.;; 
    5959Sound.preview remix sound extent extent;; 
  • ocaml-remix/trunk/volume.ml

    r499 r512  
    1 type volume = Constant of float | Linear of float * float;; 
     1type volume =  
     2  | Constant of float  
     3  | Linear of float * float;; 
    24 
    35exception AmplitudeTooHigh 
     
    1012  Linear (s, e);; 
    1113 
    12 let amplitude volume position length = match volume with  
     14let amplitude remix volume position length =  
     15  match volume with  
    1316  | Constant v    -> v 
    14   | Linear (s, e) -> 
    15     (position /. length) *. (e -. s) +. s;; 
     17  | Linear (s, e) -> ( 
     18      if length = Time.Forever then 
     19        Printf.printf "I can't ramp forever\n"; 
     20      let raw_length = Time.time_to_raw_time remix length in 
     21      (float_of_int position /. float_of_int raw_length) *. (e -. s) +. s 
     22    );; 
  • ocaml-remix/trunk/volume.mli

    r499 r512  
    33val constant : float -> volume;; 
    44val ramp : float -> float -> volume;; 
    5 val amplitude : volume -> float -> float -> float;; 
     5val amplitude : Remix.remix -> volume -> int -> Time.time -> float;; 
  • ocaml-remix/trunk/wave.ml

    r499 r512  
    3333  let raw_start = Time.time_to_raw_samples remix start in 
    3434  let raw_ss = Time.time_to_raw_samples remix ss in 
    35   let raw_slen = Time.time_to_raw_samples remix slen in 
    3635  let period = float_of_int (Remix.samplerate remix * Remix.channels remix)  
    3736                                                            /. rate in 
    3837  let offset = (raw_start - raw_ss) in 
    3938  let channels = Remix.channels remix in 
    40   let vfunc = fun p -> Volume.amplitude volume (float_of_int (p + offset))  
    41                                                   (float_of_int raw_slen) in 
     39  let vfunc = fun p -> Volume.amplitude remix volume (p + offset) slen in 
    4240  Array.init raw_length  
    4341          (fun p -> generator (vfunc p) period raw_start channels p);;