This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorbis.c
78 lines (69 loc) · 1.54 KB
/
vorbis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include "dat.h"
#include "fncs.h"
void
finddefmeta(VorbisMeta *v)
{
uint i;
for(i=0;i<v->ncom;i++){
if(runecstrcmp(v->key[i], L"album") == 0){
v->album = v->val[i];
continue;
}
if(runecstrcmp(v->key[i], L"title") == 0){
v->title = v->val[i];
continue;
}
if(runecstrcmp(v->key[i], L"artist") == 0){
v->artist = v->val[i];
continue;
}
if(runecstrcmp(v->key[i], L"tracknumber") == 0){
char buf[16];
snprint(buf, sizeof buf, "%S", v->val[i]);
v->tracknumber = atoi(buf);
continue;
}
}
}
void
parsevorbismeta(int fd, uvlong offset, VorbisMeta *v)
{
u32int size;
uchar buf[4096];
uint i;
char *sep;
/* Vendor String */
pread(fd, buf, 4, offset);
size = lebtoi(buf, 4);
offset+=size+4;
pread(fd, buf, 4, offset);
v->ncom = lebtoi(buf, 4);
v->key = emalloc(sizeof(Rune*) * v->ncom);
v->val = emalloc(sizeof(Rune*) * v->ncom);
offset+=4;
for(i=0;i<v->ncom;i++){
pread(fd, buf, 4, offset);
size = lebtoi(buf, 4);
/* TODO: We should ignore large comments, and trim those that we dont use */
if(size >= sizeof buf)
sysfatal("parsevorbismeta: comment greater then buff size");
offset+=4;
pread(fd, buf, size, offset);
offset+=size;
buf[size] = '\0';
sep = strchr((char*)buf, '=');
if(sep == nil){
fprint(2, "Invalid vorbis header format\n");
quit("Invalid vorbis header format");
continue;
}
*sep = '\0';
v->key[i] = runesmprint("%s", (char*)buf);
v->val[i] = runesmprint("%s", sep+1);
}
finddefmeta(v);
}