-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain_sp_nf.pas
820 lines (714 loc) · 26.7 KB
/
main_sp_nf.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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
/////////////////// Demo how to use United Openlib of Sound ////////////////////
unit main_sp_nf;
{$mode objfpc}{$H+}
interface
uses
uos,
Forms,
Dialogs,
SysUtils,
fileutil,
Graphics,
ctypes,
StdCtrls,
ComCtrls,
ExtCtrls,
Classes,
Controls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
chkstereo2mono: TCheckBox;
Edit1: TEdit;
Edit10: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit11: TEdit;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
llength: TLabel;
lposition: TLabel;
Label8: TLabel;
OpenDialog1: TOpenDialog;
PaintBox1: TPaintBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioGroup1: TRadioGroup;
Shape1: TShape;
ShapeRight: TShape;
ShapeLeft: TShape;
TrackBar2: TTrackBar;
TrackBar1: TTrackBar;
TrackBar3: TTrackBar;
TrackBar4: TTrackBar;
TrackBar5: TTrackBar;
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 Button8Click(Sender: TObject);
procedure CheckBox1Change(Sender: TObject);
procedure CheckBox3Change(Sender: TObject);
procedure chkstereo2monoChange(Sender: TObject);
procedure Edit5Change(Sender: TObject);
procedure Edit11Change(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure TrackBar2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure ClosePlayer1;
procedure LoopProcPlayer1;
procedure ShowPosition;
procedure ShowLevel;
procedure ChangePlugSet(Sender: TObject);
procedure ResetPlugClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
////// This is the "standart" DSP procedure look.
function DSPReverseBefore(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
function DSPReverseAfter(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
function DSPStereo2Mono(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
procedure uos_logo();
var
Form1: TForm1;
BufferBMP: TBitmap;
plugsoundtouch: Boolean = False;
plugbs2b: Boolean = False;
PlayerIndex1: Tuos_Player;
OutputIndex1, InputIndex1, DSPIndex1, DSPIndex2, DSPVolume, PluginIndex1, PluginIndex2: integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ChangePlugSet(Sender: TObject);
var
tempo, rate: cfloat;
begin
if (trim(PChar(edit5.Text)) <> '') and fileexists(edit5.Text) then
begin
if (2 * (TrackBar4.Position / 100)) < 0.3 then
tempo := 0.3
else
tempo := (2 * (TrackBar4.Position / 100));
if (2 * (TrackBar5.Position / 100)) < 0.3 then
rate := 0.3
else
rate := (2 * (TrackBar5.Position / 100));
label7.Caption := 'Tempo: ' + floattostrf(tempo, ffFixed, 15, 1);
label9.Caption := 'Pitch: ' + floattostrf(rate, ffFixed, 15, 1);
if radiogroup1.Enabled = False then /// player1 was created
PlayerIndex1.SetPluginSoundTouch(PluginIndex2, tempo, rate, checkbox2.Checked);
end;
end;
procedure TForm1.ResetPlugClick(Sender: TObject);
begin
TrackBar4.Position := 50;
TrackBar5.Position := 50;
if radiogroup1.Enabled = False then /// player1 was created
PlayerIndex1.SetPluginSoundTouch(PluginIndex2, 1, 1, checkbox2.Checked);
end;
procedure TForm1.ClosePlayer1;
begin
Form1.button3.Enabled := True;
Form1.button4.Enabled := False;
Form1.button5.Enabled := False;
Form1.button6.Enabled := False;
Form1.trackbar2.Enabled := False;
Form1.radiogroup1.Enabled := True;
Form1.TrackBar2.Position := 0;
Form1.ShapeLeft.Height := 0;
Form1.ShapeRight.Height := 0;
Form1.ShapeLeft.top := 414;
Form1.ShapeRight.top := 414;
form1.lposition.Caption := '00:00:00.000';
end;
procedure TForm1.FormActivate(Sender: TObject);
var
ordir: string;
{$IFDEF Darwin}
opath: string;
{$ENDIF}
begin
ordir := application.Location;
uos_logo();
{$IFDEF Windows}
{$if defined(cpu64)}
Edit1.Text := ordir + 'lib\Windows\64bit\LibPortaudio-64.dll';
Edit2.Text := ordir + 'lib\Windows\64bit\LibSndFile-64.dll';
Edit3.Text := ordir + 'lib\Windows\64bit\LibMpg123-64.dll';
Edit11.text := ordir + 'lib\Windows\64bit\libxmp-64.dll';
Edit5.Text := ordir + 'lib\Windows\64bit\plugin\LibSoundTouch-64.dll';
{$else}
Edit1.Text := ordir + 'lib\Windows\32bit\LibPortaudio-32.dll';
Edit2.Text := ordir + 'lib\Windows\32bit\LibSndFile-32.dll';
Edit3.Text := ordir + 'lib\Windows\32bit\LibMpg123-32.dll';
Edit11.text := ordir + 'lib\Windows\32bit\libxmp-32.dll';
Edit7.text := ordir + 'lib\Windows\32bit\LibMp4ff-32.dll';
Edit10.text := ordir + 'lib\Windows\32bit\LibOpusFile-32.dll';
Edit8.text := ordir + 'lib\Windows\32bit\LibFaad2-32.dll';
Edit5.Text := ordir + 'lib\Windows\32bit\plugin\LibSoundTouch-32.dll';
// Error on Windows10 with libbs2b --> when closing application.
//Edit6.Text := ordir + 'lib\Windows\32bit\plugin\Libbs2b-32.dll';
{$endif}
Edit4.Text := ordir + 'sound\test.ogg';
{$ENDIF}
{$IFDEF freebsd}
{$if defined(cpu64)}
Edit1.Text := ordir + 'lib/FreeBSD/64bit/libportaudio-64.so';
Edit2.Text := ordir + 'lib/FreeBSD/64bit/libsndfile-64.so';
Edit3.Text := ordir + 'lib/FreeBSD/64bit/libmpg123-64.so';
Edit5.text := ordir + 'lib/FreeBSD/64bit/plugin/libsoundtouch-64.so';
Edit6.text := ordir + 'lib/FreeBSD/64bit/plugin/libbs2b-64.so';
Edit10.text := ordir + 'lib/FreeBSD/64bit/libopusfile-64.so';
{$else}
Edit1.Text := ordir + 'lib/FreeBSD/32bit/libportaudio-32.so';
Edit2.Text := ordir + 'lib/FreeBSD/32bit/libsndfile-32.so';
Edit3.Text := ordir + 'lib/FreeBSD/32bit/libmpg123-32.so';
Edit5.Text := '' ;
{$endif}
Edit4.Text := ordir + 'sound/test.ogg';
{$ENDIF}
{$IFDEF Darwin}
{$IFDEF CPU32}
opath := ordir;
opath := copy(opath, 1, Pos('/uos', opath) - 1);
Edit1.Text := opath + '/lib/Mac/32bit/LibPortaudio-32.dylib';
Edit2.Text := opath + '/lib/Mac/32bit/LibSndFile-32.dylib';
Edit3.Text := opath + '/lib/Mac/32bit/LibMpg123-32.dylib';
Edit5.Text := opath + '/lib/Mac/32bit/plugin/LibSoundTouch-32.dylib';
Edit4.Text := ordir + '/sound/test.ogg';
{$ENDIF}
{$IFDEF CPU64}
opath := ordir;
opath := copy(opath, 1, Pos('/uos', opath) - 1);
Edit1.Text := opath + '/lib/Mac/64bit/LibPortaudio-64.dylib';
Edit2.Text := opath + '/lib/Mac/64bit/LibSndFile-64.dylib';
Edit3.Text := opath + '/lib/Mac/64bit/LibMpg123-64.dylib';
Edit11.Text := opath + '/lib/Mac/64bit/libxmp-64.dylib';
Edit5.Text := opath + '/lib/Mac/64bit/plugin/libSoundTouchDLL-64.dylib';
Edit4.Text := ordir + '/sound/test.ogg';
{$ENDIF}
{$ENDIF}
{$if defined(CPUAMD64) and defined(openbsd) }
Edit1.Text := ordir + 'lib/OpenBSD/64bit/LibPortaudio-64.so';
Edit2.Text := ordir + 'lib/OpenBSD/64bit/LibSndFile-64.so';
Edit3.Text := ordir + 'lib/OpenBSD/64bit/LibMpg123-64.so';
Edit5.Text := ordir + 'lib/OpenBSD/64bit/plugin/LibSoundTouch-64.so';
Edit4.Text := ordir + '/sound/test.ogg';
{$ENDIF}
{$if defined(CPUAMD64) and defined(linux) }
Edit1.Text := ordir + 'lib/Linux/64bit/LibPortaudio-64.so';
Edit2.Text := ordir + 'lib/Linux/64bit/LibSndFile-64.so';
Edit3.Text := ordir + 'lib/Linux/64bit/LibMpg123-64.so';
Edit7.text := ordir + 'lib/Linux/64bit/LibMp4ff-64.so';
Edit8.text := ordir + 'lib/Linux/64bit/LibFaad2-64.so';
Edit10.text := ordir + 'lib/Linux/64bit/LibOpusFile-64.so';
Edit11.text := ordir + 'lib/Linux/64bit/libxmp-64.so';
Edit5.Text := ordir + 'lib/Linux/64bit/plugin/LibSoundTouch-64.so';
Edit6.Text := ordir + 'lib/Linux/64bit/plugin/libbs2b-64.so';
Edit4.Text := ordir + 'sound/test.ogg';
{$ENDIF}
{$if defined(cpu86) and defined(linux)}
Edit1.Text := ordir + 'lib/Linux/32bit/LibPortaudio-32.so';
Edit2.Text := ordir + 'lib/Linux/32bit/LibSndFile-32.so';
Edit3.Text := ordir + 'lib/Linux/32bit/LibMpg123-32.so';
Edit7.text := ordir + 'lib/Linux/32bit/LibMp4ff-32.so';
Edit8.text := ordir + 'lib/Linux/32bit/LibFaad2-32.so';
Edit5.Text := ordir + 'lib/Linux/32bit/plugin/LibSoundTouch-32.so';
Edit11.text := ordir + 'lib/Linux/32bit/libxmp-32.so';
Edit4.Text := ordir + 'sound/test.ogg';
{$ENDIF}
{$if defined(linux) and defined(cpuarm)}
Edit1.Text := ordir + 'lib/Linux/arm_raspberrypi/libportaudio-arm.so';
Edit2.Text := ordir + 'lib/Linux/arm_raspberrypi/libsndfile-arm.so';
Edit3.Text := ordir + 'lib/Linux/arm_raspberrypi/libmpg123-arm.so';
Edit11.Text := ordir + 'lib/Linux/arm_raspberrypi/libxmp-arm.so';
Edit5.Text := ordir + 'lib/Linux/arm_raspberrypi/plugin/libsoundtouch-32.so';
Edit4.Text := ordir + 'sound/test.ogg';
{$ENDIF}
{$if defined(linux) and defined(cpuaarch64)}
Edit1.Text := ordir + 'lib/Linux/aarch64_raspberrypi/libportaudio_aarch64.so';
Edit2.Text := ordir + 'lib/Linux/aarch64_raspberrypi/libsndfile_aarch64.so';
Edit3.Text := ordir + 'lib/Linux/aarch64_raspberrypi/libmpg123_aarch64.so';
Edit11.text := ordir + 'lib/Linux/aarch64_raspberrypi/libxmp-aarch64.so';
Edit5.Text := ordir + 'lib/Linux/aarch64_raspberrypi/plugin/libsoundtouch_aarch64.so';
Edit4.Text := ordir + 'sound/test.ogg';
{$ENDIF}
opendialog1.Initialdir := application.Location + 'sound';
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
PaintBox1.Canvas.Draw(0, 0, BufferBMP);
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if (button3.Enabled = False) then
PlayerIndex1.InputSetDSPVolume(InputIndex1, DSPVolume, TrackBar1.position / 100,
TrackBar3.position / 100, True);
end;
procedure TForm1.TrackBar2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
TrackBar2.Tag := 1;
end;
procedure TForm1.TrackBar2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
PlayerIndex1.InputSeek(InputIndex1, TrackBar2.position);
TrackBar2.Tag := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
loadok: Boolean = False;
begin
{$if defined(CPUAMD64) and defined(linux) }
// For Linux amd64, check libsndfile.so
if (Edit2.Text <> 'system') and (Edit2.Text <> '') then
if uos_TestLoadLibrary(PChar(Edit2.Text)) = false then
begin
Edit2.Text := Edit2.Text + '.2';
if uos_TestLoadLibrary(PChar(Edit2.Text)) = false then
MessageDlg('Error while loading SndFile library...', mtWarning, [mbYes], 0);
end;
{$endif}
// Load the libraries
// function uos_loadlib(PortAudioFileName, SndFileFileName, Mpg123FileName, Mp4ffFileName, FaadFileName, opusfilefilename, xmpfilename: PChar) : LongInt;
if uos_LoadLib(PChar(Edit1.Text), PChar(Edit2.Text),
PChar(Edit3.Text), PChar(Edit7.Text), PChar(Edit8.Text), PChar(Edit10.Text), PChar(Edit11.Text)) = 0 then
// You may load one or more libraries . When you want... :
begin
form1.hide;
loadok := True;
button1.Enabled := False;
edit1.ReadOnly := True;
edit2.ReadOnly := True;
edit3.ReadOnly := True;
edit5.ReadOnly := True;
button1.Caption :=
'PortAudio, SndFile and Mpg123 libraries are loaded...';
end
else
MessageDlg('Error while loading libraries...', mtWarning, [mbYes], 0);
if loadok = True then
begin
if ((trim(PChar(edit5.Text)) <> '') and fileexists(edit5.Text)) and (uos_LoadPlugin('soundtouch', PChar(Edit5.Text)) = 0) then
begin
plugsoundtouch := True;
button1.Caption :=
'PortAudio, SndFile, Mpg123 and Plugin are loaded...';
end
else
begin
TrackBar4.Enabled := False;
TrackBar5.Enabled := False;
CheckBox2.Enabled := False;
Button7.Enabled := False;
label9.Enabled := False;
label7.Enabled := False;
end;
if ((trim(PChar(edit6.Text)) <> '') and fileexists(edit6.Text)) and (uos_LoadPlugin('bs2b', PChar(edit6.Text)) = 0) then
plugbs2b := True
else
CheckBox3.Enabled := False;
form1.Height := 626;
form1.Position := poScreenCenter;
form1.Caption := 'Simple Player. uos version ' + IntToStr(uos_getversion());
form1.Show;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
PlayerIndex1.Pause();
Button4.Enabled := True;
Button5.Enabled := False;
Form1.ShapeLeft.Height := 0;
Form1.ShapeRight.Height := 0;
Form1.ShapeLeft.top := 414;
Form1.ShapeRight.top := 414;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Button4.Enabled := False;
Button5.Enabled := True;
Button6.Enabled := True;
application.ProcessMessages;
PlayerIndex1.RePlay();
end;
procedure TForm1.Button3Click(Sender: TObject);
var
samformat: shortint;
temptime: ttime;
ho, mi, se, ms: word;
begin
if fileexists(Edit4.Text) then
begin
// PlayerIndex : from 0 to what your computer can do ! (depends of ram, cpu, ...)
// If PlayerIndex exists already, it will be overwritten...
if radiobutton1.Checked = True then
samformat := 0;
if radiobutton2.Checked = True then
samformat := 1;
if radiobutton3.Checked = True then
samformat := 2;
radiogroup1.Enabled := False;
{$IF (FPC_FULLVERSION >= 20701) or DEFINED(Windows)}
PlayerIndex1 := Tuos_Player.Create();
{$else}
PlayerIndex1 := Tuos_Player.Create(true,self);
{$endif}
//// Create the player.
//// PlayerIndex : from 0 to what your computer can do !
//// If PlayerIndex exists already, it will be overwriten...
InputIndex1 := PlayerIndex1.AddFromFile(PChar(Edit4.Text), -1, samformat, -1);
//// add input from audio file with custom parameters
////////// FileName : filename of audio file
//////////// PlayerIndex : Index of a existing Player
////////// OutputIndex : OutputIndex of existing Output // -1 : all output, -2: no output, other integer : existing output)
////////// SampleFormat : -1 default : Int16 : (0: Float32, 1:Int32, 2:Int16) SampleFormat of Input can be <= SampleFormat float of Output
//////////// FramesCount : default : -1 (65536 div channels)
// result : -1 nothing created, otherwise Input Index in array
if InputIndex1 > -1 then
begin
// OutputIndex1 := uos_AddIntoDevOut(PlayerIndex1) ;
//// add a Output into device with default parameters
OutputIndex1 := PlayerIndex1.AddIntoDevOut(-1, -1, PlayerIndex1.StreamIn[InputIndex1].Data.SampleRate, -1, samformat, -1, -1);
// Add a Output into Device Output
// Device ( -1 is default device )
// Latency ( -1 is latency suggested )
// SampleRate : delault : -1 (44100)
// Channels : delault : -1 (2:stereo) (0: no channels, 1:mono, 2:stereo, ...)
// SampleFormat : default : -1 (2:Int16) (0: Float32, 1:Int32, 2:Int16)
// FramesCount : default : -1 (= 65536)
// ChunkCount : default : -1 (= 512)
// result : Output Index in array -1 = error
// example : OutputIndex1 := AddIntoDevOut(-1,-1,-1,-1,0,-1,-1);
// PlayerIndex1.StreamIn[In1Index].Data.levelEnable:=2 ;
PlayerIndex1.InputSetLevelEnable(InputIndex1, 2);
///// set calculation of level/volume (usefull for showvolume procedure)
///////// set level calculation (default is 0)
// 0 => no calcul
// 1 => calcul before all DSP procedures.
// 2 => calcul after all DSP procedures.
// 3 => calcul before and after all DSP procedures.
// PlayerIndex1.StreamIn[In1Index].Data.PositionEnable:= 1 ;
PlayerIndex1.InputSetPositionEnable(InputIndex1, 1);
///// set calculation of position (usefull for positions procedure)
///////// set position calculation (default is 0)
// 0 => no calcul
// 1 => calcul position.
PlayerIndex1.StreamIn[InputIndex1].LoopProc := @LoopProcPlayer1;
///// Assign the procedure of object to execute inside the loop
//////////// PlayerIndex : Index of a existing Player
//////////// InputIndex1 : Index of a existing Input
//////////// LoopProcPlayer1 : procedure of object to execute inside the loop
DSPVolume := PlayerIndex1.InputAddDSPVolume(InputIndex1, 1, 1);
///// DSP Volume changer
////////// PlayerIndex1 : Index of a existing Player
////////// InputIndex1 : Index of a existing input
////////// VolLeft : Left volume
////////// VolRight : Right volume
PlayerIndex1.InputSetDSPVolume(InputIndex1, DSPVolume, TrackBar1.position / 100,
TrackBar3.position / 100, True); /// Set volume
////////// PlayerIndex1 : Index of a existing Player
////////// DSPVolume : Index of a existing dsp
////////// InputIndex1 : InputIndex of a existing Input
////////// VolLeft : Left volume
////////// VolRight : Right volume
////////// Enable : Enabled
DSPIndex1 := PlayerIndex1.InputAddDSP(InputIndex1, @DSPReverseBefore, @DSPReverseAfter, nil, nil);
///// add a custom DSP procedure for input
////////// PlayerIndex1 : Index of a existing Player
////////// InputIndex1: InputIndex of existing input
////////// BeforeFunc : function to do before the buffer is filled
////////// AfterFunc : function to do after the buffer is filled
////////// EndedFunc : function to do at end of thread
////////// LoopProc : external procedure to do after the buffer is filled
//// set the parameters of custom DSP
PlayerIndex1.InputSetDSP(InputIndex1, DSPIndex1, checkbox1.Checked);
// This is a other custom DSP...stereo to mono to show how to do a DSP ;-)
DSPIndex2 := PlayerIndex1.InputAddDSP(InputIndex1, nil, @DSPStereo2Mono, nil, nil);
PlayerIndex1.InputSetDSP(InputIndex1, DSPIndex2, chkstereo2mono.Checked);
///// add bs2b plugin with samplerate_of_input1 / default channels (2 = stereo)
if plugbs2b = True then
begin
PlugInIndex1 := PlayerIndex1.AddPlugin('bs2b', PlayerIndex1.StreamIn[InputIndex1].Data.SampleRate, -1);
PlayerIndex1.SetPluginbs2b(PluginIndex1, -1, -1, -1, checkbox3.Checked);
end;
/// add SoundTouch plugin with samplerate of input1 / default channels (2 = stereo)
/// SoundTouch plugin should be the last added.
if plugsoundtouch = True then
begin
PlugInIndex2 := PlayerIndex1.AddPlugin('soundtouch',
PlayerIndex1.StreamIn[InputIndex1].Data.SampleRate, -1);
ChangePlugSet(self); //// custom procedure to Change plugin settings
end;
trackbar2.Max := PlayerIndex1.InputLength(InputIndex1);
////// Length of Input in samples
if trackbar2.Max > 0 then // mod's can not calculate length
begin
trackbar2.enabled := true;
temptime := PlayerIndex1.InputLengthTime(InputIndex1);
////// Length of input in time
DecodeTime(temptime, ho, mi, se, ms);
llength.Caption := format('%d:%d:%d.%d', [ho, mi, se, ms]);
end else
begin
trackbar2.enabled := false;
llength.Caption := '??:??:??.???';
end;
/////// procedure to execute when stream is terminated
PlayerIndex1.EndProc := @ClosePlayer1;
///// Assign the procedure of object to execute at end
//////////// PlayerIndex : Index of a existing Player
//////////// ClosePlayer1 : procedure of object to execute inside the general loop
TrackBar2.position := 0;
CheckBox1.Enabled := True;
button3.Enabled := False;
button6.Enabled := True;
button5.Enabled := True;
button4.Enabled := False;
PlayerIndex1.Play();
end;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
PlayerIndex1.Stop();
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
PlayerIndex1.PlayNoFree();
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
Edit4.Text := opendialog1.FileName;
end;
procedure TForm1.CheckBox1Change(Sender: TObject);
begin
if (button3.Enabled = False) then
PlayerIndex1.InputSetDSP(InputIndex1, DSPIndex1, checkbox1.Checked);
end;
procedure TForm1.CheckBox3Change(Sender: TObject);
begin
if radiogroup1.Enabled = False then /// player1 was created
PlayerIndex1.SetPluginbs2b(PluginIndex1, -1, -1, -1, checkbox3.Checked);
end;
procedure TForm1.chkstereo2monoChange(Sender: TObject);
begin
if radiogroup1.Enabled = False then
PlayerIndex1.InputSetDSP(InputIndex1, DSPIndex2, chkstereo2mono.Checked);
end;
procedure TForm1.Edit5Change(Sender: TObject);
begin
end;
procedure TForm1.Edit11Change(Sender: TObject);
begin
end;
procedure uos_logo();
var
xpos, ypos: integer;
ratio: double;
begin
xpos := 0;
ypos := 0;
ratio := 1;
BufferBMP := TBitmap.Create;
with form1 do
begin
form1.PaintBox1.Parent.DoubleBuffered := True;
PaintBox1.Height := round(ratio * 116);
PaintBox1.Width := round(ratio * 100);
BufferBMP.Height := PaintBox1.Height;
BufferBMP.Width := PaintBox1.Width;
BufferBMP.Canvas.AntialiasingMode := amOn;
BufferBMP.Canvas.Pen.Width := round(ratio * 6);
BufferBMP.Canvas.brush.Color := clmoneygreen;
BufferBMP.Canvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);
BufferBMP.Canvas.Pen.Color := clblack;
BufferBMP.Canvas.brush.Color := $70FF70;
BufferBMP.Canvas.Ellipse(round(ratio * (22) + xpos),
round(ratio * (30) + ypos), round(ratio * (72) + xpos),
round(ratio * (80) + ypos));
BufferBMP.Canvas.brush.Color := clmoneygreen;
BufferBMP.Canvas.Arc(round(ratio * (34) + xpos), round(ratio * (8) + ypos),
round(ratio * (58) + xpos), round(ratio * (32) + ypos), round(ratio * (58) + xpos),
round(ratio * (20) + ypos), round(ratio * (46) + xpos),
round(ratio * (32) + xpos));
BufferBMP.Canvas.Arc(round(ratio * (34) + xpos), round(ratio * (32) + ypos),
round(ratio * (58) + xpos), round(ratio * (60) + ypos), round(ratio * (34) + xpos),
round(ratio * (48) + ypos), round(ratio * (46) + xpos),
round(ratio * (32) + ypos));
BufferBMP.Canvas.Arc(round(ratio * (-28) + xpos), round(ratio * (18) + ypos),
round(ratio * (23) + xpos), round(ratio * (80) + ypos), round(ratio * (20) + xpos),
round(ratio * (50) + ypos), round(ratio * (3) + xpos), round(ratio * (38) + ypos));
BufferBMP.Canvas.Arc(round(ratio * (70) + xpos), round(ratio * (18) + ypos),
round(ratio * (122) + xpos), round(ratio * (80) + ypos),
round(ratio * (90 - xpos)),
round(ratio * (38) + ypos), round(ratio * (72) + xpos),
round(ratio * (50) + ypos));
BufferBMP.Canvas.Font.Name := 'Arial';
BufferBMP.Canvas.Font.Size := round(ratio * 10);
BufferBMP.Canvas.TextOut(round(ratio * (4) + xpos),
round(ratio * (83) + ypos), 'United Openlib');
BufferBMP.Canvas.Font.Size := round(ratio * 7);
BufferBMP.Canvas.TextOut(round(ratio * (20) + xpos),
round(ratio * (101) + ypos), 'of');
BufferBMP.Canvas.Font.Size := round(ratio * 10);
BufferBMP.Canvas.TextOut(round(ratio * (32) + xpos),
round(ratio * (98) + ypos), 'Sound');
end;
end;
procedure TForm1.ShowPosition;
var
temptime: ttime;
ho, mi, se, ms: word;
begin
if form1.TrackBar2.Tag = 0 then
begin
if trackbar2.Max > 0 then
form1.TrackBar2.Position := PlayerIndex1.InputPosition(InputIndex1);
temptime := PlayerIndex1.InputPositionTime(InputIndex1);
////// Length of input in time
DecodeTime(temptime, ho, mi, se, ms);
form1.lposition.Caption := format('%.2d:%.2d:%.2d.%.3d', [ho, mi, se, ms]);
end;
end;
procedure Tform1.ShowLevel;
begin
ShapeLeft.Height := round(PlayerIndex1.InputGetLevelLeft(InputIndex1) * 92);
ShapeRight.Height := round(PlayerIndex1.InputGetLevelRight(InputIndex1) * 92);
ShapeLeft.top := 506 - ShapeLeft.Height;
ShapeRight.top := 506 - ShapeRight.Height;
end;
procedure Tform1.LoopProcPlayer1;
begin
ShowPosition;
ShowLevel;
end;
//{
function DSPReverseBefore(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
begin
if Data.position > Data.OutFrames div Data.ratio then
PlayerIndex1.InputSeek(InputIndex1, Data.position - (Data.OutFrames div (Data.Ratio)));
end;
function DSPReverseAfter(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
var
x: integer;
arfl: TDArFloat;
begin
SetLength(arfl, length(Data.Buffer));
for x := 0 to ((Data.OutFrames * Data.Ratio) - 1) do
if odd(x) then
arfl[x] := Data.Buffer[((Data.OutFrames * Data.Ratio) - 1) - x - 1]
else
arfl[x] := Data.Buffer[((Data.OutFrames * Data.Ratio) - 1) - x + 1];
Result := arfl;
end;
//}
function DSPStereo2Mono(var Data: Tuos_Data; var fft: Tuos_FFT): TDArFloat;
var
x: integer = 0;
ps: PDArShort; //////// if input is Int16 format
pl: PDArLong; //////// if input is Int32 format
pf: PDArFloat; //////// if input is Float32 format
samplef: cFloat;
samplei: integer;
begin
if (Data.channels = 2) then
begin
case Data.SampleFormat of
2:
begin
ps := @Data.Buffer;
while x < Data.OutFrames do
begin
samplei := round((ps^[x] + ps^[x + 1]) / 2);
ps^[x] := samplei;
ps^[x + 1] := samplei;
x := x + 2;
end;
end;
1:
begin
pl := @Data.Buffer;
while x < Data.OutFrames do
begin
samplei := round((pl^[x] + pl^[x + 1]) / 2);
pl^[x] := samplei;
pl^[x + 1] := samplei;
x := x + 2;
end;
end;
0:
begin
pf := @Data.Buffer;
while x < Data.OutFrames do
begin
samplef := (pf^[x] + pf^[x + 1]) / 2;
pf^[x] := samplef;
pf^[x + 1] := samplef;
x := x + 2;
end;
end;
end;
Result := Data.Buffer;
end
else
Result := Data.Buffer;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Height := 396;
ShapeLeft.Height := 0;
ShapeRight.Height := 0;
trackbar1.Position := 100;
trackbar3.Position := 100;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if (button3.Enabled = False) then
begin
button6.Click;
sleep(500);
end;
if button1.Enabled = False then
begin
PlayerIndex1.Free;
uos_free;
end;
BufferBMP.free;
end;
end.