Changeset 513
- Timestamp:
- 10/24/07 16:54:11 (10 months ago)
- Files:
-
- ocaml-remix/trunk/continuous_sound_test.ml (modified) (2 diffs)
- ocaml-remix/trunk/noteUtil.ml (modified) (2 diffs)
- ocaml-remix/trunk/track.ml (modified) (3 diffs)
- ocaml-remix/trunk/transparency.ml (modified) (2 diffs)
- ocaml-remix/trunk/transparency.mli (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ocaml-remix/trunk/continuous_sound_test.ml
r512 r513 5 5 let envelope = Note.from_envelope 6 6 (Envelope.adsr (Time.Seconds 0.1) (Time.Seconds 0.4) 0.8 (Time.Seconds 0.1));; 7 let envelope2 = Note.from_envelope 8 (Envelope.adsr (Time.Seconds 0.2) (Time.Seconds 0.2) 0.9 (Time.Seconds 0.3));; 7 9 8 10 let continuous = (Time.Seconds 0.0, Time.Forever);; … … 13 15 let env_layer = Layer.empty ();; 14 16 Layer.add_note env_layer 15 (NoteUtil.repeat (Time.Seconds 1.0) envelope) continuous;; 17 (NoteUtil.repeat (Time.Seconds 0.75) envelope) continuous;; 18 Layer.add_transparency env_layer (Transparency.constant 0.5) continuous;; 19 20 let env_layer2 = Layer.empty ();; 21 Layer.add_note env_layer2 22 (NoteUtil.repeat (Time.Seconds 0.8) envelope2) continuous;; 23 Layer.add_transparency env_layer2 (Transparency.constant 0.5) continuous;; 16 24 17 25 let track = Track.empty ();; 26 Track.add_layer track env_layer2;; 18 27 Track.add_layer track env_layer;; 19 28 Track.add_layer track sound_layer;; ocaml-remix/trunk/noteUtil.ml
r512 r513 1 (* shift takes an input note, and shifts its render window: 2 3 <-----------------note extent-------------------------> 4 <------------------------shift amount-----------<---render request---> 5 <---actual render---> 6 *) 7 1 8 let shift slength note initsound remix extent render_extent = 2 9 let raw_rstart, raw_rlength = Time.extent_to_raw_time remix render_extent in 3 10 let raw_shift = Time.time_to_raw_time remix slength in 4 11 Printf.printf "shift (%d,%d) by %d\n%!" raw_rstart raw_rlength raw_shift; 12 Printf.printf "render at (%d,%d) in (%d,%d)\n%!" (raw_rstart + raw_shift) 13 raw_rlength (Time.time_to_raw_time remix (fst extent)) 14 (Time.time_to_raw_time remix (snd extent)); 5 15 note initsound remix extent 6 16 (Time.Samples (raw_rstart + raw_shift), Time.Samples raw_rlength);; 7 17 18 (* repeat takes an input length and note, and duplicates the note with length 19 as the size. e.g. 20 21 <----------------------------------------> (input extent) 22 <---length---><---length---><---length---> (actual note extents) 23 24 For a render request within a single length, this is easy: 25 26 <---length---><---length---><---length---> 27 <ren-req> 28 29 Simply use a note extent of 30 (render_start - note_start)/length*length + note_start, length 31 and the existing render request. 32 33 For a render request that crosses multiple lengths, it's slightly harder: 34 35 <---length---><---length---><---length---> 36 <--render-request--> 37 38 We'll use a layer, add three notes of full size: 39 40 <---length---><---length---><---length---> 41 42 then render the size of the render extent out as a new note 43 44 *) 8 45 let repeat length note initsound remix extent render_extent = 9 46 let raw_start, raw_length = Time.extent_to_raw_time remix render_extent in 10 47 let raw_replength = Time.time_to_raw_time remix length in 11 48 let reps = raw_start / raw_replength in 12 let repe = (raw_start + raw_length) / raw_replength in 13 let theshift l = shift (Time.Samples (-l)) note in 49 let repe = (raw_start + raw_length - 1) / raw_replength in 14 50 if reps = repe then ( 15 theshift (reps * raw_replength)initsound remix16 (fst extent, length) render_extent51 note initsound remix 52 (Time.Samples (reps * raw_replength), length) render_extent 17 53 ) else ( 18 54 let l = Layer.empty () in 55 let add n s len = Layer.add_note l n (Time.Samples s, Time.Samples len) in 56 for i = reps to repe do 57 add note (i * raw_replength) raw_replength 58 done; 59 Layer.to_note l initsound remix extent render_extent 60 61 (* 19 62 let first_seg_len = ((reps + 1) * raw_replength) - raw_start in 20 63 let last_seg_start = repe * raw_replength in … … 27 70 add (theshift (i * raw_replength)) (i * raw_replength) raw_replength 28 71 done; 29 Layer.to_note l initsound remix extent render_extent72 *) 30 73 );; ocaml-remix/trunk/track.ml
r512 r513 1 1 type tcache_elem = { 2 2 tce_raw_start: Time.raw_time; 3 tce_raw_length: Time.raw_time;4 3 tce_start: Time.time; 5 4 tce_length:Time.time; … … 11 10 let gen_tcache_elem remix (start, length) trans = 12 11 {tce_raw_start = Time.time_to_raw_time remix start; 13 tce_raw_length = Time.time_to_raw_time remix length;14 12 tce_start = start; 15 13 tce_length = length; … … 117 115 ) else ( 118 116 (* case 3,4,5,6 *) 119 let trans_end = elem.tce_raw_start + elem.tce_raw_length in 120 let render_end = raw_start + raw_length in 121 let l = (min trans_end render_end) - raw_start in 117 let ext = Time.overlap remix (elem.tce_start, elem.tce_length) 118 (Time.Samples raw_start, Time.Samples raw_length) in 122 119 let sound2 = _render_at (pos + 1) in 123 120 let sound1 = (Layer.to_note layer sound2) in 124 121 let trans = elem.tce_transparency in 125 let ext = (Time.Samples raw_start, Time.Samples l)in122 let raw_start, l = Time.extent_to_raw_time remix ext in 126 123 _add_s_to_out (apply_transparency sound1 ext sound2 ext 127 124 trans (elem.tce_start, elem.tce_length)) raw_start l; ocaml-remix/trunk/transparency.ml
r490 r513 7 7 let _to_raw a = (Time.time_to_raw_time remix a) * Remix.channels remix in 8 8 let raw_start = _to_raw start in 9 if length = Time.Forever then 10 Printf.printf "can't create a linear ramp with an unbounded end time!\n%!"; 9 11 let raw_length = _to_raw length in 10 12 let raw_ostart = _to_raw ostart in … … 14 16 float_of_int raw_length *. (end_val -. start_val) in 15 17 Array.init raw_olength _fill;; 18 19 let constant value remix size (rstart, rlength) = 20 Array.create (Time.time_to_raw_samples remix rlength) value;; ocaml-remix/trunk/transparency.mli
r488 r513 4 4 -> raw_transparency;; 5 5 6 val linear_ramp : float -> float -> transparency 6 val linear_ramp : float -> float -> transparency;; 7 8 val constant : float -> transparency;;
