Initialize jitter buffer delay with half of its size

Also add a function to reset jitter buffer
pull/1/head
Andreas Eversberg 2 years ago
parent 118b0260bc
commit 55a5a4ea2b
  1. 12
      src/libjitter/jitter.c
  2. 1
      src/libjitter/jitter.h

@ -30,16 +30,26 @@
int jitter_create(jitter_t *jitter, int length)
{
memset(jitter, 0, sizeof(*jitter));
jitter->spl = calloc(length * sizeof(sample_t), 1);
jitter->spl = malloc(length * sizeof(sample_t));
if (!jitter->spl) {
PDEBUG(DDSP, DEBUG_ERROR, "No memory for jitter buffer.\n");
return -ENOMEM;
}
jitter->len = length;
jitter_reset(jitter);
return 0;
}
void jitter_reset(jitter_t *jitter)
{
memset(jitter->spl, 0, jitter->len * sizeof(sample_t));
/* put write pointer ahead by half of the buffer length */
jitter->inptr = jitter->len / 2;
}
void jitter_destroy(jitter_t *jitter)
{
if (jitter->spl) {

@ -6,6 +6,7 @@ typedef struct jitter {
} jitter_t;
int jitter_create(jitter_t *jitter, int length);
void jitter_reset(jitter_t *jitter);
void jitter_destroy(jitter_t *jitter);
void jitter_save(jitter_t *jb, sample_t *samples, int length);
void jitter_load(jitter_t *jb, sample_t *samples, int length);

Loading…
Cancel
Save