Add data structures and functions
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
84595eff00
commit
7e190a5729
1 changed files with 38 additions and 2 deletions
40
shadermeh.c
40
shadermeh.c
|
@ -85,6 +85,27 @@ static int write_retry(int fd, const void *buffer, size_t size)
|
|||
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[] = {
|
||||
{ "width", required_argument, NULL, 'w' },
|
||||
{ "height", required_argument, NULL, 'h' },
|
||||
|
@ -110,7 +131,6 @@ static const char *usage_str =
|
|||
" --shader, -s <shader file>\n"
|
||||
"\n";
|
||||
|
||||
#define SND_BUFFER_SIZE 512
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -125,7 +145,7 @@ int main(int argc, char **argv)
|
|||
float iTime, iTimeDelta;
|
||||
bool to_stdout = false;
|
||||
window *wnd;
|
||||
int i;
|
||||
int i, ret;
|
||||
unsigned int sampling_rate = 0; /* Leaving this at 0 disables audio
|
||||
* input
|
||||
*/
|
||||
|
@ -220,6 +240,15 @@ int main(int argc, char **argv)
|
|||
fputs("Sampling rate specified and STDIN not a tty! "
|
||||
"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 **********/
|
||||
wnd = window_create(width, height, "shader meh...");
|
||||
|
@ -332,6 +361,13 @@ int main(int argc, char **argv)
|
|||
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 */
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_end);
|
||||
|
|
Loading…
Reference in a new issue