Skip to content

Commit

Permalink
aumix: add record sum handler (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored Jul 15, 2023
1 parent 9cecb6e commit bfdbe04
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/rem_aumix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef void (aumix_read_h)(struct auframe *af, void *arg);
int aumix_alloc(struct aumix **mixp, uint32_t srate,
uint8_t ch, uint32_t ptime);
void aumix_recordh(struct aumix *mix, aumix_record_h *recordh);
void aumix_record_sumh(struct aumix *mix, aumix_record_h *recordh);
int aumix_playfile(struct aumix *mix, const char *filepath);
uint32_t aumix_source_count(const struct aumix *mix);
int aumix_source_alloc(struct aumix_source **srcp, struct aumix *mix,
Expand Down
59 changes: 57 additions & 2 deletions rem/aumix/aumix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct aumix {
uint32_t srate;
uint8_t ch;
aumix_record_h *recordh;
aumix_record_h *record_sumh;
struct auframe rec_sum;
bool run;
};

Expand Down Expand Up @@ -189,7 +191,7 @@ static int aumix_thread(void *arg)
for (size_t i = 0; i < mix->frame_size; i++) {
sample = mix_frame[i] + csrc->frame[i];

/* soft clipping */
/* hard clipping */
if (sample >= 32767)
sample = 32767;
if (sample <= -32767)
Expand All @@ -202,6 +204,38 @@ static int aumix_thread(void *arg)
src->fh(mix_frame, mix->frame_size, src->arg);
}

if (mix->record_sumh) {
struct le *cle;

memcpy(mix_frame, base_frame, mix->frame_size * 2);

LIST_FOREACH(&mix->srcl, cle)
{
struct aumix_source *csrc = cle->data;
int32_t sample;

if (csrc->muted)
continue;

for (size_t i = 0; i < mix->frame_size; i++) {
sample = mix_frame[i] + csrc->frame[i];

/* hard clipping */
if (sample >= 32767)
sample = 32767;
if (sample <= -32767)
sample = -32767;

mix_frame[i] = (int16_t)sample;
}
}

mix->rec_sum.timestamp = now;
mix->rec_sum.sampv = mix_frame;

mix->record_sumh(&mix->rec_sum);
}

ts += mix->ptime;
}

Expand Down Expand Up @@ -245,6 +279,10 @@ int aumix_alloc(struct aumix **mixp, uint32_t srate,
mix->ch = ch;
mix->recordh = NULL;

mix->rec_sum.ch = ch;
mix->rec_sum.srate = srate;
mix->rec_sum.sampc = mix->frame_size;

err = mtx_init(&mix->mutex, mtx_plain) != thrd_success;
if (err) {
err = ENOMEM;
Expand Down Expand Up @@ -276,7 +314,7 @@ int aumix_alloc(struct aumix **mixp, uint32_t srate,


/**
* Add record handler
* Add multitrack record handler (each source can be identified by auframe->id)
*
* @param mix Audio mixer
* @param recordh Record Handler
Expand All @@ -292,6 +330,23 @@ void aumix_recordh(struct aumix *mix, aumix_record_h *recordh)
}


/**
* Add sum record handler
*
* @param mix Audio mixer
* @param recordh Record Handler
*/
void aumix_record_sumh(struct aumix *mix, aumix_record_h *recordh)
{
if (!mix)
return;

mtx_lock(&mix->mutex);
mix->record_sumh = recordh;
mtx_unlock(&mix->mutex);
}


/**
* Load audio file for mixer announcements
*
Expand Down

0 comments on commit bfdbe04

Please sign in to comment.