-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmain_mt.pas
More file actions
179 lines (144 loc) · 4.36 KB
/
Copy pathmain_mt.pas
File metadata and controls
179 lines (144 loc) · 4.36 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
unit main_mt;
{$mode objfpc}{$H+}
interface
uses
SysUtils,
Forms,
StdCtrls,
Buttons,
uos_flat,
Classes;
type
{ TForm1 }
TForm1 = class(TForm)
BitBtnPlay: TBitBtn;
ButtonQuit: TButton;
interchar: TEdit;
interspace: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
procedure BitBtnPlayClick(Sender: TObject);
procedure ButtonQuitClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CreateMorsePlayer();
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
i: cardinal;
ordir: string;
implementation
{$R *.lfm}
procedure TForm1.CreateMorsePlayer();
var
filetoplay, fileerror: string;
chara: string;
player: cardinal;
begin
if i <= length(Memo1.Text) then
begin
chara := copy(Memo1.Text, i, 1);
fileerror := ordir + 'sound' + directoryseparator + 'morse_audio' + directoryseparator + '0.mp3';
if odd(i) then
player := 0
else
player := 1; ///// to switch between player1 <> player2
if chara <> ' ' then
begin
uos_CreatePlayer(player);
{$if defined(cpuarm) or defined(cpuaarch64)} // need a lower latency
uos_AddIntoDevOut(player, -1, 0.08, -1, -1, -1, -1, -1) ;
{$else}
uos_AddIntoDevOut(player);
{$endif}
filetoplay := ordir + 'sound' + directoryseparator + 'morse_audio' + directoryseparator + lowercase(chara) + '.mp3';
if fileexists(PChar(filetoplay)) then
uos_AddFromFile(player, PChar(filetoplay))
else
uos_AddFromFile(player, PChar(fileerror)); /// if not existing char
if length(Memo1.Text) > i then
uos_EndProc(player, @CreateMorsePlayer); /// assign EndProc
sleep(StrToInt(interchar.Text)); ///// the pause between each character
uos_Play(player);
Inc(i);
end
else
begin
sleep(StrToInt(interspace.Text)); ///// the pause if space character
Inc(i);
if length(Memo1.Text) >= i then
CreateMorsePlayer;
end;
end;
end;
procedure TForm1.BitBtnPlayClick(Sender: TObject);
var
charac: string;
begin
if Memo1.Text <> '' then
begin
i := 1;
CreateMorsePlayer();
end;
end;
procedure TForm1.ButtonQuitClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormActivate(Sender: TObject);
var
PA_FileName, MP_FileName: string;
begin
memo1.Text := '';
ordir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
{$IFDEF Windows}
{$if defined(cpu64)}
PA_FileName := ordir + 'lib\Windows\64bit\LibPortaudio-64.dll';
MP_FileName := ordir + 'lib\Windows\64bit\LibMpg123-64.dll';
{$else}
PA_FileName := ordir + 'lib\Windows\32bit\LibPortaudio-32.dll';
MP_FileName := ordir + 'lib\Windows\32bit\LibMpg123-32.dll';
{$endif}
{$ENDIF}
{$if defined(CPUAMD64) and defined(openbsd) }
PA_FileName := ordir + 'lib/OpenBSD/64bit/LibPortaudio-64.so';
MP_FileName := ordir + 'lib/OpenBSD/64bit/LibMpg123-64.so';
{$ENDIF}
{$if defined(CPUAMD64) and defined(linux) }
PA_FileName := ordir + 'lib/Linux/64bit/LibPortaudio-64.so';
MP_FileName := ordir + 'lib/Linux/64bit/LibMpg123-64.so';
{$ENDIF}
{$if defined(cpu86) and defined(linux)}
PA_FileName := ordir + 'lib/Linux/32bit/LibPortaudio-32.so';
MP_FileName := ordir + 'lib/Linux/32bit/LibMpg123-32.so';
{$endif}
{$if defined(linux) and defined(cpuarm)}
PA_FileName := ordir + 'lib/Linux/arm_raspberrypi/libportaudio-arm.so';
MP_FileName := ordir + 'lib/Linux/arm_raspberrypi/libsndfile-arm.so';
{$ENDIF}
{$if defined(linux) and defined(cpuaarch64)}
PA_FileName := ordir + 'lib/Linux/aarch64_raspberrypi/libportaudio_aarch64.so';
MP_FileName := ordir + 'lib/Linux/aarch64_raspberrypi/libmpg123_aarch64.so';
{$ENDIF}
{$IFDEF freebsd}
{$if defined(cpu64)}
PA_FileName := ordir + 'lib/FreeBSD/64bit/libportaudio-64.so';
MP_FileName := ordir + 'lib/FreeBSD/64bit/libmpg123-64.so';
{$else}
PA_FileName := ordir + 'lib/FreeBSD/32bit/libportaudio-32.so';
MP_FileName := ordir + 'lib/FreeBSD/32bit/libmpg123-32.so';
{$endif}
{$ENDIF}
uos_LoadLib(PChar(PA_FileName), nil, PChar(MP_FileName), nil, nil, nil, nil);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
uos_free; /// for release dynamic loaded libraries
end;
end.