|
| 1 | +title: "How Does Timecode Vinyl Actually Work? (Pt. 3)" |
| 2 | +authors: Jan Claußen |
| 3 | +tags: traktor, timecode, dvs, vinyl control |
| 4 | +status: draft |
| 5 | +math: yes |
| 6 | + |
| 7 | +Since its release in 2011, the **Traktor Control Vinyl MK2** has sparked |
| 8 | +curiosity among digital DJs and audio developers alike. Its timecode format |
| 9 | +stands apart from Serato’s, which we explored in the previous posts. With the |
| 10 | +MK2 system, Native Instruments introduced a more advanced timecode that boosts |
| 11 | +resolution and accuracy by applying advanced cryptographic techniques. |
| 12 | + |
| 13 | +In this post, we’ll break down how it works at a basic level and how Mixxx is processing the signal. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Recap: How Serato Timecode Works |
| 18 | + |
| 19 | +Serato’s timecode is built around a |
| 20 | +[Linear Feedback Shift Register](https://en.wikipedia.org/wiki/Linear-feedback_shift_register), |
| 21 | +modulated onto a 1 kHz carrier using |
| 22 | +[amplitude modulation (AM)](https://en.wikipedia.org/wiki/Amplitude_modulation) - a legacy |
| 23 | +technique from radio transmission. |
| 24 | + |
| 25 | +The demodulation process is relatively simple: when one stereo channel crosses |
| 26 | +the x-axis, the other hits a peak. If that peak exceeds a certain threshold, |
| 27 | +the system reads it as a **1**, if not, it’s a **0**. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +We covered this in more detail in |
| 32 | +[DVS Internals Pt. 1]({filename}/news/2021-11-21-dvs-internals-pt1.md) |
| 33 | +and [Pt. 2]({filename}/news/2021-12-22-dvs-internals-pt2.md). |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## The Traktor MK2 Signal |
| 38 | + |
| 39 | +Below is a signal that resembles what you’ll find on the Traktor MK2 |
| 40 | +Control vinyl/CD, which has been specifcally generated for this blog post by |
| 41 | +using a [Raised-Cosine Filter](https://de.wikipedia.org/wiki/Raised-Cosine-Filter) to |
| 42 | +modulate a random sequence onto the carrier. |
| 43 | + |
| 44 | +The carrier wave operates at **2500 Hz**, a significant increase from Serato’s |
| 45 | +**1000 Hz**. |
| 46 | + |
| 47 | +> **Advantage:** The higher carrier frequency allows for 2.5× greater resolution. |
| 48 | +
|
| 49 | + |
| 50 | + |
| 51 | +Upon inspection, this waveform clearly doesn’t use amplitude modulation - the |
| 52 | +amplitude remains constant. Instead, it appears to be **offset-modulated**, |
| 53 | +where the signal is shifted vertically from the x-axis. This is a non-standard |
| 54 | +technique not commonly used in typical modulation schemes. |
| 55 | + |
| 56 | +On the original vinyl version (not shown here due to copyright), the offset |
| 57 | +can be so large that the signal floats entirely above the x-axis for multiple |
| 58 | +cycles - making zero-crossing detection impossible. |
| 59 | + |
| 60 | +Even when that doesn’t happen, the offset causes the time interval $\Delta t$ |
| 61 | +between zero-crossings to become irregular, introducing audible pitch flutter. |
| 62 | + |
| 63 | +To decode the signal, we must solve: |
| 64 | + |
| 65 | +1. How to filter the signal to enable pitch detection |
| 66 | +2. How to demodulate this non-standard modulation |
| 67 | +3. How to decipher the code that is modulated onto the carrier |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Pitch Detection |
| 72 | + |
| 73 | +> **Note:** If you're unfamiliar with pitch detection in DVS systems, revisit |
| 74 | +> [DVS Internals Pt. 1]({filename}/news/2021-11-21-dvs-internals-pt1.md). |
| 75 | +
|
| 76 | +Our goal is to produce a signal that oscillates evenly around the x-axis. This |
| 77 | +filtered waveform can then be processed by the existing pitch detection algorithm. |
| 78 | + |
| 79 | +A simple discrete derivative operation achieves this: |
| 80 | + |
| 81 | +$$ |
| 82 | +y[n] = x[n] - x[n-1] \tag{1} |
| 83 | +$$ |
| 84 | + |
| 85 | +$\text{where:}$<br> |
| 86 | +$\text{- x[n]: Input sample}$<br> |
| 87 | +$\text{- x[n-1]: Delayed input sample}$<br> |
| 88 | +$\text{- y[n]: Difference of both values}$<br> |
| 89 | +<br> |
| 90 | + |
| 91 | +When applied to the offset-modulated signal, we get: |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +The resulting waveform oscillates cleanly around zero, which is ideal for |
| 96 | +analysis. It also makes it easier to pinpoint the half-cycle peaks needed for |
| 97 | +bit detection. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Demodulation Techniques |
| 102 | + |
| 103 | +To extract bits from the signal, we detect the zero-crossings and sample the |
| 104 | +amplitude of the sinusoid at those moments. |
| 105 | + |
| 106 | + |
| 108 | + |
| 109 | +You may notice that the derivative’s zero-crossings don’t align perfectly with |
| 110 | +the original peaks. That’s due to a delay introduced by the filter. Smoothing |
| 111 | +the signal first, then compensating for the delay (e.g., by selecting |
| 112 | +$x[n-3]$), yields better results. |
| 113 | + |
| 114 | +For greater accuracy, one could analyze the phase response $\phi(\omega)$, |
| 115 | +which shows how filter delay varies with input frequency - but for this use case, |
| 116 | +a fixed delay works well enough. |
| 117 | + |
| 118 | +The filtered signal can cross the x-axis in two directions-positive to |
| 119 | +negative or vice versa. Based on the direction, we determine which half-cycle |
| 120 | +contains the encoded bit. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +Demodulation is then as simple as applying a threshold: amplitudes above it |
| 125 | +are **1**, and below it are **0**. |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +On actual vinyl, the physical behavior of the needle causes the offset to |
| 130 | +decay over time, because the needle slowly drifts back to the middle. This decay complicates bit extraction. |
| 131 | + |
| 132 | +To compensate, we analyze the **slope** between subsequent readings by |
| 133 | +reusing the derivative equation in $\text{(1)}$. |
| 134 | + |
| 135 | +$$slope[n] = reading[n] - reading[n-1]$$ |
| 136 | + |
| 137 | +$\text{where:}$<br> |
| 138 | +$\text{- x[n]: Current reading}$<br> |
| 139 | +$\text{- x[n-1]: Last reading}$<br> |
| 140 | +$\text{- y[n]: Difference of both values}$<br> |
| 141 | +<br> |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +This method helps isolate the encoded signal from the floating zero line |
| 146 | +caused by mechanical drift. |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## The Code |
| 151 | + |
| 152 | +> **Note:** A deeper explanation of LFSRs can be found in [DVS Internals Pt. 2]({filename}/news/2021-12-22-dvs-internals-pt2.md) |
| 153 | +
|
| 154 | +Interestingly, the Traktor MK2 system also uses a [Linear Feedback Shift Register](https://en.wikipedia.org/wiki/Linear-feedback_shift_register) - but with different properties. While Serato’s LFSR has a |
| 155 | +**20-bit** length, Traktor’s appears to use a **110-bit** register with a minimum |
| 156 | +run length of two symbols. |
| 157 | + |
| 158 | +The number of unique states an LFSR can generate is: |
| 159 | + |
| 160 | +$$n_{max} = 2^m -1$$ |
| 161 | + |
| 162 | +Hence for the Serato timecode |
| 163 | + |
| 164 | +$$n_{serato} = 2^{20} -1 = 1\,048\,575$$ |
| 165 | + |
| 166 | +and for the Traktor MK2 timecode |
| 167 | + |
| 168 | +$$n_{mk2} = 2^{110} -1 = 1.298 \cdot 10^{33} = 1\,298\,074\,214\,633\,706\,907\,132\,624\,082\,305\,023$$ |
| 169 | + |
| 170 | +That’s an astronomically high number-far beyond what’s required for this |
| 171 | +application. |
| 172 | + |
| 173 | +But how many states are actually needed? With a 2500 Hz carrier, you get 2500 bits per second.<br> |
| 174 | + |
| 175 | +For 12 minutes of timecode: |
| 176 | + |
| 177 | +$$12 \text{ min} \cdot 60 = 720 \text{ s}$$ |
| 178 | +$$720 \text{ s} \cdot 2500 \text{ states/s} = 1\,800\,000 \text{ states}$$ |
| 179 | + |
| 180 | +which exceeds the maximum state range of Serato’s 20-bit LFSR by far. |
| 181 | + |
| 182 | +However, a downside appears: each 110-bit state must be stored in 128 bits (4 |
| 183 | +× 32-bit integers). |
| 184 | + |
| 185 | +So for the A-side with 12 minutes: |
| 186 | + |
| 187 | +$$1\,800\,000 \text{ states} \cdot 128 \text{ bit} = 230\,400\,000 \text{ bit} = 28\,800\,000 \text{ byte} = 27.46 \text{ MB}$$ |
| 188 | + |
| 189 | +And for a 25-minute CD: |
| 190 | + |
| 191 | +$$4\,500\,000 \text{ states} \cdot 128 \text{ bit} = 576\,000\,000 \text{ bit} = 72\,000\,000 \text{ byte} = 68.66 \text{ MB}$$ |
| 192 | + |
| 193 | +> **Disadvantage:** The memory footprint is large-even a single side of timecode can exceed 27 MB. |
| 194 | +
|
| 195 | +This makes storing a full lookup table impractical in production software. |
| 196 | + |
| 197 | +It's important to point out that the current implementation is naive, because it treats the |
| 198 | +Traktor MK2 code as if it were Serato code. Since Mark Hills designed the xwax |
| 199 | +library, which is used by vinyl control in Mixxx, for exactly this style of |
| 200 | +timecode, changes would have to be made to make the decoder more modular. |
| 201 | + |
| 202 | +Nonetheless, the current technique works and it represents the current state |
| 203 | +of the decoder in Mixxx. |
| 204 | + |
| 205 | +--- |
| 206 | + |
| 207 | +## Conclusion |
| 208 | + |
| 209 | +Fortunately, there are mathematical methods to reduce the memory requirements. |
| 210 | +This requires diving deeper into the crypthographic theory. |
| 211 | + |
| 212 | +First tests show that this can possibly be achieved by applying a fixed tap |
| 213 | +pattern (e.g. every 5th bit) to a 110-bit LFSR window - a form of structured |
| 214 | +decimation or undersampling. This collapses the sequence into a 22-bit |
| 215 | +[Gold code](https://en.wikipedia.org/wiki/Gold_code), whose two sequences alternate. |
| 216 | +The implementation of this technique is far more complex and not completed |
| 217 | +yet. |
| 218 | + |
| 219 | +We’ll explore those strategies in the next part of this series. |
0 commit comments