-
Notifications
You must be signed in to change notification settings - Fork 1
/
efm.py
329 lines (326 loc) · 9.13 KB
/
efm.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# efm.py
#
# Copyright (c) 2005--2015 by Sidney Cadot <[email protected]>
# This software is licensed under the GNU General Public License (GPL).
#
# This file is part of laser2wav, a software-only implementation of
# an audio CD decoder.
# The lookup dictionary that defines the Eight-To-Fourteen (EFM)
# decoding algorithm as used in the CD audio channel encoding.
#
# The compact disc channel, scanned by the laser, consists of lands and pits.
# Let T be 1/4321800 seconds; then the valid length for both lands and pits is
# 3*T, 4*T, 5*T, 6*T, 7*T, 8*T, 9*T, 10*T or 11*T.
#
# Note: the allowed physical length of the lands/pits can be deduced from the
# fact that the CD is specified to be read at a constant linear velocity (CLV)
# of 1.2 m/s to 1.4 m/s. This means that T corresponds to a length of
# 277.662 nm (when read at 1.2 m/s) to 323.939 nm (when read at 1.4 m/s), giving
# a valid pit length of between 832.986 nm and 3054.283 nm (when read at 1.2 m/s),
# and between 971.817 nm and 3563.330 nm (when read at 1.4 m/s).
#
# CD surface:
#
# 3 3 4 4 5 5 6 6 7 7 8 8
# -___---____----_____-----______------_______-------________-------- (etc)
#
# Level:
#
# 1000111000011110000011111000000111111000000011111110000000011111111
#
# The first step of decoding detects whether the sampled signal has changed
# its level since the previous (1/4321800)-second interval.
#
# For the sample above, this results in:
#
# Delta-level:
#
# 0100100100010001000010000100000100000100000010000001000000010000000
#
# It is upon blocks of this form that the digital processing chain goes to work;
# Specifically, synchronization to the start-of-frame marker
# ("100000000001000000000010") and Fourteen-To-Eight demodulation work on
# the "delta level" signal.
#
# The "3 to 11" length constraint for pit- and land-lengths translates to a
# "2 to 10" constraint for the "number of zeroes between two successive lengths.
#
# Of the 16,384 14-bit patterns that exist, only 267 do not violate the constraint.
# 256 are used to encode byte patterns; two are used to encode unique
# synchronization patterns that are used to identify the first two frames of an
# 98-frame sector; and exactly nine patterns /could/ be used, but are not:
#
# 00000000001000
# 00000000001001
# 00000000010000
# 00000000010001
# 00001000000000
# 00010000000000
# 01001000000000
# 10001000000000
# 10010000000000
#
# All 258 patterns that /are/ used are listed in the dictionary below.
#
# Despite its name, the EFM dictionary given below is mainly useful for fourteen-to-eight
# demodulation.
EFM = {
"00100000000001" : 'SYNC0', # special CONTROL pattern (first frame of sector)
"00000000010010" : 'SYNC1', # special CONTROL pattern (second frame of sector)
"01001000100000" : 0,
"10000100000000" : 1,
"10010000100000" : 2,
"10001000100000" : 3,
"01000100000000" : 4,
"00000100010000" : 5,
"00010000100000" : 6,
"00100100000000" : 7,
"01001001000000" : 8,
"10000001000000" : 9,
"10010001000000" : 10,
"10001001000000" : 11,
"01000001000000" : 12,
"00000001000000" : 13,
"00010001000000" : 14,
"00100001000000" : 15,
"10000000100000" : 16,
"10000010000000" : 17,
"10010010000000" : 18,
"00100000100000" : 19,
"01000010000000" : 20,
"00000010000000" : 21,
"00010010000000" : 22,
"00100010000000" : 23,
"01001000010000" : 24,
"10000000010000" : 25,
"10010000010000" : 26,
"10001000010000" : 27,
"01000000010000" : 28,
"00001000010000" : 29,
"00010000010000" : 30,
"00100000010000" : 31,
"00000000100000" : 32,
"10000100001000" : 33,
"00001000100000" : 34,
"00100100100000" : 35,
"01000100001000" : 36,
"00000100001000" : 37,
"01000000100000" : 38,
"00100100001000" : 39,
"01001001001000" : 40,
"10000001001000" : 41,
"10010001001000" : 42,
"10001001001000" : 43,
"01000001001000" : 44,
"00000001001000" : 45,
"00010001001000" : 46,
"00100001001000" : 47,
"00000100000000" : 48,
"10000010001000" : 49,
"10010010001000" : 50,
"10000100010000" : 51,
"01000010001000" : 52,
"00000010001000" : 53,
"00010010001000" : 54,
"00100010001000" : 55,
"01001000001000" : 56,
"10000000001000" : 57,
"10010000001000" : 58,
"10001000001000" : 59,
"01000000001000" : 60,
"00001000001000" : 61,
"00010000001000" : 62,
"00100000001000" : 63,
"01001000100100" : 64,
"10000100100100" : 65,
"10010000100100" : 66,
"10001000100100" : 67,
"01000100100100" : 68,
"00000000100100" : 69,
"00010000100100" : 70,
"00100100100100" : 71,
"01001001000100" : 72,
"10000001000100" : 73,
"10010001000100" : 74,
"10001001000100" : 75,
"01000001000100" : 76,
"00000001000100" : 77,
"00010001000100" : 78,
"00100001000100" : 79,
"10000000100100" : 80,
"10000010000100" : 81,
"10010010000100" : 82,
"00100000100100" : 83,
"01000010000100" : 84,
"00000010000100" : 85,
"00010010000100" : 86,
"00100010000100" : 87,
"01001000000100" : 88,
"10000000000100" : 89,
"10010000000100" : 90,
"10001000000100" : 91,
"01000000000100" : 92,
"00001000000100" : 93,
"00010000000100" : 94,
"00100000000100" : 95,
"01001000100010" : 96,
"10000100100010" : 97,
"10010000100010" : 98,
"10001000100010" : 99,
"01000100100010" : 100,
"00000000100010" : 101,
"01000000100100" : 102,
"00100100100010" : 103,
"01001001000010" : 104,
"10000001000010" : 105,
"10010001000010" : 106,
"10001001000010" : 107,
"01000001000010" : 108,
"00000001000010" : 109,
"00010001000010" : 110,
"00100001000010" : 111,
"10000000100010" : 112,
"10000010000010" : 113,
"10010010000010" : 114,
"00100000100010" : 115,
"01000010000010" : 116,
"00000010000010" : 117,
"00010010000010" : 118,
"00100010000010" : 119,
"01001000000010" : 120,
"00001001001000" : 121,
"10010000000010" : 122,
"10001000000010" : 123,
"01000000000010" : 124,
"00001000000010" : 125,
"00010000000010" : 126,
"00100000000010" : 127,
"01001000100001" : 128,
"10000100100001" : 129,
"10010000100001" : 130,
"10001000100001" : 131,
"01000100100001" : 132,
"00000000100001" : 133,
"00010000100001" : 134,
"00100100100001" : 135,
"01001001000001" : 136,
"10000001000001" : 137,
"10010001000001" : 138,
"10001001000001" : 139,
"01000001000001" : 140,
"00000001000001" : 141,
"00010001000001" : 142,
"00100001000001" : 143,
"10000000100001" : 144,
"10000010000001" : 145,
"10010010000001" : 146,
"00100000100001" : 147,
"01000010000001" : 148,
"00000010000001" : 149,
"00010010000001" : 150,
"00100010000001" : 151,
"01001000000001" : 152,
"10000010010000" : 153,
"10010000000001" : 154,
"10001000000001" : 155,
"01000010010000" : 156,
"00001000000001" : 157,
"00010000000001" : 158,
"00100010010000" : 159,
"00001000100001" : 160,
"10000100001001" : 161,
"01000100010000" : 162,
"00000100100001" : 163,
"01000100001001" : 164,
"00000100001001" : 165,
"01000000100001" : 166,
"00100100001001" : 167,
"01001001001001" : 168,
"10000001001001" : 169,
"10010001001001" : 170,
"10001001001001" : 171,
"01000001001001" : 172,
"00000001001001" : 173,
"00010001001001" : 174,
"00100001001001" : 175,
"00000100100000" : 176,
"10000010001001" : 177,
"10010010001001" : 178,
"00100100010000" : 179,
"01000010001001" : 180,
"00000010001001" : 181,
"00010010001001" : 182,
"00100010001001" : 183,
"01001000001001" : 184,
"10000000001001" : 185,
"10010000001001" : 186,
"10001000001001" : 187,
"01000000001001" : 188,
"00001000001001" : 189,
"00010000001001" : 190,
"00100000001001" : 191,
"01000100100000" : 192,
"10000100010001" : 193,
"10010010010000" : 194,
"00001000100100" : 195,
"01000100010001" : 196,
"00000100010001" : 197,
"00010010010000" : 198,
"00100100010001" : 199,
"00001001000001" : 200,
"10000100000001" : 201,
"00001001000100" : 202,
"00001001000000" : 203,
"01000100000001" : 204,
"00000100000001" : 205,
"00000010010000" : 206,
"00100100000001" : 207,
"00000100100100" : 208,
"10000010010001" : 209,
"10010010010001" : 210,
"10000100100000" : 211,
"01000010010001" : 212,
"00000010010001" : 213,
"00010010010001" : 214,
"00100010010001" : 215,
"01001000010001" : 216,
"10000000010001" : 217,
"10010000010001" : 218,
"10001000010001" : 219,
"01000000010001" : 220,
"00001000010001" : 221,
"00010000010001" : 222,
"00100000010001" : 223,
"01000100000010" : 224,
"00000100000010" : 225,
"10000100010010" : 226,
"00100100000010" : 227,
"01000100010010" : 228,
"00000100010010" : 229,
"01000000100010" : 230,
"00100100010010" : 231,
"10000100000010" : 232,
"10000100000100" : 233,
"00001001001001" : 234,
"00001001000010" : 235,
"01000100000100" : 236,
"00000100000100" : 237,
"00010000100010" : 238,
"00100100000100" : 239,
"00000100100010" : 240,
"10000010010010" : 241,
"10010010010010" : 242,
"00001000100010" : 243,
"01000010010010" : 244,
"00000010010010" : 245,
"00010010010010" : 246,
"00100010010010" : 247,
"01001000010010" : 248,
"10000000010010" : 249,
"10010000010010" : 250,
"10001000010010" : 251,
"01000000010010" : 252,
"00001000010010" : 253,
"00010000010010" : 254,
"00100000010010" : 255
}