Rockbox Utility: update russian translation by Постолати Максим.
[maemo-rb.git] / apps / metadata / sgc.c
blob78cacb9b1b97246f03d263a527e959f92791e2f3
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <ctype.h>
5 #include <inttypes.h>
7 #include "system.h"
8 #include "metadata.h"
9 #include "metadata_common.h"
10 #include "metadata_parsers.h"
11 #include "rbunicode.h"
13 static bool parse_sgc_header(int fd, struct mp3entry* id3)
15 /* Use the trackname part of the id3 structure as a temporary buffer */
16 unsigned char* buf = (unsigned char *)id3->path;
18 lseek(fd, 0, SEEK_SET);
19 if (read(fd, buf, 0xA0) < 0xA0)
20 return false;
22 /* calculate track length with number of tracks */
23 id3->length = buf[37] * 1000;
25 /* If meta info was found in the m3u skip next step */
26 if (id3->title && id3->title[0]) return true;
28 char *p = id3->id3v2buf;
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;
36 /* Artist */
37 memcpy(p, &buf[96], 32); *(p + 33) = '\0';
38 id3->artist = p;
39 p += strlen(p)+1;
41 /* Copyright */
42 memcpy(p, &buf[128], 32); *(p + 33) = '\0';
43 id3->album = p;
44 p += strlen(p)+1;
45 return true;
49 bool get_sgc_metadata(int fd, struct mp3entry* id3)
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;
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;
62 /* Make sure this is an SGC file */
63 if (sgc_type != FOURCC('S','G','C',0x1A))
64 return false;
66 return parse_sgc_header(fd, id3);