forked from fnec/openaloberon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestOpenAL0.Mod
More file actions
202 lines (139 loc) · 4.78 KB
/
TestOpenAL0.Mod
File metadata and controls
202 lines (139 loc) · 4.78 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
MODULE TestOpenAL0; (** AUTHOR ""; PURPOSE ""; *)
IMPORT AL:=OpenAL, ALU := OpenALUtil, Math, Kernel, KernelLog;
VAR
timer: Kernel.Timer;
PROCEDURE Play1*;
VAR
buffer : AL.ALint;
source : AL.ALuint;
test : POINTER TO ARRAY OF CHAR;
z : SIGNED32;
BEGIN
NEW(test, 1000);
FOR z := 0 TO 999 DO
test[z] := CHR(SHORT(ENTIER(128*Math.sin(z*(2*Math.pi)/9.0)+128)));
END;
AL.alGenBuffers(1, ADDRESSOF(buffer));
AL.alBufferData(buffer, AL.AL_FORMAT_MONO8, ADDRESSOF(test[0]), 1000, 11024);
KernelLog.String("1-- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
AL.alGenSources(1, ADDRESSOF(source));
AL.alSourcef(source, AL.AL_PITCH, 1.0);
AL.alSourcef(source, AL.AL_GAIN, 1.0);
AL.alSourcei(source, AL.AL_LOOPING, AL.AL_TRUE);
AL.alSourcei(source, AL.AL_BUFFER, buffer);
KernelLog.String("2- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
AL.alSourcePlay(source);
KernelLog.String("3- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
timer.Sleep(2000);
AL.alSourceStop(source);
AL.alDeleteSources(1, ADDRESSOF(source));
AL.alDeleteBuffers(1, ADDRESSOF(buffer));
KernelLog.String("-------- Ok ------- "); KernelLog.Ln;
END Play1;
PROCEDURE Play2*;
CONST D2R = 0.0174532925;
VAR
buffer : AL.ALint;
source : AL.ALuint;
data: POINTER TO ARRAY OF CHAR;
i : SIGNED32;
x: FLOAT32;
samples: SIGNED32;
frequency: SIGNED32;
size, freq: SIGNED32;
srcPos, lstPos: ARRAY [3] OF AL.ALfloat;
BEGIN
AL.alGenBuffers(1, ADDRESSOF(buffer));
IF AL.alIsBuffer(buffer) THEN
KernelLog.String("isbuffer"); KernelLog.Ln;
ELSE
KernelLog.String("isnotbuffer"); KernelLog.Ln;
END;
KernelLog.String("Generating sine wave on user parameters"); KernelLog.Ln;
(* Generate using math
We want a note of 440 Hz. 32 samples for each oscillation
for 1 seconds, means 440*32 bytes
*)
frequency := 1000; (* which freaquency *)
samples := 4; (* How many samples for the wave? [try me between 2 and 16] *)
freq := samples * frequency;
size := freq; (* We don't need an higher frequency than the signal*)
NEW( data, size);
FOR i := 0 TO size-1 DO
x := i * 360.0 / samples;
data[i] := CHR(SHORT(ENTIER(128*Math.sin(x * D2R) + 128))) ; (* Clamp to [0,255] *)
END;
AL.alBufferData(buffer, AL.AL_FORMAT_MONO8, ADDRESSOF(data), samples, freq);
KernelLog.String("1-- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
AL.alGenSources(1, ADDRESSOF(source));
IF AL.alIsSource(source) THEN
KernelLog.String("issource"); KernelLog.Ln;
ELSE
KernelLog.String("isnotsource"); KernelLog.Ln;
END;
srcPos := [-0.3, 0.0, -3.0];
AL.alSourcef(source, AL.AL_PITCH, 1.0);
AL.alSourcef(source, AL.AL_GAIN, 1.0);
AL.alSourcefv(source, AL.AL_POSITION, ADDRESSOF(srcPos[0]));
AL.alSourcei(source, AL.AL_LOOPING, AL.AL_TRUE);
AL.alSourcei(source, AL.AL_BUFFER, buffer);
lstPos := [0.0, 0.0, -3.0];
AL.alListenerfv(AL.AL_POSITION, ADDRESSOF(lstPos[0]));
AL.alSourcePlay(source);
timer.Sleep(2000);
(* AL.alSourceStop(source); *)
(* Clear the things *)
AL.alDeleteSources(1, ADDRESSOF(source));
AL.alDeleteBuffers(1, ADDRESSOF(buffer));
KernelLog.String("-------- Ok ------- "); KernelLog.Ln;
END Play2;
(* 16 bit data *)
PROCEDURE Play3*;
VAR
buffer : AL.ALint;
source : AL.ALuint;
test : POINTER TO ARRAY OF SIGNED16; (* for 16 bits data*)
z : SIGNED32;
sizeBytes: SIGNED32;
y: FLOAT32;
freq: SIGNED32;
BEGIN
NEW(test, 10000);
freq := 11025;
FOR z := 0 TO 9999 DO
y := Math.exp(-z/10000)*Math.sin(z*(2.0*Math.pi*freq)/10000);
test[z] := SHORT(ENTIER(32760*(y-0.5)));
END;
AL.alGenBuffers(1, ADDRESSOF(buffer));
sizeBytes := LEN(test)(AL.ALsizei)*SIZEOF(SIGNED16);
AL.alBufferData(buffer, AL.AL_FORMAT_MONO16, ADDRESSOF(test[0]), sizeBytes, freq);
KernelLog.String("1-- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
AL.alGenSources(1, ADDRESSOF(source));
AL.alSourcef(source, AL.AL_PITCH, 1.0);
AL.alSourcef(source, AL.AL_GAIN, 1.0);
(* AL.alSourcei(source, AL.AL_LOOPING, AL.AL_TRUE); *)
AL.alSourcei(source, AL.AL_BUFFER, buffer);
KernelLog.String("2- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
AL.alSourcePlay(source);
KernelLog.String("3- alGetError= "); KernelLog.Hex(AL.alGetError(), 4); KernelLog.Ln;
timer.Sleep(2000);
(* AL.alSourceStop(source);*)
AL.alDeleteSources(1, ADDRESSOF(source));
AL.alDeleteBuffers(1, ADDRESSOF(buffer));
KernelLog.String("-------- Ok ------- "); KernelLog.Ln;
END Play3;
(* for commandline run*)
PROCEDURE Do*;
BEGIN
Play1;
Play2;
Play3;
END Do;
BEGIN
NEW(timer);
END TestOpenAL0.
TestOpenAL0.Play1 ~
TestOpenAL0.Play2 ~
TestOpenAL0.Play3 ~
TestOpenAL0.Do ~
System.Free TestOpenAL0~