Changeset 494

Show
Ignore:
Timestamp:
08/08/07 22:55:01 (1 year ago)
Author:
shans
Message:

Instruments created from simple wave functions (for now - from
parameterised sound functions soon!)

Files:

Legend:

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

    r493 r494  
    11ALL: all 
    22 
    3 COMPONENTS = remix time sound wave envelope transparency layer track 
    4 TESTS = sound_test_sin layer_test_sins track_test_sins 
     3COMPONENTS = remix time sound tone wave envelope transparency layer track \ 
     4                                     instrument 
     5TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test 
    56INCLUDES=-I +extlib 
    67OBJECTS=extLib unix oss 
     
    1415OPTTESTS = $(patsubst %, %.opt, $(TESTS)) 
    1516 
    16 OCAMLCARGS = $(INCLUDES) $(OBJECTS_CMA) -g 
    17 OCAMLOPTARGS = $(INCLUDES) $(OBJECTS_CMXA)  
     17OCAMLPP = -pp "camlp4o ./pa_operators.cmo" 
     18OCAMLCARGS = $(INCLUDES) $(OBJECTS_CMA) -w s -g $(OCAMLPP) 
     19OCAMLOPTARGS = $(INCLUDES) $(OBJECTS_CMXA) -w s -g $(OCAMLPP) 
     20 
     21 
     22pa_operators.cmo: pa_operators.ml 
     23        ocamlc -I +camlp4 camlp4lib.cma -pp camlp4of pa_operators.ml 
    1824 
    1925remix.cma: $(INTERFACES) $(SOURCES) oss.cma 
     
    3743        ocamlopt $(OCAMLOPTARGS) $^ -o $@ 
    3844 
    39 all: remix.cma $(BINTESTS) 
     45all: pa_operators.cmo remix.cma $(BINTESTS) 
    4046 
    41 all.opt: remix.cmxa $(OPTTESTS) 
     47all.opt: pa_operators.cmo remix.cmxa $(OPTTESTS) 
    4248 
    4349clean:  
  • ocaml-remix/trunk/layer_test_sins.ml

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

    r493 r494  
    66let len = float_of_string Sys.argv.(3);; 
    77 
    8 let period = Time.Hertz rate;; 
    9  
    108let r = Remix.create 44000 2 120.;; 
    11 let four_second_A = Wave.sin amp period;; 
     9let four_second_A = Wave.sin amp rate;; 
    1210let envelope = Envelope.adsr (Time.Seconds 0.1) (Time.Seconds 0.4) 0.8 
    1311                                                        (Time.Seconds 0.1);; 
  • ocaml-remix/trunk/time.ml

    r488 r494  
    1818  | Seconds f -> sec_to_sam f 
    1919  | Samples i -> i 
    20   | Beats   f -> sec_to_sam (f /. (Remix.bpm r) /. 60.) 
     20  | Beats   f -> sec_to_sam (f /. (Remix.bpm r) *. 60.) 
    2121  | Hertz   f -> sec_to_sam (1. /. f);; 
    2222 
  • ocaml-remix/trunk/track_test_sins.ml

    r493 r494  
    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. (Time.Hertz 440.);; 
    8 let e = Wave.sin 20000. (Time.Hertz 660.);; 
     7let a = Wave.sin 30000. (Tone.note Tone.a 0);; 
     8let e = Wave.sin 20000. (Tone.note Tone.e 1);; 
    99let [a; e] = List.map (Envelope.apply env) [a; e];; 
    1010 
  • ocaml-remix/trunk/wave.ml

    r493 r494  
    1 type wave = float -> Time.time -> Sound.sound;; 
     1type wave = float -> float -> Sound.sound;; 
    22 
    33(* generator amplitude period(in samples) start(in samples) channels  
    44                                                        time(in samples) *) 
    5 type generator = float -> int -> int -> int -> int -> int;; 
     5type generator = float -> float -> int -> int -> int -> int;; 
    66 
    77exception AmplitudeTooHigh;; 
     
    1818  let stime = (time + start) / channels * channels in 
    1919  let coef = (float_of_int stime) *. 3.142 *. 2. in 
    20   round_to_int (amp *. (sin (coef /. (float_of_int period))));;  
     20  round_to_int (amp *. (sin (coef /. period)));;  
    2121 
    2222let square_generator amp period start channels time = 
    23   if (time + start) mod period < period/2 then int_of_float amp else 0;; 
     23  if mod_float (float_of_int (time + start)) period < period/.2.  
     24  then int_of_float amp else 0;; 
    2425 
    2526let tri_generator amp period start channels time = 
    2627  let stime = (time + start) / channels * channels in  
    2728  int_of_float ( 
    28     float_of_int (stime mod period) /. float_of_int period *. amp);; 
     29    (mod_float (float_of_int stime) period) /. period *. amp);; 
    2930 
    30 let generate generator amp period remix sound_extent (start, length) =  
     31let generate generator amp rate remix sound_extent (start, length) =  
    3132  if (amp > 32767. || amp < 0.) then raise AmplitudeTooHigh; 
    32   let raw_period = Time.time_to_raw_samples remix period in 
    3333  let raw_length = Time.time_to_raw_samples remix length in 
    3434  let raw_start = Time.time_to_raw_samples remix start in 
     35  let period = float_of_int (Remix.samplerate remix * Remix.channels remix)  
     36                                                            /. rate in 
    3537  let channels = Remix.channels remix in 
    36   Array.init raw_length (generator amp raw_period raw_start channels);; 
     38  Array.init raw_length (generator amp period raw_start channels);; 
    3739 
    3840let sin = generate sin_generator;; 
  • ocaml-remix/trunk/wave.mli

    r493 r494  
    1 type wave = float -> Time.time -> Sound.sound;; 
     1type wave = float -> float -> Sound.sound;; 
    22 
    33(* generator amplitude period(in samples) start(in samples) channels  
    44                                                        time(in samples) *) 
    5 type generator = float -> int -> int -> int -> int -> int;; 
     5type generator = float -> float -> int -> int -> int -> int;; 
    66 
    77val generate : generator -> wave;;