This repository has been archived by the owner on Sep 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
161 lines (142 loc) · 5.38 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Audio Demo</title>
<meta name="Author" content="Scott Michaud"/>
<script src="src/pmeAudio.js"></script>
<script src="classes/boid.js"></script>
<script src="webglstuff.js"></script>
<script src="main.js"></script>
<script src="util.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="x-shader/x-vertex" id="vtxRainPoints">
attribute vec3 points;
varying float life;
void main() {
life = points.z;
gl_Position = vec4((2.0 * points.x) - 1.0, (2.0 * points.y) - 1.0, 0.0, 1.0);
gl_PointSize = 7.0;
}
</script>
<script type="x-shader/x-fragment" id="pxRainPoints">
precision mediump float;
varying float life;
void main() {
gl_FragColor = vec4(0.0, 0.0, 1.0, life);
}
</script>
<script type="text/x-opencl" id="clMixSamples">
// Structure of Arrays
//
// f_particles: x then y of each particle
//
// i_particles: sampleStart then sampleEnd then interpPosition
// for each particle's sample space.
//
// output: left then right
//
// soundCues: each source stacked, with sample.
//
__kernel void clMixSamples(__global float* f_particles,
__global int* i_particles,
__global float* output,
__global float* soundCues,
float2 obsLocation,
float2 obsDirection,
int numParticles,
int numCues)
{
int i = get_global_id(0); //Sample number
int itr = 0;
int numOutput = get_global_size(0);
//Copy the lookup table to local memory.
//THIS IS ONLY APPLICABLE BECAUSE soundCues IS SMALL
//But that's OKAY. Depending on the performance we get, this
//optimization can let us do a multi-kernel run where we
//load chunks of soundCues buffer into local memory and
//use it to populate a sorted list of needed samples
//in global memory (if a lot of samples are reused).
//Array size is baked in for simplicity. In real usage, it will be
//adjusted by JavaScript before the kernel is sent to the GPU compiler.
//That way, we can adjust for other variables, etc.
__local float _soundCues[4533];
for (itr = get_local_id(0); itr < numCues; itr += get_local_size(0))
{
_soundCues[itr] = soundCues[itr];
}
barrier(CLK_LOCAL_MEM_FENCE);
if (i >= numOutput)
{
return;
}
int isLeftEar = select(-1, 1, i > (numOutput / 2));
float SumOutput = 0.0f;
float2 EarDirection = isLeftEar * (float2)(-obsDirection.y, obsDirection.x);
float2 CurrentDirection = (float2)(0.0f, 0.0f);
int CurrentSamplePosition = 0;
float CurrentSample = 0.0f;
float2 CurrentLocation = (float2)(0.0f, 0.0f);
float SourceDistance = 0.0f;
float CurrentDistanceGain = 0.0f;
float CurrentBalance = 0.0f;
for (itr = 0; itr < numParticles; itr++)
{
CurrentSamplePosition = i_particles[itr + (2 * numParticles)] + i;
if ((CurrentSamplePosition >= i_particles[itr]) &&
(CurrentSamplePosition < i_particles[itr + numParticles]))
{
CurrentSample = _soundCues[CurrentSamplePosition];
CurrentLocation = (float2)(f_particles[itr], f_particles[itr + numParticles]);
SourceDistance = distance(obsLocation, CurrentLocation);
SourceDistance = clamp(SourceDistance, 200.f, 1000.f);
CurrentDistanceGain = 200.f / SourceDistance;
CurrentDirection = CurrentLocation - obsLocation;
CurrentDirection = normalize(CurrentDirection);
CurrentBalance = dot(CurrentDirection, EarDirection);
CurrentBalance += 1.0f;
CurrentBalance *= 0.5f;
CurrentBalance *= CurrentSample;
CurrentBalance *= CurrentDistanceGain;
SumOutput += CurrentBalance;
}
}
output[i] = SumOutput;
}
</script>
</head>
<body>
<div id="top">
<div id="topCenter">
<div id="leftOptions">
<div class="upperOptions">
<label for="webaudio">No Offloading</label>
<input id="typeWebAudio" type="radio" name="apiType" value="webaudio" onclick="app.selectNoOffload();" autocomplete="off">
<label for="webcl">WebCL Offload</label>
<input id="typeWebCL" type="radio" name="apiType" value="webcl" onclick="app.selectWebCL();" autocomplete="off">
</div>
<div class="lowerOptions">
<select name="webclDevice" id="webclDeviceSelector">
</select>
</div>
</div>
<div id="rightOptions">
<div class="upperOptions">
<label>Maximum Particles</label>
<input id="inputParticleCount" type="number" autocomplete="off" value="50">
<button autocomplete="off" id="startStop" onclick="app.beginPress();" disabled>
Begin
</button>
</div>
<div class="lowerOptions">
</div>
</div>
</div>
</div>
<div id="main">
<div id="tinRoof"></div>
<canvas id="glPoints"></canvas>
<canvas id="boid"></canvas>
</div>
</body>
</html>