Changeset 6696
- Timestamp:
- 06/29/09 16:17:17 (14 months ago)
- Location:
- trunk/liquidsoap/src/synth
- Files:
-
- 3 modified
-
keyboard_sdl.ml (modified) (1 diff)
-
synth.ml (modified) (1 diff)
-
synth_op.ml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/liquidsoap/src/synth/keyboard_sdl.ml
r6695 r6696 70 70 let c = Sdlkey.char_of_key k.Sdlevent.keysym in 71 71 let n = note_of_char c in 72 Printf.printf "Playing note %d.\n%!" n;72 (* Printf.printf "Playing note %d.\n%!" n; *) 73 73 ans := (0,Midi.Note_on (n, velocity))::!ans 74 74 | Some (Sdlevent.KEYUP k) -> 75 75 let c = Sdlkey.char_of_key k.Sdlevent.keysym in 76 76 let n = note_of_char c in 77 Printf.printf "Stopping note %d.\n%!" n;77 (* Printf.printf "Stopping note %d.\n%!" n; *) 78 78 ans := (0,Midi.Note_off (n, velocity))::!ans 79 79 | _ -> () -
trunk/liquidsoap/src/synth/synth.ml
r6695 r6696 64 64 end 65 65 66 type sine_gs = unit 67 type sine_ns = 66 type simple_gs = unit 67 (* Period is 1. *) 68 type simple_ns = 68 69 { 69 si ne_phase : float;70 si ne_freq : float;71 si ne_ampl : float;70 simple_phase : float; 71 simple_freq : float; 72 simple_ampl : float; 72 73 } 73 74 74 class si ne=75 class simple f = 75 76 object (self) 76 inherit [si ne_gs, sine_ns] base77 inherit [simple_gs, simple_ns] base 77 78 78 79 method state_init = () 79 80 80 method note_init n v = { si ne_phase = (*Random.float (2. *. pi)*) 0.; sine_freq = freq_of_note n; sine_ampl = v }81 method note_init n v = { simple_phase = (*Random.float 1.*) 0.; simple_freq = freq_of_note n; simple_ampl = v } 81 82 82 83 method synth_note_mono gs ns freq buf ofs len = 83 let phase i = ns.si ne_phase +. float i /. freq *. ns.sine_freq *. 2. *. piin84 let phase i = ns.simple_phase +. float i /. freq *. ns.simple_freq in 84 85 for i = ofs to ofs + len - 1 do 85 buf.(i) <- buf.(i) +. ns.si ne_ampl *. sin(phase i)86 buf.(i) <- buf.(i) +. ns.simple_ampl *. f (phase i) 86 87 done; 87 gs, { ns with si ne_phase = phase len}88 gs, { ns with simple_phase = fst (modf (phase len)) } 88 89 end 90 91 class sine = object inherit simple (fun x -> sin (x *. 2. *. pi)) end 92 93 class square = object inherit simple (fun x -> let x = fst (modf x) in if x < 0.5 then 1. else -1.) end -
trunk/liquidsoap/src/synth/synth_op.ml
r6695 r6696 71 71 let src = Lang.to_source (f "") in 72 72 new synth (new Synth.sine :> Synth.synth) src 0) 73 74 let () = 75 Lang.add_operator "synth.square" 76 [ "", Lang.source_t, None, None ] 77 ~category:Lang.SoundSynthesis 78 ~descr:"Square synthesiser." 79 (fun p _ -> 80 let f v = List.assoc v p in 81 let src = Lang.to_source (f "") in 82 new synth (new Synth.square :> Synth.synth) src 0)
