summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-09 11:49:41 -0500
committerXANTRONIX Development2022-03-09 11:49:41 -0500
commitc9232a69a0c44afd90be01137369e692672007c4 (patch)
tree8d23e069ca83a0c11cf0a7bb9519daf5f7685f03
parentba45cfe089c6430ab80bc8652dc88a837a59fc9a (diff)
downloadxas-c9232a69a0c44afd90be01137369e692672007c4.tar.gz
xas-c9232a69a0c44afd90be01137369e692672007c4.tar.bz2
xas-c9232a69a0c44afd90be01137369e692672007c4.zip
Kill xas_seq_event_list_item linked list wrapper
-rw-r--r--include/xas/seq.h11
-rw-r--r--src/seq.c81
2 files changed, 37 insertions, 55 deletions
diff --git a/include/xas/seq.h b/include/xas/seq.h
index 86acefc..f7ec322 100644
--- a/include/xas/seq.h
+++ b/include/xas/seq.h
@@ -50,20 +50,15 @@ struct _xas_seq_event {
enum xas_synth_type synth_type;
const char *phrase;
};
-};
-
-typedef struct _xas_seq_event_list_item xas_seq_event_list_item;
-struct _xas_seq_event_list_item {
- xas_seq_event *ev;
- xas_seq_event_list_item *next;
+ xas_seq_event *next;
};
typedef struct _xas_seq {
xas_spatial_scene *scene;
- xas_seq_event_list_item *first,
- *last;
+ xas_seq_event *first,
+ *last;
size_t buffer_size;
} xas_seq;
diff --git a/src/seq.c b/src/seq.c
index b9e3072..26e4abe 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -26,45 +26,32 @@ error_malloc_seq:
}
void xas_seq_destroy(xas_seq *seq) {
- xas_seq_event_list_item *item = seq->first;
+ xas_seq_event *ev = seq->first;
- while (item) {
- xas_seq_event_list_item *next = item->next;
+ while (ev) {
+ xas_seq_event *next = ev->next;
- free(item->ev);
- free(item);
+ free(ev);
- item = next;
+ ev = next;
}
free(seq);
}
static int event_add(xas_seq *seq, xas_seq_event *ev) {
- xas_seq_event_list_item *item;
-
- if ((item = malloc(sizeof(*item))) == NULL) {
- goto error_malloc_item;
- }
-
- item->ev = ev;
- item->next = NULL;
-
if (seq->first == NULL) {
- seq->first = item;
- seq->last = item;
+ seq->first = ev;
+ seq->last = ev;
} else {
- seq->last->next = item;
- seq->last = item;
+ seq->last->next = ev;
+ seq->last = ev;
}
return 0;
-
-error_malloc_item:
- return -1;
}
-static xas_seq_event_list_item *event_list_tail(xas_seq_event_list_item *head) {
+static xas_seq_event *event_tail(xas_seq_event *head) {
if (head == NULL) {
return NULL;
}
@@ -76,17 +63,17 @@ static xas_seq_event_list_item *event_list_tail(xas_seq_event_list_item *head) {
return head;
}
-static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *head,
- xas_seq_event_list_item *end,
- xas_seq_event_list_item **head_new,
- xas_seq_event_list_item **end_new) {
- xas_seq_event_list_item *pivot = end,
- *prev = NULL,
- *cur = head,
- *tail = pivot;
+static xas_seq_event *event_list_partition(xas_seq_event *head,
+ xas_seq_event *end,
+ xas_seq_event **head_new,
+ xas_seq_event **end_new) {
+ xas_seq_event *pivot = end,
+ *prev = NULL,
+ *cur = head,
+ *tail = pivot;
while (cur != pivot) {
- if (timercmp(&cur->ev->timestamp, &pivot->ev->timestamp, <)) {
+ if (timercmp(&cur->timestamp, &pivot->timestamp, <)) {
if (*head_new == NULL) {
*head_new = cur;
}
@@ -94,7 +81,7 @@ static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *he
prev = cur;
cur = cur->next;
} else {
- xas_seq_event_list_item *tmp;
+ xas_seq_event *tmp;
if (prev) {
prev->next = cur->next;
@@ -118,11 +105,11 @@ static xas_seq_event_list_item *event_list_partition(xas_seq_event_list_item *he
return pivot;
}
-static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *head,
- xas_seq_event_list_item *end) {
- xas_seq_event_list_item *head_new = NULL,
- *end_new = NULL,
- *pivot;
+static xas_seq_event *event_list_sort_recur(xas_seq_event *head,
+ xas_seq_event *end) {
+ xas_seq_event *head_new = NULL,
+ *end_new = NULL,
+ *pivot;
if (head == NULL || head == end) {
return head;
@@ -131,7 +118,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h
pivot = event_list_partition(head, end, &head_new, &end_new);
if (head_new != pivot) {
- xas_seq_event_list_item *tmp = head_new;
+ xas_seq_event *tmp = head_new;
while (tmp->next != pivot) {
tmp = tmp->next;
@@ -141,7 +128,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h
head_new = event_list_sort_recur(head_new, tmp);
- tmp = event_list_tail(head_new);
+ tmp = event_tail(head_new);
tmp->next = pivot;
}
@@ -152,7 +139,7 @@ static xas_seq_event_list_item *event_list_sort_recur(xas_seq_event_list_item *h
static void event_sort(xas_seq *seq) {
seq->first = event_list_sort_recur(seq->first, seq->last);
- seq->last = event_list_tail(seq->first);
+ seq->last = event_tail(seq->first);
}
int xas_seq_add_event_off(xas_seq *seq,
@@ -563,7 +550,7 @@ static inline void timerupdate(struct timeval *tv,
}
int xas_seq_play(xas_seq *seq, xas_audio_stream *sink) {
- xas_seq_event_list_item *item;
+ xas_seq_event *ev;
xas_audio_stream *source;
size_t frame = 0,
@@ -581,21 +568,21 @@ int xas_seq_play(xas_seq *seq, xas_audio_stream *sink) {
event_sort(seq);
- item = seq->first;
+ ev = seq->first;
- while (item) {
+ while (ev) {
struct timeval tv;
ssize_t readlen;
timerupdate(&tv, interval, frame);
- while (item && !timercmp(&tv, &item->ev->timestamp, <)) {
- if (event_trigger(seq->scene, item->ev) < 0) {
+ while (ev && !timercmp(&tv, &ev->timestamp, <)) {
+ if (event_trigger(seq->scene, ev) < 0) {
goto error_event_trigger;
}
- item = item->next;
+ ev = ev->next;
}
if ((readlen = xas_audio_stream_read(source,