root/ocaml-remix/trunk/track_test_sins.ml

Revision 529, 2.3 kB (checked in by shans, 4 years ago)

Replacing sound implementation - WAS ocaml int arrays, IS native float
arrays. This has not yet been completely been debugged!

Line 
1 (* middle A has a frequency of 440 Hz.  at a samplerate of 44 kHz, that is
2    a period of 100 samples *)
3
4 let env t = Envelope.adsr t (Time.Seconds 0.2) (Time.Seconds 0.6) 0.7
5                                                            (Time.Seconds 0.1);;
6 let a = Wave.sin (Volume.constant 1.) (Tone.note Tone.a 0);;
7 let e = Wave.sin (Volume.constant 0.7) (Tone.note Tone.e 1);;
8 let a t = Envelope.apply (env t) a;;
9 let e t = Envelope.apply (env t) e;;
10 let a t = Note.from_sound (a t);;
11 let e t = Note.from_sound (e t);;
12
13 let add layer note start length =
14   Layer.add_note layer (note (Time.Seconds length))
15           (Time.Seconds start, Time.Seconds length);;
16
17 (* AAAA  AAAA EEEE
18    .oO0    .oO00Oo.
19    EEEE EEEEEE AAAA
20 *)
21 let layer1 = Layer.empty ();;
22 let trans1 = Transparency.linear_ramp 0.0 1.0;;
23 let trans2 = Transparency.linear_ramp 1.0 0.0;;
24 add layer1 a 0.0 4.0;;
25 add layer1 a 6.0 4.0;;
26 add layer1 e 11.0 4.0;;
27
28 let noise = Ladspa_raw.open_plugin "noise:noise_white";;
29 let setup_noise _ = 1.0;;
30 let noise_p = Note.from_ladspa noise (Note.ladspa_init setup_noise);;
31 Layer.add_note layer1 noise_p (Time.Seconds 4.0, Time.Seconds 2.0);;
32
33 Layer.add_transparency layer1 trans1 (Time.Seconds 0.0, Time.Seconds 4.0);;
34 Layer.add_transparency layer1 trans1 (Time.Seconds 8.0, Time.Seconds 4.0);;
35 Layer.add_transparency layer1 trans2 (Time.Seconds 12.0, Time.Seconds 4.0);;
36
37 let layer2 = Layer.empty ();;
38 add layer2 e 0.0 4.0;;
39 add layer2 e 5.0 6.0;;
40 add layer2 a 12.0 4.0;;
41
42 let layer3 = Layer.empty();;
43 let ladspa = Ladspa_raw.open_plugin "tap_vibrato:tap_vibrato";;
44 let setup_plugin v = match v with
45   | 0 -> 5.0
46   | 1 -> 5.0
47   | 2 -> -90.0
48   | _ -> 0.0;;
49 let plugin = Note.from_ladspa ladspa (Note.ladspa_init setup_plugin);;
50 Layer.add_note layer3 plugin (Time.Seconds 2.0, Time.Seconds 7.0);;
51 let trans = Transparency.constant 1.0;;
52 Layer.add_transparency layer3 trans (Time.Seconds 0.0, Time.Seconds 2.0);;
53 Layer.add_transparency layer3 trans (Time.Seconds 9.0, Time.Seconds 16.0);;
54
55 let track = Track.empty ();;
56 Track.add_layer track layer3;;
57 Track.add_layer track layer1;;
58 Track.add_layer track layer2;;
59
60 let sound = Track.to_note track Sound.silence;;
61 let extent = (Time.Seconds 0.0, Time.Seconds 16.0);;
62
63 let remix = Remix.create 44000 2 120.;;
64 Sound.preview remix sound (Time.Seconds 0.0) extent;;
Note: See TracBrowser for help on using the browser.