summaryrefslogtreecommitdiff
path: root/apps/metadata/sgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata/sgc.c')
-rw-r--r--apps/metadata/sgc.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/apps/metadata/sgc.c b/apps/metadata/sgc.c
new file mode 100644
index 0000000000..9e16de2c76
--- /dev/null
+++ b/apps/metadata/sgc.c
@@ -0,0 +1,67 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <ctype.h>
5#include <inttypes.h>
6
7#include "system.h"
8#include "metadata.h"
9#include "metadata_common.h"
10#include "metadata_parsers.h"
11#include "rbunicode.h"
12
13bool parse_sgc_header(int fd, struct mp3entry* id3)
14{
15 /* Use the trackname part of the id3 structure as a temporary buffer */
16 unsigned char* buf = (unsigned char *)id3->path;
17
18 lseek(fd, 0, SEEK_SET);
19 if (read(fd, buf, 0xA0) < 0xA0)
20 return false;
21
22 /* calculate track length with number of tracks */
23 id3->length = buf[37] * 1000;
24
25 /* If meta info was found in the m3u skip next step */
26 if (id3->title && id3->title[0]) return true;
27
28 char *p = id3->id3v2buf;
29
30 /* Some metadata entries have 32 bytes length */
31 /* Game */
32 memcpy(p, &buf[64], 32); *(p + 33) = '\0';
33 id3->title = p;
34 p += strlen(p)+1;
35
36 /* Artist */
37 memcpy(p, &buf[96], 32); *(p + 33) = '\0';
38 id3->artist = p;
39 p += strlen(p)+1;
40
41 /* Copyright */
42 memcpy(p, &buf[128], 32); *(p + 33) = '\0';
43 id3->album = p;
44 p += strlen(p)+1;
45 return true;
46}
47
48
49bool get_sgc_metadata(int fd, struct mp3entry* id3)
50{
51 uint32_t sgc_type;
52 if ((lseek(fd, 0, SEEK_SET) < 0) ||
53 read_uint32be(fd, &sgc_type) != (int)sizeof(sgc_type))
54 return false;
55
56 id3->vbr = false;
57 id3->filesize = filesize(fd);
58 /* we only render 16 bits, 44.1KHz, Stereo */
59 id3->bitrate = 706;
60 id3->frequency = 44100;
61
62 /* Make sure this is an SGC file */
63 if (sgc_type != FOURCC('S','G','C',0x1A))
64 return false;
65
66 return parse_sgc_header(fd, id3);
67}