Add data structures and functions

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
Tyrolyean 2022-07-18 19:56:18 +02:00
parent 84595eff00
commit 7e190a5729
No known key found for this signature in database
GPG key ID: 81EC9BAC5E9667C6

View file

@ -85,6 +85,27 @@ static int write_retry(int fd, const void *buffer, size_t size)
return 0; return 0;
} }
#define SND_BUFFER_SIZE 512
static int read_audio_buffers(int fd, float buffer[SND_BUFFER_SIZE],
unsigned int sampling_rate){
return 0;
}
static void normalize_audio_buffers(float buffer_in[SND_BUFFER_SIZE],
float buffer_out[SND_BUFFER_SIZE]){
if(buffer_in == NULL || buffer_out == NULL){
return;
}
for(size_t i = 0; i < SND_BUFFER_SIZE; i++){
buffer_out[i] = (buffer_in[i]+1.0)/2.0;
}
return;
}
static const struct option long_opts[] = { static const struct option long_opts[] = {
{ "width", required_argument, NULL, 'w' }, { "width", required_argument, NULL, 'w' },
{ "height", required_argument, NULL, 'h' }, { "height", required_argument, NULL, 'h' },
@ -110,7 +131,6 @@ static const char *usage_str =
" --shader, -s <shader file>\n" " --shader, -s <shader file>\n"
"\n"; "\n";
#define SND_BUFFER_SIZE 512
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -125,7 +145,7 @@ int main(int argc, char **argv)
float iTime, iTimeDelta; float iTime, iTimeDelta;
bool to_stdout = false; bool to_stdout = false;
window *wnd; window *wnd;
int i; int i, ret;
unsigned int sampling_rate = 0; /* Leaving this at 0 disables audio unsigned int sampling_rate = 0; /* Leaving this at 0 disables audio
* input * input
*/ */
@ -220,6 +240,15 @@ int main(int argc, char **argv)
fputs("Sampling rate specified and STDIN not a tty! " fputs("Sampling rate specified and STDIN not a tty! "
"You habe been warnded!\n", stderr); "You habe been warnded!\n", stderr);
} }
if(sampling_rate != 0){
ret = fcntl(STDIN_FILENO, F_SETFL,
fcntl(STDIN_FILENO,F_GETFL)
|(O_NONBLOCK));
if(ret == -1){
perror("Failed to set STDIN_FILENO to non-blocking "
"mode! This will likely mean failure");
}
}
/********** create window and make context current **********/ /********** create window and make context current **********/
wnd = window_create(width, height, "shader meh..."); wnd = window_create(width, height, "shader meh...");
@ -332,6 +361,13 @@ int main(int argc, char **argv)
break; break;
} }
} }
if(sampling_rate != 0){
if(read_audio_buffers(STDIN_FILENO, in_samples,
sampling_rate) < 0){
break;
}
normalize_audio_buffers(in_samples, norm_samples);
}
/* update timers */ /* update timers */
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_end); clock_gettime(CLOCK_MONOTONIC_RAW, &frame_end);