home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February / PCWorld_2008-02_cd.bin / audio-video / reaper / reaper2028-install.exe / Effects / Utility / smpte_ltc_reader < prev    next >
Text File  |  2007-12-18  |  4KB  |  187 lines

  1. desc:SMPTE LTC display
  2.  
  3. slider1:0<0,3,1.0{30,24,25,29.97}>frame rate
  4.  
  5. @init
  6. minthresh=10^(-80/20);
  7. threshenv=exp(-1/(0.1*srate)); // 100ms
  8. gfx_clear=-1;
  9. syncstate=0;
  10. itm1=otm1=0;
  11. thresh = 1; // ~-10dB
  12. lastsign=1;
  13. sillen=0;
  14. buf=0;
  15. bufpos=0;
  16. gotbit=-1;
  17. syncpos=-1;
  18. blitparmbuf=1000;
  19. frates=2000;
  20. frates[0]=30;
  21. frates[1]=24;
  22. frates[2]=25;
  23. frates[3]=30*1000/1001;
  24.  
  25. @slider
  26. pulsesize = (srate / frates[slider1] / (80.0 * 2.0));
  27.  
  28. @sample
  29.  
  30. // remove DC offset
  31. otm1=0.999*otm1 + spl0 - itm1; itm1=spl0; s=otm1;
  32. // s has DC offset removed sample 
  33.  
  34. sillen+=1;
  35.  
  36. sillen > pulsesize * 2.2 ? 
  37. (
  38.   syncpos=-1;
  39.    sillen=0;
  40.    gotbit=-1;
  41.    syncstate=1;
  42.  );
  43.  
  44. thresh = thresh*threshenv + abs(s)*(1-threshenv);
  45. thresh < minthresh=thresh=minthresh;
  46.  
  47. (s < -thresh*0.8 && lastsign > 0) || (s > thresh*0.8 && lastsign < 0) ? (
  48.   lastsign=-lastsign;
  49.   gotbit+=1;
  50.   sillen > pulsesize*1.8 ? // done with bit 
  51.   (  
  52.     gotbit=min(gotbit,1);
  53.     sillen=0;
  54.  
  55.     buf[bufpos]=gotbit;
  56.     (bufpos += 1) >= 80 ? bufpos=0;
  57.  
  58.     syncpos >= 0 ? syncpos += 1;
  59.     (syncpos < 0 || syncpos >= 80) ? 
  60.     (
  61.       syncpos=-1;
  62.        // try to get sync
  63.       (
  64.        buf[(bufpos+64)%80]==0 &&
  65.        buf[(bufpos+65)%80]==0 &&
  66.        buf[(bufpos+66)%80]==1 &&
  67.        buf[(bufpos+67)%80]==1 &&
  68.        buf[(bufpos+68)%80]==1 &&
  69.        buf[(bufpos+69)%80]==1 &&
  70.        buf[(bufpos+70)%80]==1 &&
  71.        buf[(bufpos+71)%80]==1 &&
  72.        buf[(bufpos+72)%80]==1 &&
  73.        buf[(bufpos+73)%80]==1 &&
  74.        buf[(bufpos+74)%80]==1 &&
  75.        buf[(bufpos+75)%80]==1 &&
  76.        buf[(bufpos+76)%80]==1 &&
  77.        buf[(bufpos+77)%80]==1 &&
  78.        buf[(bufpos+78)%80]==0 &&
  79.        buf[(bufpos+79)%80]==1) ?
  80.      (
  81.           
  82.        new_f=buf[(bufpos+0)%80]+
  83.               buf[(bufpos+1)%80]*2 + 
  84.               buf[(bufpos+2)%80]*4 +        
  85.               buf[(bufpos+3)%80]*8 +
  86.              10*(
  87.               buf[(bufpos+8)%80] + 
  88.               buf[(bufpos+9)%80]*2;// +
  89. //              buf[(bufpos+10)%80]*4      
  90.              );        
  91.  
  92.        new_s=buf[(bufpos+16)%80]+
  93.               buf[(bufpos+17)%80]*2 + 
  94.               buf[(bufpos+18)%80]*4 +        
  95.               buf[(bufpos+19)%80]*8 +
  96.              10*(
  97.               buf[(bufpos+24)%80] + 
  98.               buf[(bufpos+25)%80]*2+       
  99.               buf[(bufpos+26)%80]*4       
  100.             );
  101.  
  102.        new_m=buf[(bufpos+32)%80]+
  103.               buf[(bufpos+33)%80]*2 + 
  104.               buf[(bufpos+34)%80]*4 +        
  105.               buf[(bufpos+35)%80]*8 +
  106.              10*(
  107.               buf[(bufpos+40)%80] + 
  108.               buf[(bufpos+41)%80]*2+
  109.               buf[(bufpos+42)%80]*4       
  110.              );        
  111.  
  112.        new_h=buf[(bufpos+48)%80]+
  113.               buf[(bufpos+49)%80]*2 + 
  114.               buf[(bufpos+50)%80]*4 +        
  115.               buf[(bufpos+51)%80]*8 +
  116.              10*(
  117.               buf[(bufpos+56)%80] + 
  118.               buf[(bufpos+57)%80]*2       
  119.              );        
  120.  
  121.         hours=new_h; minutes=new_m; seconds=new_s; frames=new_f;
  122.     new_time = ((hours*80 + minutes)*80+seconds)*100+frames;
  123.  
  124.         syncpos=0;
  125.         syncstate=2;
  126.      ) : 
  127.      (
  128.         syncstate=0;
  129.       );
  130.     ); 
  131.  
  132.     gotbit=-1;
  133.   );   
  134. );
  135.  
  136.  
  137. @gfx
  138. gfxsize=gfx_w*10000  + gfx_h;
  139. new_time != old_time || gfxsize != old_size ? (
  140. old_time=new_time;
  141. old_size=gfxsize;
  142. gfx_r=gfx_g=gfx_b=0; gfx_a=1;
  143. gfx_x=gfx_y=0;
  144. gfx_rectto(gfx_w,gfx_h);
  145. gfx_r=gfx_g=gfx_b=1; 
  146. gfx_x=gfx_y=2;
  147. gfx_drawnumber((hours/10),0);
  148. gfx_drawchar($'0' + (hours%10));
  149. gfx_drawchar($':');
  150. gfx_drawchar($'0' + ((minutes/10)%10));
  151. gfx_drawchar($'0' + (minutes%10));
  152. gfx_drawchar($':');
  153. gfx_drawchar($'0' + ((seconds/10)%10));
  154. gfx_drawchar($'0' + (seconds%10));
  155. gfx_drawchar($':');
  156. gfx_drawchar($'0' + ((frames/10)%10));
  157. gfx_drawchar($'0' + (frames%10));
  158.  
  159. draw1wid=gfx_x;
  160.  
  161. blitparmbuf[0]=0;
  162. blitparmbuf[1]=0;
  163. blitparmbuf[2]=gfx_x;
  164. blitparmbuf[3]=(gfx_texth+4);
  165.  
  166. ow=gfx_w;
  167. oh=(gfx_texth+4) * gfx_w / gfx_x * 1.3;
  168.  
  169. oh > gfx_h ? oh=gfx_h;
  170.  
  171. blitparmbuf[4]=0;
  172. blitparmbuf[5]=(gfx_h-oh)/2;
  173. blitparmbuf[6]=ow;
  174. blitparmbuf[7]=oh;
  175.  
  176.  
  177. gfx_blitext(-1,blitparmbuf,0);
  178.  
  179. gfx_x=0;
  180. gfx_y=0;
  181. gfx_r=gfx_g=gfx_b=0;
  182. gfx_rectto(draw1wid,min(gfx_texth+2,blitparmbuf[5]));
  183.  
  184. );
  185.  
  186.  
  187.