From c2acd80236e0e4a11270e9a1eb342f37f2af3e2b Mon Sep 17 00:00:00 2001 From: "gregory.hainaut" Date: Wed, 11 Sep 2013 20:56:48 +0000 Subject: [PATCH] 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 --- plugins/spu2-x/src/Timestretcher.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/spu2-x/src/Timestretcher.cpp b/plugins/spu2-x/src/Timestretcher.cpp index 5466a876d0..f11b0a4468 100644 --- a/plugins/spu2-x/src/Timestretcher.cpp +++ b/plugins/spu2-x/src/Timestretcher.cpp @@ -98,22 +98,21 @@ int targetIPS=750; //#define NEWSTRETCHER_USE_DYNAMIC_TUNING -//running average can be implemented in O(1) time. +//running average can be implemented in O(1) time. //For the sake of simplicity, this average is calculated in O(). 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