[16] | 1 | <html> |
---|
| 2 | |
---|
| 3 | <head> |
---|
| 4 | <title>Vorbisfile - Sample Crosslapping</title> |
---|
| 5 | <link rel=stylesheet href="style.css" type="text/css"> |
---|
| 6 | </head> |
---|
| 7 | |
---|
| 8 | <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff"> |
---|
| 9 | <table border=0 width=100%> |
---|
| 10 | <tr> |
---|
| 11 | <td><p class=tiny>Vorbisfile documentation</p></td> |
---|
| 12 | <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> |
---|
| 13 | </tr> |
---|
| 14 | </table> |
---|
| 15 | |
---|
| 16 | <h1>What is Crosslapping?</h1> |
---|
| 17 | |
---|
| 18 | <p>Crosslapping blends two samples together using a window function, |
---|
| 19 | such that any sudden discontinuities between the samples that may |
---|
| 20 | cause clicks or thumps are eliminated or blended away. The technique |
---|
| 21 | is nearly identical to how Vorbis internally splices together frames |
---|
| 22 | of audio data during normal decode. API functions are provided to <a |
---|
| 23 | href="ov_crosslap.html">crosslap transitions between seperate |
---|
| 24 | streams</a>, or to crosslap when <a href="seeking.html">seeking within |
---|
| 25 | a single stream</a>. |
---|
| 26 | |
---|
| 27 | <h1>Why Crosslap?</h1> |
---|
| 28 | <h2>The source of boundary clicks</h2> |
---|
| 29 | |
---|
| 30 | <p>Vorbis is a lossy compression format such that any compressed |
---|
| 31 | signal is at best a close approximation of the original. The |
---|
| 32 | approximation may be very good (ie, indistingushable to the human |
---|
| 33 | ear), but it is an approximation nonetheless. Even if a sample or set |
---|
| 34 | of samples is contructed carefully such that transitions from one to |
---|
| 35 | another match perfectly in the original, the compression process |
---|
| 36 | introduces minute amplitude and phase errors. It's an unavoidable |
---|
| 37 | result of such high compression rates. |
---|
| 38 | |
---|
| 39 | <p>If an application transitions instantly from one sample to another, |
---|
| 40 | any tiny discrepancy introduced in the lossy compression process |
---|
| 41 | becomes audible as a stairstep discontinuity. Even if the discrepancy |
---|
| 42 | in a normal lapped frame is only .1dB (usually far below the |
---|
| 43 | threshhold of perception), that's a sudden cliff of 380 steps in a 16 |
---|
| 44 | bit sample (when there's a boundary with no lapping). |
---|
| 45 | |
---|
| 46 | <h2>I thought Vorbis was gapless</h2> |
---|
| 47 | |
---|
| 48 | <p>It is. Vorbis introduces no extra samples at the beginning or end |
---|
| 49 | of a stream, nor does it remove any samples. Gapless encoding |
---|
| 50 | eliminates 99% of the click, pop or outright blown speaker that would |
---|
| 51 | occur if boundaries had gaps or made no effort to align |
---|
| 52 | transitions. However, gapless encoding is not enough to entirely |
---|
| 53 | eliminate stairstep discontinuities all the time for exactly the |
---|
| 54 | reasons described above. |
---|
| 55 | |
---|
| 56 | <p>Frame lapping, like Vorbis performs internally during continuous |
---|
| 57 | playback, is necessary to eliminate that last epsilon of trouble. |
---|
| 58 | |
---|
| 59 | <h1>Easiest Crosslap</h1> |
---|
| 60 | |
---|
| 61 | The easiest way to perform crosslapping in Vorbis is to use the |
---|
| 62 | lapping functions with no other extra effort. These functions behave |
---|
| 63 | identically to when lapping isn't used except to provide |
---|
| 64 | at-least-very-good lapping results. Crosslapping will not introduce |
---|
| 65 | any samples into or remove any samples from the decoded audio; the |
---|
| 66 | only difference is that the transition is lapped. Lapping occurs from |
---|
| 67 | the current PCM position (either in the old stream, or at the position |
---|
| 68 | prior to calling a lapping seek) forward into the next |
---|
| 69 | half-short-block of audio data to be read from the new stream or |
---|
| 70 | position. |
---|
| 71 | |
---|
| 72 | <p>Ideally, vorbisfile internally reads an extra frame of audio from |
---|
| 73 | the old stream/position to perform lapping into the new |
---|
| 74 | stream/position. However, automagic crosslapping works properly even |
---|
| 75 | if the old stream/position is at EOF. In this case, the synthetic |
---|
| 76 | post-extrapolation generated by the encoder to pad out the last block |
---|
| 77 | with appropriate data (and avoid encoding a stairstep, which is |
---|
| 78 | inefficient) is used for crosslapping purposes. Although this is |
---|
| 79 | synthetic data, the result is still usually completely unnoticable |
---|
| 80 | even in careful listening (and always preferable to a click or pop). |
---|
| 81 | |
---|
| 82 | <p>Vorbisfile will lap between streams of differing numbers of |
---|
| 83 | channels. Any extra channels from the old stream are ignored; playback |
---|
| 84 | of these channels simply ends. Extra channels in the new stream are |
---|
| 85 | lapped from silence. Vorbisfile will also lap between streams links |
---|
| 86 | of differing sample rates. In this case, the sample rates are ignored |
---|
| 87 | (no implicit resampling is done to match playback). It is up to the |
---|
| 88 | application developer to decide if this behavior makes any sense in a |
---|
| 89 | given context; in practical use, these default behaviors perform |
---|
| 90 | sensibly. |
---|
| 91 | |
---|
| 92 | <h1>Best Crosslap</h1> |
---|
| 93 | |
---|
| 94 | <p>To acheive the best possible crosslapping results, avoid the case |
---|
| 95 | where synthetic extrapolation data is used for crosslapping. That is, |
---|
| 96 | design loops and samples such that a little bit of data is left over |
---|
| 97 | in sample A when seeking to sample B. Normally, the end of sample A |
---|
| 98 | and the beginning of B would overlap exactly; this allows |
---|
| 99 | crosslapping to perform exactly as it would within vorbis when |
---|
| 100 | stitching audio frames together into continuous decoded audio. |
---|
| 101 | |
---|
| 102 | <p>The optimal amount of overlap is half a short-block, and this |
---|
| 103 | varies by compression mode. Each encoder will vary in exact block |
---|
| 104 | size selection; for vorbis 1.0, for -q0 through -q10 and 44kHz or |
---|
| 105 | greater, a half-short block is 64 samples. |
---|
| 106 | |
---|
| 107 | <br><br> |
---|
| 108 | <hr noshade> |
---|
| 109 | <table border=0 width=100%> |
---|
| 110 | <tr valign=top> |
---|
| 111 | <td><p class=tiny>copyright © 2007 Xiph.org</p></td> |
---|
| 112 | <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td> |
---|
| 113 | </tr><tr> |
---|
| 114 | <td><p class=tiny>Vorbisfile documentation</p></td> |
---|
| 115 | <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> |
---|
| 116 | </tr> |
---|
| 117 | </table> |
---|
| 118 | |
---|
| 119 | </body> |
---|
| 120 | |
---|
| 121 | </html> |
---|