<commit_before>#include <unistd.h>
#define BUFSIZE 1024
int rc;

struct audio_data {

        int audio_out_r[2048];
        int audio_out_l[2048];
        int format;
        unsigned int rate ;
        char *source; //alsa device, fifo path or pulse source
        int im; //input mode alsa, fifo or pulse
        int channels;
	int terminate; // shared variable used to terminate audio thread
        char error_message[1024];
};


//input: FIFO
void* input_fifo(void* data)
{
	struct audio_data *audio = (struct audio_data *)data;
	int fd;
	int n = 0;
	//signed char buf[1024];
	//int tempr, templ, lo, q;
	int i;
	int t = 0;
	//int size = 1024;
	int bytes = 0;
	int flags;
	int16_t buf[BUFSIZE / 2];
	struct timespec req = { .tv_sec = 0, .tv_nsec = 10000000 };




	fd = open(audio->source, O_RDONLY);
	flags = fcntl(fd, F_GETFL, 0);
	fcntl(fd, F_SETFL, flags | O_NONBLOCK);

	while (1) {

		bytes = read(fd, buf, sizeof(buf));

		if (bytes == -1) { //if no bytes read sleep 10ms and zero shared buffer
			nanosleep (&req, NULL);
			t++;
			if (t > 10) {
				for (i = 0; i < 2048; i++)audio->audio_out_l[i] = 0;
				for (i = 0; i < 2048; i++)audio->audio_out_r[i] = 0;
				t = 0;
			}
		} else { //if bytes read go ahead
			t = 0;

            for (i = 0; i < BUFSIZE / 2; i += 2) {

                if (audio->channels == 1) audio->audio_out_l[n] = (buf[i] + buf[i + 1]) / 2;

                //stereo storing channels in buffer
                if (audio->channels == 2) {<commit_msg>Reopen FIFO if closed or deleted<commit_after>#include <unistd.h>
#define BUFSIZE 1024
int rc;

struct audio_data {

        int audio_out_r[2048];
        int audio_out_l[2048];
        int format;
        unsigned int rate ;
        char *source; //alsa device, fifo path or pulse source
        int im; //input mode alsa, fifo or pulse
        int channels;
	int terminate; // shared variable used to terminate audio thread
        char error_message[1024];
};

int open_fifo(const char *path)
{
	int fd = open(path, O_RDONLY);
	int flags = fcntl(fd, F_GETFL, 0);
	fcntl(fd, F_SETFL, flags | O_NONBLOCK);
	return fd;
}


//input: FIFO
void* input_fifo(void* data)
{
	struct audio_data *audio = (struct audio_data *)data;
	int fd;
	int n = 0;
	//signed char buf[1024];
	//int tempr, templ, lo, q;
	int i;
	int t = 0;
	//int size = 1024;
	int bytes = 0;
	int16_t buf[BUFSIZE / 2];
	struct timespec req = { .tv_sec = 0, .tv_nsec = 10000000 };




	fd = open_fifo(audio->source);

	while (1) {

		bytes = read(fd, buf, sizeof(buf));

		if (bytes < 1) { //if no bytes read sleep 10ms and zero shared buffer
			nanosleep (&req, NULL);
			t++;
			if (t > 10) {
				for (i = 0; i < 2048; i++)audio->audio_out_l[i] = 0;
				for (i = 0; i < 2048; i++)audio->audio_out_r[i] = 0;
				close(fd);
				fd = open_fifo(audio->source);
				t = 0;
			}
		} else { //if bytes read go ahead
			t = 0;

            for (i = 0; i < BUFSIZE / 2; i += 2) {

                if (audio->channels == 1) audio->audio_out_l[n] = (buf[i] + buf[i + 1]) / 2;

                //stereo storing channels in buffer
                if (audio->channels == 2) {
{'fraction_non_alphanumeric': 0.14253611556982343, 'fraction_numerical': 0.04301765650080257, 'mean_word_length': 2.361380798274002, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1816315', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1153, 'n_words': 376}