1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 16:27:45 +02:00

Dynamically allocate audio frame buffer memory

This commit is contained in:
jfreegman 2020-10-25 15:37:45 -04:00
parent 4d96d6a753
commit 478762f76c
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -452,15 +452,21 @@ inline__ DeviceError write_out(uint32_t device_idx, const int16_t *data, uint32_
return de_None;
}
#define FRAME_BUF_SIZE 16000
void *thread_poll(void *arg) // TODO: maybe use thread for every input source
{
/*
* NOTE: We only need to poll input devices for data.
*/
UNUSED_VAR(arg);
uint32_t i;
int32_t sample = 0;
int16_t *frame_buf = malloc(FRAME_BUF_SIZE * sizeof(int16_t));
if (frame_buf == NULL) {
exit_toxic_err("failed in thread_poll", FATALERR_MEMORY);
}
while (1) {
lock;
@ -479,7 +485,7 @@ void *thread_poll(void *arg) // TODO: maybe use thread for every input source
}
else {
for (i = 0; i < size[input]; ++i) {
for (uint32_t i = 0; i < size[input]; ++i) {
lock;
if (running[input][i] != NULL) {
@ -487,15 +493,14 @@ void *thread_poll(void *arg) // TODO: maybe use thread for every input source
int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000);
if (sample < f_size) {
if (sample < f_size || f_size > FRAME_BUF_SIZE) {
unlock;
continue;
}
Device *device = running[input][i];
int16_t frame[16000];
alcCaptureSamples(device->dhndl, frame, f_size);
alcCaptureSamples(device->dhndl, frame_buf, f_size);
if (device->muted) {
unlock;
@ -503,7 +508,7 @@ void *thread_poll(void *arg) // TODO: maybe use thread for every input source
}
if (device->cb) {
device->cb(frame, f_size, device->cb_data);
device->cb(frame_buf, f_size, device->cb_data);
}
}
@ -514,6 +519,8 @@ void *thread_poll(void *arg) // TODO: maybe use thread for every input source
}
}
free(frame_buf);
pthread_exit(NULL);
}