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 

libsd.irx?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sat Jul 01, 2006 7:05 pm    Post subject: libsd.irx? Reply with quote

I'm trying to add some music to my game using the ps2snd demo as a template, but it loads two irx files from the host side. One, ps2snd.irx i found in the iop folder, but the other, libsd.irx was nowhere to be found.
Any clues?

I did do a forum search but for some reason it won't let me search for a single word "Libsd.irx" it keeps tokenizing it and searching for libsd and irx seperately.
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sat Jul 01, 2006 7:14 pm    Post subject: Reply with quote

Got it to work by loading it from the rom \/
ret = SifLoadModule("rom0:LIBSD", 0, NULL);

Any reason why the ps2sdk demo uses a irx thats not included with the package or is just my precompiled package that doesn't have it? (I'd prefer to use it host side since not all rom versions have libsd according to one post i read)
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sat Jul 01, 2006 7:22 pm    Post subject: Reply with quote

Now it's refusing to link properly.
I've added -lps2snd.a and -lc as does the ps2snd demo but it bulks on,
SdSetParam(0 | SD_PARAM_MVOLL, 0x3fff);
SdSetParam(0 | SD_PARAM_MVOLR, 0x3fff);
SdSetParam(1 | SD_PARAM_MVOLL, 0x3fff);
SdSetParam(1 | SD_PARAM_MVOLR, 0x3fff);

IT compiles fine though, so no missing includes.
Back to top
View user's profile Send private message
evilo



Joined: 22 Apr 2004
Posts: 230

PostPosted: Sat Jul 01, 2006 8:25 pm    Post subject: Reply with quote

The LIBSD irx is contained in the PS2 rom.

beware that early japanese version don't include it, so you should prefer using FREESD instead (LIBS replacement included in the PS2SDK).

jbit will confirm it, but it should be compatible with his ps2snd library.
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sat Jul 01, 2006 9:13 pm    Post subject: Reply with quote

Ok thanks I'll switch over then.

While you're about d'you have any idea why it isn't linking? I'd appreciate any advice you could give, I'm stomped :)
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sat Jul 01, 2006 11:31 pm    Post subject: Reply with quote

Well I've tried just about everything, even copied over the ps2snd make file word for word to mine in case it was a makefile issue.

Here's my full source, it's all single source and everything runs perfectly except the four calls to the sound lib to set the volume, which do not link.(And when i say everything elses runs perfectly i of course mean when i cut the four offending lines)


(Btw if this post is too big for the server lemme know and i'll remove it)
Code:


#include "gsKit.h"
#include "dmaKit.h"
#include "malloc.h"
#include "libpad.h"
#include "kernel.h"
#include "stdio.h"
#include "loadfile.h"
#include <sifrpc.h>
#include <ps2snd.h>

typedef char int8;
typedef short int16;
typedef int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long uint64;
typedef long int64;
typedef struct int128
{
int64 lo, hi;
} int128 __attribute__((aligned(16)));
typedef struct uint128
{
uint64 lo, hi;
} uint128 __attribute__((aligned(16)));

uint64 MakeRgb(int r,int g,int b)
{
   return ((uint64)(r) <<0) | ((uint64)(g) << 8) | ((uint64)(b) << 16);
}

uint64 MakeRgba(int r,int g,int b,int a)
{
      return ((uint64)(r) <<0) | ((uint64)(g) << 8) | ((uint64)(b) << 16) | ((uint64)(a) << 32);
}

template <class T>
class ListNode
{

public:
    T &get()
    {
        return object;
    };
    void set(T &object)
    {
        this->object = object;
    };

    ListNode<T> *getNext()
    {
        return nextNode;
    };
    void setNext(ListNode<T> *nextNode)
    {
        this->nextNode = nextNode;
    };

private:
    T object;
    ListNode<T> *nextNode;
};

template <class T>
class List
{

public:
    // Constructor
    List()
    {
        headNode = new ListNode<T>;
        headNode->setNext(NULL);

        currentNode = NULL;
        size = 0;
    };

    // Destructor
    ~List()
    {

        ListNode<T> *pointerToDelete, *pointer = headNode;

        while (pointer != NULL)
        {
            pointerToDelete = pointer;
            pointer = pointer->getNext();
            delete pointerToDelete;
        }
    };

    T &get()
    {

        if (currentNode == NULL)
            start();

        return currentNode->get()
               ;
    };

    void add(T &addObject)
    {

        ListNode<T> *newNode = new ListNode<T>;

        newNode->set(addObject)
        ;

        newNode->setNext(headNode->getNext());
        headNode->setNext(newNode);

        size++;
    };

    void remove()
    {

        lastCurrentNode->setNext(currentNode->getNext());

        delete currentNode;

        currentNode = lastCurrentNode;

        size--;
    };

    void start()
    {
        lastCurrentNode = headNode;
        currentNode = headNode;
    };

    bool next()
    {

        // If the currentNode now points at nothing, we've reached the end
        if (currentNode == NULL)
            return false;

        // Update the last node and current node
        lastCurrentNode = currentNode;
        currentNode = currentNode->getNext();

        // If currentNode points at nothing or there is nothing added, we can immediately return false
        if (currentNode == NULL || size == 0)
            return false;
        else
            return true;
    };

    int getSize()
    {
        return size;
    };

private:
    int size;
    ListNode<T> *headNode;
    ListNode<T> *currentNode, *lastCurrentNode;
};


extern "C"
{
void UpdatePad()
{
   int i=0;
   int ret=0;
   int port=0,slot=0;
   ret=padGetState(port, slot);
  while((ret != PAD_STATE_STABLE) && (ret != PAD_STATE_FINDCTP1)) {
           if(ret==PAD_STATE_DISCONN) {
            printf("Pad(%d, %d) is disconnected\n", port, slot);
        }
        ret=padGetState(port, slot);
       }
       if(i==1) {
           printf("Pad: OK!\n");
       }
           
}

struct padButtonStatus buttons;
u32 paddata;
u32 old_pad = 0;
u32 new_pad;
int but_select,but_start;
int but_cross,but_circle,but_square,but_triangle;
float but_crossp,but_circlep,but_squarep,but_trianglep;
int but_l1,but_l2,but_r1,but_r2;
int but_l3,but_r3;
float but_l1p,but_l2p,but_r1p,but_r2p;
float joy_lx,joy_ly;
float joy_rx,joy_ry;
float joy_hx,joy_hy;

void ReadPad()
{
   int ret;
   int port = 0,slot =0;
   but_square=0;
   but_triangle=0;
   but_circle=0;
   but_cross=0;
   but_l1=0;
   but_l2=0;
   but_r1=0;
   but_r2=0;
   but_select=0;
   but_start=0;
   but_l3=0;
   but_r3=0;
   
   ret = padRead(port, slot, &buttons);   
   if (ret != 0) {
            paddata = 0xffff ^ buttons.btns;
               
            new_pad = paddata;//'paddata & ~old_pad;
            old_pad = paddata;
                             
            // Directions
            if(new_pad & PAD_LEFT) {
                joy_hx = -1;
            }
            if(new_pad & PAD_DOWN) {
                joy_hy = 1;
            }
            if(new_pad & PAD_RIGHT) {
                joy_hx = 1;
            }
            if(new_pad & PAD_UP) {
                joy_hy = 1;
            }
            if(new_pad & PAD_START) {
                but_start = 1;
            }
            if(new_pad & PAD_R3) {
                but_r3 = 1;
            }
            if(new_pad & PAD_L3) {
                but_l3 = 1;
            }
            if(new_pad & PAD_SELECT) {
                   but_select = 1;
             }
            if(new_pad & PAD_SQUARE) {
                but_square = 1;
            }
            if(new_pad & PAD_CROSS) {
             
                but_cross = 1;
            }
            if(new_pad & PAD_CIRCLE) {
             
                but_circle = 1;
            }
            if(new_pad & PAD_TRIANGLE) {
                but_triangle = 1;
            }
            if(new_pad & PAD_R1) {
         
                but_r1 = 1;
            }
            if(new_pad & PAD_L1) {
                     
                but_l1 = 1;
            }
            if(new_pad & PAD_R2) {
                but_r2 = 1;
            }
            if(new_pad & PAD_L2) {
                but_l2 = 1;
            }
            but_crossp = buttons.cross_p;
            but_squarep = buttons.square_p;
            but_circlep = buttons.circle_p;
            but_trianglep = buttons.triangle_p;
            but_l1p = buttons.l1_p;
            but_r1p = buttons.r1_p;
            but_l2p = buttons.l2_p;
            but_r2p = buttons.r2_p;
               joy_hx -= buttons.left_p;
               joy_hx += buttons.right_p;
               joy_hy -= buttons.up_p;
               joy_hy += buttons.down_p;
                              
        }
}

int waitPadReady(int port, int slot)
{
    int state;
    int lastState;
    char stateString[16];

    state = padGetState(port, slot);
    lastState = -1;
    while((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
        if (state != lastState) {
            padStateInt2String(state, stateString);
            printf("Please wait, pad(%d,%d) is in state %s\n",
                       port, slot, stateString);
        }
        lastState = state;
        state=padGetState(port, slot);
    }
    // Were the pad ever 'out of sync'?
    if (lastState != -1) {
        printf("Pad OK!\n");
    }
    return 0;
}

}

u64 cur_col;

GSGLOBAL *gs_Global;


inline void SetColor(int r,int g,int b,int a=255)
{
   cur_col = MakeRgba(r,g,b,a); ;//GS_SETREG_RGBAQ(r,g,b,a,0);
}

inline void DrawRect(float x,float y,float w,float h,int z)
{
   gsKit_prim_sprite(gs_Global, x,y, x+w,y+h, z, cur_col );
}

//consts instead of enum 'cos they wern't compiling for some reason.
const int Control_Pad = 1,Control_AI = 2;


class Bat
{
public:
   Bat(float x,float y,int control)
   {
      _x=x;
      _y=y;
      _yi=0;
      _len=90;
      _cpu = control;
      _lenInc=0;
   }
   ~Bat()
   {
   }
   void Render()
   {
      _len +=_lenInc;
      DrawRect(_x,_y-(_len/2),20,_len,5);
      _len -=_lenInc;
   }
   
   void Update()
   {
      switch(_cpu)
      {
         case Control_Pad:
               _lenInc = but_crossp * 0.2;
               //print'f("LenInc: %f \n",_lenInc);
               if(abs(joy_hy)>30)
               _yi += joy_hy *0.02;
               
            break;
         case Control_AI:
               
            break;
      }
      _y += _yi;
      
      if(_y<( (_len/2)+(_lenInc/2)) ) _y=( (_len/2)+(_lenInc/2));
      if(_y>(gs_Global->Height-( (_len/2)+(_lenInc/2) ) ))
         _y = (gs_Global->Height-( (_len/2)+(_lenInc/2) ) );
         
      _yi *= 0.95;
      
      
   };
   float _lenInc;
   float _x,_y;
   float _yi,_len;
   int _cpu;
};

class Star
{
public:
   Star(float x,float y,float z)
   {
      _x = x;
      _y = y;
      _z = z;
      _lx = x;
   }
   void Move(float x)
   {
      _x +=(x/(255-_z));
      if( _x<-10 )
      {
         _x=gs_Global->Width+10;
         _y=rand()%gs_Global->Height;
         _z=rand()%255;
         _lx = _x;
      }
   }
   float _x,_y,_z;
   float _lx;
};

class Ball
{
public:
   Ball(float x,float y)
   {
      _x = x;
      _y = y;
   }
   void Update()
   {
      _x+=_xi;
      _y+=_yi;
   }
   void Render()
   {
      SetColor(255,255,255,255);
      DrawRect(_x-8,_y-8,16,16,1 );
   }
   float _x,_y;
   float _xi,_yi;
         
};

Ball *ball;

void UpdateAndRenderBall()
{
   ball->Update();
   ball->Render();
}

List<Star *>stars;
List<Bat *>bats;

void AddStar(float x,float y,float z)
{
   Star *star = new Star(x,y,z);
   stars.add( star );
}

void StarsUpdateAndRender()
{
   stars.start();
   while( stars.next() )
   {
      Star * star = stars.get();
      star->_lx = star->_x+2;
      star->Move( -50 );
      //SetColor( star->_z,star->_z,star->_z,255 );
      
      //DrawRect( star->_x-2,star->_y-2,4,4,(int)(255-star->_z) );
      float xd;
      xd = star->_lx - star->_x;
      xd = xd *2;
      gsKit_prim_line( gs_Global, star->_x,star->_y,star->_x+xd,star->_y,(255-star->_z),MakeRgb(star->_z,star->_z,star->_z) );
   }
   
}



void AddBat(float x,int control)
{
   Bat *bat = new Bat(x,gs_Global->Height/2.0,control);
   bats.add( bat );
}

void RenderBats()
{
   bats.start();
   SetColor(255,255,255,255);
   while( bats.next() )
   {
      Bat *bat = bats.get();
      bat->Render();
   }
}

void UpdateBats()
{
   bats.start();
   while( bats.next() )
   {
      Bat *bat = bats.get();
      bat->Update();
   }
}

extern "C" {
int main(int argc, char ** argv) {
   u64 White, Black, Red, Green, Blue, BlueTrans, RedTrans, GreenTrans, WhiteTrans;
//   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_VGA_640_60); // VGA 640x480@60Hz

   //   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_DTV_480P); // HTDV 480P
   //   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_DTV_720P); // HTDV 720P
   //   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_DTV_1080I); // HDTV 1080I Full Buffers
   //   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_DTV_1080I_I); // HDTV 1080I Half Buffers
   SifInitRpc(0);
   SifLoadModule("rom0:SIO2MAN", 0, NULL);
   SifLoadModule("rom0:PADMAN", 0, NULL);
   int ret;
   /* Load LibSD (freesd will work too one day, I promise ;) */
   ret = SifLoadModule("rom0:LIBSD", 0, NULL);
   if (ret<0)
   {
      printf("XXXXX failed to load host:LIBSD.IRX (%d)\n", ret);
      return 0;
   }

   /* Load ps2snd */
   ret = SifLoadModule("host:ps2snd.irx", 0, NULL);
   if (ret<0)
   {
      printf("XXXXX failed to load host:ps2snd.irx (%d)\n", ret);
      return 0;
   }

   SdSetParam(0 | SD_PARAM_MVOLL, 0x3fff);
   SdSetParam(0 | SD_PARAM_MVOLR, 0x3fff);
   SdSetParam(1 | SD_PARAM_MVOLL, 0x3fff);
   SdSetParam(1 | SD_PARAM_MVOLR, 0x3fff);

      
   printf("About to init pad. \n");
   static char padBuf[256] __attribute__((aligned(64)));
   printf("Created structure \n");
   padInit(0);    
   printf("Called padinit.\n");
   if((padPortOpen(0, 0, padBuf)) == 0) {
      printf("padOpenPort failed");
       return 0;
    }
    printf("Joypad Initialized");
    waitPadReady(0,0);
   padSetMainMode(0,0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
   waitPadReady(0,0);
   padEnterPressMode(0,0);
   waitPadReady(0,0);
   
   gs_Global = gsKit_init_global(GS_MODE_PAL); // Full Buffers
//   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_PAL_I); // NTSC Half Buffers

//   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_NTSC); // NTSC Full Buffers
//   GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_NTSC_I); // NTSC Half Buffers

   // You can use these to turn off Z/Double Buffering. They are on by default.
   // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
   // gsGlobal->ZBuffering = GS_SETTING_OFF;

   // This makes things look marginally better in half-buffer mode...
   // however on some CRT and all LCD, it makes a really horrible screen shake.
   // Uncomment this to disable it. (It is on by default)
   // gsGlobal->DoSubOffset = GS_SETTING_OFF;   

   gs_Global->PrimAlphaEnable = GS_SETTING_ON;   
   
   float x = 10;
   float y = 10;
   float width = 150;
   float height = 150;

   float VHeight;

   VHeight = gs_Global->Height;

   float *LineStrip;
   float *LineStripPtr;
   float *TriStrip;
   float *TriStripPtr;
   float *TriFanPtr;
   float *TriFan;

   
   dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
          D_CTRL_STD_OFF, D_CTRL_RCYC_8);

   // Initialize the DMAC
   dmaKit_chan_init(DMA_CHANNEL_GIF);
   dmaKit_chan_init(DMA_CHANNEL_FROMSPR);
   dmaKit_chan_init(DMA_CHANNEL_TOSPR);

   White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);

   
   gsKit_init_screen(gs_Global);
   gsKit_clear(gs_Global, White);
   gsKit_set_test(gs_Global, GS_ZTEST_OFF);
   gsKit_mode_switch(gs_Global, GS_ONESHOT);
   
   //Init paddles
   
   AddBat( 20,Control_Pad );
   AddBat( gs_Global->Width-40,Control_AI );
   SetColor(255,255,255,255);
   
   for(int i=0;i<500;i++)
   {
      AddStar( rand()%gs_Global->Width,rand()%gs_Global->Height,rand()%255);
   }
   
   ball = new Ball( gs_Global->Width/2,gs_Global->Height/2 );
   
   while(1)
   {
      gsKit_clear(gs_Global,MakeRgb(0,0,0));
      
      UpdatePad();
      ReadPad();
      UpdateBats();
      StarsUpdateAndRender();
      RenderBats();
      UpdateAndRenderBall();
      
      if( y <= 10  && (x + width) < (gs_Global->Width - 10))
         x+=1;
      else if( (y + height)  <  (VHeight - 10) && (x + width) >= (gs_Global->Width - 10) )
         y+=1;      
      else if( (y + height) >=  (VHeight - 10) && x > 10 )
         x-=1;
      else if( y > 10 && x <= 10 )
         y-=1;

   //   gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 4, MakeRgb(255,0,0));
      
      //gsKit_prim_sprite(gsGlobal,20,20,140,140,4,MakeRgba(255,255,128,255));
      // RedTrans must be a oneshot for proper blending!
      //gsKit_prim_sprite(gsGlobal, 100.0f, 100.0f, 200.0f, 200.0f, 5, MakeRgba(128,128,128,128));



      gsKit_queue_exec(gs_Global);

      // Flip before exec to take advantage of DMA execution double buffering.
      gsKit_sync_flip(gs_Global);

   }
   
   return 0;
}
}

Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 12:20 am    Post subject: Reply with quote

Do not use the LIBSD from rom0: with ps2snd, the LIBSD from rom0 is EXTREMLY broken.
You can use libsd.irx from a ps2 game or use freesd.irx (from ps2sdk) instead!

Oh, and what link errors are you getting? I don't think you've pasted them anywhere.
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 12:42 am    Post subject: Reply with quote

Yeah sorry, I thought I pasted it.

C:\ps2dev\gskit\examples\basic>make
ee-gcc -mno-crt0 -TC:/ps2dev/ps2sdk/ee/startup/linkfile -LC:/ps2dev/ps2sdk/ee/li
b \
-o basic.elf C:/ps2dev/ps2sdk/ee/startup/crt0.o basic.o -lpad -lgskit -l
dmakit -lstdc++ -lps2snd -lc -lc -lkernel
basic.o(.text+0xbb0): In function `main':
basic.cc: undefined reference to `SdSetParam(unsigned short, unsigned short)'
basic.o(.text+0xbbc):basic.cc: undefined reference to `SdSetParam(unsigned short
, unsigned short)'
basic.o(.text+0xbc8):basic.cc: undefined reference to `SdSetParam(unsigned short
, unsigned short)'
basic.o(.text+0xbd4):basic.cc: undefined reference to `SdSetParam(unsigned short
, unsigned short)'
collect2: ld returned 1 exit status
make: *** [basic.elf] Error 1

C:\ps2dev\gskit\examples\basic>


And thanks for the heads up, I'll go through my games see if theres a libsd.
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 12:47 am    Post subject: Reply with quote

Ah, it's probably because ps2snd's header doesn't have extern "C" things (I don't use C++ much on the PS2), so C++ is doing its function name mangling stuff, and ld can't find the functions.

I'll try fixing it now, update your SVN bin in a few minutes.

EDIT: Done, but not tested with A C++ program.
EDIT: Had to commit another revision, 1329, since i forgot to commit the main ps2snd.h file hte first time round.


Last edited by jbit on Sun Jul 02, 2006 12:55 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 12:52 am    Post subject: Reply with quote

Nice one, thanks, I'll try it now and let you know if it works.

-edit-Yep works fine, thanks again.
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 1:41 am    Post subject: Reply with quote

Hmm it compiles now, but as soon as it reaches the set volume call it freezes the ps2 completely. Not even ps2client reset unfreezes it, I need to manually reboot the ps2.

Any idea if it's another c++ related problem or a irx conflict?(I'm now using freesd found in the 03 june package from xorloser's site)
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 2:13 am    Post subject: Reply with quote

Fixed it, didn't see the SdInit() call in the sound demo, worked soon as I added that.

Btw, can I legally include LibSD.irx from a commercial game or should I use freesd for stuff i release?
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 3:09 am    Post subject: Reply with quote

No, you can't legally include any Sony IRX in anything your release.
FreeSD is definatly usable enough for most things, if you enocunter any bugs please let me know. And I'd highly recommend developing and testing your code with only FreeSD.
(Unfortuantly FreeSD is based on quite an old LIBSD, but ps2snd was written against a relativly new version, so there may be some bugs)

In fact, I'm aware of one bug, which is FreeSD doesn't properly reset the SPU2, so sometimes the channels are in weird modes.

I now do this when initializing Sd... for both cores i do: (where "core" is 0 and 1)
Code:

/* Stop all voices */
SdSetSwitch(core | SD_SWITCH_KEYUP,   0xffffff);

/* Disable all pitch modulation */
SdSetSwitch(core | SD_SWITCH_PMON, 0);

/* Switch off all noise generation */
SdSetSwitch(core | SD_SWITCH_NON, 0);

/* Enable direct output */
SdSetSwitch(core | SD_SWITCH_VMIXL, 0xffffff);
SdSetSwitch(core | SD_SWITCH_VMIXR, 0xffffff);

/* Disable effects output */
SdSetSwitch(core | SD_SWITCH_VMIXEL, 0);
SdSetSwitch(core | SD_SWITCH_VMIXER, 0);

/* Set master volume of SPU core0 */
SdSetParam(core | SD_PARAM_MVOLL, 0x3fff);
SdSetParam(core | SD_PARAM_MVOLR, 0x3fff);

And then:

Code:

/* Enable only direct voice output for core0 */
SdSetParam(0 | SD_PARAM_MMIX, (1<<10) | (1<<11));

/* NOTE: core0s output goes to core1s external input, core1s output goes to the DAC. */
/* Enable direct voice output and external input for core1 */
SdSetParam(1 | SD_PARAM_MMIX, (1<<2) | (1<<3) | (1<<10) | (1<<11));

This seems to fix some fun noises I was getting without this code.

I want to move this init code into FreeSD, rather than requiring all apps that use sd to do it, but I'd like to do it correctly, so it's not done yet.
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 3:22 am    Post subject: Reply with quote

Thanks, I'll use that if I get any of the same bugs (Which I probably, not like we're talking pcs/different configs)

Btw can you do single channel sounds with pssnd? I see theres only a single function called sndStreamPlay() which takes no 'channel' parameter or sound parameter.
or would I have to do it like on a gba and write my own mixer?
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 3:27 am    Post subject: Reply with quote

When streaming ADPCM with ps2snd you can use mono or stereo streams. But ps2snd only supports one stream at a time for now (in the future it'll probably support more).
Back to top
View user's profile Send private message Visit poster's website
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Sun Jul 02, 2006 3:27 am    Post subject: Reply with quote

You trigger a SD_SWITCH_KEYDOWN on a channel to start it playing.. there should be an example of that in whatever code jbit pointed you at
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 3:35 am    Post subject: Reply with quote

Doesn't the core refer to each spu core, if so does that limit me to two channels which i have to mix myself? (I don't want streams I mean for normal in game soundfx)
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 3:56 am    Post subject: Reply with quote

btw can you suggest a good prog to convert mp3/wavs etc to ADPCM? I can't find any that save at 48khz, and only the microsoft ADPCM format. (No idea if they're compatible.)

-edit- btw you need to do the extern "c" thing for ps2snd.h aswell. just did it and it works. (same deal as before without it)
I'd upload to the svn but i'm new to svn so i'm afraid i'll end up messing it up and destroying the community in one fell swoop :)
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 4:49 am    Post subject: Reply with quote

Kojima wrote:
btw can you suggest a good prog to convert mp3/wavs etc to ADPCM?

You can use my ps2adpcm tool from ps2sdk, on a unix system with sox installed you can do:
Code:
sox "input file" -t raw -r 48000 -c 1 -w -s - | ps2adpcm - "output file"

To convert from anything sox supports (mp3/wav/aiff/ogg/etc) to ADPCM (replay "input file" with "output file")
That command will make a "one shot" (non-repeating) sample. Add "-l0" to the end if you want the sample to repeat from the start.



Kojima wrote:
-edit- btw you need to do the extern "c" thing for ps2snd.h aswell. just did it and it works

I did that update a few seconds after the first update, recheck out, you should get it (but you might get a conflict if you edited it yourself).

Kojima wrote:
Doesn't the core refer to each spu core, if so does that limit me to two channels which i have to mix myself? (I don't want streams I mean for normal in game soundfx)

As i've said before, each SPU core has 24 voices that you can use for playing samples, it has a couple of PCM streaming channels (which ps2snd doesn't really support decently yet).
ps2snd's streaming stuff fakes ADPCM streaming using one hardware voice per stream channel, and only support one stream at a time for now (so one or two channels), it could in theory support upto 24 stereo streams, mixed in hardware at any one time, but I don't know if the IOPs DMAC would be upto that, (and i don't really see a use for it).

For game sound FX, you do _NOT_ want to use the streaming functionality, only use the streaming stuff for music. The example I pasted before (from ps2kit) has examples of how to use ps2snd for sound FX (using different voices and KEYON registers, etc)

If you wait a few days, i should have a pretty decent tutorial up on my site, including some decent explanations on the concepts the SPU2 uses for audio output.
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 4:53 am    Post subject: Reply with quote

Ok look forward to seeing it, please lay a post down with a link to your site when you do.

As for your tool, does it have a windows port? I dont use linux cos I could never get broadband to run on it.
-edit- found it with a file search, trying it now, thanks.


Last edited by Kojima on Sun Jul 02, 2006 4:56 am; edited 1 time in total
Back to top
View user's profile Send private message
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Sun Jul 02, 2006 4:56 am    Post subject: Reply with quote

...you using cygwin? ... get it to install sox then, and jbit's tool is part of ps2sdk
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 4:58 am    Post subject: Reply with quote

No afraid not, I'm using the prebuilt ps2 sdk. unless that includes some version of cyngwin or other. regular cygwin is too big for my hd(14gig with most of it used)

but like i said this build has his tool anyway.
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 5:19 am    Post subject: Reply with quote

Hmm a couple of issues. I used this --
:\ps2dev\ps2sdk\bin>ps2adpcm c:\ps2dev\gskit\examples\basic\track1.wav ntrack1.
adpcm -s -c1024 -s1000
loop end!
-- to convert a mp3 into a 8bit stero pcm .wav in goldwave, it worked, but it was only 5mb compared to the wavs 40. then playing it, it was litterally 3-4x faster than it should be and distorted heavily.(Probably just the volume too high causing the distortion?)

But worse than that, ps2client reset no longer works. when i call it, the sound just loops a half a second interval(I.e (bleep)s up) and thats it. ps2client exits and ps2link doesn't reset.
Is this because I'm using v1.24 of ps2link? (been too lazy to use the new version)
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 5:52 am    Post subject: Reply with quote

Just tried the new ps2link(v1.46) and it still crashes. nice init speed boost though ;p

-edit- just commented out the few lines of sound code and it now works perfectly, so definitely the sound lib interfering.
I'm using a mod-chip (Matrix Infinity) to boot, dunno whether that could be an issue or not.
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Sun Jul 02, 2006 7:07 am    Post subject: Reply with quote

The ps2adpcm tool doesn't understand wave, or aiff, or anything, it only takes in raw PCM, that's why i recommend using sox with it.
I'm not sure what's causing your lock-up, it sounds like it could be graphics related, rather than sound related. Although I assume you've read the README that comes with ps2snd which states you CAN'T use ps2client reset when streaming audio.... it's a known bug and is in the process of being fixed (hint: it's not ps2snds fault, it's to do with the network stack on the IOP).
EDIT: (But if you stop and close the stream, you can reset using ps2client safely though)

Please note that the SPU2 only has 2mbytes of sound ram, so you can only upload a maximum of about 1.8mbytes of samples. If you're streaming, this obviously doesn't matter and I've used streams upto about 100mbytes big without any problem.
And yes, the ADPCM output will be much smaller than the PCM input, iirc the ratio is about 3.5 or so.
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 8:04 am    Post subject: Reply with quote

Oh ok I never saw the read me, I did think it might work if I stopped the stream but as soon as I realised the only way to do that would be to detect the rest, then stop the stream. which of course is (probably)impossible.

I'll just add a quick press l1+l2 hook to silently exit the game 'fore I reset.

As for wav, it is pcm. GoldWav lets you pick many wav formats, and I used pcm. it just uses the wav extension.(At least that's what it says.)
If that's wrong, can you reccomend a tool to save pcm data that's compatible?
Back to top
View user's profile Send private message
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Sun Jul 02, 2006 5:39 pm    Post subject: Reply with quote

Kojima wrote:

As for wav, it is pcm. GoldWav lets you pick many wav formats, and I used pcm. it just uses the wav extension.(At least that's what it says.)
If that's wrong, can you reccomend a tool to save pcm data that's compatible?

sox


...wav files are a container format, they just happen to typically be used for storing various formats of uncompressed pcm... there is still the header and such on it.
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 6:12 pm    Post subject: Reply with quote

Just grabbed it, didn't know it had a windows release(That didn't require cygwin anyway)

Can you give me an example of converting a wav not using his tool(I'll use that after)? I tried jbits example and it started spewing out gibberish, my pc's internal speaker started bleeping and i had to reboot.
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 6:16 pm    Post subject: Reply with quote

no matter, i just missed the output file parameter, probably why it outputed to the command line instead.
Back to top
View user's profile Send private message
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Sun Jul 02, 2006 6:28 pm    Post subject: Reply with quote

Ok now it sounds fine, no distortion but it's about 2x-3x faster than it should be. And it appears to be a conversation issue as the adpcm is only 5mb. (The raw file produced by sox and the wav are both 20mb)

Heres what i used to convert it.


C:\ps2dev\gskit\examples\basic>sox track1.wav -t raw -r 48000 -c 1 -w -s output.
raw

then

C:\ps2dev\gskit\examples\basic>ps2adpcm output.raw ntrack5.adpcm -s -c1024 -s100
0
loop end!

have i made a mistake somewhere?
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 -> PS2 Development All times are GMT + 10 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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