Changeset 6695
- Timestamp:
- 06/29/09 16:06:52 (14 months ago)
- Location:
- trunk/liquidsoap/src
- Files:
-
- 1 added
- 5 modified
- 1 copied
-
Makefile (modified) (1 diff)
-
lang/lang.ml (modified) (2 diffs)
-
lang/lang.mli (modified) (1 diff)
-
synth/keyboard.ml (modified) (2 diffs)
-
synth/keyboard_sdl.ml (copied) (copied from trunk/liquidsoap/src/synth/keyboard.ml) (5 diffs)
-
synth/synth.ml (modified) (3 diffs)
-
synth/synth_op.ml (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/liquidsoap/src/Makefile
r6694 r6695 146 146 visualization/video_volume.ml 147 147 148 synth = synth/synth.ml \ 149 synth/keyboard.ml 148 synth = synth/synth.ml synth/synth_op.ml \ 149 synth/keyboard.ml \ 150 $(if $(W_SDL),synth/keyboard_sdl.ml) 150 151 151 152 liquidsoap_sources= $(tools) SVN.ml audio_converter.ml $(stream) \ -
trunk/liquidsoap/src/lang/lang.ml
r6527 r6695 80 80 | Input | Output 81 81 | TrackProcessing | SoundProcessing | VideoProcessing 82 | Visualization 82 | Visualization | SoundSynthesis 83 83 84 84 let string_of_category x = "Source / " ^ match x with … … 88 88 | SoundProcessing -> "Sound Processing" 89 89 | VideoProcessing -> "Video Processing" 90 | SoundSynthesis -> "Sound Synthesis" 90 91 | Visualization -> "Visualization" 91 92 -
trunk/liquidsoap/src/lang/lang.mli
r6527 r6695 87 87 | VideoProcessing (** Operations on video. *) 88 88 | Visualization (** Visializations of the sound. *) 89 | SoundSynthesis (** Synthesis. *) 89 90 90 91 (** Get a string representation of a [doc_flag]. *) -
trunk/liquidsoap/src/synth/keyboard.ml
r6694 r6695 33 33 34 34 let note_of_char c = 35 array_index knotes c + 9435 array_index knotes c + 72 36 36 37 37 class keyboard = … … 60 60 e 61 61 62 val mutable reader = None 63 62 64 method output_get_ready = 63 let _ = 64 Tutils.create 65 (fun () -> 66 while true do 67 let c = input_char stdin in 68 try 69 Printf.printf "\nPlaying note %d.\n%!" (note_of_char c); 70 self#add_event 0 (Midi.Note_on (note_of_char c, 0.8)) 71 with 72 | Not_found -> () 73 done 74 ) () "Virtual keyboard" 75 in 76 () 65 if reader = None then 66 reader <- 67 Some 68 (Tutils.create 69 (fun () -> 70 while true do 71 let c = 72 let c = String.create 1 in 73 ignore (Unix.read Unix.stdin c 0 1); 74 c.[0] 75 in 76 try 77 Printf.printf "\nPlaying note %d.\n%!" (note_of_char c); 78 self#add_event 0 (Midi.Note_on (note_of_char c, 0.8)) 79 with 80 | Not_found -> () 81 done 82 ) () "Virtual keyboard") 77 83 78 84 method output_reset = () -
trunk/liquidsoap/src/synth/keyboard_sdl.ml
r6694 r6695 21 21 *****************************************************************************) 22 22 23 let knotes = [|'a'; ' ?'; 'z'; '"'; 'e'; 'r'; '('; 't'; '-'; 'y'; '?'; 'u'; 'i'; '?'; 'o'; '?'; 'p'|]23 let knotes = [|'a'; '\233'; 'z'; '"'; 'e'; 'r'; '('; 't'; '-'; 'y'; '\232'; 'u'; 'i'; '\231'; 'o'; '\224'; 'p'|] 24 24 25 25 let array_index a x = … … 33 33 34 34 let note_of_char c = 35 array_index knotes c + 9435 array_index knotes c + 72 36 36 37 class keyboard =37 class keyboard velocity = 38 38 object (self) 39 39 inherit Source.active_source … … 45 45 method output = if AFrame.is_partial memo then self#get_frame memo 46 46 47 val mutable ev = [] 48 val ev_m = Mutex.create () 47 initializer 48 Sdl.init [`EVENTTHREAD; `VIDEO]; 49 Sdlevent.disable_events (Sdlevent.all_events_mask); 50 Sdlevent.enable_events (Sdlevent.make_mask [Sdlevent.KEYDOWN_EVENT; Sdlevent.KEYUP_EVENT; Sdlevent.QUIT_EVENT]); 51 ignore (Sdlvideo.set_video_mode ~w:640 ~h:480 ~bpp:16 []) 49 52 50 method add_event (t:int) (e:Midi.event) = 51 Mutex.lock ev_m; 52 ev <- (t,e)::ev; 53 Mutex.unlock ev_m 53 val mutable reader = None 54 54 55 method get_events = 56 Mutex.lock ev_m; 57 let e = List.rev ev in 58 ev <- []; 59 Mutex.unlock ev_m; 60 e 61 62 method output_get_ready = 63 let _ = 64 Tutils.create 65 (fun () -> 66 while true do 67 let c = input_char stdin in 68 try 69 Printf.printf "\nPlaying note %d.\n%!" (note_of_char c); 70 self#add_event 0 (Midi.Note_on (note_of_char c, 0.8)) 71 with 72 | Not_found -> () 73 done 74 ) () "Virtual keyboard" 75 in 76 () 55 method output_get_ready = () 77 56 78 57 method output_reset = () … … 82 61 assert (0 = MFrame.position frame); 83 62 let m = MFrame.tracks frame in 84 let t = self#get_events in 63 let t = 64 let ans = ref [] in 65 Sdlevent.pump (); 66 while Sdlevent.has_event () do 67 try 68 match Sdlevent.poll () with 69 | Some (Sdlevent.KEYDOWN k) -> 70 let c = Sdlkey.char_of_key k.Sdlevent.keysym in 71 let n = note_of_char c in 72 Printf.printf "Playing note %d.\n%!" n; 73 ans := (0,Midi.Note_on (n, velocity))::!ans 74 | Some (Sdlevent.KEYUP k) -> 75 let c = Sdlkey.char_of_key k.Sdlevent.keysym in 76 let n = note_of_char c in 77 Printf.printf "Stopping note %d.\n%!" n; 78 ans := (0,Midi.Note_off (n, velocity))::!ans 79 | _ -> () 80 with 81 | Not_found 82 | Invalid_argument _ -> () 83 done; 84 !ans 85 in 85 86 for c = 0 to Array.length m - 1 do 86 87 m.(c) := t … … 90 91 91 92 let () = 92 Lang.add_operator "input.keyboard "93 Lang.add_operator "input.keyboard.sdl" 93 94 [ 95 "velocity", Lang.float_t, Some (Lang.float 0.3), Some "Velocity of notes." 94 96 ] 95 97 ~category:Lang.Input 96 ~flags:[Lang. Hidden; Lang.Experimental]98 ~flags:[Lang.Experimental] 97 99 ~descr:"Play notes from the keyboard." 98 100 (fun p _ -> 99 (* let e f v = f (List.assoc v p) in *) 100 ((new keyboard):>Source.source) 101 let f v = List.assoc v p in 102 let velocity = Lang.to_float (f "velocity") in 103 ((new keyboard velocity):>Source.source) 101 104 ) -
trunk/liquidsoap/src/synth/synth.ml
r6694 r6695 3 3 let freq_of_note n = 440. *. (2. ** ((float n -. 69.) /. 12.)) 4 4 5 class type synth = 6 object 7 method note_on : int -> float -> unit 8 9 method note_off : int -> float -> unit 10 11 method synth : float -> float array array -> int -> int -> unit 12 end 13 5 14 (* Global state and note state. *) 6 class virtual ['gs,'ns] synth=15 class virtual ['gs,'ns] base = 7 16 object (self) 8 17 val mutable state = None … … 22 31 state <- Some (self#state_init) 23 32 33 initializer 34 self#init 35 24 36 method note_on n v = 25 37 notes <- (n, ref (self#note_init n v))::notes 26 38 27 39 method note_off n (v:float) = 40 (* TODO: remove only one note *) 28 41 notes <- List.filter (fun (m, _) -> m <> n) notes 29 42 … … 61 74 class sine = 62 75 object (self) 63 inherit [sine_gs, sine_ns] synth76 inherit [sine_gs, sine_ns] base 64 77 65 78 method state_init = () 66 79 67 method note_init n v = { sine_phase = 0.; sine_freq = freq_of_note n; sine_ampl = v }80 method note_init n v = { sine_phase = (*Random.float (2. *. pi)*) 0.; sine_freq = freq_of_note n; sine_ampl = v } 68 81 69 82 method synth_note_mono gs ns freq buf ofs len = 70 83 let phase i = ns.sine_phase +. float i /. freq *. ns.sine_freq *. 2. *. pi in 71 84 for i = ofs to ofs + len - 1 do 72 buf.(i) <- ns.sine_ampl *. sin (phase i)85 buf.(i) <- buf.(i) +. ns.sine_ampl *. sin (phase i) 73 86 done; 74 gs, { ns with sine_phase = phase len }87 gs, { ns with sine_phase = phase len } 75 88 end
