[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any appetite for patches for EMMS support for SNES SPC files?

From: Warren Wilkinson
Subject: Re: Any appetite for patches for EMMS support for SNES SPC files?
Date: Thu, 27 Jul 2023 08:12:31 -0600
User-agent: Gnus/5.13 (Gnus v5.13)

I've created the patch and attached it here. I'll be simultaneously be
sending the assignment for to GNU.

Both mplayer and VLC are able to play .spc files, and those seem to be
the only two players that use the common-formats variable that I
modified in emms.el.

diff --git a/emms-info-native.el b/emms-info-native.el
index 3e3e2d4..88ea481 100644
--- a/emms-info-native.el
+++ b/emms-info-native.el
@@ -922,6 +922,67 @@ Return the text as string."
   (cdr (assoc (seq-first bytes)
+;;;; id666 code (SNES spc files)
+(defconst emms-info-native--id666-magic-array
+  [#x53 #x4e #x45 #x53 #x2d #x53 #x50#x43 #x37 #x30 #x30 #x20 #x53 #x6f #x75 
#x6e #x64 #x20 #x46 #x69 #x6c #x65 #x20 #x44 #x61 #x74 #x61 #x20 #x76 #x30 #x2e 
#x33 #x30]
+  "id666 header magic pattern `SNES-SPC700 Sound File Data v0.30'")
+(defconst emms-info-native--id666-header-bindat-spec
+  '((file-identifier vec 33)
+    (eval (unless (equal last emms-info-native--id666-magic-array)
+            (error "id666 framing mismatch: expected `%s', got `%s'"
+                   emms-info-native--id666-magic-array
+                   last)))
+    (unused u16)
+    (has-id666 u8);;(setq emms-info-native--id666-has-id666-data (= 27 last)))
+    (revision u8)
+    (pc-reg u16)
+    (a-reg u8)
+    (x-reg u8)
+    (y-reg u8)
+    (psw-reg u8)
+    (sp-reg u8)
+    (res-reg u16)
+    (song-title strz 32)
+    (game-title strz 32)
+    (dumper strz 16)
+    (comment strz 32)
+    (date strz 11)
+    (fadeout vec 3)
+    (fadeout-length vec 5)
+    (artist strz 32))
+  "id666 header specification.
+- URL `https://ocremix.org/info/SPC_Format_Specification'
+- URL `https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html'")
+(defun emms-info-native--decode-id666-header (filename)
+  "Read and decode id666 header from FILENAME."
+  (with-temp-buffer
+    (set-buffer-multibyte nil)
+    (insert-file-contents-literally filename nil 0 210)
+    (bindat-unpack emms-info-native--id666-header-bindat-spec
+                   (buffer-string))))
+(defun emms-info-native--decode-id666 (filename)
+  "Read and decode id666 metadata from FILENAME.
+Return metadata in a list of (FIELD . VALUE) cons cells, or nil
+in case of errors or if there were no known fields in FILENAME."
+  (condition-case nil
+      (let ((header (emms-info-native--decode-id666-header filename)))
+       (when (= 26 (bindat-get-field header 'has-id666))
+         (list
+          (cons 'info-title (bindat-get-field header 'song-title))
+          (cons 'info-album (bindat-get-field header 'game-title))
+          (cons 'info-artist (bindat-get-field header 'artist))
+          (cons 'info-composer (bindat-get-field header 'artist))
+          (cons 'info-note (bindat-get-field header 'comment)))))
+    (error nil)))
 ;;;; EMMS code
 (defun emms-info-native (track)
@@ -954,6 +1015,8 @@ strings."
            (emms-info-native--decode-flac-comments filename))
           ((eq stream-type 'mp3)
            (emms-info-native--decode-id3v2 filename))
+         ((eq stream-type 'spc)
+          (emms-info-native--decode-id666 filename))
           (t nil))))
 (defun emms-info-native--find-stream-type (filename)
@@ -967,6 +1030,7 @@ Return one of symbols `vorbis', `opus', `flac', or `mp3'."
           ((string-match ".opus$" filename) 'opus)
           ((string-match ".flac$" filename) 'flac)
           ((string-match ".mp3$" filename) 'mp3)
+         ((string-match ".spc$" filename) 'spc)
           (t nil))))
 (provide 'emms-info-native)
diff --git a/emms.el b/emms.el
index 8581dfe..e003c72 100644
--- a/emms.el
+++ b/emms.el
@@ -376,7 +376,7 @@ Point will not be restored afterward."
   '("ogg" "mp3" "wav" "mpg" "mpeg" "wmv" "wma"
     "mov" "avi" "divx" "ogm" "ogv" "asf" "mkv"
     "rm" "rmvb" "mp4" "flac" "vob" "m4a" "ape"
-    "flv" "webm" "aif" "opus")
+    "flv" "webm" "aif" "opus" "spc")
   "A list of common formats which player definitions can use.")

reply via email to

[Prev in Thread] Current Thread [Next in Thread]