-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathnoiseremover_fpGUI.pas
More file actions
510 lines (449 loc) · 14.8 KB
/
noiseremover_fpGUI.pas
File metadata and controls
510 lines (449 loc) · 14.8 KB
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
program noiseremove_fpGUI;
{$mode objfpc}{$H+}
{$DEFINE UseCThreads}
uses
{$IFDEF UNIX} {$IFDEF UseCThreads}
cthreads,
cwstring, {$ENDIF} {$ENDIF}
SysUtils,
uos_flat,
fpg_style_chrome_silver_flatmenu,
fpg_stylemanager,
ctypes,
Math,
Classes,
fpg_button,
fpg_widget,
fpg_label,
fpg_Editbtn,
fpg_RadioButton,
fpg_trackbar,
fpg_CheckBox,
fpg_base,
fpg_main,
fpg_form { you can add units after this };
type
TSimpleplayer = class(TfpgForm)
procedure uos_logo(Sender: TObject);
private
{@VFD_HEAD_BEGIN: Simpleplayer}
Custom1: TfpgWidget;
Labelport: TfpgLabel;
btnLoad: TfpgButton;
FilenameEdit1: TfpgFileNameEdit;
FilenameEdit2: TfpgFileNameEdit;
FilenameEdit4: TfpgFileNameEdit;
btnStart: TfpgButton;
btnStop: TfpgButton;
Labelsnf: TfpgLabel;
btnpause: TfpgButton;
btnresume: TfpgButton;
chknoise: TfpgCheckBox;
{@VFD_HEAD_END: Simpleplayer}
public
procedure AfterCreate; override;
// constructor Create(AOwner: TComponent);
procedure btnLoadClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnStartClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure btnPauseClick(Sender: TObject);
procedure btnResumeClick(Sender: TObject);
{$IF (FPC_FULLVERSION >= 20701) or DEFINED(Windows)}
{$else}
procedure CustomMsgReceived(var msg: TfpgMessageRec); message MSG_CUSTOM1;
{$ENDIF}
procedure ClosePlayer1;
procedure ChangeNoise(Sender: TObject);
end;
{@VFD_NEWFORM_DECL}
{@VFD_NEWFORM_IMPL}
var
PlayerIndex1: integer;
ordir, opath: string;
OutputIndex1, InputIndex1 : integer;
procedure TSimpleplayer.ChangeNoise(Sender: TObject);
begin
if btnStart.Enabled = False then /// player1 was created
uos_InputSetDSPNoiseRemoval(PlayerIndex1, InputIndex1, chknoise.Checked);
end;
procedure TSimpleplayer.btnResumeClick(Sender: TObject);
begin
uos_RePlay(PlayerIndex1);
btnStart.Enabled := False;
btnStop.Enabled := True;
btnPause.Enabled := True;
btnresume.Enabled := False;
end;
procedure TSimpleplayer.btnPauseClick(Sender: TObject);
begin
uos_Pause(PlayerIndex1);
btnStart.Enabled := False;
btnStop.Enabled := True;
btnPause.Enabled := False;
btnresume.Enabled := True;
end;
procedure TSimpleplayer.btnCloseClick(Sender: TObject);
begin
if (btnstart.Enabled = False) then
begin
uos_stop(PlayerIndex1);
sleep(100);
end;
end;
procedure TSimpleplayer.btnLoadClick(Sender: TObject);
var
loadok : boolean = false;
begin
// Load the libraries
// function uos_loadlib(PortAudioFileName, SndFileFileName, Mpg123FileName, Mp4ffFileName, FaadFileName, opusfilefilename, libxmpfilename: PChar) : LongInt;
{$if defined(CPUAMD64) and defined(linux) }
// For Linux amd64, check libsndfile.so
if (FilenameEdit2.FileName <> 'system') and (FilenameEdit2.FileName <> '') then
if uos_TestLoadLibrary(PChar(FilenameEdit2.FileName)) = false then
FilenameEdit2.FileName := FilenameEdit2.FileName + '.2';
if (FilenameEdit1.FileName <> 'system') and (FilenameEdit1.FileName <> '') then
if uos_TestLoadLibrary(PChar(FilenameEdit1.FileName)) = false then
FilenameEdit1.FileName := FilenameEdit1.FileName + '.2';
{$endif}
if uos_LoadLib(Pchar(FilenameEdit1.FileName), Pchar(FilenameEdit2.FileName),
nil, nil, nil, nil, nil) = 0 then
begin
hide;
loadok := true;
Height := 230;
btnStart.Enabled := True;
btnLoad.Enabled := False;
FilenameEdit1.ReadOnly := True;
FilenameEdit2.ReadOnly := True;
UpdateWindowPosition;
btnLoad.Text :=
'PortAudio, SndFile, Mpg123 libraries are loaded...';
WindowPosition := wpScreenCenter;
WindowTitle := 'Noise Remover. uos Version ' + inttostr(uos_getversion());
fpgapplication.ProcessMessages;
sleep(500);
Show;
end else btnLoad.Text :=
'One or more libraries did not load, check filenames...';
end;
procedure TSimpleplayer.ClosePlayer1;
begin
btnStart.Enabled := True;
btnStop.Enabled := False;
btnPause.Enabled := False;
btnresume.Enabled := False;
end;
procedure TSimpleplayer.btnStopClick(Sender: TObject);
begin
uos_Stop(PlayerIndex1);
closeplayer1;
end;
///// example how to do custom dsp
procedure TSimpleplayer.btnStartClick(Sender: TObject);
var
samformat: shortint;
begin
samformat := 0;
PlayerIndex1 := 0;
// PlayerIndex : from 0 to what your computer can do ! (depends of ram, cpu, ...)
// If PlayerIndex exists already, it will be overwritten...
{$IF (FPC_FULLVERSION >= 20701) or DEFINED(Windows)}
uos_CreatePlayer(PlayerIndex1);
{$else}
uos_CreatePlayer(PlayerIndex1,self);
{$endif}
//// Create the player.
//// PlayerIndex : from 0 to what your computer can do !
//// If PlayerIndex exists already, it will be overwriten...
InputIndex1 := uos_AddFromFile(PlayerIndex1, pchar(filenameEdit4.filename), -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
{$if defined(cpuarm) or defined(cpuaarch64)} // need a lower latency
OutputIndex1 := uos_AddIntoDevOut(PlayerIndex1, -1, 0.3, uos_InputGetSampleRate(PlayerIndex1, InputIndex1),
uos_InputGetChannels(PlayerIndex1, InputIndex1), samformat, -1, -1);
{$else}
OutputIndex1 := uos_AddIntoDevOut(PlayerIndex1, -1, -1, uos_InputGetSampleRate(PlayerIndex1, InputIndex1),
uos_InputGetChannels(PlayerIndex1, InputIndex1), samformat, -1, -1);
{$endif}
//// add a Output into device with custom parameters
//////////// PlayerIndex : Index of a existing Player
//////////// Device ( -1 is default Output device )
//////////// Latency ( -1 is latency suggested ) )
//////////// SampleRate : delault : -1 (44100) /// here default samplerate of input
//////////// Channels : delault : -1 (2:stereo) (0: no channels, 1:mono, 2:stereo, ...)
//////////// SampleFormat : -1 default : Int16 : (0: Float32, 1:Int32, 2:Int16)
//////////// FramesCount : default : -1 (65536)
// ChunkCount : default : -1 (= 512)
// result : -1 nothing created, otherwise Output Index in array
uos_InputAddDSPNoiseRemoval(PlayerIndex1, InputIndex1);
uos_InputSetDSPNoiseRemoval(PlayerIndex1, InputIndex1, chknoise.Checked);
/// Add DSP Noise removal. First chunck will be the noise sample.
/////// procedure to execute when stream is terminated
uos_EndProc(PlayerIndex1, @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
btnStart.Enabled := False;
btnStop.Enabled := True;
btnpause.Enabled := True;
btnresume.Enabled := False;
uos_Play(PlayerIndex1); /////// everything is ready, here we are, lets play it...
end;
end;
{$IF (FPC_FULLVERSION >= 20701) or DEFINED(Windows)}
{$else}
procedure TSimpleplayer.CustomMsgReceived(var msg: TfpgMessageRec);
begin
ShowLevel;
ShowPosition ;
end;
{$ENDIF}
procedure TSimpleplayer.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: Simpleplayer}
Name := 'Simpleplayer';
SetPosition(396, 317, 503, 229);
WindowTitle := 'Noise remover';
IconName := '';
BackGroundColor := $80000001;
Hint := '';
WindowPosition := wpScreenCenter;
Ondestroy := @btnCloseClick;
Custom1 := TfpgWidget.Create(self);
with Custom1 do
begin
Name := 'Custom1';
SetPosition(10, 16, 115, 107);
OnPaint := @uos_logo;
end;
Labelport := TfpgLabel.Create(self);
with Labelport do
begin
Name := 'Labelport';
SetPosition(136, 4, 320, 15);
Alignment := taCenter;
FontDesc := '#Label1';
ParentShowHint := False;
Text := 'Folder + filename of PortAudio Library';
Hint := '';
end;
btnLoad := TfpgButton.Create(self);
with btnLoad do
begin
Name := 'btnLoad';
SetPosition(4, 130, 488, 24);
Text := 'Load that libraries';
FontDesc := '#Label1';
ImageName := '';
ParentShowHint := False;
TabOrder := 0;
Hint := '';
onclick := @btnLoadClick;
end;
FilenameEdit1 := TfpgFileNameEdit.Create(self);
with FilenameEdit1 do
begin
Name := 'FilenameEdit1';
SetPosition(140, 24, 356, 24);
ExtraHint := '';
FileName := '';
Filter := '';
InitialDir := '';
TabOrder := 3;
end;
FilenameEdit2 := TfpgFileNameEdit.Create(self);
with FilenameEdit2 do
begin
Name := 'FilenameEdit2';
SetPosition(140, 84, 356, 24);
ExtraHint := '';
FileName := '';
Filter := '';
InitialDir := '';
TabOrder := 4;
end;
FilenameEdit4 := TfpgFileNameEdit.Create(self);
with FilenameEdit4 do
begin
Name := 'FilenameEdit4';
SetPosition(168, 160, 320, 24);
ExtraHint := '';
FileName := '';
Filter := '';
InitialDir := '';
TabOrder := 5;
end;
btnStart := TfpgButton.Create(self);
with btnStart do
begin
Name := 'btnStart';
SetPosition(92, 196, 66, 23);
Text := 'Play';
Enabled := False;
FontDesc := '#Label1';
ImageName := '';
ParentShowHint := False;
TabOrder := 6;
Hint := '';
onclick := @btnstartClick;
end;
btnStop := TfpgButton.Create(self);
with btnStop do
begin
Name := 'btnStop';
SetPosition(320, 196, 66, 23);
Text := 'Stop';
Enabled := False;
FontDesc := '#Label1';
ImageName := '';
ParentShowHint := False;
TabOrder := 7;
Hint := '';
onclick := @btnStopClick;
end;
Labelsnf := TfpgLabel.Create(self);
with Labelsnf do
begin
Name := 'Labelsnf';
SetPosition(144, 64, 316, 15);
Alignment := taCenter;
FontDesc := '#Label1';
ParentShowHint := False;
Text := 'Folder + filename of SndFile Library';
Hint := '';
end;
btnpause := TfpgButton.Create(self);
with btnpause do
begin
Name := 'btnpause';
SetPosition(168, 196, 66, 23);
Text := 'Pause';
Enabled := False;
FontDesc := '#Label1';
ImageName := '';
ParentShowHint := False;
TabOrder := 15;
Hint := '';
onclick := @btnPauseClick;
end;
btnresume := TfpgButton.Create(self);
with btnresume do
begin
Name := 'btnresume';
SetPosition(244, 196, 66, 23);
Text := 'Resume';
Enabled := False;
FontDesc := '#Label1';
ImageName := '';
ParentShowHint := False;
TabOrder := 16;
Hint := '';
onclick := @btnResumeClick;
end;
chknoise := TfpgCheckBox.Create(self);
with chknoise do
begin
Name := 'chknoise';
SetPosition(20, 160, 136, 19);
FontDesc := '#Label1';
ParentShowHint := False;
TabOrder := 38;
Text := 'Noise Remover';
Hint := 'Noise remover';
OnChange := @Changenoise;
end;
{@VFD_BODY_END: Simpleplayer}
{%endregion}
//////////////////////
ordir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
Height := 159;
{$IFDEF Windows}
{$if defined(cpu64)}
FilenameEdit1.FileName := ordir + 'lib\Windows\64bit\LibPortaudio-64.dll';
FilenameEdit2.FileName := ordir + 'lib\Windows\64bit\LibSndFile-64.dll';
{$else}
FilenameEdit1.FileName := ordir + 'lib\Windows\32bit\LibPortaudio-32.dll';
FilenameEdit2.FileName := ordir + 'lib\Windows\32bit\LibSndFile-32.dll';
{$endif}
FilenameEdit4.FileName := ordir + 'sound\noisyvoice.ogg';
{$ENDIF}
{$IFDEF Darwin}
opath := ordir;
opath := copy(opath, 1, Pos('/uos', opath) - 1);
FilenameEdit1.FileName := opath + '/lib/Mac/32bit/LibPortaudio-32.dylib';
FilenameEdit2.FileName := opath + '/lib/Mac/32bit/LibSndFile-32.dylib';
FilenameEdit4.FileName := opath + 'sound/noisyvoice.ogg';
{$ENDIF}
{$if defined(CPUAMD64) and defined(linux) }
FilenameEdit1.FileName := ordir + 'lib/Linux/64bit/LibPortaudio-64.so';
FilenameEdit2.FileName := ordir + 'lib/Linux/64bit/LibSndFile-64.so';
FilenameEdit4.FileName := ordir + 'sound/noisyvoice.ogg';
{$ENDIF}
{$if defined(cpu86) and defined(linux)}
FilenameEdit1.FileName := ordir + 'lib/Linux/32bit/LibPortaudio-32.so';
FilenameEdit2.FileName := ordir + 'lib/Linux/32bit/LibSndFile-32.so';
FilenameEdit4.FileName := ordir + 'sound/noisyvoice.ogg';
{$ENDIF}
{$if defined(linux) and defined(cpuaarch64)}
FilenameEdit1.FileName := ordir + 'lib/Linux/aarch64_raspberrypi/libportaudio_aarch64.so';
FilenameEdit2.FileName := ordir + 'lib/Linux/aarch64_raspberrypi/libsndfile_aarch64.so';
FilenameEdit4.FileName := ordir + 'sound/noisyvoice.ogg';
{$ENDIF}
{$if defined(linux) and defined(cpuarm)}
FilenameEdit1.FileName := ordir + 'lib/Linux/arm_raspberrypi/libportaudio-arm.so';
FilenameEdit2.FileName := ordir + 'lib/Linux/arm_raspberrypi/libsndfile-arm.so';
FilenameEdit4.FileName := ordir + 'sound/noisyvoice.ogg';
{$ENDIF}
{$IFDEF freebsd}
{$if defined(cpu64)}
FilenameEdit1.FileName := ordir + 'lib/FreeBSD/64bit/libportaudio-64.so';
FilenameEdit2.FileName := ordir + 'lib/FreeBSD/64bit/libsndfile-64.so';
{$else}
FilenameEdit1.FileName := ordir + 'lib/FreeBSD/32bit/libportaudio-32.so';
FilenameEdit2.FileName := ordir + 'lib/FreeBSD/32bit/libsndfile-32.so';
{$endif}
FilenameEdit4.FileName := ordir + 'sound/noisyvoice.ogg';
{$ENDIF}
FilenameEdit4.Initialdir := ordir + 'sound';
FilenameEdit1.Initialdir := ordir + 'lib';
FilenameEdit2.Initialdir := ordir + 'lib';
end;
procedure TSimpleplayer.uos_logo(Sender: TObject);
begin
with Custom1 do
begin
Canvas.GradientFill(GetClientRect, clgreen, clBlack, gdVertical);
Canvas.TextColor := clWhite;
Canvas.DrawText(60, 20, 'uos');
end;
end;
procedure MainProc;
var
frm: TSimpleplayer;
begin
fpgApplication.Initialize;
if fpgStyleManager.SetStyle('Chrome silver flat menu') then
fpgStyle := fpgStyleManager.Style;
fpgApplication.CreateForm(TSimpleplayer, frm);
try
frm.Show;
fpgApplication.Run;
finally
uos_free; // do not forget this...
frm.Free;
end;
end;
begin
MainProc;
end.