This commit is contained in:
Nishi 2025-11-29 22:27:30 +09:00
commit da8f6313a9
Signed by: nishi
GPG key ID: 27EF69B208EB9343
2 changed files with 23 additions and 23 deletions

View file

@ -4,21 +4,21 @@
#define DR_FLAC_IMPLEMENTATION
#include <dr_flac.h>
static void meta(void* user, drflac_metadata* metadata){
static void meta(void* user, drflac_metadata* metadata) {
MDESoundContext ctx = user;
if(metadata->type == DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT){
const char* comment;
if(metadata->type == DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT) {
const char* comment;
drflac_vorbis_comment_iterator it;
drflac_uint32 len;
drflac_uint32 len;
drflac_init_vorbis_comment_iterator(&it, metadata->data.vorbis_comment.commentCount, metadata->data.vorbis_comment.pComments);
while((comment = drflac_next_vorbis_comment(&it, &len)) != NULL){
while((comment = drflac_next_vorbis_comment(&it, &len)) != NULL) {
char* s = malloc(len + 1);
char* p;
memcpy(s, comment, len);
s[len] = 0;
p = strchr(s, '=');
p = strchr(s, '=');
if(p != NULL) {
p[0] = 0;
if(strcasecmp(s, "TITLE") == 0) {
@ -44,14 +44,14 @@ static MDESoundContext flac_open(const char* path) {
memset(ctx, 0, sizeof(*ctx));
ctx->opaque = drflac_open_file_with_metadata(path, meta, ctx, NULL);
if(ctx->opaque == NULL){
if(ctx->opaque == NULL) {
free(ctx);
return NULL;
}
ctx->sample_rate = ((drflac*)ctx->opaque)->sampleRate;
ctx->channels = ((drflac*)ctx->opaque)->channels;
ctx->frames = ((drflac*)ctx->opaque)->totalPCMFrameCount;
ctx->channels = ((drflac*)ctx->opaque)->channels;
ctx->frames = ((drflac*)ctx->opaque)->totalPCMFrameCount;
return ctx;
}

View file

@ -99,29 +99,29 @@ char* MDEID3GetString(const char* path, const char* name) {
memcpy(s, d + 1, sz - 1);
s[sz - 1] = 0;
if(d[0] == 1) {
unsigned short bom = *(unsigned short*)&s[0];
int incr = 0;
unsigned short bom = *(unsigned short*)&s[0];
int incr = 0;
for(i = 1; i < (sz) / 2; i++) {
if(bom == 0xfffe) {
unsigned int n = 0;
char b[4];
int l;
n = n << 8;
n = n | d[1 + 2 * i + 0];
n = n << 8;
n = n | d[1 + 2 * i + 1];
char b[4];
int l;
n = n << 8;
n = n | d[1 + 2 * i + 0];
n = n << 8;
n = n | d[1 + 2 * i + 1];
l = MwUTF32ToUTF8(n, b);
memcpy(s + incr, b, l);
incr += l;
} else if(bom == 0xfeff) {
unsigned int n = 0;
char b[4];
int l;
n = n << 8;
n = n | d[1 + 2 * i + 1];
n = n << 8;
n = n | d[1 + 2 * i + 0];
char b[4];
int l;
n = n << 8;
n = n | d[1 + 2 * i + 1];
n = n << 8;
n = n | d[1 + 2 * i + 0];
l = MwUTF32ToUTF8(n, b);
memcpy(s + incr, b, l);
incr += l;