-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemms-info-native-opus.el
147 lines (127 loc) · 5.96 KB
/
emms-info-native-opus.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;; emms-info-native-opus.el --- EMMS Opus info support -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
;; Author: Petteri Hintsanen <[email protected]>
;; This file is part of EMMS.
;; EMMS 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 3, or (at your option)
;; any later version.
;; EMMS 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 EMMS; see the file COPYING. If not, write to the Free
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
;; MA 02110-1301, USA.
;;; Commentary:
;; This file contains Opus-specific code for `emms-info-native-ogg'
;; feature.
;;; Code:
(require 'emms-info-native-vorbis)
(require 'bindat)
(defvar bindat-raw)
(defvar emms-info-native-opus--channel-count 0
"Last decoded Opus channel count.")
(defconst emms-info-native-opus--id-magic-pattern "OpusHead"
"Opus identification header magic pattern.")
(defconst emms-info-native-opus--channel-mapping-bindat-spec
(if (eval-when-compile (fboundp 'bindat-type))
(bindat-type
(stream-count u8)
(coupled-count u8)
(channel-mapping vec emms-info-native-opus--channel-count))
'((stream-count u8)
(coupled-count u8)
(channel-mapping vec (eval emms-info-native-opus--channel-count))))
"Opus channel mapping table specification.")
(defconst emms-info-native-opus--id-header-bindat-spec
(if (eval-when-compile (fboundp 'bindat-type))
(bindat-type
(opus-head str 8)
(_ unit (unless (equal opus-head emms-info-native-opus--id-magic-pattern)
(error "Opus framing mismatch: expected `%s', got `%s'"
emms-info-native-opus--id-magic-pattern
opus-head)))
(opus-version u8)
(_ unit (unless (< opus-version 16)
(error "Opus version mismatch: expected < 16, got %s"
opus-version)))
(channel-count u8)
(_ unit (progn (setq emms-info-native-opus--channel-count channel-count) nil))
(pre-skip uintr 16)
(sample-rate uintr 32)
(output-gain uintr 16)
(channel-mapping-family u8)
(_ . (if (> channel-mapping-family 0)
(type emms-info-native-opus--channel-mapping-bindat-spec)
(unit nil))))
'((opus-head str 8)
(eval (unless (equal last emms-info-native-opus--id-magic-pattern)
(error "Opus framing mismatch: expected `%s', got `%s'"
emms-info-native-opus--id-magic-pattern
last)))
(opus-version u8)
(eval (unless (< last 16)
(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)
(union (channel-mapping-family)
(0 nil)
(t (struct emms-info-native-opus--channel-mapping-bindat-spec)))))
"Opus identification header specification.")
(defconst emms-info-native-opus--tags-magic-pattern "OpusTags"
"Opus comment header magic pattern.")
(defconst emms-info-native-opus--comment-header-bindat-spec
(if (eval-when-compile (fboundp 'bindat-type))
(bindat-type
(opus-tags str 8)
(_ unit (unless (equal opus-tags emms-info-native-opus--tags-magic-pattern)
(error "Opus framing mismatch: expected `%s', got `%s'"
emms-info-native-opus--tags-magic-pattern
opus-tags)))
(vendor-length uintr 32)
(_ unit (when (> vendor-length (length bindat-raw))
(error "Opus vendor length %s is too long"
vendor-length)))
(vendor-string str vendor-length)
(user-comments-list-length uintr 32)
(_ unit (when (> user-comments-list-length (length bindat-raw))
(error "Opus user comment list length %s is too long"
user-comments-list-length)))
(user-comments repeat user-comments-list-length
type emms-info-native-vorbis--comment-field-bindat-spec))
'((opus-tags str 8)
(eval (unless (equal last emms-info-native-opus--tags-magic-pattern)
(error "Opus framing mismatch: expected `%s', got `%s'"
emms-info-native-opus--tags-magic-pattern
last)))
(vendor-length u32r)
(eval (when (> last (length bindat-raw))
(error "Opus vendor length %s is too long" last)))
(vendor-string str (vendor-length))
(user-comments-list-length u32r)
(eval (when (> last (length bindat-raw))
(error "Opus user comment list length %s is too long"
last)))
(user-comments repeat
(user-comments-list-length)
(struct emms-info-native-vorbis--comment-field-bindat-spec))))
"Opus comment header specification.")
(defconst emms-info-native-opus--headers-bindat-spec
(if (eval-when-compile (fboundp 'bindat-type))
(bindat-type
(identification-header type emms-info-native-opus--id-header-bindat-spec)
(comment-header type emms-info-native-opus--comment-header-bindat-spec))
'((identification-header struct emms-info-native-opus--id-header-bindat-spec)
(comment-header struct emms-info-native-opus--comment-header-bindat-spec)))
"Specification for two first Opus header packets.
They are always an identification header followed by a comment
header.")
(provide 'emms-info-native-opus)
;;; emms-info-native-opus.el ends here