Skip to content

Commit

Permalink
Accumulate audio frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaneo committed Sep 12, 2023
1 parent ed734cd commit ff936b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
17 changes: 14 additions & 3 deletions app/sources/junie.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,22 @@ static size_t audio_sample_batch(const int16_t *data, size_t frames)
if (!CTX.audio.enable)
return frames;

CTX.audio.data = data;
size_t new_size = (CTX.audio.frames + frames) * 2 * sizeof(int16_t);
if (new_size > CTX.audio.size) {
CTX.audio.data = realloc((void *) CTX.audio.data, new_size);
CTX.audio.size = new_size;
}

const int16_t *current = &CTX.audio.data[CTX.audio.frames * 2];
memcpy((void *) current, (void *) data, frames * 2 * sizeof(int16_t));

CTX.audio.frames += frames;
CTX.audio.rate = CTX.av.timing.sample_rate * CTX.speed;
CTX.audio.frames = frames;

JunieInteropAudio(&CTX.audio);
if (CTX.audio.frames >= CTX.audio.rate / 100) {
JunieInteropAudio(&CTX.audio);
CTX.audio.frames = 0;
}

return frames;
}
Expand Down
1 change: 1 addition & 0 deletions app/sources/junie.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct {
const int16_t *data;
float rate;
size_t frames;
size_t size;
bool enable;
} JunieAudio;

Expand Down
6 changes: 5 additions & 1 deletion ui/sources/entities/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export class Audio {
/** @type {number} */
frames;

/** @type {number} */
size;

/** @type {boolean} */
enable;

Expand All @@ -23,7 +26,8 @@ export class Audio {
data: view.getUint32(0, true),
rate: view.getFloat32(4, true),
frames: view.getUint32(8, true),
enable: view.getUint32(12, true),
size: view.getUint32(12, true),
enable: view.getUint32(16, true),
}
}
}

0 comments on commit ff936b7

Please sign in to comment.