forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Music plays choppy

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
hpnuts



Joined: 20 Jun 2006
Posts: 1

PostPosted: Tue Jun 20, 2006 12:37 am    Post subject: Music plays choppy Reply with quote

Hi,

I'm writing a game in Lua and trying to add music playback.
I've tried to play a .xm or .s3m music file but they are playing pausing playing pausing....
Actually the .xm is giving better result but still not smooth.

Is there something to add in my code to have a smooth music ?

I was thinking that may be a wait time was needed to allow lua to fill is buffer... So I've tried to add some screen:waitVblankStart() all over my code without any good result...

Any help ?

Thanks in advance, Pascal
_________________
PSP 2.01
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Jun 20, 2006 5:06 am    Post subject: Reply with quote

The biggest problem with LUAPlayer is that it uses a single thread for almost everything. When you blit/print too many images during each frame the entire system gets choppy and slows down. In order to decrease the time between. Just remember kids Simpler is better! I do believe you should totally rewrite your code.
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Tue Jun 20, 2006 7:57 am    Post subject: Reply with quote

Yeah same problem here. But how do I cut down on the choppyness if I need alot of units on the screen. I tried to optimize my code and cut out 16 for loops (but without any extra blitting), but still not enough.

I also tried to blit one half of the amount of units one loop and then the second time it blits the other half, but that doesn't really help so it seems. Hmm maybe I should give that another try, because Im running out of ideas here.

Do you have any tips maybe?
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Jun 20, 2006 5:15 pm    Post subject: Reply with quote

Eliminate blitting, and use less code. Less is more!The more functions you use the slower it becomes. The less functions you use.. can also slow it down. Find the right combination. Also use the blit buffer! Only reblit changes in the picture. Never do more than that. Complex code makes it harder for it to work. Steer clear of "if 1 > variable then else end" code it slows stuff down.

Dont reblit every frame.
Limit code so its reactive. And based on timers. It helps

Use Coroutines.
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Wed Jun 21, 2006 5:01 am    Post subject: Reply with quote

Quote:
Eliminate blitting, and use less code. Less is more!The more functions you use the slower it becomes. The less functions you use.. can also slow it down. Find the right combination. Also use the blit buffer! Only reblit changes in the picture. Never do more than that. Complex code makes it harder for it to work. Steer clear of "if 1 > variable then else end" code it slows stuff down.

Dont reblit every frame.
Limit code so its reactive. And based on timers. It helps

Use Coroutines.


The thing is I eliminated as much as possible. I only blit stuff when its actually visible and moves/changes and I use in fact only a few functions, but only for stuff thats done ones, so not for loops that call upon it every loop.

What exactly is the "blit buffer"? Do you mean the second screen? As in you have to flip the two screens, and I shouldn't do that every loop?

And you're also saying I shouldn't use to many if statements in general, or ones with numbers in them, or other specific ones? Are some things faster than other ones? I mean is for faster/slower or equally fast as while for instance? And are boolean if statemnets faster then numbers?

Also what exactly do you mean by limiting the code so its reactive? It should react to changes? But isn't that (almost) always?

Do you maybe have a good tut on coroutines? Otherwise I'll just read the manual.

Thx for the advice!
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Wed Jun 21, 2006 6:36 am    Post subject: Reply with quote

I dont really have a tutorial. But I do have an example useing a Corutine SDK I made.

Code:

Process_LIB = {
   ["ThreadList"] = { },
   Exit = nil
}

function Process_LIB:init ()
   while true do
      if (self.Exit) then
         break
      end
      for key,value in pairs(Process_LIB["ThreadList"]) do

         -- GetStatus()
         -- 1 - Go
         -- 2 - Pause
         -- 3 - SelfTerm
         -- 4 - Term (Cleanup)
         if (value:GetStatus() == 1) then
            -- Do Threadlist
            --local Status
            if (coroutine.status(value.ThreadID) == "dead") then
               -- Thread Ended cleanup
               --value = nil
            else
               errorfree, errorvalue = coroutine.resume(value.ThreadID, value)
               if (self.Exit) then
                  break
               end
            end
         end
         if (value:GetStatus() == 2) then
            -- Pause
            -- Do nothing
         end
         if (value:GetStatus() == 3) then   
            -- Self Term
         end

         if (value:GetStatus() == 4) then
            -- Terminate Code
         end
         if (value:GetStatus() == 5) then
            -- Unknown Command
         end
      end
   end
end


function Process_LIB:exit()
   self.Exit = true
end

function Process_LIB:cleanup()
   ProcessThread_LIB = nil
   Process_LIB = nil
end










-- Table here
ProcessThread_LIB = { }

function ProcessThread_LIB:new(name)
   if (not name) then
      return nil
   end
   NewThread = { }
   local exists = nil
   for key,value in pairs(Process_LIB["ThreadList"]) do
      if (value:GetName() == name) then
         exists = 1
      end
   end
   if (not exists) then
      setmetatable(NewThread, self)
      table.insert(Process_LIB["ThreadList"], NewThread)
      self.__index = self
      self.status = 1
      self["Name"] = name
      return NewThread
   end
   return nil
end

function ProcessThread_LIB:Startup()
   self.ThreadID = coroutine.create(function(self) self:Thread(self) end)
end

function ProcessThread_LIB:Thread()
   self.wait()
end








function ProcessThread_LIB:GetStatus()
   return self["status"]
end


function ProcessThread_LIB:wait()
   return coroutine.yield()
end

function ProcessThread_LIB:GetName()
   return self["Name"]
end


An example of the code

Code:

if (Process_LIB) then
   _Wifi = ProcessThread_LIB:new("_Wifi")
   if (_Wifi) then
      function _Wifi:Thread(self)
         while true do

            self = self.wait() -- Waits every loop (without this itll lock up)
            

         end
         

      end
      _Wifi:Startup()

   end
end
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Wed Jun 21, 2006 9:19 am    Post subject: Reply with quote

Alright I'll try and see if I can understand it. Thx for the example!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group