spu2x: correct the modulo parameter of the Timestretcher. Use a size of 128 so the compiler can optimize the code a bit.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5728 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-09-11 20:56:48 +00:00
parent 44d8301bb2
commit c2acd80236
1 changed files with 6 additions and 7 deletions

View File

@ -101,19 +101,18 @@ int targetIPS=750;
//running average can be implemented in O(1) time.
//For the sake of simplicity, this average is calculated in O(<buffer-size>). Possibly improve later.
//
//Additional performance note: if MAX_STRETCH_AVERAGE_LEN = 128 (or any power of 2), the '%' below
//could be replaced with a faster '&'. However analysis of NEWSTRETCHER_USE_DYNAMIC_TUNING impact must be done
#define MAX_STRETCH_AVERAGE_LEN 100
// Use a power of 2 numbers so the compiler can optimize 'modulo' as 'and'
#define MAX_STRETCH_AVERAGE_LEN 128
int STRETCH_AVERAGE_LEN=50.0 *targetIPS/750;
//adds a value to the running average buffer, and return new running average.
float addToAvg(float val){
static float avg_fullness[MAX_STRETCH_AVERAGE_LEN]={0};
static int nextAvgPos=0;
static uint nextAvgPos=0;
avg_fullness[nextAvgPos]=val;
nextAvgPos=(nextAvgPos+1)%STRETCH_AVERAGE_LEN;
nextAvgPos=(nextAvgPos+1)%MAX_STRETCH_AVERAGE_LEN;
float sum=0;
for(int c=0, i=(nextAvgPos+STRETCH_AVERAGE_LEN-1)%STRETCH_AVERAGE_LEN; c<STRETCH_AVERAGE_LEN; c++, i=(i+STRETCH_AVERAGE_LEN-1)%STRETCH_AVERAGE_LEN)
for(int c=0, i=(nextAvgPos+MAX_STRETCH_AVERAGE_LEN-1)%MAX_STRETCH_AVERAGE_LEN; c<STRETCH_AVERAGE_LEN; c++, i=(i+MAX_STRETCH_AVERAGE_LEN-1)%MAX_STRETCH_AVERAGE_LEN)
sum+=avg_fullness[i];
sum= (float)sum/(float)STRETCH_AVERAGE_LEN;