Forum: PS2 Homebrew/Dev & Emu Scene - Topics relating to homebrew PS2 development and emulation. Stay current and up to date on the latest homebrew releases from the best devs on the scene.


The above video goes away if you are a member and logged in, so log in now!




 
Would you like to get all the new info from
PSX-Scene in your email each day?




Want to learn more about the team keeping you up to date with the latest scene news?

Read about them now!

Check out our Developer bios, too!

 


User Tag List

Thread: Call for help - Fixing SDL_Mixer
  

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1 Call for help - Fixing SDL_Mixer 
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    Hello.
    PS2SDK have a almost working mixer library for SDL. It runs, works and plays sound, but it does not play it well, just segmented and stopped.

    I am willing to fix it, but I do not have much knowledge about the PS2SDK itself (as I use it throught the SDL lib). So if anyone can help me, or just review the code and point me the right direction, I'll be most thankful.

    Looking at the sdlmixer code itself, I found no aparent error, everything seems to be ok. My currenct guess is that the problem lies in sdl_sound (in the SDL lib itself), probally due to wrong or absent thread code.

    As I've said before, any help is welcome, and I believe a working sdlmixer will help to port LOTS of games to PS2.
    Reply With Quote  

  2. #2  
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    SOme new information:

    I've changed the priority in the SDL sound from 64 to 42, and it now runs fine! Plays MODs, Waves, everthuyng working beautifully... only on ps2client...

    If I run the exact same binary with the exact same files on a mass: device from uLaunchELF.. sound is choppy again. Tryied several different values for priority, but still no luck.
    Maybe uLaunchELF itself is a problem?
    Reply With Quote  

  3. #3  
    dlanor is offline Member
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    10,107
    Downloads
    5
    Uploads
    0
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)
    Likes Given
    0
    Likes Received
    126
    Quote Originally Posted by protomank View Post
    SOme new information:

    I've changed the priority in the SDL sound from 64 to 42, and it now runs fine!
    Getting better operation by lowering this priority probably means that the higher priority of its routines blocked something else preventing it from delivering file data in a properly streamed manner, for example.

    Plays MODs, Waves, everthuyng working beautifully... only on ps2client...
    'Only' you say. But how many other launch methods did you try ?

    If I run the exact same binary with the exact same files on a mass: device from uLaunchELF.. sound is choppy again. Tryied several different values for priority, but still no luck.
    Maybe uLaunchELF itself is a problem?
    Not very likely, considering the wide variety of applications it can launch without problems.

    It is far more likely that it is your test application that has a serious problem with its initialization routine, being affected by remnant modules used by previous applications.

    It is an ancient PS2 homebrew custom for launching applications to leave all active device drivers active, so that the launched application shall be able to use some device drivers without having to load them explicitly, primarily for loading config files etc from its own launch directory. But after doing that the program should perform an IOP reset, so as to reinitialize the IOP module system. After which the program must itself reload all those modules that it needs for proper operation.

    This is how all major applications on the PS2 work, including uLaunchELF, SMS, OPL, and many others.

    But I suspect that your application does not do this correctly and therefore suffers from trying to use either the remnant drivers of the previous application, or by improperly initialized newly loaded drivers, whose init failed because of remnant modules.

    My advice to you is to check and double-check your program initialization routines.

    Best regards: dlanor
    Reply With Quote  

  4. #4  
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    Quote Originally Posted by dlanor View Post
    'Only' you say. But how many other launch methods did you try ?
    None, I was not able to run from a CD-RW (will try again later). But it should not matter, because the game I'm developing is meant to be run from mass: using uLaunchELF anyway. I'll try to run directly from the memory card just in case, using the matrix R1-hold method.

    Quote Originally Posted by dlanor View Post
    It is far more likely that it is your test application that has a serious problem with its initialization routine, being affected by remnant modules used by previous applications (...)
    But I suspect that your application does not do this correctly and therefore suffers from trying to use either the remnant drivers of the previous application, or by improperly initialized newly loaded drivers, whose init failed because of remnant modules.

    My advice to you is to check and double-check your program initialization routines.

    Best regards: dlanor
    Here is my initialization part of the code:
    Code:
    #ifdef PLAYSTATION
        //SifResetIop(); // commented out because if caused crashed
        PS2loadMinimal();
        PS2loadUSB();
        if (!strncmp(argv[0], "cdfs", 4) || !strncmp(argv[0], "cdrom", 5)) {
            PS2loadCD();
    }
    #endif
    PS2loadMinimal is as follows:

    Code:
    #ifndef __PS2SDK_1_1__
    #include <stdio.h>
    #endif
    #include <tamtypes.h>
    #include <sifrpc.h>
    #include <kernel.h>
    #include <loadfile.h>
    #include <fileio.h>
    #include <errno.h>
    #include <debug.h>
    #include <iopcontrol.h>
    #include "cdvd_rpc.h"
    
    
    //Declare usbd module //
    extern unsigned char usbd[];
    extern unsigned int size_usbd;
    //Declare usbhdfsd module //
    extern unsigned char usbhdfsd[];
    extern unsigned int size_usbhdfsd;
    // cdfs IRX
    extern unsigned char cdvd[];
    extern unsigned int size_cdvd;
    
    
    // adds support for basic I/O such as MC
    void PS2loadMinimal() {
    	int ret;
    	ret = SifLoadModule("rom0:XSIO2MAN", 0, NULL);
        ret = SifLoadModule("rom0:XMCMAN", 0, NULL);
    	#ifdef DEBUG_PS2
    		if (ret < 0) {
    			printf("Error '%d' loading module rom0:MCMAN\n", ret);
    		}
    	#endif
    	ret = SifLoadModule("rom0:XMCSERV", 0, NULL);
        ret = SifLoadModule("rom0:XPADMAN", 0, NULL);
        ret = SifLoadModule("rom0:XIOMAN", 0, NULL); 
    	
    	//mcInit(MC_TYPE_MC); 
    }
    
    
    // usb mass support
    void PS2loadUSB() {
    	int ret;
    	SifExecModuleBuffer(usbd, size_usbd, 0, NULL, &ret);
    	SifExecModuleBuffer(usbhdfsd, size_usbhdfsd, 0, NULL, &ret);
    }
    
    void PS2loadCD() {
    	int ret;
    	SifExecModuleBuffer(cdvd, size_cdvd, 0, NULL, &ret);
    	CDVD_Init();
    }
    I can't see my error, can you please just take a look on this?
    I've got all this code from exemples here and there, I've found on forums, but maybe it is old/outdated/wrong.
    Thanks in advance.
    Reply With Quote  

  5. #5  
    dlanor is offline Member
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    10,107
    Downloads
    5
    Uploads
    0
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)
    Likes Given
    0
    Likes Received
    126
    Quote Originally Posted by protomank View Post
    None, I was not able to run from a CD-RW (will try again later).
    Very few PS2 consoles have CDVD drives capable of using CD-RW discs.
    But that is not at all what I meant in asking how many launch methods you had tried.

    Since you suspected uLE of being responsible for faults in your program after launch by uLE, the obvious thing to do in testing that hypothesis is to launch your program by other homebrew means than uLE. There are other homebrew launchers, and if you have FMCB you could try installing your application to its menu, and launch it from there.

    But it should not matter, because the game I'm developing is meant to be run from mass: using uLaunchELF anyway. I'll try to run directly from the memory card just in case, using the matrix R1-hold method.
    Or you could just store it on MC and then reboot uLE and use its FileBrowser to launch it from MC. That would still be a uLE launch then, but different in that uLE would not have loaded the USB drivers for that launch, and so those modules would not be active already before the start of your application.

    Here is my initialization part of the code:
    Code:
    #ifdef PLAYSTATION
        //SifResetIop(); // commented out because if caused crashed
        PS2loadMinimal();
        PS2loadUSB();
        if (!strncmp(argv[0], "cdfs", 4) || !strncmp(argv[0], "cdrom", 5)) {
            PS2loadCD();
    }
    #endif
    And there we have it in clear. You are first skipping IOP reset, so that all modules uLE used remain in memory, and then you proceed to load modules which partly conflict with what uLE used. No wonder things work badly then...

    And launching that application from MC without using "mass:" from uLE could make a big difference.

    PS2loadMinimal is as follows:
    That is not the main culprit (though it is partly involved)

    The real culprit is down here:
    Code:
    // usb mass support
    void PS2loadUSB() {
    	int ret;
    	SifExecModuleBuffer(usbd, size_usbd, 0, NULL, &ret);
    	SifExecModuleBuffer(usbhdfsd, size_usbhdfsd, 0, NULL, &ret);
    }
    This is not OK at all, loading another instance of the already active USB drivers.
    (possibly a different version too)

    I've got all this code from exemples here and there, I've found on forums, but maybe it is old/outdated/wrong.
    A common effect when basing code on several different examples is that you put together a jigsaw puzzle where all the separate pieces are fine, but they just don't fit together, or at least not in the order you are trying to connect them.

    We had a very bad time long ago in trying to compose a good module initialization sequence for uLE, including a proper IOP reset at the right time (after reading initial CNF info). This works fine nowdays, but it took us years (literally) to get it to the current level.

    Your own code is currently working without any IOP reset at all, and that is the main problem with it. You will never be able to make it work independently of pre-launch conditions unless you implement a proper IOP reset.

    Best regards: dlanor
    Reply With Quote  

  6. #6  
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    Sorry, no deal. I've disabled the USB loading and run it directly from memory card, and got the same chopping sound issue.

    Running from mc0, the only part of the code that load modules is:

    Code:
    void PS2loadMinimal() {
    	int ret;
    	ret = SifLoadModule("rom0:XSIO2MAN", 0, NULL);
        ret = SifLoadModule("rom0:XMCMAN", 0, NULL);
    	ret = SifLoadModule("rom0:XMCSERV", 0, NULL);
        ret = SifLoadModule("rom0:XPADMAN", 0, NULL);
        ret = SifLoadModule("rom0:XIOMAN", 0, NULL); 
    }
    But, this same code when executed from ps2link have normal sound...

    Also, if I uncomment the SifResetIop, the game does not load.

    Anf finnaly, I believe usbd and usbhdfsd are not what you are thinking. usbd is the driver to access the PS2 USB hardware, and usbhdfsd is to load the mass: filesystem (FAT).

    Sadly, it seems like the solution is not so simple, I do not think, after all my testings, that the problem lies in module conflict, but somewhere else. WHY it runs fine from ps2link amuses me :-P

    Maybe I should try a lot of different values for the sound thread priority until I find one that works? I've tryied some, but did not worked.

    Thanks anyway, I am glad someone finally took a time to help me
    Reply With Quote  

  7. #7  
    ragnarok2040 is offline Member
    Join Date
    Dec 2002
    Posts
    548
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Likes Given
    0
    Likes Received
    3
    For the basic minimal modules, you can use the modules that were loaded by ps2link, if they're of a compatible type. You just reset the EE-side rpc clients for your program so they can resync up with their IOP modules.

    Here's some old code that should work.
    Code:
    int LoadBasicModules()
    {
        int ret = 0;
        int old = 0;
    
        smod_mod_info_t	mod_t;
    
        if(!smod_get_mod_by_name("sio2man", &mod_t))
        {
            ret = SifLoadModule("rom0:XSIO2MAN", 0, NULL);
    
            if (ret < 0)
            {
                printf("Failed to load module: SIO2MAN\n");
            }
        }
        if(mod_t.version == 257)
        {
            old = 1;
        }
    
        if(!smod_get_mod_by_name("mcman", &mod_t))
        {
            ret = SifLoadModule("rom0:XMCMAN", 0, NULL);
            
            if (ret < 0)
            {
                printf("Failed to load module: MCMAN\n");
            }
        }
        if(mod_t.version == 257)
        {
            old = 1;
        }
    
        if(!smod_get_mod_by_name("mcserv", &mod_t))
        {
            ret = SifLoadModule("rom0:XMCSERV", 0, NULL);
    
            if (ret < 0)
            {
                printf("Failed to load module: MCSERV\n");
            }
        }
        if(mod_t.version == 257)
            old = 1;
        else
            mcReset();
    
        if(!smod_get_mod_by_name("padman", &mod_t))
        {
            ret = SifLoadModule("rom0:XPADMAN", 0, NULL);
    
            if (ret < 0)
            {
                printf("Failed to load module: PADMAN\n");
            }
        }
        if(mod_t.version == 276)
            old = 1;
        else
            padReset();
    
        return old;
    }
    
       if(LoadBasicModules())
       {
            SifIopReset("rom0:UDNL rom0:EELOADCNF",0);
            while(!SifIopSync());
    
            fioExit();
            SifExitIopHeap();
            SifLoadFileExit();
            SifExitRpc();
            SifExitCmd();
    
            SifInitRpc(0);
            FlushCache(0);
            FlushCache(2);
    
            LoadBasicModules();
        }
    The above code should detect the new mcman/mcserv modules that uLE uses and reboot the IOP when booted by uLE as well, so you don't have to worry about old usb drivers either.

    Also, does rom0:XIOMAN exist? And, if so, is it usable with ps2sdk? I usually use iomanX.irx.

    dlanor, is there a reason why usbhdfsd doesn't use IRX_ID() so we can detect if it's loaded? It looks like IRX_ID("usbhdfsd",MAJOR_VER,MINOR_VER); in usbhdfsd.c is all that's needed. Maybe I missed it somewhere...
    Reply With Quote  

  8. #8  
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    Well, I've used the reset-iop part of your code, and it does not crash the game anymore.
    Did not used the modules loading part, because it does need some more work (I am missing some include file) and, anyway, it seems like it is not the cause of my problems, once I have the same issue when running directly from memory card using my matrix chip.

    If it servers as inspiration, I'm willing to pay 20 dollars if someone can help me fix this sound issue
    I can upload all my sources and SDK directory, if needed.
    Reply With Quote  

  9. #9  
    ragnarok2040 is offline Member
    Join Date
    Dec 2002
    Posts
    548
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Likes Given
    0
    Likes Received
    3
    Hrmm... 64 is the priority of the thread for the elf that ps2link launches. I can't quite remember what the default priority is but you can get it pretty easily by using:
    Code:
    ee_thread_status_t main_thread_status; 
    int main_id = GetThreadId();
    ReferThreadStatus(main_id,&main_thread_status);
    printf("priority = %d\n", main_thread_status.current_priority);
    or just change main's priority to 64 after you get the main thread id. I'm not sure if that would break anything, however. Make sure to not run it using ps2link.
    Reply With Quote  

  10. #10  
    protomank is offline Member
    Join Date
    Mar 2008
    Location
    Porto Alegre, RS, Brazil
    Posts
    210
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    1
    Likes Received
    5
    Yep, that is it! I should have tought on that before.
    Ragnarok, send me your playpal account again if you wish 20 bucks to buy a usb keyboard to plug on your notebook, so you can code snes9x
    Reply With Quote  

Page 1 of 2 1 2 LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •