|
|
|
@ -22,6 +22,9 @@ static GLfloat vertex_buffer[] = {
|
|
|
|
|
|
|
|
|
|
static GLubyte audio_buffer[AUDIO_SAMPLES * AUDIO_CHANNELS];
|
|
|
|
|
static float audio_sample_data[AUDIO_SAMPLES];
|
|
|
|
|
static fftw_complex fftw_in[AUDIO_SAMPLES];
|
|
|
|
|
static fftw_complex fftw_out[AUDIO_SAMPLES];
|
|
|
|
|
static fftw_plan plan;
|
|
|
|
|
|
|
|
|
|
static int try_fetch_audio(void)
|
|
|
|
|
{
|
|
|
|
@ -48,9 +51,17 @@ static int try_fetch_audio(void)
|
|
|
|
|
count += ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < (count / sizeof(float)); ++i) {
|
|
|
|
|
for (i = 0; i < AUDIO_SAMPLES; ++i)
|
|
|
|
|
fftw_in[i][0] = audio_sample_data[i];
|
|
|
|
|
|
|
|
|
|
fftw_execute(plan);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < AUDIO_SAMPLES; ++i) {
|
|
|
|
|
float x = fftw_out[i][0], y = fftw_out[i][1];
|
|
|
|
|
float a = sqrt(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
audio_buffer[i + AUDIO_SAMPLES] = audio_sample_data[i] * 127.0f + 127.0f;
|
|
|
|
|
audio_buffer[i] = 0.0f;
|
|
|
|
|
audio_buffer[i] = 127.0f + a * 127.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
@ -329,6 +340,11 @@ int main(int argc, char **argv)
|
|
|
|
|
glSamplerParameteri(sampler_sound, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glBindSampler(0, sampler_sound);
|
|
|
|
|
|
|
|
|
|
if (have_audio) {
|
|
|
|
|
plan = fftw_plan_dft_1d(AUDIO_SAMPLES, fftw_in, fftw_out,
|
|
|
|
|
FFTW_FORWARD, FFTW_ESTIMATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************** framebuffer object ********************/
|
|
|
|
|
if (to_stdout) {
|
|
|
|
|
glGenFramebuffers(1, &fbo);
|
|
|
|
@ -349,10 +365,6 @@ int main(int argc, char **argv)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************** drawing loop ********************/
|
|
|
|
|
for (i = 0; i < AUDIO_SAMPLES; ++i) {
|
|
|
|
|
audio_sample_data[i] = (float)i / (float)AUDIO_SAMPLES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
|
|
|
|
|
|
|
|
|
while (to_stdout || window_handle_events()) {
|
|
|
|
@ -426,6 +438,10 @@ int main(int argc, char **argv)
|
|
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
glDeleteProgram(prog);
|
|
|
|
|
|
|
|
|
|
if (have_audio) {
|
|
|
|
|
fftw_destroy_plan(plan);
|
|
|
|
|
}
|
|
|
|
|
fail_vao:
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
glDeleteBuffers(1, &vbo);
|
|
|
|
|