Changeset 498

Show
Ignore:
Timestamp:
08/18/07 13:08:29 (1 year ago)
Author:
shans
Message:

Simple volume specs and ramping implemented for sounds. Not correct for
instruments yet.

Files:

Legend:

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

    r494 r498  
    11ALL: all 
    22 
    3 COMPONENTS = remix time sound tone wave envelope transparency layer track
    4                                     instrument 
     3COMPONENTS = remix time volume sound tone wave envelope transparency layer
     4                        track instrument 
    55TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test 
    66INCLUDES=-I +extlib 
  • ocaml-remix/trunk/instrument.ml

    r495 r498  
    11 
    22type length = float;; 
    3 type amplitude = float;; 
     3type amplitude = Volume.volume;; 
    44 
    55type soundFunction = amplitude -> Tone.tone -> Sound.sound;; 
  • ocaml-remix/trunk/instrument.mli

    r495 r498  
    22 
    33type length = float;; (* measure length in beats *) 
    4 type amplitude = float;; 
     4type amplitude = Volume.volume;; 
    55 
    66val add_note : instrument -> Layer.layer -> amplitude -> Tone.tone -> length ->  
  • ocaml-remix/trunk/instrument_test.ml

    r497 r498  
    1212let instrument2 = Instrument.from_sound_function ~start:6. (sf Wave.square);; 
    1313 
    14 let noteify (t,r,l) = (note t r, l);; 
     14let tonote (t,r,l) = (note t r, l);; 
    1515 
    1616let layer = Layer.empty ();; 
    17 Instrument.add_notes instrument1 layer 30000. (List.map noteify 
     17Instrument.add_notes instrument1 layer (Volume.Constant 30000.) (List.map tonote 
    1818  [(c, 0, 0.5); (d, 0, 0.5); (e, 0, 0.5); (f, 0, 0.5);  
    1919   (g, 0, 0.5); (a, 0, 0.5); (b, 0, 0.5); (c, 1, 2.5)]);; 
    2020 
    21 Instrument.add_notes instrument2 layer 30000. (List.map noteify 
     21Instrument.add_notes instrument2 layer (Volume.Constant 30000.) (List.map tonote 
    2222  [(g, -1, 0.5); (a, -1, 0.5); (b flat, -1, 0.5); (c, 0, 0.5);  
    2323   (d, 0, 0.5); (e flat, 0, 0.5); (f sharp, 0, 0.5); (g, 0, 2.5)]);; 
  • ocaml-remix/trunk/layer_test_sins.ml

    r494 r498  
    77                                                          (Time.Seconds 0.1);; 
    88 
    9 let a    = Envelope.apply e (Wave.sin 30000.    440.);; 
    10 let hi_a = Envelope.apply e (Wave.square 20000. 880.);; 
    11 let e    = Envelope.apply e (Wave.tri 20000.    660.);; 
     9let a    = Envelope.apply e (Wave.sin    (Volume.Constant 30000.) 440.);; 
     10let hi_a = Envelope.apply e (Wave.square (Volume.Constant 20000.) 880.);; 
     11let e    = Envelope.apply e (Wave.tri    (Volume.Constant 20000.) 660.);; 
    1212 
    1313let layer = Layer.empty ();; 
  • ocaml-remix/trunk/sound_test_sin.ml

    r494 r498  
    77 
    88let r = Remix.create 44000 2 120.;; 
    9 let four_second_A = Wave.sin amp rate;; 
     9let four_second_A = Wave.sin (Volume.Linear (0., amp)) rate;; 
    1010let envelope = Envelope.adsr (Time.Seconds 0.1) (Time.Seconds 0.4) 0.8 
    1111                                                        (Time.Seconds 0.1);; 
  • ocaml-remix/trunk/track_test_sins.ml

    r494 r498  
    55let env = Envelope.adsr (Time.Seconds 0.2) (Time.Seconds 0.6) 0.7  
    66                                                           (Time.Seconds 0.1);; 
    7 let a = Wave.sin 30000. (Tone.note Tone.a 0);; 
    8 let e = Wave.sin 20000. (Tone.note Tone.e 1);; 
     7let a = Wave.sin (Volume.Constant 30000.) (Tone.note Tone.a 0);; 
     8let e = Wave.sin (Volume.Constant 20000.) (Tone.note Tone.e 1);; 
    99let [a; e] = List.map (Envelope.apply env) [a; e];; 
    1010 
  • ocaml-remix/trunk/wave.ml

    r494 r498  
    1 type wave = float -> float -> Sound.sound;; 
     1type wave = Volume.volume -> float -> Sound.sound;; 
    22 
    33(* generator amplitude period(in samples) start(in samples) channels  
     
    2929    (mod_float (float_of_int stime) period) /. period *. amp);; 
    3030 
    31 let generate generator amp rate remix sound_extent (start, length) =  
    32   if (amp > 32767. || amp < 0.) then raise AmplitudeTooHigh; 
     31let generate generator volume rate remix (ss, slen) (start, length) =  
     32  let (startvol, endvol) = (match volume with 
     33    | Volume.Constant v -> (v,v) 
     34    | Volume.Linear (s,e) -> (s, e)) in 
     35  if (startvol > 32767. || startvol < 0.) then raise AmplitudeTooHigh; 
     36  if (endvol > 32767. || endvol < 0.) then raise AmplitudeTooHigh; 
    3337  let raw_length = Time.time_to_raw_samples remix length in 
    3438  let raw_start = Time.time_to_raw_samples remix start in 
     39  let raw_ss = Time.time_to_raw_samples remix ss in 
     40  let raw_slen = Time.time_to_raw_samples remix slen in 
    3541  let period = float_of_int (Remix.samplerate remix * Remix.channels remix)  
    3642                                                            /. rate in 
     43  let offset = (raw_start - raw_ss) in 
    3744  let channels = Remix.channels remix in 
    38   Array.init raw_length (generator amp period raw_start channels);; 
     45  let vfunc = fun p -> (float_of_int (p + offset) /. float_of_int raw_slen) *. 
     46                       (endvol -. startvol) +. startvol in 
     47  Array.init raw_length  
     48          (fun p -> generator (vfunc p) period raw_start channels p);; 
    3949 
    4050let sin = generate sin_generator;; 
  • ocaml-remix/trunk/wave.mli

    r494 r498  
    1 type wave = float -> float -> Sound.sound;; 
     1type wave = Volume.volume -> float -> Sound.sound;; 
    22 
    33(* generator amplitude period(in samples) start(in samples) channels