-
Notifications
You must be signed in to change notification settings - Fork 4
/
soundgen.pas
668 lines (617 loc) · 20.6 KB
/
soundgen.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
(******************************************************************************)
(* sfxr ??.??.???? *)
(* *)
(* Version : 1.02 *)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* Support : www.Corpsman.de *)
(* *)
(* Description : Sound generator, C-port from drpetter *)
(* *)
(* License : See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(* Warranty : There is no warranty, neither in correctness of the *)
(* implementation, nor anything other that could happen *)
(* or go wrong, use at your own risk. *)
(* *)
(* Known Issues: none *)
(* *)
(* History : 1.02 - Initial version *)
(* *)
(******************************************************************************)
(*
* Original Source from : http://www.drpetter.se/project_sfxr.html
*)
Unit soundgen;
{$MODE objfpc}{$H+}
Interface
(*
* In case you downloaded and just want to test the app without ocnfiguring Bass
* you can switch off usage of bass.
* Save will still work, but no sound preview.
*)
{$define .UseBass}
Uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, usfxr
{$IFDEF UseBass}
, bass
{$ENDIF}
;
Type
{ TSoundGeneratorForm }
TSoundGeneratorForm = Class(TForm)
Button1: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
GroupBox5: TGroupBox;
GroupBox6: TGroupBox;
GroupBox7: TGroupBox;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label2: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
OpenDialog1: TOpenDialog;
RadioGroup1: TRadioGroup;
SaveDialog1: TSaveDialog;
SaveDialog2: TSaveDialog;
ScrollBar1: TScrollBar;
ScrollBar10: TScrollBar;
ScrollBar11: TScrollBar;
ScrollBar12: TScrollBar;
ScrollBar13: TScrollBar;
ScrollBar14: TScrollBar;
ScrollBar15: TScrollBar;
ScrollBar16: TScrollBar;
ScrollBar17: TScrollBar;
ScrollBar18: TScrollBar;
ScrollBar19: TScrollBar;
ScrollBar2: TScrollBar;
ScrollBar20: TScrollBar;
ScrollBar21: TScrollBar;
ScrollBar22: TScrollBar;
ScrollBar23: TScrollBar;
ScrollBar3: TScrollBar;
ScrollBar4: TScrollBar;
ScrollBar5: TScrollBar;
ScrollBar6: TScrollBar;
ScrollBar7: TScrollBar;
ScrollBar8: TScrollBar;
ScrollBar9: TScrollBar;
Procedure Button14Click(Sender: TObject);
Procedure Button15Click(Sender: TObject);
Procedure Button16Click(Sender: TObject);
Procedure Button17Click(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure Button3Click(Sender: TObject);
Procedure Button4Click(Sender: TObject);
Procedure Button5Click(Sender: TObject);
Procedure Button6Click(Sender: TObject);
Procedure Button7Click(Sender: TObject);
Procedure Button8Click(Sender: TObject);
Procedure Button9Click(Sender: TObject);
Procedure ComboBox1Change(Sender: TObject);
Procedure ComboBox2Change(Sender: TObject);
Procedure FormCreate(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
Procedure RadioGroup1Click(Sender: TObject);
Procedure ScrollBar1Change(Sender: TObject);
private
{ private declarations }
{$IFDEF UseBass}
UseBass: Boolean;
PreviewStream: HSTREAM;
{$ENDIF}
SFXR: TSFXR;
Vars: Array Of Pointer; //Mapper TScrollbar auf sfxr Parameter
Procedure do_play; // Started das Abspielen, wenn Möglich
Procedure ReloadLCL; // SFXR -> LCL
Procedure Link(Const ScrollBar: TScrollBar; Data: Pointer; Bipolar: Boolean); // LCL -> SFXR
public
{ public declarations }
End;
Var
SoundGeneratorForm: TSoundGeneratorForm;
// Leider klappt es nicht, wenn man via Bass.dll die SynthSample Routine aufruft, deswegen muss hier der Umweg über den Stream gegangen werden.
m: TMemoryStream;
mp: int64;
ms: int64;
Implementation
Uses math;
{$R *.lfm}
{$IFDEF UseBass}
Function GetPreviewData(handle: HSTREAM; buffer: Pointer; length: DWORD; user: Pointer): DWORD;
{$IFDEF Windows} stdcall;
{$ELSE} cdecl;
{$ENDIF}
Var
i: integer;
w: Word;
buf: PWord;
Begin
buf := buffer;
w := 32767; // Beruhigt nur den Compiler
For i := 0 To length Div 2 - 1 Do Begin // Puffergröße ist in Bytes, wir haben aber Word's die sind 2-Byte => also length / 2
m.Read(w, 2);
buf^ := w;
inc(mp, 2);
inc(buf);
End;
result := length;
If mp >= ms Then Begin
BASS_ChannelStop(SoundGeneratorForm.PreviewStream);
End;
End;
{$ENDIF}
{ TSoundGeneratorForm }
Procedure TSoundGeneratorForm.FormCreate(Sender: TObject);
Begin
// caption := 'sfxr ver. 1.02 by DrPetter, ported by corpsman';
Randomize;
SFXR := TSFXR.create;
Vars := Nil;
(*
* !! ACHTUNG !!
*
* Die Reihenfolge der Scrollbars muss aufsteigend und zusammenhängend
* von 1 bis k sein !!
*)
// Initialisieren der Scrollbars und verbinden mit der jeweiligen Variable
Link(ScrollBar1, @sfxr.p_env_attack, false);
Link(ScrollBar2, @sfxr.p_env_sustain, false);
Link(ScrollBar3, @sfxr.p_env_punch, false);
Link(ScrollBar4, @sfxr.p_env_decay, false);
Link(ScrollBar5, @sfxr.p_base_freq, false);
Link(ScrollBar6, @sfxr.p_freq_limit, false);
Link(ScrollBar7, @sfxr.p_freq_ramp, true);
Link(ScrollBar8, @sfxr.p_freq_dramp, true);
Link(ScrollBar9, @sfxr.p_vib_strength, false);
Link(ScrollBar10, @sfxr.p_vib_speed, false);
Link(ScrollBar11, @sfxr.p_arp_mod, true);
Link(ScrollBar12, @sfxr.p_arp_speed, false);
Link(ScrollBar13, @sfxr.p_duty, false);
Link(ScrollBar14, @sfxr.p_duty_ramp, true);
Link(ScrollBar15, @sfxr.p_repeat_speed, false);
Link(ScrollBar16, @sfxr.p_pha_offset, true);
Link(ScrollBar17, @sfxr.p_pha_ramp, true);
Link(ScrollBar18, @sfxr.p_lpf_freq, false);
Link(ScrollBar19, @sfxr.p_lpf_ramp, true);
Link(ScrollBar20, @sfxr.p_lpf_resonance, false);
Link(ScrollBar21, @sfxr.p_hpf_freq, false);
Link(ScrollBar22, @sfxr.p_hpf_ramp, true);
Link(ScrollBar23, @sfxr.sound_vol, false);
sfxr.ResetParams;
ReloadLCL;
{$IFDEF UseBass}
// Bass Sample : http://www.delphipraxis.net/180321-bass-dll-rauschen-erzeugen-create-noise.html
// Bass Source : http://www.un4seen.com/
// Laden der Bass.dll
UseBass := true;
If (BASS_GetVersion() Shr 16) <> Bassversion Then Begin
showmessage('Unable to init the Bass Library ver. :' + BASSVERSIONTEXT);
UseBass := false;
End;
If UseBass And (Not Bass_init(-1, 44100, 0, {$IFDEF Windows}0{$ELSE}Nil{$ENDIF}, Nil)) Then Begin
showmessage('Unable to init sound device, playsound option will be disabled.');
Button14.Enabled := false;
UseBass := false;
End;
If UseBass Then Begin
PreviewStream := BASS_StreamCreate(44100, 1, 0, @GetPreviewData, Nil);
m := TMemoryStream.create;
End;
{$ENDIF}
End;
Procedure TSoundGeneratorForm.FormDestroy(Sender: TObject);
Begin
{$IFDEF UseBass}
If UseBass Then Begin
BASS_ChannelStop(PreviewStream);
BASS_StreamFree(PreviewStream);
Bass_Free;
m.free;
End;
{$ENDIF}
SFXR.free;
setlength(Vars, 0);
End;
Procedure TSoundGeneratorForm.RadioGroup1Click(Sender: TObject);
Begin
// Wellenform
SFXR.wave_type := RadioGroup1.ItemIndex;
End;
Procedure TSoundGeneratorForm.ScrollBar1Change(Sender: TObject);
Var
p: ^Single;
Begin
p := vars[TScrollBar(sender).Tag];
p^ := TScrollBar(sender).Position / 1000;
End;
Procedure TSoundGeneratorForm.ReloadLCL;
Var
i: Integer;
s: TScrollBar;
p: ^Single;
Begin
RadioGroup1.ItemIndex := SFXR.wave_type;
For i := 0 To high(Vars) Do Begin
s := TScrollBar(FindComponent('Scrollbar' + inttostr(i + 1)));
p := vars[i];
s.Position := round(p^ * 1000);
End;
End;
Procedure TSoundGeneratorForm.do_play;
Begin
{$IFDEF UseBass}
If UseBass Then Begin
Button14.Click;
End;
{$ENDIF}
End;
Procedure TSoundGeneratorForm.Link(Const ScrollBar: TScrollBar; Data: Pointer;
Bipolar: Boolean);
Begin
setlength(Vars, high(Vars) + 2);
vars[high(Vars)] := Data;
ScrollBar.Tag := high(Vars);
ScrollBar.Position := 0;
If Bipolar Then Begin
ScrollBar.Min := -1000;
End
Else Begin
ScrollBar.Min := 0;
End;
ScrollBar.Max := 1000;
ScrollBar.OnChange := @ScrollBar1Change;
End;
Procedure TSoundGeneratorForm.Button17Click(Sender: TObject);
Begin
// Export Wave
If SaveDialog1.Execute Then Begin
If Not SFXR.ExportWav(SaveDialog1.FileName) Then Begin
showmessage('Could not export.');
End;
End;
End;
Procedure TSoundGeneratorForm.Button14Click(Sender: TObject);
Begin
{$IFDEF UseBass}
// Play Sound
If Not UseBass Then Begin
showmessage('No preview available.');
exit;
End;
// Wir spielen bereits -> abbruch
If BASS_ChannelIsActive(PreviewStream) <> 0 Then Begin
BASS_ChannelStop(PreviewStream);
End;
// Den Stream als Rohdatenstream empfangen
m.Clear;
SFXR.ExportBassStream(m);
mp := 0;
ms := m.Size;
m.Position := 0;
If Not BASS_ChannelPlay(PreviewStream, true) Then Begin
showmessage('Could not start stream playback');
End;
{$ELSE}
showmessage('Application was build without use of bass, so no preview available.' + LineEnding +
'You have to store the result and play it with your own player of choise.');
{$ENDIF}
End;
Procedure TSoundGeneratorForm.Button15Click(Sender: TObject);
Begin
// Load Settings
If OpenDialog1.Execute Then Begin
If Not SFXR.LoadSettings(OpenDialog1.FileName) Then Begin
showmessage('Error, could not save settings.');
exit;
End;
ReloadLCL;
End;
End;
Procedure TSoundGeneratorForm.Button16Click(Sender: TObject);
Begin
// Save Settings
If SaveDialog2.Execute Then Begin
If Not SFXR.SaveSettings(SaveDialog2.FileName) Then Begin
showmessage('Error, could not save settings.');
End;
End;
End;
Procedure TSoundGeneratorForm.Button1Click(Sender: TObject);
Begin
// pickup/coin
SFXR.ResetParams();
SFXR.p_base_freq := 0.4 + frnd(0.5);
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := frnd(0.1);
SFXR.p_env_decay := 0.1 + frnd(0.4);
SFXR.p_env_punch := 0.3 + frnd(0.3);
If (random(100) >= 50) Then Begin
SFXR.p_arp_speed := 0.5 + frnd(0.2);
SFXR.p_arp_mod := 0.2 + frnd(0.4);
End;
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button2Click(Sender: TObject);
Begin
// Laser Shoot
SFXR.ResetParams();
SFXR.wave_type := rnd(2);
If (SFXR.wave_type = 2) And (random(100) >= 50) Then Begin
SFXR.wave_type := rnd(1);
End;
SFXR.p_base_freq := 0.5 + frnd(0.5);
SFXR.p_freq_limit := SFXR.p_base_freq - 0.2 - frnd(0.6);
If (SFXR.p_freq_limit < 0.2) Then SFXR.p_freq_limit := 0.2;
SFXR.p_freq_ramp := -0.15 - frnd(0.2);
If (rnd(2) = 0) Then Begin
SFXR.p_base_freq := 0.3 + frnd(0.6);
SFXR.p_freq_limit := frnd(0.1);
SFXR.p_freq_ramp := -0.35 - frnd(0.3);
End;
If (random(100) >= 50) Then Begin
SFXR.p_duty := frnd(0.5);
SFXR.p_duty_ramp := frnd(0.2);
End
Else Begin
SFXR.p_duty := 0.4 + frnd(0.5);
SFXR.p_duty_ramp := -frnd(0.7);
End;
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := 0.1 + frnd(0.2);
SFXR.p_env_decay := frnd(0.4);
If (random(100) >= 50) Then SFXR.p_env_punch := frnd(0.3);
If (rnd(2) = 0) Then Begin
SFXR.p_pha_offset := frnd(0.2);
SFXR.p_pha_ramp := -frnd(0.2);
End;
If (random(100) >= 50) Then SFXR.p_hpf_freq := frnd(0.3);
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button3Click(Sender: TObject);
Begin
// Explosion
SFXR.ResetParams();
SFXR.wave_type := 3;
If (random(100) >= 50) Then Begin
SFXR.p_base_freq := 0.1 + frnd(0.4);
SFXR.p_freq_ramp := -0.1 + frnd(0.4);
End
Else Begin
SFXR.p_base_freq := 0.2 + frnd(0.7);
SFXR.p_freq_ramp := -0.2 - frnd(0.2);
End;
SFXR.p_base_freq := SFXR.p_base_freq * SFXR.p_base_freq;
If (rnd(4) = 0) Then SFXR.p_freq_ramp := 0.0;
If (rnd(2) = 0) Then SFXR.p_repeat_speed := 0.3 + frnd(0.5);
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := 0.1 + frnd(0.3);
SFXR.p_env_decay := frnd(0.5);
If (rnd(1) = 0) Then Begin
SFXR.p_pha_offset := -0.3 + frnd(0.9);
SFXR.p_pha_ramp := -frnd(0.3);
End;
SFXR.p_env_punch := 0.2 + frnd(0.6);
If (random(100) >= 50) Then Begin
SFXR.p_vib_strength := frnd(0.7);
SFXR.p_vib_speed := frnd(0.6);
End;
If (rnd(2) = 0) Then Begin
SFXR.p_arp_speed := 0.6 + frnd(0.3);
SFXR.p_arp_mod := 0.8 - frnd(1.6);
End;
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button4Click(Sender: TObject);
Begin
// Power Up
SFXR.ResetParams();
If (random(100) >= 50) Then Begin
SFXR.wave_type := 1;
End
Else Begin
SFXR.p_duty := frnd(0.6);
End;
If (random(100) >= 50) Then Begin
SFXR.p_base_freq := 0.2 + frnd(0.3);
SFXR.p_freq_ramp := 0.1 + frnd(0.4);
SFXR.p_repeat_speed := 0.4 + frnd(0.4);
End
Else Begin
SFXR.p_base_freq := 0.2 + frnd(0.3);
SFXR.p_freq_ramp := 0.05 + frnd(0.2);
If (random(100) >= 50) Then Begin
SFXR.p_vib_strength := frnd(0.7);
SFXR.p_vib_speed := frnd(0.6);
End;
End;
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := frnd(0.4);
SFXR.p_env_decay := 0.1 + frnd(0.4);
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button5Click(Sender: TObject);
Begin
// Hit
SFXR.ResetParams();
SFXR.wave_type := rnd(2);
If (SFXR.wave_type = 2) Then SFXR.wave_type := 3;
If (SFXR.wave_type = 0) Then SFXR.p_duty := frnd(0.6);
SFXR.p_base_freq := 0.2 + frnd(0.6);
SFXR.p_freq_ramp := -0.3 - frnd(0.4);
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := frnd(0.1);
SFXR.p_env_decay := 0.1 + frnd(0.2);
If (random(100) >= 50) Then SFXR.p_hpf_freq := frnd(0.3);
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button6Click(Sender: TObject);
Begin
// Jump
SFXR.ResetParams();
SFXR.wave_type := 0;
SFXR.p_duty := frnd(0.6);
SFXR.p_base_freq := 0.3 + frnd(0.3);
SFXR.p_freq_ramp := 0.1 + frnd(0.2);
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := 0.1 + frnd(0.3);
SFXR.p_env_decay := 0.1 + frnd(0.2);
If (random(100) >= 50) Then SFXR.p_hpf_freq := frnd(0.3);
If (random(100) >= 50) Then SFXR.p_lpf_freq := 1.0 - frnd(0.6);
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button7Click(Sender: TObject);
Begin
// Blip
SFXR.ResetParams();
SFXR.wave_type := rnd(1);
If (SFXR.wave_type = 0) Then SFXR.p_duty := frnd(0.6);
SFXR.p_base_freq := 0.2 + frnd(0.4);
SFXR.p_env_attack := 0.0;
SFXR.p_env_sustain := 0.1 + frnd(0.1);
SFXR.p_env_decay := frnd(0.2);
SFXR.p_hpf_freq := 0.1;
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button8Click(Sender: TObject);
Begin
// Mutate
If (random(100) >= 50) Then SFXR.p_base_freq := SFXR.p_base_freq + frnd(0.1) - 0.05;
//If (random(100) >= 50) Then SFXR.p_freq_limit := SFXR.p_freq_limit + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_freq_ramp := SFXR.p_freq_ramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_freq_dramp := SFXR.p_freq_dramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_duty := SFXR.p_duty + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_duty_ramp := SFXR.p_duty_ramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_vib_strength := SFXR.p_vib_strength + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_vib_speed := SFXR.p_vib_speed + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_vib_delay := SFXR.p_vib_delay + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_env_attack := SFXR.p_env_attack + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_env_sustain := SFXR.p_env_sustain + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_env_decay := SFXR.p_env_decay + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_env_punch := SFXR.p_env_punch + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_lpf_resonance := SFXR.p_lpf_resonance + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_lpf_freq := SFXR.p_lpf_freq + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_lpf_ramp := SFXR.p_lpf_ramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_hpf_freq := SFXR.p_hpf_freq + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_hpf_ramp := SFXR.p_hpf_ramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_pha_offset := SFXR.p_pha_offset + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_pha_ramp := SFXR.p_pha_ramp + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_repeat_speed := SFXR.p_repeat_speed + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_arp_speed := SFXR.p_arp_speed + frnd(0.1) - 0.05;
If (random(100) >= 50) Then SFXR.p_arp_mod := SFXR.p_arp_mod + frnd(0.1) - 0.05;
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.Button9Click(Sender: TObject);
Begin
// Randomize
SFXR.p_base_freq := power(frnd(2.0) - 1.0, 2.0);
If (random(100) >= 50) Then Begin
SFXR.p_base_freq := power(frnd(2.0) - 1.0, 3.0) + 0.5;
End;
SFXR.p_freq_limit := 0.0;
SFXR.p_freq_ramp := power(frnd(2.0) - 1.0, 5.0);
If (SFXR.p_base_freq > 0.7) And (SFXR.p_freq_ramp > 0.2) Then Begin
SFXR.p_freq_ramp := -SFXR.p_freq_ramp;
End;
If (SFXR.p_base_freq < 0.2) And (SFXR.p_freq_ramp < -0.05) Then Begin
SFXR.p_freq_ramp := -SFXR.p_freq_ramp;
End;
SFXR.p_freq_dramp := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_duty := frnd(2.0) - 1.0;
SFXR.p_duty_ramp := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_vib_strength := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_vib_speed := frnd(2.0) - 1.0;
SFXR.p_vib_delay := frnd(2.0) - 1.0;
SFXR.p_env_attack := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_env_sustain := power(frnd(2.0) - 1.0, 2.0);
SFXR.p_env_decay := frnd(2.0) - 1.0;
SFXR.p_env_punch := power(frnd(0.8), 2.0);
If (SFXR.p_env_attack + SFXR.p_env_sustain + SFXR.p_env_decay < 0.2) Then Begin
SFXR.p_env_sustain := SFXR.p_env_sustain + 0.2 + frnd(0.3);
SFXR.p_env_decay := SFXR.p_env_decay + 0.2 + frnd(0.3);
End;
SFXR.p_lpf_resonance := frnd(2.0) - 1.0;
SFXR.p_lpf_freq := 1.0 - power(frnd(1.0), 3.0);
SFXR.p_lpf_ramp := power(frnd(2.0) - 1.0, 3.0);
If (SFXR.p_lpf_freq < 0.1) And (SFXR.p_lpf_ramp < -0.05) Then Begin
SFXR.p_lpf_ramp := -SFXR.p_lpf_ramp;
End;
SFXR.p_hpf_freq := power(frnd(1.0), 5.0);
SFXR.p_hpf_ramp := power(frnd(2.0) - 1.0, 5.0);
SFXR.p_pha_offset := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_pha_ramp := power(frnd(2.0) - 1.0, 3.0);
SFXR.p_repeat_speed := frnd(2.0) - 1.0;
SFXR.p_arp_speed := frnd(2.0) - 1.0;
SFXR.p_arp_mod := frnd(2.0) - 1.0;
ReloadLCL;
do_play;
End;
Procedure TSoundGeneratorForm.ComboBox1Change(Sender: TObject);
Begin
Case ComboBox1.ItemIndex Of
0: SFXR.wav_freq := 44100;
1: SFXR.wav_freq := 22050;
End;
End;
Procedure TSoundGeneratorForm.ComboBox2Change(Sender: TObject);
Begin
Case ComboBox2.ItemIndex Of
0: SFXR.wav_bits := 16;
1: SFXR.wav_bits := 8;
End;
End;
End.