-Added new function that allows porters to change sound cores after emulation has been initialized.

This commit is contained in:
cyberwarriorx 2006-11-12 18:23:14 +00:00
parent b0d4e97fde
commit 9c39bf3241
2 changed files with 25 additions and 5 deletions

View File

@ -73,14 +73,19 @@ FILE *spufp=NULL;
//////////////////////////////////////////////////////////////////////////////
int SPU_Init(int coreid, int buffersize)
int SPU_ChangeSoundCore(int coreid, int buffersize)
{
int i;
if ((SPU = (SPU_struct *)malloc(sizeof(SPU_struct))) == NULL)
return -1;
if (SPU->sndbuf)
free(SPU->sndbuf);
SPU_Reset();
if (SPU->outbuf)
free(SPU->outbuf);
// Make sure the old core is freed
if (SNDCore)
SNDCore->DeInit();
// Allocate memory for sound buffer
if ((SPU->sndbuf = malloc(buffersize * 4 * 2)) == NULL)
@ -110,14 +115,16 @@ int SPU_Init(int coreid, int buffersize)
}
if (SNDCore == NULL)
{
SNDCore = &SNDDummy;
return -1;
}
if (SNDCore->Init(buffersize * 2) == -1)
{
// Since it failed, instead of it being fatal, we'll just use the dummy
// core instead
SNDCore = &SNDDummy;
SNDCore->Init(buffersize * 2);
}
return 0;
@ -125,6 +132,18 @@ int SPU_Init(int coreid, int buffersize)
//////////////////////////////////////////////////////////////////////////////
int SPU_Init(int coreid, int buffersize)
{
if ((SPU = (SPU_struct *)malloc(sizeof(SPU_struct))) == NULL)
return -1;
SPU_Reset();
return SPU_ChangeSoundCore(coreid, buffersize);
}
//////////////////////////////////////////////////////////////////////////////
void SPU_Reset(void)
{
int i;

View File

@ -82,6 +82,7 @@ typedef struct
extern SPU_struct *SPU;
int SPU_ChangeSoundCore(int coreid, int buffersize);
int SPU_Init(int coreid, int buffersize);
void SPU_Reset(void);
void SPU_DeInit(void);