-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
34 lines (30 loc) · 1 KB
/
common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "common.h"
#include <math.h>
#include <string.h>
int write_to_input_buffers(int16_t size, int16_t buf[size], void *data) {
if (size == 0)
return 0;
struct audio_data *audio = (struct audio_data *)data;
pthread_mutex_lock(&audio->lock);
if (audio->samples_counter + size > audio->buffer_size) {
// buffer overflow, discard what ever is in the buffer and start over
for (uint16_t n = 0; n < audio->buffer_size; n++) {
audio->in[n] = 0;
}
audio->samples_counter = 0;
}
for (uint16_t i = 0; i < size; i++) {
audio->in[i + audio->samples_counter] = buf[i];
}
audio->samples_counter += size;
pthread_mutex_unlock(&audio->lock);
return 0;
}
void reset_output_buffers(struct audio_data *data) {
struct audio_data *audio = (struct audio_data *)data;
pthread_mutex_lock(&audio->lock);
for (uint16_t n = 0; n < audio->buffer_size; n++) {
audio->in[n] = 0;
}
pthread_mutex_unlock(&audio->lock);
}