Changeset 499
- Timestamp:
- 08/18/07 13:44:24 (1 year ago)
- Files:
-
- ocaml-remix/trunk/instrument.ml (modified) (1 diff)
- ocaml-remix/trunk/instrument_test.ml (modified) (1 diff)
- ocaml-remix/trunk/layer_test_sins.ml (modified) (1 diff)
- ocaml-remix/trunk/sound_test_sin.ml (modified) (1 diff)
- ocaml-remix/trunk/track_test_sins.ml (modified) (1 diff)
- ocaml-remix/trunk/volume.ml (modified) (1 diff)
- ocaml-remix/trunk/volume.mli (modified) (1 diff)
- ocaml-remix/trunk/wave.ml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ocaml-remix/trunk/instrument.ml
r498 r499 13 13 instrument.position <- instrument.position +. length;; 14 14 15 let rec add_notes instrument layer amplitude notes = match notes with 16 | (t,l)::r -> ( 17 add_note instrument layer amplitude t l; 18 add_notes instrument layer amplitude r) 19 | [] -> ();; 15 let calc_length l = List.fold_right (fun (t,l) s -> l +. s) l 0.;; 16 17 let add_notes instrument layer volume notes = 18 let start_pos = instrument.position in 19 let len = calc_length notes in 20 let rec _add_notes notes = 21 match notes with 22 | (t,l)::r -> ( 23 let spos = instrument.position -. start_pos in 24 let epos = spos +. l in 25 let s = Volume.amplitude volume spos len in 26 let e = Volume.amplitude volume epos len in 27 let newv = Volume.ramp s e in 28 add_note instrument layer newv t l; 29 _add_notes r) 30 | [] -> () in 31 _add_notes notes;; 20 32 ocaml-remix/trunk/instrument_test.ml
r498 r499 15 15 16 16 let layer = Layer.empty ();; 17 Instrument.add_notes instrument1 layer (Volume. Constant 30000.) (List.map tonote18 [(c, 0, 0.5); (d, 0, 0.5); (e, 0, 0.5); (f, 0, 0.5);19 (g, 0, 0.5); (a, 0, 0.5); (b, 0, 0.5); (c, 1, 2.5)]);;17 Instrument.add_notes instrument1 layer (Volume.ramp 5000. 30000.) 18 (List.map tonote [(c, 0, 0.5); (d, 0, 0.5); (e, 0, 0.5); (f, 0, 0.5); 19 (g, 0, 0.5); (a, 0, 0.5); (b, 0, 0.5); (c, 1, 2.5)]);; 20 20 21 Instrument.add_notes instrument2 layer (Volume. Constant 30000.) (List.map tonote22 [(g, -1, 0.5); (a, -1, 0.5); (b flat, -1, 0.5); (c, 0, 0.5);23 (d, 0, 0.5); (e flat, 0, 0.5); (f sharp, 0, 0.5); (g, 0, 2.5)]);;21 Instrument.add_notes instrument2 layer (Volume.ramp 30000. 5000.) 22 (List.map tonote [(g, -1, 0.5); (a, -1, 0.5); (b flat, -1, 0.5); (c, 0, 0.5); 23 (d, 0, 0.5); (e flat, 0, 0.5); (f sharp, 0, 0.5); (g, 0, 2.5)]);; 24 24 25 25 let sound = Layer.to_sound layer;; ocaml-remix/trunk/layer_test_sins.ml
r498 r499 7 7 (Time.Seconds 0.1);; 8 8 9 let a = Envelope.apply e (Wave.sin (Volume. Constant 30000.) 440.);;10 let hi_a = Envelope.apply e (Wave.square (Volume. Constant 20000.) 880.);;11 let e = Envelope.apply e (Wave.tri (Volume. Constant 20000.) 660.);;9 let a = Envelope.apply e (Wave.sin (Volume.constant 30000.) 440.);; 10 let hi_a = Envelope.apply e (Wave.square (Volume.constant 20000.) 880.);; 11 let e = Envelope.apply e (Wave.tri (Volume.constant 20000.) 660.);; 12 12 13 13 let layer = Layer.empty ();; ocaml-remix/trunk/sound_test_sin.ml
r498 r499 7 7 8 8 let r = Remix.create 44000 2 120.;; 9 let four_second_A = Wave.sin (Volume. Linear (0., amp)) rate;;9 let four_second_A = Wave.sin (Volume.ramp 0. amp) rate;; 10 10 let envelope = Envelope.adsr (Time.Seconds 0.1) (Time.Seconds 0.4) 0.8 11 11 (Time.Seconds 0.1);; ocaml-remix/trunk/track_test_sins.ml
r498 r499 5 5 let env = Envelope.adsr (Time.Seconds 0.2) (Time.Seconds 0.6) 0.7 6 6 (Time.Seconds 0.1);; 7 let a = Wave.sin (Volume. Constant 30000.) (Tone.note Tone.a 0);;8 let e = Wave.sin (Volume. Constant 20000.) (Tone.note Tone.e 1);;7 let a = Wave.sin (Volume.constant 30000.) (Tone.note Tone.a 0);; 8 let e = Wave.sin (Volume.constant 20000.) (Tone.note Tone.e 1);; 9 9 let [a; e] = List.map (Envelope.apply env) [a; e];; 10 10 ocaml-remix/trunk/volume.ml
r498 r499 1 1 type volume = Constant of float | Linear of float * float;; 2 2 3 exception AmplitudeTooHigh 4 5 let constant v = if (v > 32767. || v < 0.) then raise AmplitudeTooHigh; 6 Constant v;; 7 8 let ramp s e = if (s > 32767. || s < 0.) then raise AmplitudeTooHigh; 9 if (e > 32767. || e < 0.) then raise AmplitudeTooHigh; 10 Linear (s, e);; 11 12 let amplitude volume position length = match volume with 13 | Constant v -> v 14 | Linear (s, e) -> 15 (position /. length) *. (e -. s) +. s;; ocaml-remix/trunk/volume.mli
r498 r499 1 type volume = Constant of float | Linear of float * float;;1 type volume;; 2 2 3 val constant : float -> volume;; 4 val ramp : float -> float -> volume;; 5 val amplitude : volume -> float -> float -> float;; ocaml-remix/trunk/wave.ml
r498 r499 30 30 31 31 let generate generator volume rate remix (ss, slen) (start, length) = 32 let (startvol, endvol) = (match volume with33 | Volume.Constant v -> (v,v)34 | Volume.Linear (s,e) -> (s, e)) in35 if (startvol > 32767. || startvol < 0.) then raise AmplitudeTooHigh;36 if (endvol > 32767. || endvol < 0.) then raise AmplitudeTooHigh;37 32 let raw_length = Time.time_to_raw_samples remix length in 38 33 let raw_start = Time.time_to_raw_samples remix start in … … 43 38 let offset = (raw_start - raw_ss) in 44 39 let channels = Remix.channels remix in 45 let vfunc = fun p -> (float_of_int (p + offset) /. float_of_int raw_slen) *.46 (endvol -. startvol) +. startvolin40 let vfunc = fun p -> Volume.amplitude volume (float_of_int (p + offset)) 41 (float_of_int raw_slen) in 47 42 Array.init raw_length 48 43 (fun p -> generator (vfunc p) period raw_start channels p);;
