Skip to content

Commit 98879d8

Browse files
committed
Add spectrogram shader. Update README.
1 parent a5584a7 commit 98879d8

File tree

7 files changed

+143
-7
lines changed

7 files changed

+143
-7
lines changed

docs/README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,38 @@ visualizers might look like when visualizing the same sound.
1111
Here is a youtube video of the app displaying a waveform.<br>
1212
<a href="https://youtu.be/yxGM7H1RFRA">https://youtu.be/yxGM7H1RFRA</a>
1313

14-
![](example6.PNG)
15-
![](example0.PNG)
16-
![](example3.png)
17-
![](example1.png)
18-
![](example2.png)
19-
![](example4.png)
20-
![](example5.png)
14+
<p align="center">
15+
<img src="example6.PNG" />
16+
</p>
17+
18+
<p align="center">
19+
<img src="example7.PNG" />
20+
</p>
21+
22+
<p align="center">
23+
<img src="example0.PNG" />
24+
</p>
25+
26+
<p align="center">
27+
<img src="example3.png" />
28+
</p>
29+
30+
<p align="center">
31+
<img src="example1.png" />
32+
</p>
33+
34+
<p align="center">
35+
<img src="example2.png" />
36+
</p>
37+
38+
<p align="center">
39+
<img src="example4.png" />
40+
</p>
41+
42+
<p align="center">
43+
<img src="example5.png" />
44+
</p>
45+
2146

2247
# Usage
2348

docs/example7.PNG

926 KB
Loading

src/shaders/spectrogram/a.frag

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
in vec2 p;
2+
out vec4 c;
3+
void main () {
4+
if (gl_FragCoord.x >= iRes.x-1) {
5+
float freq = log(1. + texture(iFreqL, (exp2(p.y / 1.5) - 1.) ).r);
6+
c = vec4(freq);
7+
}
8+
else {
9+
vec4 adjcol = texture(ia, p + vec2(1. / iRes.x, 0.));
10+
c = vec4(adjcol);
11+
}
12+
}

src/shaders/spectrogram/a.geom

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
layout(triangle_strip, max_vertices = 6) out;
2+
out vec2 p;
3+
void main() {
4+
/* 1------3
5+
| \ |
6+
| \ |
7+
| \|
8+
0------2 */
9+
const vec2 p0 = vec2(-1., -1.);
10+
const vec2 p1 = vec2(-1., 1.);
11+
gl_Position = vec4(p0, 0., 1.);
12+
p = p0 * .5 + .5;
13+
EmitVertex(); // 0
14+
gl_Position = vec4(p1, 0., 1.);
15+
p = p1 * .5 + .5;
16+
EmitVertex(); // 1
17+
gl_Position = vec4(-p1, 0., 1.);
18+
p = -p1 * .5 + .5;
19+
EmitVertex(); // 2
20+
EndPrimitive();
21+
22+
gl_Position = vec4(-p1, 0., 1.);
23+
p = -p1 * .5 + .5;
24+
EmitVertex(); // 2
25+
gl_Position = vec4(p1, 0., 1.);
26+
p = p1 * .5 + .5;
27+
EmitVertex(); // 1
28+
gl_Position = vec4(-p0, 0., 1.);
29+
p = -p0 * .5 + .5;
30+
EmitVertex(); // 3
31+
EndPrimitive();
32+
}

src/shaders/spectrogram/image.frag

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
in vec2 p;
2+
out vec4 c;
3+
4+
float hash(float p) {
5+
vec3 p3 = fract(vec3(p) * 443.8975);
6+
p3 += dot(p3, p3.yzx + 19.19);
7+
return fract((p3.x + p3.y) * p3.z);
8+
}
9+
10+
void main () {
11+
c = texture(ia, p);
12+
c.a = 1.;
13+
}

src/shaders/spectrogram/image.geom

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
layout(triangle_strip, max_vertices = 6) out;
2+
out vec2 p;
3+
void main() {
4+
/* 1------3
5+
| \ |
6+
| \ |
7+
| \|
8+
0------2 */
9+
const vec2 p0 = vec2(-1., -1.);
10+
const vec2 p1 = vec2(-1., 1.);
11+
gl_Position = vec4(p0, 0., 1.);
12+
p = p0 * .5 + .5;
13+
EmitVertex(); // 0
14+
gl_Position = vec4(p1, 0., 1.);
15+
p = p1 * .5 + .5;
16+
EmitVertex(); // 1
17+
gl_Position = vec4(-p1, 0., 1.);
18+
p = -p1 * .5 + .5;
19+
EmitVertex(); // 2
20+
EndPrimitive();
21+
22+
gl_Position = vec4(-p1, 0., 1.);
23+
p = -p1 * .5 + .5;
24+
EmitVertex(); // 2
25+
gl_Position = vec4(p1, 0., 1.);
26+
p = p1 * .5 + .5;
27+
EmitVertex(); // 1
28+
gl_Position = vec4(-p0, 0., 1.);
29+
p = -p0 * .5 + .5;
30+
EmitVertex(); // 3
31+
EndPrimitive();
32+
}

src/shaders/spectrogram/shader.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"initial_window_size":[350,175],
3+
"image": {
4+
"geom_iters":1,
5+
"clear_color":[0,0,0]
6+
},
7+
"buffers": {
8+
"a": {
9+
"size":"window_size",
10+
"geom_iters":1,
11+
"clear_color":[0,0,0]
12+
}
13+
},
14+
// TODO rendering two b's doesnt help because I b doesn't read from b, it reads from a, but it needs to read from b on the second iteration
15+
"audio_enabled":true,
16+
"audio_options": {
17+
"fft_sync":true,
18+
"diff_sync":true,
19+
"fft_smooth":0.5,
20+
"wave_smooth":0.8
21+
}
22+
}

0 commit comments

Comments
 (0)