From 5f2e84d8cf2d210d83fe76bcb89de908207421b6 Mon Sep 17 00:00:00 2001 From: mid <> Date: Sat, 12 Jul 2025 23:27:33 +0300 Subject: [PATCH] Support LOOPPOINT metadata field for ogg files --- src/k3mix.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/k3mix.c b/src/k3mix.c index a62f0b2..2c260bc 100644 --- a/src/k3mix.c +++ b/src/k3mix.c @@ -1,11 +1,13 @@ #include"k3mix.h" +#define _GNU_SOURCE #include #include #include #include #include #include +#include"k3.h" static uint32_t FinalSampleRate; static uint8_t FinalChannels; @@ -19,12 +21,22 @@ struct k3MixSource { char *filepath; OggVorbis_File vf; int bitstream; + size_t looppoint; }; struct k3MixSource *k3MixSourceFile(const char *path) { struct k3MixSource *ret = calloc(1, sizeof(*ret)); ret->filepath = strdup(path); ov_fopen(path, &ret->vf); ret->bitstream = 0; + + ret->looppoint = 0; + for(size_t ci = 0; ci < ret->vf.vc->comments; ci++) { + if(strcasestr(ret->vf.vc->user_comments[ci], "looppoint=") == ret->vf.vc->user_comments[ci]) { + ret->looppoint = strtol(ret->vf.vc->user_comments[ci] + 10, NULL, 0); + k3Log(k3_DEBUG, "%s has loop point %lu", path, ret->looppoint); + } + } + return ret; } void k3MixSourceClose(struct k3MixSource *src) { @@ -42,7 +54,7 @@ __attribute__((optimize("Ofast"))) static intmax_t ogg_read(struct k3MixWave *th long lastRead = ov_read_float(&od->vf, &ni, sampleCount, &od->bitstream); if(this->loop && lastRead == 0) { - ov_pcm_seek(&od->vf, 0); + ov_pcm_seek(&od->vf, od->looppoint); continue; } else if(lastRead <= 0) { this->end = true;