PS2 OPL SND TEST

Discussion in 'Open PS2 Loader (OPL)' started by Krah, Aug 11, 2018.

  1. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    Ok I think its best to start a new thread here rather than clogging up ifcaro repo.
    Even if this doesn't get merged with the offical repo i'm hoping to set up a kind of skeletal frame work in case someone more efficient/skilled comes along and wishes to finish it off/use it as reference.

    @TnA You've made some great suggestions and will do my best to implement them, majority of them seem doable for me.

    Please keep in mind this is my first real coding project and I'm doing it for fun and a learning experience. I'm nowhere near the level of real devs;
    sp193, uyjulian, docxyz, ifcaro, jimmikaelkael, maximus32, ffgriever, akuhak, krhacken etc etc the list goes on and on.

    First step is working with audsrv libs, problem i'm facing is pathing i'm hoping @sp193 is able to spare a minute to try and offer some advice. audsrv doesn't use memory pointers afaik which is great for me but it does use fopen.
    This is currently where i'm running into issues as I can't get it to find/read my wave file.

    wav = fopen("SOUND/UP_DOWN.WAV;1", "rb");

    I would think this would look for the wave file at the current working dir (where ever your OPNPS2LDR.ELF is placed) go another folder deep 'SOUND' and then read the file but it never finds my file. I have tried many variants (./SOUND)(/SOUND) as well as having it compiled into OPL with similar pathing. I haven't tried a static path like mc0:\\ for obvious reasons this would not be a great idea, I don't want dupe code for every possible device.

    Any help or suggestions would be greatly appreciated.

     
    TnA, sandungas and jolek like this.
  2. 114
    137
    72
    NewFile

    NewFile Member

    Joined:
    Oct 11, 2017
    Messages:
    114
    Likes Received:
    137
    Trophy Points:
    72
    Gender:
    Male
    You must remove ";1" from the filepath. That ia only needed when accessing files located in cdrom0.
    Try using the absolute path for now aswell(there could be problems with trying to identify the boot directory). Be careful on the slashes aswell, habe a look on different sources codes, uLe for example to have an idea of how files path, dirs in the PS2 work.
     
    Krah likes this.
  3. 422
    690
    147
    sp193

    sp193 Developer

    Joined:
    Oct 13, 2014
    Messages:
    422
    Likes Received:
    690
    Trophy Points:
    147
    Location:
    Singapore
    Home Page:
    In 2009, I just begun my first project as somebody who only had some light coding experience. My first project was PS2ESDL, as we had no free game loader that was good.
    Don't worry, everybody started somewhere, for one reason or another.

    You do not have to strictly do what the sample does. fopen() might have been selected as it is a standard C I/O function, which perhaps offers some clarity over using the homebrew fio* and fileXio* functions.
    In our SDK, fopen() will internally call _ps2sdk_open, which is mapped to either fioOpen or fileXioOpen (depending on which library was initialized).

    By the way, some codecs are quite heavy for the EE. And so it is not possible to decode a block of audio within 1/60th a second.
    In PicoDrive, I used Audsrv. The MP3 BGMs (for MegaCD) were streamed and decoded within a dedicated sound thread that has a lower priority than the main thread, so that it won't drag down the FPS.
    The same thing was done for some game that I was making in 2012, which was using Ogg Vorbis.

    Other than what @NewFile mentioned, you're right. However, the PS2 software has full control over the PS2. As such, it must provide the necessary drivers to access the devices that it supports. OPL might not necessarily support all devices that it was booted from (i.e. host, which is used during development).
    Only rom and cdrom devices will have their drivers loaded through the IOP reboot process.

    OPL will only automatically load memory card and USB modules after IOP reboots.
    Other device drivers for devices like smb and pfs are only loaded if the device is "enabled" in settings.

    For the "alternate mode" for configuration, the device drivers are forcibly loaded, regardless of whether the device is enabled or not.
    For now, that's only for configuration stored on PFS.

    For language fonts, OPL will try loading fonts from memory card, mass and pfs.

    @Krah, while we are on this topic: if you were planning to use cdrom, please don't use cdrom.
    While it exists, not everybody has a modchip installed.

    There are also some additional restrictions if you do use cdrom:
    • Names must be in uppercase and only the 8.3 format is supported.
    • Paths must use the backslash, rather than the forward slash.
    • There are no directory functions (i.e. dopen, dread, dclose).
    • Filenames must have the file version suffix.
     
    Last edited: Aug 12, 2018
    Krah, bguerville, TnA and 2 others like this.
  4. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    I am quite certain, that it will get merged, if the implementation is good! :)

    Well, if atleast the calling to the function is done from the function which marks the items, this would eliminate some bugs and structural misconceptions like:
    • Playing a sound, even if there is nothing to scroll through, would not happen
    • It will be 'in-sync' with the marked items... Else it might play (i.e.) 8 clicks, while scrolling through 12 icons (via holding the button) or vice versa.
    • etc.
    However... You might want to implement a small portion of code, which determines if the selected item is the first selected item shown, before you even scrolled (and thus avoid a click, when the device is started, but Noone scrolled yet)... But that's just an end-polish...
    That could be done quite easily via a 'variable' (int) which is changed from 0 to 1 (or whatever you prefer), once a scrolling-button is used and the function which calls for playing the sound (the function which marks the item) would then 'request' from the variable, 'if' the value is 1 and only play a sound, if that's true... ;)

    We all do... It's also a reason, why I sometimes choose to rather inspire, or give some structural ideas which I am sure I can implement, but rather show others how my structural idea would look like and how to implement it (basically letting someone else write the stuff, even tho I can write the code, I sometimes rather explain where to put what, so others have a learning experience).
    I just don't learn that much from this kind of feature, so I rather help you out with it and see your skills develop. More Devs can't be bad, tho'. :D

    Btw.: For a first addition to a program, it's not bad! It's just some structural ideas (i.e. where to call from), which are not so thoroughly 'thought through' (lol... A new internet-acronym 'ttt'... And where is the crazy smiley, when I need it?)

    But everyone of those started out on that topic as well... I've never seen a Hacker-Baby which... erm... 'plopped out' ('was born') and could write a Software... ^^

    (Edit: This essentially means... 'No problem.'.)

    -change the call to play the sound, from button-input to item-marking
    -add the var, to 'mark' if there has been any scrolling yet

    That would pretty much be it (currently). ;)


    @sp193: You are a special case... Lol.
    It is clearly not 'normal' that a guy who isn't even adult [in any country] (back then), writes it's own freakin' Game-loader for an even weird Hardware/Console + extending it with firewire-support, while there even was no ported firewire-lib... :rolleyes:

    Have you been a Hacker-Baby, or do you just speak to the hardware as if it were your best buddy (like a dog) and 'he' does what you say (I am just honoring your skills and making a bit fun.)? o_O
     
    Last edited: Aug 13, 2018
    uyjulian, svotib, sandungas and 2 others like this.
  5. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    https://github.com/KrahJohlito/Open-PS2-Loader/tree/audio

    haven't been able to work on this for a while but this is it so far, remember im an amateur :)
    there are still many problems,

    no multithreading
    device paths are all set to mass0 atm cause Im testing from mass and the audio path settings dont save properly due to bad code
    up/down is the only sfx used still as no array setup with multiple sounds to call on specific file under conditions
    overall efficiency could probably be better

    might notice the click sound seems different from the first test, this is because I didnt realise at the time sjpcm was playing the file at 2x speed audsrv was also doing this when set to 44.1khz stereo which is why I had bump it down to 22.05

    currently Sound folder included needs to be placed on root of your usb to be used in mass0 if you want to test this as sounds are not compiled into OPL.
     

    Attached Files:

    TnA, jolek, Vedita BR and 1 other person like this.
  6. 2
    0
    5
    Vedita BR

    Vedita BR Forum Noob

    Joined:
    Aug 5, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    5
    Gender:
    Male
    Occupation:
    Caregiver, student and gamer?
    Location:
    Brazil
    Home Page:
    and how music file should me named?
     
  7. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    THX for opening a branch for that. :)


    Some suggestions:
    • It would be neat, if 'audsrv_init()' could 'get' the file-properties or calls a sub-function (erm... 'get_audio_prop()'?) which gets it/the values of the audio-file, instead of having fixed values. ;)
    • The lag-issue might be fixed, if you add a 'while' (in the function where you call the sound-playback --> 'cur && cur->prev'), which points back to the animation-function... (so 'while' should point back) But I suppose a 'while'+point to animation (1st and before 'Play_SFX') and then the playback-function (2nd) would be better, then adding the 'while' after the (playback-)call, could/might make a difference. I am not sure, if the placing of the 'while' would make a difference... It (placing within the function) might not make a difference (entirely depend on the compiler)...

    I can't test that approach yet, because I am in Munich/München. I just took a glance at the code and thought I give/post some ideas which came to mind.

    I hope that explaination is good enough. I am on my mobile (I mean I am writing on/from it.) and am not sure, how to explain it as short as possible, while still accurate.


    THX for moving the call to play the music, to the new place. :)
     
    Last edited: Aug 25, 2018
    Krah likes this.
  8. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    @Vedita BR :

    Use a "Sound"-Folder and "up_down.wav", "Sound/left_right.wav".
     
    Krah and jolek like this.
  9. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    new test if anyone wants to play around, feel free to swap out the files in the sound folder just make sure they're named the same.

    loading from specific device chosen in settings menu should work now, paths are.
    mc1:Sound
    hdd0:+OPL/Sound // its not pathed that way in the elf but when I tested from internal hdd it worked
    mass0:Sound

    up/down, left/right and confirm (launch game with X) are the only calls set currently.
     

    Attached Files:

    Vedita BR, TnA and jolek like this.
  10. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    mc1? Why not mc0 or both?
     
  11. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    WIP, intention is to have both but it doesn't seem priority atm. I get very limited time to work on it due to working full-time having 2 babies under 2y and a wife. So I need to try use my time wisely
     
    TnA likes this.
  12. 422
    690
    147
    sp193

    sp193 Developer

    Joined:
    Oct 13, 2014
    Messages:
    422
    Likes Received:
    690
    Trophy Points:
    147
    Location:
    Singapore
    Home Page:
    haha. I wasn't an adult in 2009, but I was only a little short of being one.
    Programming was my passion for a long time, and I am making it my profession.

    This console is difficult to program. For us who are unlicensed developers, there is generally a lack of proper tools.

    As for the i.Link stuff: there was no library that could be used, indeed. There was a document for the registers of a similar device, by LSI Logic. Most things were done by the hardware anyway, since it is OHCI.
    We can't use any IEEE1394 library anyway, since the i.Link controller interface here does not comply with the OHCI register standard, although it is a standard IEEE1394 OHCI controller. So if @Berion wants to say that the i.Link register definitions is a Sony thing, yes it is.
    It might be that there was no standard for registers back then.

    The SPU cores operate at 48000Hz, stereo. If you use anything else, then AUDSRV will down/upsample in software.
    If you use some compressed audio format like MP3, then there will be a need to decompress the stream. That will take up CPU time.

    In Picodrive, I made it so that the sound thread has a lower priority than the drawing thread. You can do this too, in OPL.
    I may have wrote that OPL might poll on the GS CSR for the VSync event, but it does not; it will sleep until the VSync interrupt event takes place. So you can have threads with lower priorities.

    For sound effects, you should consider converting them to ADPCM and using the voice channels. I don't think you need to constantly transfer the voices. This should have little to no overhead.
     
    TnA, Tupakaveli, Krah and 1 other person like this.
  13. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    ADPCM for SFX is definitely working better, I know you mentioned initially to do it this way but to be honest I couldn't figure out how to do it as I didn't realize at the time ps2sdk had an adpcm encoder.

    I gotta play around with it a bit as I've only got one SFX working atm which is predefined before mainloop so there is no real-time adjusting of devices through the menu, but it's definitely a big improvement with no stalls.
    Progress is slow but its progress none the less.
     
    Tupakaveli likes this.
  14. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    having some trouble with adpcm sfx.
    looking at this messy and inefficient code - https://github.com/KrahJohlito/Open-PS2-Loader/commit/056e4e5e8e305ce64066f747830791a3041d35a2

    using external sounds this way I can only get 2 sfx to play; playing a 3rd (type) freezes the console.
    tried to switch tac and use pointers to compiled in sounds, along the lines of

    int play_sfx(void ** ptr, int size)
    {
    audsrv_adpcm_t sfx;
    audsrv_load_adpcm(&sfx, ptr, size);
    audsrv_play_adpcm(&sfx);
    free(ptr);
    return 1;
    }

    using internal sounds this way I can only get 1 sfx to play; playing a 2nd (type) freezes the console.
    this is the snd call
    if (gEnableSFX){
    play_sfx(&scrollV_adp, size_scrollV_adp);
    free(&scrollV_adp);
    }

    am I not freeing the buffer correctly / at all? i'm getting a bit stumped
     
    TnA likes this.
  15. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    You are not using different 'channels' (not related to the output-mode, like mono, stereo, surround, etc., but the 'voice-channels') like @sp193 and I suggested (to) you, (or) do you?

    Edit: ...and if it only uses one buffer, that would likely cause issues as well...

    Edit 2: Btw.: This is, why I mentioned/said, that the 'interleaving' of those, different audios or voice-channels should rather be done on the SPU2! ;)
     
    Last edited: Sep 6, 2018
  16. 422
    690
    147
    sp193

    sp193 Developer

    Joined:
    Oct 13, 2014
    Messages:
    422
    Likes Received:
    690
    Trophy Points:
    147
    Location:
    Singapore
    Home Page:
    Once you free() a buffer, do not call free() on it again. It may not give an error, but it might crash the memory allocation mechanism.
    If you really want to free the buffer, you should do it only once. Maybe during deinitialization, since AUDSRV records the pointer, even if it doesn't seem to use it.

    What's the purpose of this loop?
    Code:
    void getAudioDevice(void)
    {
        int i;
        for (i=0; i<2; i++) {
          if ((gAudioPath == 0))
             sprintf(device_path, "mc%d:Sound/", i);
          else if ((gAudioPath == 1))
             sprintf(device_path, "pfs0:Sound/");
          else if ((gAudioPath == 2))
             sprintf(device_path, "mass0:Sound/");
    	}
    }
    
     
    TnA and Krah like this.
  17. 114
    137
    72
    NewFile

    NewFile Member

    Joined:
    Oct 11, 2017
    Messages:
    114
    Likes Received:
    137
    Trophy Points:
    72
    Gender:
    Male
    It seems to be checking for which memory card it's using. It will work fine if booting from HDD or or from USB but it will always default to mc1, second slot if the gAudioPath = 0, (mc boot path).
    He is basically looping from 0 to 1 for both slots. The solution would need to either define a MC0_PATH and MC1_PATH or use another way to further check which memory card.

    Option 1:
    Code:
    void getAudioDevice(void)
    {
          if ((gAudioPath == 0))                  // MC0_PATH
             sprintf(device_path, "mc%d:Sound/", i);
             else if ((gAudioPath == 1))           // MC1_PATH
                 sprintf(device_path, "pfs0:Sound/");
          else if ((gAudioPath == 2))          // HDD_PATH
             sprintf(device_path, "pfs0:Sound/");
          else if ((gAudioPath == 3))           // // USB_PATH
             sprintf(device_path, "mass0:Sound/");
       
    }
    
    or do some further checking:
    Code:
    void getAudioDevice(void)
    {
      
          if ((gAudioPath == 0)) {
           // Further work to determine which MC. 
           }
          else if ((gAudioPath == 1))
             sprintf(device_path, "pfs0:Sound/");
          else if ((gAudioPath == 2))
             sprintf(device_path, "mass0:Sound/");
    }
    
     
    TnA and Krah like this.
  18. 100
    101
    47
    Krah

    Krah Member

    Joined:
    Jul 20, 2018
    Messages:
    100
    Likes Received:
    101
    Trophy Points:
    47
    That was the intention yea, but I know it's wrong.
    I did leave it in there for the commit as I was about to delete the vast majority of the latest commit locally to make changes for internal sounds but I still like to be able to look back at it for reference and it's much easier to check github on my phone at work lunch time etc as I don't get a lot of time in front of the computer.

    People seem to want external SFX but internal SFX seems much more efficient and I doubt ppl with want to convert to adpcm so that's the way Im trying to head. Bgm could still be external and that makes more sense...Bgm still needs a lot of work though.
     
    Last edited: Sep 6, 2018
    TnA likes this.
  19. 114
    137
    72
    NewFile

    NewFile Member

    Joined:
    Oct 11, 2017
    Messages:
    114
    Likes Received:
    137
    Trophy Points:
    72
    Gender:
    Male
    You are progressing wonderfully. Please keep up the good work!
     
    TnA likes this.
  20. 254
    149
    47
    TnA

    TnA Member

    Joined:
    Jul 1, 2018
    Messages:
    254
    Likes Received:
    149
    Trophy Points:
    47
    Well, you would not have been adult (after your 'next' birthday) in some countries (where 21 is the limit, instead of 18)! ;)
    Writing a game-loader for a weird hardware + adding support for a pretty much never explored device&connection on that platform, whilst being 17 o_O is just not normal... There you've shown quite some talent! ...and it was one of the main-reasons why you were promoted to get the FMCB-Source! :)

    That's great! I hope the ([PS2-]Homebrew-)scene did have some influence on you and sparked some interesting ideas outside of the sscene as well!

    Well... It could be worse, but there definitely are a lot of things, which make it hard for developers to create (complex) tools/apps for it... (tools and hardware-structure, etc.)

    Yes, very true... .:-/

    I am not 100% sure... If I remember correctly there was some FireWire-Related stuff... I know it for sure for Linux, but not some 'native' IRX tho' (or possibly even that?). But there was DEFINITELY no other game-loader (and there still isn't one), which supported/-s FireWire!

    Well, as long as there is progress... ;)

    Different voice-channels? Possibly a modified buffer-behavior or separated or an extra-buffer/cache?

    Yes, support for external files would be neat!

    Agreed!
     

Share This Page