libretro / desmume

DeSmuME is a Nintendo DS emulator
http://desmume.org
GNU General Public License v2.0
35 stars 33 forks source link

Possibility to turn off Advanced SPU Logic (Fixes some audio issues)? #87

Open lukek19 opened 2 years ago

lukek19 commented 2 years ago

I was wondering if it was possible to add the option to turn off the Advanced SPU Logic to the libretro core? For me, this is the only way to fix the audio issues with the echo/reverb effect in Phantom Hourglass (#43) (tested it on the standalone version).

lukek19 commented 2 years ago

I can now confirm that the fix also works on the libretro core. I managed to build the core with the Advanced SPU Logic switched off by default, and it does indeed solve the issue with the reverb effect (albeit at the cost of having no reverb at all – but the effect isn't that great anyway). So a simple switch in the core options menu would be great for people who are experiencing the same problems.

Nova77x commented 2 years ago

If anyone wants to apply the fix themselves:

Install msys https://www.msys2.org/#installation

Launch MSYS2 MinGW x64

pacman -S mingw-w64-x86_64-gcc pacman -S make

cd "/drive/folder/desmume-master/desmume/src/frontend/libretro"

make clean

make platform=windows

SPU.cpp

/*
if (advanced && SPU == SPU_core)
    {
        SPU_MixAudio_Advanced(actuallyMix, SPU, length);
    }
    else
    {
*/

//  } //non-advanced branch

To blow out the candles in phantom hourglass, apply this fix. Make sure "pattern" is selected in the options. It seems the pattern needed a minimum length of 128. It's taken from a recording of an actual blowing sound.

mic.cpp

static u8 Mic_GenerateInternalNoiseSample(void)
{
    const u8 noiseSample[NUM_INTERNAL_NOISE_SAMPLES] =
    {
        //0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF5, 0xFF, 0xFF, 0xFF, 0xFF, 0x8E, 0xFF, 
        //0xF4, 0xE1, 0xBF, 0x9A, 0x71, 0x58, 0x5B, 0x5F, 0x62, 0xC2, 0x25, 0x05, 0x01, 0x01, 0x01, 0x01

        0x08, 0x93, 0xff, 0xdf, 0x10, 0x01, 0x1b, 0xe6, 0xff, 0xf9, 0xff, 0xab, 0x00, 0x04, 0x19, 0xe4, 
        0xf4, 0xf8, 0xff, 0x7a, 0x00, 0x06, 0x16, 0xe3, 0xff, 0xdd, 0x07, 0x00, 0x8a, 0xff, 0xf9, 0xf8, 
        0xd4, 0x1c, 0x0a, 0x99, 0xff, 0x46, 0x00, 0x09, 0x6e, 0xe2, 0x02, 0x09, 0x0d, 0x04, 0x02, 0x01, 
        0x0d, 0x09, 0x04, 0x06, 0x00, 0x00, 0x09, 0x1c, 0x04, 0x3f, 0xfd, 0xfa, 0xf4, 0x33, 0x00, 0x33, 
        0xff, 0xfc, 0xfb, 0xf9, 0xfd, 0xfd, 0xe9, 0xf4, 0xfa, 0xff, 0xdf, 0x06, 0x00, 0x03, 0x00, 0x03, 
        0x07, 0x2d, 0xef, 0x33, 0x00, 0x14, 0x00, 0x04, 0x66, 0x97, 0x00, 0x11, 0x00, 0x06, 0xc1, 0xff, 
        0xf8, 0xce, 0x00, 0x01, 0x53, 0xff, 0xfb, 0xfc, 0xcc, 0x00, 0x43, 0xff, 0xf5, 0xf9, 0xeb, 0xf4, 
        0xff, 0xf6, 0x6e, 0x00, 0x8e, 0xff, 0xe7, 0xe4, 0x68, 0x00, 0x0b, 0x00, 0x02, 0x07, 0x00, 0x03
    };
    static unsigned int i = 0;

    if (++i >= NUM_INTERNAL_NOISE_SAMPLES) {
        i = 0;
    }

    return noiseSample[i];
}

Also regarding phantom hourglass, to autohide the cursor when not in use with the d-pad patch. Default is 500ms. Something really needs to be done about that tiny thin crosshair, it's... not great.

frontend/libretro/main.cpp

#include <chrono>
#include <sys/time.h>
#include <ctime>

using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::system_clock;

int cursor_timer = 0;
int prev_cursor_timer = 0;
bool hide_cursor = true;

static void DrawPointer(uint16_t* aOut, uint32_t aPitchInPix)
{
   if (hide_cursor)
      return;

   (...)
}

static void DrawPointerHybrid(uint16_t* aOut, uint32_t aPitchInPix, bool large)
{
   if (hide_cursor)
      return;

   (...)
}

void retro_run (void)
{

(...)

   if(radius > (float)analog_stick_deadzone*max/100)
   {
      (...)
      hide_cursor = false;
      prev_cursor_timer = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
   }
   else {
      if (!hide_cursor) {
         cursor_timer = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

         if ((cursor_timer - prev_cursor_timer) > 500)
         {
            hide_cursor = true;
         }
      } 
   }

(...)

}

Also the mouse acceleration is wrong, it decreases it rather than increasing it. Fix:

frontend/libretro/main.cpp

float final_acceleration = analog_stick_acceleration * (1.0 - (float)analog_stick_acceleration_modifier / 100.0);