Support LOOPPOINT metadata field for ogg files
Some checks failed
k4 Build Test / do_the_build (push) Failing after 30s
Some checks failed
k4 Build Test / do_the_build (push) Failing after 30s
This commit is contained in:
parent
7754e410fd
commit
5f2e84d8cf
14
src/k3mix.c
14
src/k3mix.c
@ -1,11 +1,13 @@
|
|||||||
#include"k3mix.h"
|
#include"k3mix.h"
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include<vorbis/vorbisfile.h>
|
#include<vorbis/vorbisfile.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<math.h>
|
#include<math.h>
|
||||||
#include<pthread.h>
|
#include<pthread.h>
|
||||||
#include<assert.h>
|
#include<assert.h>
|
||||||
|
#include"k3.h"
|
||||||
|
|
||||||
static uint32_t FinalSampleRate;
|
static uint32_t FinalSampleRate;
|
||||||
static uint8_t FinalChannels;
|
static uint8_t FinalChannels;
|
||||||
@ -19,12 +21,22 @@ struct k3MixSource {
|
|||||||
char *filepath;
|
char *filepath;
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
int bitstream;
|
int bitstream;
|
||||||
|
size_t looppoint;
|
||||||
};
|
};
|
||||||
struct k3MixSource *k3MixSourceFile(const char *path) {
|
struct k3MixSource *k3MixSourceFile(const char *path) {
|
||||||
struct k3MixSource *ret = calloc(1, sizeof(*ret));
|
struct k3MixSource *ret = calloc(1, sizeof(*ret));
|
||||||
ret->filepath = strdup(path);
|
ret->filepath = strdup(path);
|
||||||
ov_fopen(path, &ret->vf);
|
ov_fopen(path, &ret->vf);
|
||||||
ret->bitstream = 0;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
void k3MixSourceClose(struct k3MixSource *src) {
|
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);
|
long lastRead = ov_read_float(&od->vf, &ni, sampleCount, &od->bitstream);
|
||||||
|
|
||||||
if(this->loop && lastRead == 0) {
|
if(this->loop && lastRead == 0) {
|
||||||
ov_pcm_seek(&od->vf, 0);
|
ov_pcm_seek(&od->vf, od->looppoint);
|
||||||
continue;
|
continue;
|
||||||
} else if(lastRead <= 0) {
|
} else if(lastRead <= 0) {
|
||||||
this->end = true;
|
this->end = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user