home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / henkyaku1.0.exe / henkyaku / Program / Kernel / Util / MediaPlayer.tonyu < prev    next >
Text File  |  2007-09-03  |  2KB  |  127 lines

  1. extends Object;
  2.  
  3. //native _n_freeAllSE;
  4.  
  5. constructor MediaPlayer() {
  6.    _stopOnPageLoad  = 1; 
  7.    prevFc=null;
  8.    soundInterval=trunc(44100*16/1000);
  9.    soundDelay   =1000;
  10.    timeLag=2000;
  11.    soundNextTime=null;
  12.    frameOffset=0;
  13.    playPosOffset=0;
  14.    bsize=6000;
  15. }
  16. function setFrameRate(r) {
  17.   soundInterval=trunc(44100*trunc(r)/1000);
  18. }
  19. function soundsPath() {
  20.    return "project.sounds";
  21. }
  22.  
  23. function init() {
  24.    initResource(soundsPath());
  25. }
  26.  
  27. function freeAllSE() {
  28.    var a,r;
  29.    r=getResource(soundsPath());
  30.    if (!r) return;
  31.    r=r.getSubRes();
  32.    for (a in r) {
  33.       a.release();
  34.    }
  35. //  _n_freeAllSE();    
  36. }
  37.  
  38. function play( s,ar,v) {
  39.   if ( s) {
  40.     if (s is BGM) stop();
  41.     if (!v || (v>=0 && v<=128)) {
  42.       s.play(ar,v);
  43.     } else {
  44.       s.play(ar,128);
  45.     }
  46.   }/* else {
  47.     (new BGM()).play();
  48.   }*/
  49. }
  50.  
  51. native _n_stop;
  52. function stop() {
  53.   _n_stop();
  54. }
  55.  
  56. native _n_setEnable;
  57. function setEnable(t) {
  58.   _n_setEnable(t);
  59. }
  60.  
  61. function setStopOnPageLoad(t) { _stopOnPageLoad=t;}
  62. function stopOnPageLoad() { return _stopOnPageLoad;}
  63.  
  64. native _n_setVolume;
  65. function setVolume(s) {
  66.   _n_setVolume(s);
  67. }
  68. native _n_sound;
  69. function sound(ch,typ,val,time) {
  70.   _n_sound(ch,typ,val,time);
  71. }
  72. function setSoundDelay(d) {
  73.   soundDelay=d;
  74. }
  75. function soundTone(ch,val) {
  76.   sound(ch,1,trunc(val*97391),calcTime());
  77. }
  78. function soundVolume(ch,val) {
  79.   sound(ch,2,val,calcTime());
  80. }
  81.  
  82. function calcTime() {
  83.   var r,p;
  84.   r=playPosOffset+($frameCount-frameOffset)*soundInterval;
  85.   p=getPlayPos()+bsize;
  86.   if (abs(r-p)>3000) {
  87.     frameOffset   = $frameCount;
  88.     playPosOffset = p;
  89.     if (r>p) soundInterval--;
  90.     else soundInterval++;
  91.     //print (r+" "+p+" "+soundInterval+" "+$frameCount);
  92.     return p;
  93.   }
  94.   return r;
  95. }
  96. native _n_setDelay;
  97. function setDelay(d) {
  98.    _n_setDelay(d);
  99. }
  100. native _n_setBSize;
  101. function setBSize(sz) {
  102.   _n_setBSize(sz);
  103.   bsize=sz;
  104. }
  105. native _n_getPlayPos;
  106. function getPlayPos(type) {
  107.   return _n_getPlayPos(type);
  108. }
  109. function getLastWriteStartPos () {
  110.   return getPlayPos(1);
  111. }
  112. function getLastWriteEndPos () {
  113.   return getPlayPos(2);
  114. }
  115. function getBufferUnderrun () {
  116.   return getPlayPos(3);
  117. }
  118. native _n_start;
  119. function start(ch,typ,val,time) {
  120.   _n_start();
  121. }
  122.  
  123. native _n_calibration;
  124. function calibration(len,lag) {
  125.   timeLag=lag;
  126.   _n_calibration(len,lag);
  127. }