Changeset 498
- Timestamp:
- 08/18/07 13:08:29 (1 year ago)
- Files:
-
- ocaml-remix/trunk/Makefile (modified) (1 diff)
- ocaml-remix/trunk/instrument.ml (modified) (1 diff)
- ocaml-remix/trunk/instrument.mli (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 (added)
- ocaml-remix/trunk/volume.mli (added)
- ocaml-remix/trunk/wave.ml (modified) (2 diffs)
- ocaml-remix/trunk/wave.mli (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ocaml-remix/trunk/Makefile
r494 r498 1 1 ALL: all 2 2 3 COMPONENTS = remix time sound tone wave envelope transparency layer track\4 instrument3 COMPONENTS = remix time volume sound tone wave envelope transparency layer \ 4 track instrument 5 5 TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test 6 6 INCLUDES=-I +extlib ocaml-remix/trunk/instrument.ml
r495 r498 1 1 2 2 type length = float;; 3 type amplitude = float;;3 type amplitude = Volume.volume;; 4 4 5 5 type soundFunction = amplitude -> Tone.tone -> Sound.sound;; ocaml-remix/trunk/instrument.mli
r495 r498 2 2 3 3 type length = float;; (* measure length in beats *) 4 type amplitude = float;;4 type amplitude = Volume.volume;; 5 5 6 6 val add_note : instrument -> Layer.layer -> amplitude -> Tone.tone -> length -> ocaml-remix/trunk/instrument_test.ml
r497 r498 12 12 let instrument2 = Instrument.from_sound_function ~start:6. (sf Wave.square);; 13 13 14 let noteify(t,r,l) = (note t r, l);;14 let tonote (t,r,l) = (note t r, l);; 15 15 16 16 let layer = Layer.empty ();; 17 Instrument.add_notes instrument1 layer 30000. (List.map noteify17 Instrument.add_notes instrument1 layer (Volume.Constant 30000.) (List.map tonote 18 18 [(c, 0, 0.5); (d, 0, 0.5); (e, 0, 0.5); (f, 0, 0.5); 19 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 30000. (List.map noteify21 Instrument.add_notes instrument2 layer (Volume.Constant 30000.) (List.map tonote 22 22 [(g, -1, 0.5); (a, -1, 0.5); (b flat, -1, 0.5); (c, 0, 0.5); 23 23 (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 7 7 (Time.Seconds 0.1);; 8 8 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.);;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
r494 r498 7 7 8 8 let r = Remix.create 44000 2 120.;; 9 let four_second_A = Wave.sin amprate;;9 let four_second_A = Wave.sin (Volume.Linear (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
r494 r498 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 30000.(Tone.note Tone.a 0);;8 let e = Wave.sin 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/wave.ml
r494 r498 1 type wave = float-> float -> Sound.sound;;1 type wave = Volume.volume -> float -> Sound.sound;; 2 2 3 3 (* generator amplitude period(in samples) start(in samples) channels … … 29 29 (mod_float (float_of_int stime) period) /. period *. amp);; 30 30 31 let generate generator amp rate remix sound_extent (start, length) = 32 if (amp > 32767. || amp < 0.) then raise AmplitudeTooHigh; 31 let 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; 33 37 let raw_length = Time.time_to_raw_samples remix length in 34 38 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 35 41 let period = float_of_int (Remix.samplerate remix * Remix.channels remix) 36 42 /. rate in 43 let offset = (raw_start - raw_ss) in 37 44 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);; 39 49 40 50 let sin = generate sin_generator;; ocaml-remix/trunk/wave.mli
r494 r498 1 type wave = float-> float -> Sound.sound;;1 type wave = Volume.volume -> float -> Sound.sound;; 2 2 3 3 (* generator amplitude period(in samples) start(in samples) channels
