commit 2c34239c8207dd8c957039958546637f5cb2f894
parent d820cc1d688847c523fb2b80227d0c0444d0c37c
Author: Toni Ruottu <toni.ruottu@helsinki.fi>
Date: Mon, 20 Nov 2006 19:42:55 +0000
Added sid support.
Diffstat:
6 files changed, 185 insertions(+), 0 deletions(-)
diff --git a/AUTHORS b/AUTHORS
@@ -34,6 +34,7 @@ exiv2 - Andreas Huggel <ahuggel@gmx.net>
language - Roberto Cappuccio <roberto.cappuccio@gmail.com> (from libkat)
word - Ariya Hidayat <ariya@kde.org> and Sacha Fuentes <mandelman@iname.com>
nsf - Toni Ruottu <toni.ruottu@iki.fi>
+sid - Toni Ruottu <toni.ruottu@iki.fi>
General contributors:
Yuri N. Sedunov <aris@altlinux.ru>
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,6 @@
+Mon Nov 20 22:08:55 EET 2006
+ Added an SID (C64 music file) plugin
+
Sat Nov 11 16:04:38 MST 2006
Fixed libltdl side-effect of loading libextractor; code
now preserves the old library search path and only appends
diff --git a/NEWS b/NEWS
@@ -1,3 +1,6 @@
+Mon Nov 20 22:08:55 EET 2006
+ Added an SID (C64 music file) plugin
+
Sat Nov 11 00:04:34 EET 2006
Added an NSF ( NES Sound Format ) plugin
diff --git a/src/main/extractor.c b/src/main/extractor.c
@@ -240,6 +240,7 @@ libextractor_mpeg:\
libextractor_elf:\
libextractor_oo:\
libextractor_asf:\
+libextractor_sid:\
libextractor_nsf"
#define DEFAULT_LIBRARIES EXSO OLESO OGGSO QTSO DEFSO
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
@@ -80,6 +80,7 @@ plugin_LTLIBRARIES = $(pdfplugin) \
$(extraqt) \
libextractor_real.la \
libextractor_riff.la \
+ libextractor_sid.la \
libextractor_split.la \
libextractor_tar.la \
libextractor_tiff.la \
@@ -292,6 +293,13 @@ libextractor_filename_la_LIBADD = \
$(top_builddir)/src/main/libextractor.la \
libconvert.la
+libextractor_sid_la_SOURCES = \
+ sidextractor.c
+libextractor_sid_la_LDFLAGS = \
+ $(PLUGINFLAGS) $(retaincommand)
+libextractor_sid_la_LIBADD = \
+ $(top_builddir)/src/main/libextractor.la
+
libextractor_nsf_la_SOURCES = \
nsfextractor.c
libextractor_nsf_la_LDFLAGS = \
diff --git a/src/plugins/sidextractor.c b/src/plugins/sidextractor.c
@@ -0,0 +1,169 @@
+/*
+ This file is part of libextractor.
+ (C) 2006 Toni Ruottu
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#include "platform.h"
+#include "extractor.h"
+#include "convert.h"
+
+
+static struct EXTRACTOR_Keywords *
+addkword(EXTRACTOR_KeywordList *oldhead,
+ const char * phrase,
+ EXTRACTOR_KeywordType type) {
+ EXTRACTOR_KeywordList * keyword;
+
+ keyword = malloc(sizeof(EXTRACTOR_KeywordList));
+ keyword->next = oldhead;
+ keyword->keyword = strdup(phrase);
+ keyword->keywordType = type;
+ return keyword;
+}
+
+
+/* "extract" keyword from a SID file
+ *
+ * This plugin is based on the nsf extractor
+ *
+ * */
+struct EXTRACTOR_Keywords *
+libextractor_sid_extract(const char * filename,
+ char * data,
+ size_t size,
+ struct EXTRACTOR_Keywords * prev) {
+ int i, version;
+ char name[33];
+ char artist[33];
+ char copyright[33];
+ char songs[32];
+ char startingsong[32];
+
+
+ /* Check header size and "magic" id bytes */
+
+ if
+ (
+ size < 0x76 ||
+ ( data[0] != 'P' && data[0] != 'R' ) ||
+ data[1] != 'S' ||
+ data[2] != 'I' ||
+ data[3] != 'D'
+ )
+ {
+ return prev;
+ }
+
+
+ /* Mime-type */
+
+ prev = addkword(prev, "audio/prs.sid", EXTRACTOR_MIMETYPE);
+
+ /* Version of SID format */
+
+ version = data[4] * 0xff + data[5];
+ sprintf( startingsong, "%d", version );
+ prev = addkword(prev, startingsong, EXTRACTOR_FORMAT_VERSION);
+
+
+ /* Get song count */
+
+ sprintf( songs, "%d", data[0x0e] * 0xff + data[0x0f] );
+ prev = addkword(prev, songs, EXTRACTOR_SONG_COUNT);
+
+
+ /* Get number of the first song to be played */
+
+ sprintf( startingsong, "%d", data[0x10] * 0xff + data[0x11] );
+ prev = addkword(prev, startingsong, EXTRACTOR_STARTING_SONG);
+
+
+ /* Parse name, artist, copyright fields */
+
+ for( i = 0; i < 32; i++ )
+ {
+ name[i] = data[ 0x16 + i ];
+ artist[i] = data[ 0x36 + i ];
+ copyright[i] = data[ 0x56 + i ];
+ }
+
+ name[32] = '\0';
+ artist[32] = '\0';
+ copyright[32] = '\0';
+
+ prev = addkword(prev, name, EXTRACTOR_TITLE);
+ prev = addkword(prev, artist, EXTRACTOR_ARTIST);
+ prev = addkword(prev, copyright, EXTRACTOR_COPYRIGHT);
+
+
+ if( version < 2 || size < 0x7c )
+ {
+ return prev;
+ }
+
+ /* Version 2 specific options follow
+ *
+ * Note: Had some troubles understanding specification
+ * on the flags in version 2. I hope this is correct.
+ *
+ */
+
+ /* PAL or NTSC */
+
+ if( data[0x77] & 16 )
+ {
+ if( data[0x77] & 32 )
+ {
+ prev = addkword(prev, "PAL/NTSC", EXTRACTOR_TELEVISION_SYSTEM);
+ }
+ else
+ {
+ prev = addkword(prev, "PAL", EXTRACTOR_TELEVISION_SYSTEM);
+ }
+ }
+ else
+ {
+ if( data[0x77] & 32 )
+ {
+ prev = addkword(prev, "NTSC", EXTRACTOR_TELEVISION_SYSTEM);
+ }
+ }
+
+ /* Detect SID Chips suitable for play the files */
+
+ if( data[0x77] & 4 )
+ {
+ if( data[0x77] & 8 )
+ {
+ prev = addkword(prev, "MOS6581/MOS8580", EXTRACTOR_HARDWARE_DEPENDENCY);
+ }
+ else
+ {
+ prev = addkword(prev, "MOS6581", EXTRACTOR_HARDWARE_DEPENDENCY);
+ }
+ }
+ else
+ {
+ if( data[0x77] & 8 )
+ {
+ prev = addkword(prev, "MOS8580", EXTRACTOR_HARDWARE_DEPENDENCY);
+ }
+ }
+
+ return prev;
+}