Changeset 494
- Timestamp:
- 08/08/07 22:55:01 (1 year ago)
- Files:
-
- ocaml-remix/trunk/Makefile (modified) (3 diffs)
- ocaml-remix/trunk/instrument.ml (added)
- ocaml-remix/trunk/instrument.mli (added)
- ocaml-remix/trunk/instrument_test.ml (added)
- ocaml-remix/trunk/layer_test_sins.ml (modified) (1 diff)
- ocaml-remix/trunk/pa_operators.ml (added)
- ocaml-remix/trunk/sound_test_sin.ml (modified) (1 diff)
- ocaml-remix/trunk/time.ml (modified) (1 diff)
- ocaml-remix/trunk/tone.ml (added)
- ocaml-remix/trunk/tone.mli (added)
- ocaml-remix/trunk/track_test_sins.ml (modified) (1 diff)
- 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
r493 r494 1 1 ALL: all 2 2 3 COMPONENTS = remix time sound wave envelope transparency layer track 4 TESTS = sound_test_sin layer_test_sins track_test_sins 3 COMPONENTS = remix time sound tone wave envelope transparency layer track \ 4 instrument 5 TESTS = sound_test_sin layer_test_sins track_test_sins instrument_test 5 6 INCLUDES=-I +extlib 6 7 OBJECTS=extLib unix oss … … 14 15 OPTTESTS = $(patsubst %, %.opt, $(TESTS)) 15 16 16 OCAMLCARGS = $(INCLUDES) $(OBJECTS_CMA) -g 17 OCAMLOPTARGS = $(INCLUDES) $(OBJECTS_CMXA) 17 OCAMLPP = -pp "camlp4o ./pa_operators.cmo" 18 OCAMLCARGS = $(INCLUDES) $(OBJECTS_CMA) -w s -g $(OCAMLPP) 19 OCAMLOPTARGS = $(INCLUDES) $(OBJECTS_CMXA) -w s -g $(OCAMLPP) 20 21 22 pa_operators.cmo: pa_operators.ml 23 ocamlc -I +camlp4 camlp4lib.cma -pp camlp4of pa_operators.ml 18 24 19 25 remix.cma: $(INTERFACES) $(SOURCES) oss.cma … … 37 43 ocamlopt $(OCAMLOPTARGS) $^ -o $@ 38 44 39 all: remix.cma $(BINTESTS)45 all: pa_operators.cmo remix.cma $(BINTESTS) 40 46 41 all.opt: remix.cmxa $(OPTTESTS)47 all.opt: pa_operators.cmo remix.cmxa $(OPTTESTS) 42 48 43 49 clean: ocaml-remix/trunk/layer_test_sins.ml
r493 r494 7 7 (Time.Seconds 0.1);; 8 8 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));;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.);; 12 12 13 13 let layer = Layer.empty ();; ocaml-remix/trunk/sound_test_sin.ml
r493 r494 6 6 let len = float_of_string Sys.argv.(3);; 7 7 8 let period = Time.Hertz rate;;9 10 8 let r = Remix.create 44000 2 120.;; 11 let four_second_A = Wave.sin amp period;;9 let four_second_A = Wave.sin amp rate;; 12 10 let envelope = Envelope.adsr (Time.Seconds 0.1) (Time.Seconds 0.4) 0.8 13 11 (Time.Seconds 0.1);; ocaml-remix/trunk/time.ml
r488 r494 18 18 | Seconds f -> sec_to_sam f 19 19 | 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.) 21 21 | Hertz f -> sec_to_sam (1. /. f);; 22 22 ocaml-remix/trunk/track_test_sins.ml
r493 r494 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. (T ime.Hertz 440.);;8 let e = Wave.sin 20000. (T ime.Hertz 660.);;7 let a = Wave.sin 30000. (Tone.note Tone.a 0);; 8 let e = Wave.sin 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
r493 r494 1 type wave = float -> Time.time-> Sound.sound;;1 type wave = float -> float -> Sound.sound;; 2 2 3 3 (* generator amplitude period(in samples) start(in samples) channels 4 4 time(in samples) *) 5 type generator = float -> int -> int -> int -> int -> int;;5 type generator = float -> float -> int -> int -> int -> int;; 6 6 7 7 exception AmplitudeTooHigh;; … … 18 18 let stime = (time + start) / channels * channels in 19 19 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)));; 21 21 22 22 let 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;; 24 25 25 26 let tri_generator amp period start channels time = 26 27 let stime = (time + start) / channels * channels in 27 28 int_of_float ( 28 float_of_int (stime mod period) /. float_of_intperiod *. amp);;29 (mod_float (float_of_int stime) period) /. period *. amp);; 29 30 30 let generate generator amp periodremix sound_extent (start, length) =31 let generate generator amp rate remix sound_extent (start, length) = 31 32 if (amp > 32767. || amp < 0.) then raise AmplitudeTooHigh; 32 let raw_period = Time.time_to_raw_samples remix period in33 33 let raw_length = Time.time_to_raw_samples remix length in 34 34 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 35 37 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);; 37 39 38 40 let sin = generate sin_generator;; ocaml-remix/trunk/wave.mli
r493 r494 1 type wave = float -> Time.time-> Sound.sound;;1 type wave = float -> float -> Sound.sound;; 2 2 3 3 (* generator amplitude period(in samples) start(in samples) channels 4 4 time(in samples) *) 5 type generator = float -> int -> int -> int -> int -> int;;5 type generator = float -> float -> int -> int -> int -> int;; 6 6 7 7 val generate : generator -> wave;;
