From a3729763e260a9ae2e7d1b9e49c27b83ca92f7a7 Mon Sep 17 00:00:00 2001 From: Petteri Hintsanen Date: Wed, 10 Feb 2021 01:07:10 +0200 Subject: Fix Opus channel mapping decoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- emms-info-native.el | 17 +++++++++++++---- 1 file 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 -- cgit v1.2.3