Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2006
    Posts
    1,443

    seconds to minutes ..?

    hi
    i have a problem

    for example:
    seconds = 186;
    186 secons = 3 minutes and 6 seconds
    how can i convert 186 to 03:06 with a simplest way

    because i am using a timer
    this routine will be called every 50 milliseconds
    and my solutions are using %10 - %15 of my 2.5 CPU

    i need a simplest solution that reduce CPU usage

    this is a media player project
    it calculates length and current position when playing an MP3 file
    thanks

  2. #2
    Join Date
    May 2006
    Posts
    5,380
    Here, try this function

    place this in globals
    Code:
    ------------------------------------------------------------
    -- this function will Convert seconds into minutes/seconds
    function sec2Min(secs)
    	if secs > 59 then
    		myMinutes = Math.Floor(secs/60);
    		mySeconds = secs-(Math.Floor(secs/60)*60);
    			if mySeconds < 10 then
    				mySeconds = "0"..mySeconds;
    			end
    		myTime = myMinutes..":"..mySeconds;
    	else
    			if secs < 10 then
    				mySeconds = "0"..secs;
    			end
    		myTime = "0:"..mySeconds;
    	end   
    	return myTime;
    end
    ------------------------------------------------------------
    -- Example Use
    Code:
    Dialog.Message("Time:", "186 Seconds = "..sec2Min(186));
    Last edited by RizlaUK; 01-21-2008 at 05:14 AM.
    Open your eyes to Narcissism, Don't let her destroy your life!!

  3. #3
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    You could try the DateDiff plugin. It formats seconds into HH:MM:SS

    http://www.indigorose.com/forums/sho...8&postcount=17

  4. #4
    Join Date
    May 2006
    Posts
    1,443
    thank a lot

    i.m using BASS sound system
    i made an action plugin for my self. this plugin calls functions from bass.dll

    actually my problem is not conversion
    also i can create DLLs Action plugins for myself
    but i want to do it interlally
    i.m using
    Page.StartTimer(50);
    and my internal procedures using %10 - %15 of CPU
    when i am using external routine (dll ,lmd) also
    On Timer:
    sec2Min(186);

    finally, i am looking for simplest calculation of this

    RizlaUK thanks i will try it
    your method is different from my methods

  5. #5
    Join Date
    Mar 2006
    Posts
    61
    Just want to make a code change here for performance. I know it isn't much probably about 4 cycles or so if I remember right from my old Assembler days...

    All I did was used the already calculated value of secs/60 in myMinutes in place of doing all the math again. no point in using up more cycles to do that math when it is already completed and stored. So just use the variable.

    I should also note that you should use local variables when ever possible. Lua by default makes all variables global, and global variables have a slower access time then local variables. It also helps in garbage collection as well. If the variables are not used by any other function, or anywhere else when created then make them local to the current working scope for speed and memory usage reasons.

    Code:
    ------------------------------------------------------------
    -- this function will Convert seconds into minutes/seconds
    function sec2Min(secs)
    
    	local myMinutes = 0;
    	local mySeconds = 0;
    	local myTime =0;
    
    	if secs > 59 then
    		myMinutes = Math.Floor(secs/60);
    		mySeconds = secs-(myMinutes*60); -- Changes here.
    			if mySeconds < 10 then
    				mySeconds = "0"..mySeconds;
    			end
    		myTime = myMinutes..":"..mySeconds;
    	else
    			if secs < 10 then
    				mySeconds = "0"..secs;
    			end
    		myTime = "0:"..mySeconds;
    	end   
    	return myTime;
    end
    ------------------------------------------------------------
    Last edited by Bags; 01-21-2008 at 08:51 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    This could be done in a single line of code..
    -Divide the seconds by 60 and convert to an integer (this is the mins).
    -Multiply the integer by 60 and Subtract from the orig numb (this is the secs).

    or:
    RealTime = ConvertToInt(OrigNumb/60)..":"..OrigNumb-ConvertToInt(OrigNumb/60);

    But there is no Integer command in AMS so you would need to add your own conversion function to your globals;

    Code:
    function ConvertToInt(Anumb)
    if String.Find(Anumb.."", ".", 1, false) > 1 then
       Anumb = String.ToNumber(String.Left(Anumb.."" , String.Find(Anumb.."", ".", 1, false)-1));
       end
    return Anumb
    end

  7. #7
    Join Date
    May 2006
    Posts
    1,443
    thanks to all.
    i will increase timer interval
    like : Page.StartTimer(90);

Similar Threads

  1. Script : Convert the AudioLength into minutes:seconds
    By CrazyFrog in forum AutoPlay Media Studio 7.5 Examples
    Replies: 8
    Last Post: 04-28-2007, 03:19 PM
  2. Counters, Timers, Clocks
    By Tux in forum AutoPlay Media Studio 5.0
    Replies: 4
    Last Post: 09-24-2005, 01:56 PM
  3. takes a long time for waiting 30 seconds
    By ovm in forum AutoPlay Media Studio 5.0
    Replies: 0
    Last Post: 07-10-2005, 05:14 PM
  4. Show time left of song etc
    By bobbie in forum AutoPlay Media Studio 5.0
    Replies: 18
    Last Post: 03-24-2005, 07:16 AM
  5. Check system date/ time every 30 Minutes
    By patrick6 in forum AutoPlay Media Studio 5.0
    Replies: 11
    Last Post: 06-16-2004, 05:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts