Advertisement
amigojapan

tascam dr-05 mark time calculator (possibly incorrect)

Apr 13th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <body>
  3.         <script>
  4.             function WindowLoad(event) {
  5.                 /*
  6.                 I have a simple math question (warning I am terrible at math) I have a recorder,
  7.                 I know it can make recordings of 1 hour 2 minutes and 6 seconds per file,
  8.                 when a file ends it automatically starts the next file, if I know the start
  9.                 time and the "mark time", what would be the formula to get which file and what
  10.                 time of that file the "mark time” is at in that file? this is not homework, it
  11.                 is a problem I am trying to solve for an actual recorder I have, but I can’t seem
  12.                 to get the right value… please give me a layman’s answer, not a mathematicians answer
  13.  
  14. something seems to be wrong cause when I enter 00:00:00 as the start time and 16:00:00 as the mark time I
  15. get "in file:16 time in file:00:28:30” but just looking at the minutes, 28 minutes seems off cause 2 minutes
  16. times 16 is 32 minutes, and it should even be 33 minutes I think because the seconds being 6 seconds times 16 would
  17. be 90 seconds, which is over a minute, what am I doing wrong?
  18.  
  19. monoprotic:amigojapan: 15 files takes 15*(01:02:06) = 15:31:30
  20.  
  21. monoprotic:amigojapan: so 15 are complete; the end point is in the 16th file, 16:00:00 - 15:31:30 = 00:28:30 into it
  22.  
  23. amigojapan: is the program output correct then?
  24.  
  25. monoprotic:amigojapan: it seems to be, i think you're just confused about what the output is  
  26.  
  27.                 */
  28.  
  29.                 function time_to_seconds(hms) {
  30.                     //var hms = '02:04:33';   // your input string
  31.                     var a = hms.split(':'); // split it at the colons
  32.  
  33.                     // minutes are worth 60 seconds. Hours are worth 60 minutes.
  34.                     var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
  35.  
  36.                     //console.log(seconds);
  37.                     return seconds;
  38.                 }
  39.                 function seconds_to_time(sec_num ) {
  40.                     var hours   = Math.floor(sec_num / 3600);
  41.                     var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
  42.                     var seconds = sec_num - (hours * 3600) - (minutes * 60);
  43.  
  44.                     if (hours   < 10) {hours   = "0"+hours;}
  45.                     if (minutes < 10) {minutes = "0"+minutes;}
  46.                     if (seconds < 10) {seconds = "0"+seconds;}
  47.                     return hours+':'+minutes+':'+seconds;
  48.                 }
  49.  
  50.                 //calculate the time in seconds of each file start
  51.                 var files_in_seconds=[];
  52.                 var GB_SD=32;//32gigabytes 2 gygabytes per file
  53.                 for(var file_index=0;file_index<(GB_SD/2)+1;file_index++) {
  54.                     files_in_seconds.push((file_index) * time_to_seconds("01:02:06"));//'01:02:06' time of one file
  55.                 }
  56.                 var start_time=time_to_seconds(prompt("start time HH:MM:SS","15:30:00"));
  57.                 var mark_time=time_to_seconds(prompt("mark time HH:MM:SS","15:30:00"));
  58.                 var time_from_start=mark_time-start_time;
  59.                 //find which file it is in
  60.                 for(var file_index in files_in_seconds) {
  61.                         if(time_from_start >= files_in_seconds[parseInt(file_index)] && time_from_start < files_in_seconds[parseInt(file_index)+1]) {
  62.                             time_in_file=time_from_start-files_in_seconds[parseInt(file_index)];
  63.                             alert(
  64.                                 "start time:"+seconds_to_time(start_time)
  65.                                 +
  66.                                 "\nmark time:"+seconds_to_time(mark_time)
  67.                                 +
  68.                                 "\ntime from start:"+seconds_to_time(time_from_start)
  69.                                 +
  70.                                 "\nin file:"+(parseInt(file_index)+1)
  71.                                 +
  72.                                 "\ntime in file:"+seconds_to_time(time_in_file)
  73.                                 );
  74.                         }
  75.                 }
  76.             }
  77.  
  78.             window.addEventListener('load', WindowLoad, false);
  79.         </script>
  80.         no output needed. hit relaod to calculate again (javascript must be enabled for this program to work)
  81.     </body>
  82.  </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement