summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Boot <rotator@gmail.com>2007-03-03 06:08:28 +0000
committerAdam Boot <rotator@gmail.com>2007-03-03 06:08:28 +0000
commitb9a71b305b98a87f747dc1e0cc91324b73693fd1 (patch)
treec6e033835b4fc63ad0955ea3124f4b699cc9fd69
parent411f8198b46764a7c29030f8da1da90dc332308c (diff)
downloadrockbox-b9a71b305b98a87f747dc1e0cc91324b73693fd1.tar.gz
rockbox-b9a71b305b98a87f747dc1e0cc91324b73693fd1.zip
Add get_metadata() and year & comment tag support for SPC.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12563 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/spc.c27
-rw-r--r--apps/metadata.c108
2 files changed, 129 insertions, 6 deletions
diff --git a/apps/codecs/spc.c b/apps/codecs/spc.c
index 12b236c53d..1cf20098fa 100644
--- a/apps/codecs/spc.c
+++ b/apps/codecs/spc.c
@@ -671,14 +671,31 @@ static int LoadID666(unsigned char *buf) {
671 ID666.emulator=*ib; 671 ID666.emulator=*ib;
672 ib++; 672 ib++;
673 } else { 673 } else {
674 int year, month, day;
675 unsigned long tmp; 674 unsigned long tmp;
676 char buf[64]; 675 char buf[64];
677 676
678 DEBUGF("text tag detected\n"); 677 DEBUGF("text tag detected\n");
679 678
680 year=month=day=0; 679 memcpy(buf, ib, 2);
681 ib+=11; 680 buf[2] = 0;
681 tmp = 0;
682 for (i=0;i<2 && buf[i]>='0' && buf[i]<='9';i++) tmp=tmp*10+buf[i]-'0';
683 ID666.month = tmp;
684 ib+=3;
685
686 memcpy(buf, ib, 2);
687 buf[2] = 0;
688 tmp = 0;
689 for (i=0;i<2 && buf[i]>='0' && buf[i]<='9';i++) tmp=tmp*10+buf[i]-'0';
690 ID666.day = tmp;
691 ib+=3;
692
693 memcpy(buf, ib, 4);
694 buf[4] = 0;
695 tmp = 0;
696 for (i=0;i<4 && buf[i]>='0' && buf[i]<='9';i++) tmp=tmp*10+buf[i]-'0';
697 ID666.year = tmp;
698 ib+=5;
682 699
683 memcpy(buf, ib, 3); 700 memcpy(buf, ib, 3);
684 buf[3] = 0; 701 buf[3] = 0;
@@ -861,6 +878,8 @@ enum codec_status codec_main(void)
861 ci->id3->title = ID666.song; 878 ci->id3->title = ID666.song;
862 ci->id3->album = ID666.game; 879 ci->id3->album = ID666.game;
863 ci->id3->artist = ID666.artist; 880 ci->id3->artist = ID666.artist;
881 ci->id3->year = ID666.year;
882 ci->id3->comment = ID666.comments;
864 883
865 reset_profile_timers(); 884 reset_profile_timers();
866 } 885 }
diff --git a/apps/metadata.c b/apps/metadata.c
index 84ee37c2fe..42ae435aea 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -33,6 +33,7 @@
33#include "system.h" 33#include "system.h"
34#include "cuesheet.h" 34#include "cuesheet.h"
35#include "structec.h" 35#include "structec.h"
36#include "settings.h"
36 37
37enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS }; 38enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS };
38 39
@@ -1858,6 +1859,104 @@ static bool get_adx_metadata(int fd, struct mp3entry* id3)
1858 return true; 1859 return true;
1859} 1860}
1860 1861
1862static bool get_spc_metadata(int fd, struct mp3entry* id3)
1863{
1864 /* Use the trackname part of the id3 structure as a temporary buffer */
1865 unsigned char * buf = (unsigned char *)id3->path;
1866 int read_bytes;
1867 char * p;
1868
1869 unsigned long length;
1870 unsigned long fade;
1871 bool isbinary = true;
1872 int i;
1873
1874 /* try to get the ID666 tag */
1875 if ((lseek(fd, 0x2e, SEEK_SET) < 0)
1876 || ((read_bytes = read(fd, buf, 0xD2)) < 0xD2))
1877 {
1878 DEBUGF("lseek or read failed\n");
1879 return false;
1880 }
1881
1882 p = id3->id3v2buf;
1883
1884 id3->title = p;
1885 buf[31] = 0;
1886 p = iso_decode(buf, p, 0, 32);
1887 buf += 32;
1888
1889 id3->album = p;
1890 buf[31] = 0;
1891 p = iso_decode(buf, p, 0, 32);
1892 buf += 48;
1893
1894 id3->comment = p;
1895 buf[31] = 0;
1896 p = iso_decode(buf, p, 0, 32);
1897 buf += 32;
1898
1899 /* Date check */
1900 if(buf[2] == '/' && buf[5] == '/')
1901 isbinary = false;
1902
1903 /* Reserved bytes check */
1904 if(buf[0xD2 - 0x2E - 112] >= '0' &&
1905 buf[0xD2 - 0x2E - 112] <= '9' &&
1906 buf[0xD3 - 0x2E - 112] == 0x00)
1907 isbinary = false;
1908
1909 /* is length & fade only digits? */
1910 for (i=0;i<8 && (
1911 (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') ||
1912 buf[0xA9 - 0x2E - 112+i]=='\0');
1913 i++);
1914 if (i==8) isbinary = false;
1915
1916 if(isbinary) {
1917 unsigned char * tbuf = buf;
1918
1919 id3->year = tbuf[0] | (tbuf[1]<<8);
1920 buf += 11;
1921
1922 length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000;
1923 buf += 3;
1924
1925 fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24));
1926 buf += 4;
1927 } else {
1928 char tbuf[6];
1929
1930 buf += 6;
1931 buf[4] = 0;
1932 id3->year = atoi(buf);
1933 buf += 5;
1934
1935 memcpy(tbuf, buf, 3);
1936 tbuf[3] = 0;
1937 length = atoi(tbuf) * 1000;
1938 buf += 3;
1939
1940 memcpy(tbuf, buf, 5);
1941 tbuf[5] = 0;
1942 fade = atoi(tbuf);
1943 buf += 5;
1944 }
1945
1946 id3->artist = p;
1947 buf[31] = 0;
1948 p = iso_decode(buf, p, 0, 32);
1949
1950 if (global_settings.repeat_mode!=REPEAT_ONE && length==0) {
1951 length=3*60*1000; /* 3 minutes */
1952 fade=5*1000; /* 5 seconds */
1953 }
1954
1955 id3->length = length+fade;
1956
1957 return true;
1958}
1959
1861static bool get_aiff_metadata(int fd, struct mp3entry* id3) 1960static bool get_aiff_metadata(int fd, struct mp3entry* id3)
1862{ 1961{
1863 /* Use the trackname part of the id3 structure as a temporary buffer */ 1962 /* Use the trackname part of the id3 structure as a temporary buffer */
@@ -2173,6 +2272,11 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
2173 } 2272 }
2174 break; 2273 break;
2175 case AFMT_SPC: 2274 case AFMT_SPC:
2275 if(!get_spc_metadata(fd, &(track->id3)))
2276 {
2277 DEBUGF("get_spc_metadata error\n");
2278 }
2279
2176 track->id3.filesize = filesize(fd); 2280 track->id3.filesize = filesize(fd);
2177 track->id3.genre_string = id3_get_num_genre(36); 2281 track->id3.genre_string = id3_get_num_genre(36);
2178 break; 2282 break;
@@ -2182,7 +2286,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
2182 DEBUGF("get_adx_metadata error\n"); 2286 DEBUGF("get_adx_metadata error\n");
2183 return false; 2287 return false;
2184 } 2288 }
2185 2289
2186 break; 2290 break;
2187 case AFMT_NSF: 2291 case AFMT_NSF:
2188 buf = (unsigned char *)track->id3.path; 2292 buf = (unsigned char *)track->id3.path;
@@ -2194,7 +2298,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
2194 track->id3.vbr = false; 2298 track->id3.vbr = false;
2195 track->id3.filesize = filesize(fd); 2299 track->id3.filesize = filesize(fd);
2196 if (memcmp(buf,"NESM",4) && memcmp(buf,"NSFE",4)) return false; 2300 if (memcmp(buf,"NESM",4) && memcmp(buf,"NSFE",4)) return false;
2197 break; 2301 break;
2198 2302
2199 case AFMT_AIFF: 2303 case AFMT_AIFF:
2200 if (!get_aiff_metadata(fd, &(track->id3))) 2304 if (!get_aiff_metadata(fd, &(track->id3)))