00001 <html> 00002 00003 <head> 00004 <title>Vorbisfile - Sample Crosslapping</title> 00005 <link rel=stylesheet href="style.css" type="text/css"> 00006 </head> 00007 00008 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff"> 00009 <table border=0 width=100%> 00010 <tr> 00011 <td><p class=tiny>Vorbisfile documentation</p></td> 00012 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td> 00013 </tr> 00014 </table> 00015 00016 <h1>What is Crosslapping?</h1> 00017 00018 <p>Crosslapping blends two samples together using a window function, 00019 such that any sudden discontinuities between the samples that may 00020 cause clicks or thumps are eliminated or blended away. The technique 00021 is nearly identical to how Vorbis internally splices together frames 00022 of audio data during normal decode. API functions are provided to <a 00023 href="ov_crosslap.html">crosslap transitions between seperate 00024 streams</a>, or to crosslap when <a href="seeking.html">seeking within 00025 a single stream</a>. 00026 00027 <h1>Why Crosslap?</h1> 00028 <h2>The source of boundary clicks</h2> 00029 00030 <p>Vorbis is a lossy compression format such that any compressed 00031 signal is at best a close approximation of the original. The 00032 approximation may be very good (ie, indistingushable to the human 00033 ear), but it is an approximation nonetheless. Even if a sample or set 00034 of samples is contructed carefully such that transitions from one to 00035 another match perfectly in the original, the compression process 00036 introduces minute amplitude and phase errors. It's an unavoidable 00037 result of such high compression rates. 00038 00039 <p>If an application transitions instantly from one sample to another, 00040 any tiny discrepancy introduced in the lossy compression process 00041 becomes audible as a stairstep discontinuity. Even if the discrepancy 00042 in a normal lapped frame is only .1dB (usually far below the 00043 threshhold of perception), that's a sudden cliff of 380 steps in a 16 00044 bit sample (when there's a boundary with no lapping). 00045 00046 <h2>I thought Vorbis was gapless</h2> 00047 00048 <p>It is. Vorbis introduces no extra samples at the beginning or end 00049 of a stream, nor does it remove any samples. Gapless encoding 00050 eliminates 99% of the click, pop or outright blown speaker that would 00051 occur if boundaries had gaps or made no effort to align 00052 transitions. However, gapless encoding is not enough to entirely 00053 eliminate stairstep discontinuities all the time for exactly the 00054 reasons described above. 00055 00056 <p>Frame lapping, like Vorbis performs internally during continuous 00057 playback, is necessary to eliminate that last epislon of trouble. 00058 00059 <h1>Easiest Crosslap</h1> 00060 00061 The easiest way to perform crosslapping in Vorbis is to use the 00062 lapping functions with no other extra effort. These functions behave 00063 identically to when lapping isn't used except to provide 00064 at-least-very-good lapping results. Crosslapping will not introduce 00065 any samples into or remove any samples from the decoded audio; the 00066 only difference is that the transition is lapped. Lapping occurs from 00067 the current PCM position (either in the old stream, or at the position 00068 prior to calling a lapping seek) forward into the next 00069 half-short-block of audio data to be read from the new stream or 00070 position. 00071 00072 <p>Ideally, vorbisfile internally reads an extra frame of audio from 00073 the old stream/position to perform lapping into the new 00074 stream/position. However, automagic crosslapping works properly even 00075 if the old stream/position is at EOF. In this case, the synthetic 00076 post-extrapolation generated by the encoder to pad out the last block 00077 with appropriate data (and avoid encoding a stairstep, which is 00078 inefficient) is used for crosslapping purposes. Although this is 00079 synthetic data, the result is still usually completely unnoticable 00080 even in careful listening (and always preferable to a click or pop). 00081 00082 <p>Vorbisfile will lap between streams of differing numbers of 00083 channels. Any extra channels from the old stream are ignored; playback 00084 of these channels simply ends. Extra channels in the new stream are 00085 lapped from silence. Vorbisfile will also lap between streams links 00086 of differing sample rates. In this case, the sample rates are ignored 00087 (no implicit resampling is done to match playback). It is up to the 00088 application developer to decide if this behavior makes any sense in a 00089 given context; in practical use, these default behaviors perform 00090 sensibly. 00091 00092 <h1>Best Crosslap</h1> 00093 00094 <p>To acheive the best possible crosslapping results, avoid the case 00095 where synthetic extrapolation data is used for crosslapping. That is, 00096 design loops and samples such that a little bit of data is left over 00097 in sample A when seeking to sample B. Normally, the end of sample A 00098 and the beginning of B would overlap exactly; this allows 00099 crosslapping to perform exactly as it would within vorbis when 00100 stitching audio frames together into continuous decoded audio. 00101 00102 <p>The optimal amount of overlap is half a short-block, and this 00103 varies by compression mode. Each encoder will vary in exact block 00104 size selection; for vorbis 1.0, for -q0 through -q10 and 44kHz or 00105 greater, a half-short block is 64 samples. 00106 00107 <br><br> 00108 <hr noshade> 00109 <table border=0 width=100%> 00110 <tr valign=top> 00111 <td><p class=tiny>copyright © 2003 Xiph.org</p></td> 00112 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td> 00113 </tr><tr> 00114 <td><p class=tiny>Vorbisfile documentation</p></td> 00115 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td> 00116 </tr> 00117 </table> 00118 00119 </body> 00120 00121 </html>