it is broken for a while now, and I have no intention to fix it.
extern int iUseInterpolation;
extern int iXAPitch;
extern int iSPUIRQWait;
-extern int iUseTimer;
extern int iVolume;
int ready_to_go;
iUseInterpolation = 1;
iXAPitch = 0;
iSPUIRQWait = 1;
- iUseTimer = 2;
iVolume = 768;
#ifndef __ARM_ARCH_7A__ /* XXX */
iUseReverb = 0;
extern int iUseInterpolation;
extern int iXAPitch;
extern int iSPUIRQWait;
-extern int iUseTimer;
extern int iVolume;
static const char *bioses[24];
CE_INTVAL_V(iXAPitch, 3),
CE_INTVAL_V(iUseInterpolation, 3),
CE_INTVAL_V(iSPUIRQWait, 3),
- CE_INTVAL_V(iUseTimer, 3),
CE_INTVAL(warned_about_bios),
CE_INTVAL(in_evdev_allow_abs_only),
CE_INTVAL(volume_boost),
static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
static const char h_spu_volboost[] = "Large values cause distortion";
static const char h_spu_irq_wait[] = "Wait for CPU (recommended set to ON)";
-static const char h_spu_thread[] = "Run sound emulation in main thread (recommended)";
static menu_entry e_menu_plugin_spu[] =
{
mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
- mee_onoff_h ("Sound in main thread", 0, iUseTimer, 2, h_spu_thread),
mee_end,
};
#include "../plugins/dfinput/main.h"
#include "maemo_common.h"
-// sound plugin
-extern int iUseTimer;
-
int g_opts = OPT_SHOWFPS;
int g_maemo_opts;
char file_name[MAXPATHLEN];
}
else if (!strcmp(argv[i],"-fullscreen")) g_maemo_opts |= 2;
else if (!strcmp(argv[i],"-accel")) g_maemo_opts |= 4;
- else if (!strcmp(argv[i],"-sputhreaded")) iUseTimer=1;
else if (!strcmp(argv[i],"-nosound")) strcpy(Config.Spu, "spunull.so");
else if (!strcmp(argv[i], "-bdir")) sprintf(Config.BiosDir, "%s", argv[++i]);
else if (!strcmp(argv[i], "-bios")) sprintf(Config.Bios, "%s", argv[++i]);
+++ /dev/null
-/***************************************************************************\r
- cfg.c - description\r
- -------------------\r
- begin : Wed May 15 2002\r
- copyright : (C) 2002 by Pete Bernert\r
- email : BlackDove@addcom.de\r
- ***************************************************************************/\r
-/***************************************************************************\r
- * *\r
- * This program is free software; you can redistribute it and/or modify *\r
- * it under the terms of the GNU General Public License as published by *\r
- * the Free Software Foundation; either version 2 of the License, or *\r
- * (at your option) any later version. See also the license.txt file for *\r
- * additional informations. *\r
- * *\r
- ***************************************************************************/\r
-\r
-#include "stdafx.h"\r
-\r
-#define _IN_CFG\r
-\r
-#include "externals.h"\r
-\r
-////////////////////////////////////////////////////////////////////////\r
-// LINUX CONFIG/ABOUT HANDLING\r
-////////////////////////////////////////////////////////////////////////\r
-\r
-#include <unistd.h>\r
-\r
-////////////////////////////////////////////////////////////////////////\r
-// START EXTERNAL CFG TOOL\r
-////////////////////////////////////////////////////////////////////////\r
-\r
-void StartCfgTool(char * pCmdLine)\r
-{\r
- FILE * cf;\r
- char filename[255];\r
-\r
- strcpy(filename,"cfgDFSound");\r
- cf=fopen(filename,"rb");\r
- if(cf!=NULL)\r
- {\r
- fclose(cf);\r
- if(fork()==0)\r
- {\r
- execl("./cfgDFSound","cfgDFSound",pCmdLine,NULL);\r
- exit(0);\r
- }\r
- }\r
- else\r
- {\r
- strcpy(filename,"cfg/cfgDFSound");\r
- cf=fopen(filename,"rb");\r
- if(cf!=NULL)\r
- {\r
- fclose(cf);\r
- if(fork()==0)\r
- {\r
- chdir("cfg");\r
- execl("./cfgDFSound","cfgDFSound",pCmdLine,NULL);\r
- exit(0);\r
- }\r
- }\r
- else\r
- {\r
- sprintf(filename,"%s/cfgDFSound",getenv("HOME"));\r
- cf=fopen(filename,"rb");\r
- if(cf!=NULL)\r
- {\r
- fclose(cf);\r
- if(fork()==0)\r
- {\r
- chdir(getenv("HOME"));\r
- execl("./cfgDFSound","cfgDFSound",pCmdLine,NULL);\r
- exit(0);\r
- }\r
- }\r
- else printf("Sound error: cfgDFSound not found!\n");\r
- }\r
- }\r
-}\r
-\r
-/////////////////////////////////////////////////////////\r
-// READ LINUX CONFIG FILE\r
-/////////////////////////////////////////////////////////\r
-\r
-static void ReadConfigFile(void)\r
-{\r
- FILE *in;char t[256];int len;\r
- char * pB, * p;\r
-\r
- strcpy(t,"dfsound.cfg");\r
- in = fopen(t,"rb"); \r
- if(!in) \r
- {\r
- strcpy(t,"cfg/dfsound.cfg");\r
- in = fopen(t,"rb"); \r
- if(!in) \r
- {\r
- sprintf(t,"%s/dfsound.cfg",getenv("HOME")); \r
- in = fopen(t,"rb"); \r
- if(!in) return;\r
- }\r
- }\r
-\r
- pB = (char *)malloc(32767);\r
- memset(pB,0,32767);\r
-\r
- len = fread(pB, 1, 32767, in);\r
- fclose(in);\r
-\r
- strcpy(t,"\nVolume");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;}\r
- if(p) iVolume=4-atoi(p+len);\r
- if(iVolume<1) iVolume=1;\r
- if(iVolume>4) iVolume=4;\r
-\r
- strcpy(t,"\nXAPitch");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;}\r
- if(p) iXAPitch=atoi(p+len);\r
- if(iXAPitch<0) iXAPitch=0;\r
- if(iXAPitch>1) iXAPitch=1;\r
-\r
- strcpy(t,"\nHighCompMode");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;} \r
- if(p) iUseTimer=atoi(p+len); \r
- if(iUseTimer<0) iUseTimer=0; \r
- // note: timer mode 1 (win time events) is not supported\r
- // in linux. But timer mode 2 (spuupdate) is safe to use.\r
- if(iUseTimer) iUseTimer=2; \r
-\r
- strcpy(t,"\nSPUIRQWait");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;} \r
- if(p) iSPUIRQWait=atoi(p+len); \r
- if(iSPUIRQWait<0) iSPUIRQWait=0; \r
- if(iSPUIRQWait>1) iSPUIRQWait=1; \r
-\r
- strcpy(t,"\nUseReverb");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;} \r
- if(p) iUseReverb=atoi(p+len); \r
- if(iUseReverb<0) iUseReverb=0; \r
- if(iUseReverb>2) iUseReverb=2; \r
-\r
- strcpy(t,"\nUseInterpolation");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;} \r
- if(p) iUseInterpolation=atoi(p+len); \r
- if(iUseInterpolation<0) iUseInterpolation=0; \r
- if(iUseInterpolation>3) iUseInterpolation=3; \r
-\r
- free(pB);\r
-}\r
-\r
-/////////////////////////////////////////////////////////\r
-// READ CONFIG called by spu funcs\r
-/////////////////////////////////////////////////////////\r
-\r
-void ReadConfigSPU(void)\r
-{\r
- iVolume=2;\r
- iXAPitch=0;\r
- iSPUIRQWait=0;\r
- iUseTimer=2;\r
- iUseReverb=2;\r
- iUseInterpolation=2;\r
-\r
- ReadConfigFile();\r
-}\r
+++ /dev/null
-/***************************************************************************\r
- cfg.h - description\r
- -------------------\r
- begin : Wed May 15 2002\r
- copyright : (C) 2002 by Pete Bernert\r
- email : BlackDove@addcom.de\r
- ***************************************************************************/\r
-/***************************************************************************\r
- * *\r
- * This program is free software; you can redistribute it and/or modify *\r
- * it under the terms of the GNU General Public License as published by *\r
- * the Free Software Foundation; either version 2 of the License, or *\r
- * (at your option) any later version. See also the license.txt file for *\r
- * additional informations. *\r
- * *\r
- ***************************************************************************/\r
-\r
-void ReadConfigSPU(void);\r
-void StartCfgTool(char * pCmdLine);\r
\r
extern int iVolume;\r
extern int iXAPitch;\r
-extern int iUseTimer;\r
extern int iSPUIRQWait;\r
extern int iDebugMode;\r
extern int iRecordMode;\r
extern unsigned short spuStat;\r
extern unsigned short spuIrq;\r
extern unsigned long spuAddr;\r
-extern int bEndThread; \r
-extern int bThreadEnded;\r
extern int bSpuInit;\r
extern unsigned int dwNewChannel;\r
extern unsigned int dwChannelOn;\r
\r
if(ulFreezeMode==2) return 1; // info mode? ok, bye\r
// save mode:\r
- RemoveTimer(); // stop timer\r
-\r
memcpy(pF->cSPURam,spuMem,0x80000); // copy common infos\r
memcpy(pF->cSPUPort,regArea,0x200);\r
\r
pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;\r
}\r
\r
- SetupTimer(); // sound processing on again\r
-\r
return 1;\r
//--------------------------------------------------//\r
}\r
\r
if(ulFreezeMode!=0) return 0; // bad mode? bye\r
\r
- RemoveTimer(); // we stop processing while doing the save!\r
-\r
memcpy(spuMem,pF->cSPURam,0x80000); // get ram\r
memcpy(regArea,pF->cSPUPort,0x200);\r
\r
// fix to prevent new interpolations from crashing\r
for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;\r
\r
- SetupTimer(); // start sound processing again\r
+ ClearWorkingState();\r
\r
return 1;\r
}\r
#include "externals.h"
#include "registers.h"
-#include "cfg.h"
#include "dsoundoss.h"
#ifdef ENABLE_NLS
int iVolume=768; // 1024 is 1.0
int iXAPitch=1;
-int iUseTimer=2;
int iSPUIRQWait=1;
int iDebugMode=0;
int iRecordMode=0;
unsigned short spuStat=0;
unsigned short spuIrq=0;
unsigned long spuAddr=0xffffffff; // address into spu mem
-int bEndThread=0; // thread handlers
-int bThreadEnded=0;
int bSpuInit=0;
int bSPUIsOpen=0;
-static pthread_t thread = (pthread_t)-1; // thread id (linux)
-
unsigned int dwNewChannel=0; // flags for faster testing, if new channel starts
unsigned int dwChannelOn=0; // not silent channels
unsigned int dwPendingChanOff=0;
////////////////////////////////////////////////////////////////////////
// MAIN SPU FUNCTION
-// here is the main job handler... thread, timer or direct func call
+// here is the main job handler...
// basically the whole sound processing is done in this fat func!
////////////////////////////////////////////////////////////////////////
-// 5 ms waiting phase, if buffer is full and no new sound has to get started
-// .. can be made smaller (smallest val: 1 ms), but bigger waits give
-// better performance
-
-#define PAUSE_W 5
-#define PAUSE_L 5000
-
-////////////////////////////////////////////////////////////////////////
-
-static void *MAINThread(void *arg)
+static int do_samples(void)
{
int volmult = iVolume;
int ns,ns_from,ns_to;
int ch,d,silentch;
int bIRQReturn=0;
- while(!bEndThread) // until we are shutting down
+ while(1)
{
// ok, at the beginning we are looking if there is
// enuff free place in the dsound/oss buffer to
}
else iSecureStart=0; // 0: no new channel should start
- while(!iSecureStart && !bEndThread && // no new start? no thread end?
+ if(!iSecureStart && // no new start?
(SoundGetBytesBuffered()>TESTSIZE)) // and still enuff data in sound buffer?
{
- iSecureStart=0; // reset secure
-
- if(iUseTimer) return 0; // linux no-thread mode? bye
- usleep(PAUSE_L); // else sleep for x ms (linux)
-
- if(dwNewChannel) iSecureStart=1; // if a new channel kicks in (or, of course, sound buffer runs low), we will leave the loop
+ return 0;
}
//--------------------------------------------------// continue from irq handling in timer mode?
{
iSpuAsyncWait=1;
bIRQReturn=0;
- if(iUseTimer!=2)
- {
- DWORD dwWatchTime=timeGetTime_spu()+2500;
-
- while(iSpuAsyncWait && !bEndThread &&
- timeGetTime_spu()<dwWatchTime)
- usleep(1000L);
- continue;
- }
- else
- {
- return 0;
- }
+ return 0;
}
}
}
- // end of big main loop...
-
- bThreadEnded = 1;
-
return 0;
}
if(iSpuAsyncWait)
{
iSpuAsyncWait++;
- if(iSpuAsyncWait<=16/2) return;
+ if(iSpuAsyncWait<=16/FRAG_MSECS) return;
iSpuAsyncWait=0;
}
- if(iUseTimer==2) // special mode, only used in Linux by this spu (or if you enable the experimental Windows mode)
- {
- if(!bSpuInit) return; // -> no init, no call
+ if(!bSpuInit) return; // -> no init, no call
- MAINThread(0); // -> linux high-compat mode
+ do_samples();
- // abuse iSpuAsyncWait mechanism to reduce calls to above function
- // to make it do larger chunks
- // note: doing it less often than once per frame causes skips
- iSpuAsyncWait=1;
- }
+ // abuse iSpuAsyncWait mechanism to reduce calls to above function
+ // to make it do larger chunks
+ // note: doing it less often than once per frame causes skips
+ iSpuAsyncWait=1;
}
// SPU UPDATE... new epsxe func
return FeedCDDA((unsigned char *)pcm, nbytes);
}
-// SETUPTIMER: init of certain buffers and threads/timers
-void SetupTimer(void)
+// to be called after state load
+void ClearWorkingState(void)
{
memset(SSumLR,0,sizeof(SSumLR)); // init some mixing buffers
- memset(iFMod,0,NSSIZE*sizeof(int));
+ memset(iFMod,0,sizeof(iFMod));
pS=(short *)pSpuBuffer; // setup soundbuffer pointer
-
- bEndThread=0; // init thread vars
- bThreadEnded=0;
- bSpuInit=1; // flag: we are inited
-
- if(!iUseTimer) // linux: use thread
- {
- pthread_create(&thread, NULL, MAINThread, NULL);
- }
-}
-
-// REMOVETIMER: kill threads/timers
-void RemoveTimer(void)
-{
- bEndThread=1; // raise flag to end thread
-
- if(!iUseTimer) // linux tread?
- {
- int i=0;
- while(!bThreadEnded && i<2000) {usleep(1000L);i++;} // -> wait until thread has ended
- if(thread!=(pthread_t)-1) {pthread_cancel(thread);thread=(pthread_t)-1;} // -> cancel thread anyway
- }
-
- bThreadEnded=0; // no more spu is running
- bSpuInit=0;
}
// SETUPSTREAMS: init most of the spu buffers
s_chan[i].pCurr=spuMemC;
}
- pMixIrq=spuMemC; // enable decoded buffer irqs by setting the address
+ pMixIrq=spuMemC; // enable decoded buffer irqs by setting the address
+
+ ClearWorkingState();
+
+ bSpuInit=1; // flag: we are inited
}
// REMOVESTREAMS: free most buffer
spuIrq = 0;
spuAddr = 0xffffffff;
- bEndThread = 0;
- bThreadEnded = 0;
spuMemC = (unsigned char *)spuMem;
pMixIrq = 0;
memset((void *)s_chan, 0, (MAXCHAN + 1) * sizeof(SPUCHAN));
//iSPUIRQWait = 0;
lastch = -1;
- //ReadConfigSPU(); // read user stuff
SetupStreams(); // prepare streaming
return 0;
if (bSPUIsOpen) return 0; // security for some stupid main emus
SetupSound(); // setup sound (before init!)
- SetupTimer(); // timer for feeding data
bSPUIsOpen = 1;
bSPUIsOpen = 0; // no more open
- RemoveTimer(); // no more feeding
RemoveSound(); // no more sound handling
return 0;
{
SPUclose();
RemoveStreams(); // no more streaming
+ bSpuInit=0;
return 0;
}
* *\r
***************************************************************************/\r
\r
-void SetupTimer(void);\r
-void RemoveTimer(void);\r
+void ClearWorkingState(void);\r
void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap);\r
int CALLBACK SPUplayCDDAchannel(short *pcm, int bytes);\r