audio/visualizer: store positive and negative values separately
This commit is contained in:
parent
32de8367b8
commit
b2dedbfbb6
@ -3,7 +3,7 @@
|
|||||||
layout (local_size_x = 128, local_size_y = 1, local_size_z = 1) in;
|
layout (local_size_x = 128, local_size_y = 1, local_size_z = 1) in;
|
||||||
|
|
||||||
layout (r16i, binding = 0) readonly uniform iimageBuffer ImageIn;
|
layout (r16i, binding = 0) readonly uniform iimageBuffer ImageIn;
|
||||||
layout (r16i, binding = 1) writeonly uniform iimageBuffer ImageOut;
|
layout (rg16i, binding = 1) writeonly uniform iimageBuffer ImageOut;
|
||||||
|
|
||||||
layout (location = 0) uniform int GlobalOffset;
|
layout (location = 0) uniform int GlobalOffset;
|
||||||
layout (location = 1) uniform int WindowLength;
|
layout (location = 1) uniform int WindowLength;
|
||||||
@ -14,14 +14,14 @@ void main()
|
|||||||
|
|
||||||
int offset = GlobalOffset + x * WindowLength;
|
int offset = GlobalOffset + x * WindowLength;
|
||||||
|
|
||||||
float sum = 0;
|
vec2 sum = vec2(0, 0);
|
||||||
//int sum = 0;
|
|
||||||
float scale = 1.0 / float(WindowLength);
|
float scale = 1.0 / float(WindowLength);
|
||||||
for (int i = 0; i < WindowLength; i++) {
|
for (int i = 0; i < WindowLength; i++) {
|
||||||
ivec4 v = imageLoad(ImageIn, offset + i);
|
ivec4 v = imageLoad(ImageIn, offset + i);
|
||||||
sum += float(abs(v.x)) * scale;
|
float value = float(v.x);
|
||||||
//sum = max(abs(v.x), sum);
|
sum += vec2(clamp(value, 0.0, 32767.0), clamp(value, -32768.0, 0.0)) * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
imageStore(ImageOut, x, ivec4(int(sum)));
|
imageStore(ImageOut, x, ivec4(int(sum.x), int(sum.y), 0, 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,21 +6,26 @@ in VS_OUT {
|
|||||||
|
|
||||||
layout (location = 0) out vec4 Color;
|
layout (location = 0) out vec4 Color;
|
||||||
|
|
||||||
layout (r16i, binding = 0) readonly uniform iimageBuffer Image;
|
layout (rg16i, binding = 0) readonly uniform iimageBuffer Image;
|
||||||
|
|
||||||
float get_sample(int coordinate)
|
vec2 get_sample(int coordinate)
|
||||||
{
|
{
|
||||||
int red = imageLoad(Image, coordinate).r;
|
ivec2 v = imageLoad(Image, coordinate).xy;
|
||||||
return float(red) * (1.0 / 32768.0);
|
return vec2(float(v.x), float(v.y)) * (1.0 / 32768.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float value = get_sample(int(gl_FragCoord.x));
|
vec2 v = get_sample(int(gl_FragCoord.x));
|
||||||
|
|
||||||
float y = -(fs_in.Texture.y * 2 - 1);
|
float y = -(fs_in.Texture.y * 2 - 1);
|
||||||
|
|
||||||
float c = float(abs(y) < abs(value));
|
float c;
|
||||||
|
if (y > 0) {
|
||||||
|
c = float(y < v.x);
|
||||||
|
} else {
|
||||||
|
c = float(y > v.y);
|
||||||
|
}
|
||||||
|
|
||||||
Color = vec4(c, 0, 0, 1);
|
Color = vec4(c, 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@ namespace audio::resampler {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// output
|
// output
|
||||||
int output_size = max_output_pixels * 2;
|
int output_size = max_output_pixels * 2 * 2;
|
||||||
glGenBuffers(1, &output.buffer);
|
glGenBuffers(1, &output.buffer);
|
||||||
glGenTextures(1, &output.texture);
|
glGenTextures(1, &output.texture);
|
||||||
glBindBuffer(GL_TEXTURE_BUFFER, output.buffer);
|
glBindBuffer(GL_TEXTURE_BUFFER, output.buffer);
|
||||||
@ -76,7 +76,7 @@ namespace audio::resampler {
|
|||||||
glBindBuffer(GL_TEXTURE_BUFFER, 0);
|
glBindBuffer(GL_TEXTURE_BUFFER, 0);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_BUFFER, output.texture);
|
glBindTexture(GL_TEXTURE_BUFFER, output.texture);
|
||||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_R16I, output.buffer);
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG16I, output.buffer);
|
||||||
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ namespace audio::resampler {
|
|||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
0,
|
0,
|
||||||
GL_WRITE_ONLY,
|
GL_WRITE_ONLY,
|
||||||
GL_R16I);
|
GL_RG16I);
|
||||||
|
|
||||||
int groups = window::width / local_size;
|
int groups = window::width / local_size;
|
||||||
if (groups == 0)
|
if (groups == 0)
|
||||||
|
|||||||
@ -79,7 +79,7 @@ namespace audio::visualizer {
|
|||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
0,
|
0,
|
||||||
GL_READ_ONLY,
|
GL_READ_ONLY,
|
||||||
GL_R16I);
|
GL_RG16I);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
|
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user