aboutsummaryrefslogtreecommitdiff
path: root/emms-info-native.el
diff options
context:
space:
mode:
authorPetteri Hintsanen <petterih@iki.fi>2021-02-10 01:07:10 +0200
committerPetteri Hintsanen <petterih@iki.fi>2021-02-10 23:29:57 +0200
commita3729763e260a9ae2e7d1b9e49c27b83ca92f7a7 (patch)
treed49b7f3d97ffbf9a34a5820dc88c39e2cf145aa2 /emms-info-native.el
parent7479d7d8f39a926a982ad6dceec34df5b7d91a64 (diff)
Fix Opus channel mapping decoding
It seems that bindat specs cannot refer outside themselves, so use a special variable ‘emms-info-native--opus-channel-count’ with dynamic binding to keep track of channel count.
Diffstat (limited to 'emms-info-native.el')
-rw-r--r--emms-info-native.el17
1 files changed, 13 insertions, 4 deletions
diff --git a/emms-info-native.el b/emms-info-native.el
index 669f3f3..dc2bbbd 100644
--- a/emms-info-native.el
+++ b/emms-info-native.el
@@ -189,8 +189,9 @@ Return a structure that corresponds to either
(bindat-unpack emms-info-native--vorbis-headers-bindat-spec
packets))
((eq stream-type 'opus)
- (bindat-unpack emms-info-native--opus-headers-bindat-spec
- packets))
+ (let (emms-info-native--opus-channel-count)
+ (bindat-unpack emms-info-native--opus-headers-bindat-spec
+ packets)))
(t (error "Unknown stream type %s" stream-type))))
;;;; Vorbis code
@@ -355,6 +356,11 @@ lower case and VALUE is the decoded value."
;;;; Opus code
+(defvar emms-info-native--opus-channel-count 0
+ "Last decoded Opus channel count.
+This is a kludge; it is needed because bindat spec cannot refer
+outside itself.")
+
(defconst emms-info-native--opus-head-magic-array
[79 112 117 115 72 101 97 100]
"Opus identification header magic pattern ‘OpusHead’.")
@@ -366,7 +372,7 @@ lower case and VALUE is the decoded value."
(defconst emms-info-native--opus-channel-mapping-table
'((stream-count u8)
(coupled-count u8)
- (channel-mapping vec (channel-count)))
+ (channel-mapping vec (eval emms-info-native--opus-channel-count)))
"Opus channel mapping table specification.")
(defconst emms-info-native--opus-identification-header-bindat-spec
@@ -380,11 +386,14 @@ lower case and VALUE is the decoded value."
(error "Opus version mismatch: expected < 16, got %s"
last)))
(channel-count u8)
+ (eval (setq emms-info-native--opus-channel-count last))
(pre-skip u16r)
(sample-rate u32r)
(output-gain u16r)
(channel-mapping-family u8)
- (eval (> last 0) (struct opus-channel-mapping-table)))
+ (union (channel-mapping-family)
+ (0 nil)
+ (t (struct emms-info-native--opus-channel-mapping-table))))
"Opus identification header specification.")
(defconst emms-info-native--opus-comment-header-bindat-spec