• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Dolphin Site › Dolphin Patches (Archive) v
« Previous 1 ... 3 4 5 6 7 Next »

[Patch] dspHLE Mario galaxy 1 music
View New Posts | View Today's Posts

Pages (18): « Previous 1 ... 3 4 5 6 7 ... 18 Next »
Jump to page 
Thread Rating:
  • 4 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
[Patch] dspHLE Mario galaxy 1 music
08-18-2010, 11:07 AM (This post was last modified: 08-18-2010, 12:25 PM by Xtreme2damax.)
#41
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
Where does UpdateSampleCounters59(PB); come from? Does that come from the AFC decoder and AFC looping, is it listed in the ucode disassm documentation or not? I have an idea how to rework the AFC code which is why I am asking. Smile
Find
08-18-2010, 03:23 PM
#42
Torin Offline
Member
***
Posts: 65
Threads: 4
Joined: Jun 2010
forget that xD, that was a stupid patch xD.
Find
08-18-2010, 03:39 PM (This post was last modified: 08-18-2010, 04:41 PM by Xtreme2damax.)
#43
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
Well it wasn't exactly stupid..

I would like to know where you got it from to see if the UpdateSampleCounters corresponds with AFC audio. I noticed that Render_AFC looks nearly similar to the code for PCM16. I am piecing in some code from PCM16 as the current AFC code is improper and has issues, here is what I've done so far:

Code:
void UpdateSampleCounters59(ZeldaVoicePB &PB)
{
    PB.RemLength = PB.Length - PB.RestartPos;
    PB.CurAddr = PB.StartAddr + (PB.RestartPos << 4);
    PB.ReachedEnd = 0;
}

void CUCode_Zelda::RenderVoice_AFC(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    // TODO: Compare mono, stereo and surround samples
#if defined DEBUG || defined DEBUGFAST
    PrintObject(PB);
#endif

    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    // initialize "decoder" if the sample is played the first time
    if (PB.NeedsReset)
    {
        // This is 0717_ReadOutPBStuff
    // increment 4fb
        // zelda:
        // perhaps init or "has played before"
        PB.CurBlock = 0x00;
        PB.YN2 = 0x00;     // history1
        PB.YN1 = 0x00;     // history2

    // Length in samples.
        PB.RemLength = PB.Length;
        // Copy ARAM addr from r to rw area.
        PB.CurAddr = PB.StartAddr;
        PB.ReachedEnd = 0;
        PB.CurSampleFrac = 0;
        UpdateSampleCounters59(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;
    }
    if (PB.ReachedEnd)
    {
        PB.ReachedEnd = 0;
reached_end:
        if (!PB.RepeatMode) {
            // One shot - play zeros the rest of the buffer.
clear_buffer:
        for (int i = 0; i < _RealSize; i++)
            *_Buffer++ = 0;
        PB.KeyOff = 1;
        return;
    }
        else
        {
            PB.RestartPos = PB.LoopStartPos;
            UpdateSampleCounters59(PB);
        }
    }

There's more to do yet and it seems I haven't broke anything so far, but I need your help and the help of another developer to fix the AFC code completely.

What are these lines of code responsible for, this just looks funky:

Code:
// This is 0717_ReadOutPBStuff
    // increment 4fb
        // zelda:
        // perhaps init or "has played before"
        PB.CurBlock = 0x00;
        PB.YN2 = 0x00;     // history1
        PB.YN1 = 0x00;     // history2

    // Length in samples.
        PB.RemLength = PB.Length;
        // Copy ARAM addr from r to rw area.
        PB.CurAddr = PB.StartAddr;
        PB.ReachedEnd = 0;
        PB.CurSampleFrac = 0;

That isn't in the PCM16 code since it relates to AFC looping. Hopefully if we can get the AFC code more corect'ish it might fix the music looping issue.



This part of the code should be focused on next:

Code:
// Round upwards how many samples we need to copy, 0759
    // u32 frac = NumberOfSamples & 0xF;
    // NumberOfSamples = (NumberOfSamples + 0xf) >> 4;   // i think the lower 4 are the fraction

    const u8 *source;
    u32 ram_mask = 1024 * 1024 * 16 - 1;
    if (IsDMAVersion()) {
        source = g_dspInitialize.pGetMemoryPointer(m_DMABaseAddr);
        ram_mask = 1024 * 1024 * 64 - 1;
    }
    else
        source = g_dspInitialize.pGetARAMPointer();

    int sampleCount = 0;  // must be above restart.

restart:
    if (PB.ReachedEnd)
    {
        PB.ReachedEnd = 0;

        if ((PB.RepeatMode == 0) || (!PB.StopOnSilence == 0))
        {
            PB.KeyOff = 1;
            PB.RemLength = 0;
            PB.CurAddr = PB.StartAddr + PB.RestartPos + PB.Length;
            
            while (sampleCount < _RealSize)
                _Buffer[sampleCount++] = 0;
            return;
        }
        else
        {
            //AFC looping
            // The loop start pos is incorrect? (Fixed?), so samples will loop a bit wrong.
            // this fixes the intro music in ZTP.
            PB.RestartPos = PB.LoopStartPos;
            PB.RemLength = PB.Length - PB.RestartPos;
            // see DSP_UC_Zelda.txt line 2817
            PB.CurAddr = ((((((PB.LoopStartPos >> 4) & 0xffff0000) * PB.Format) << 16) + (((PB.LoopStartPos >> 4) & 0xffff) * PB.Format)) + PB.StartAddr) & 0xffffffff;

            // Hmm, this shouldn't be reversed .. or should it? Is it different between versions of the ucode?
            // -> it has to be reversed in ZTP, otherwise intro music is broken...
            PB.YN1 = PB.LoopYN2;
            PB.YN2 = PB.LoopYN1;
        }
    }

And so on until all of the AFC code is corrected and accounted for. I think the above code is the last piece of code that should be focused on to fix the issue, if not we'll need to go from there to find and fix the issue. I verified that the alterations I made did not have any unwanted side effects, although it does nothing to fix the music looping issue.



According to this it appears the dsp get's desynced, then tries to write to the left/right buffer address and that's when the AFC starts going crazy. Even if this is the issue that still doesn't mean AFC can't be cleaned and properly done as it may save headaches down the road:

http://forums.dolphin-emu.org/thread-10800-post-103192.html#pid103192

Code:
26:25:920 .\Src\UCodes\UCode_Zelda.cpp:433 D[DSPHLE]: ==============================================================================
26:25:920 .\Src\UCodes\UCode_Zelda.cpp:434 D[DSPHLE]: Zelda UCode - execute dlist (cmd: 0x0002 : sync: 0x8207)
26:25:920 .\Src\UCodes\UCode_Zelda.cpp:489 D[DSPHLE]: DsyncFrame
26:25:920 .\Src\UCodes\UCode_Zelda.cpp:492 D[DSPHLE]: Right buffer address: 0x008b6160
26:25:920 .\Src\UCodes\UCode_Zelda.cpp:493 D[DSPHLE]: Left buffer address: 0x008b65c0
Find
08-19-2010, 03:31 AM (This post was last modified: 08-19-2010, 03:33 AM by Xtreme2damax.)
#44
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
I tried with the following code:

Code:
void UpdateSampleCounters4(ZeldaVoicePB &PB)
{
    PB.RemLength = PB.Length - PB.RestartPos;
    PB.CurAddr = PB.StartAddr + (PB.RestartPos << 4);
    PB.ReachedEnd = 0;
}

void CUCode_Zelda::RenderVoice_AFC(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    // TODO: Compare mono, stereo and surround samples
#if defined DEBUG || defined DEBUGFAST
    PrintObject(PB);
#endif

    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    // initialize "decoder" if the sample is played the first time
    if (PB.NeedsReset)
    {
        // This is 0717_ReadOutPBStuff
        // increment 4fb
        // zelda:
        // perhaps init or "has played before"
        PB.CurBlock = 0x32;
        PB.YN2 = 0x66;     // history1
        PB.YN1 = 0x67;     // history2

        // Length in samples.
        PB.RemLength = PB.Length;
        // Copy ARAM addr from r to rw area.
        PB.CurAddr = PB.StartAddr;
        PB.CurSampleFrac = 0;
        UpdateSampleCounters4(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;
    }

    // Round upwards how many samples we need to copy, 0759
    // u32 frac = NumberOfSamples & 0xF;
    // NumberOfSamples = (NumberOfSamples + 0xf) >> 4;   // i think the lower 4 are the fraction

    const u8 *source;
    u32 ram_mask = 1024 * 1024 * 16 - 1;
    if (IsDMAVersion()) {
        source = g_dspInitialize.pGetMemoryPointer(m_DMABaseAddr);
        ram_mask = 1024 * 1024 * 64 - 1;
    }
    else
        source = g_dspInitialize.pGetARAMPointer();

    int sampleCount = 0;  // must be above restart.
restart:
    if (PB.ReachedEnd)
    {
reached_end:
        PB.ReachedEnd = 0;
        if (!PB.RepeatMode){
clear_buffer:
            while (sampleCount < _RealSize)
                _Buffer[sampleCount++] = 0;
            PB.KeyOff = 1;
            return;
        }
        else
        {
            //AFC looping
            // The loop start pos is incorrect? (Fixed?), so samples will loop a bit wrong.
            // this fixes the intro music in ZTP.
            PB.RestartPos = PB.LoopStartPos;
            UpdateSampleCounters4(PB);
            // Hmm, this shouldn't be reversed .. or should it? Is it different between versions of the ucode?
            // -> it has to be reversed in ZTP, otherwise intro music is broken...
            PB.YN1 = PB.LoopYN2;
            PB.YN2 = PB.LoopYN1;
        }
    }

But it produced a loud screeching sound in Windwaker and other games that use AFC. My goal is to get AFC closer to PCM16 code without breaking anything, so far I had to settle with the following until the issues with the above code are worked out:

Code:
void CUCode_Zelda::RenderVoice_AFC(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    // TODO: Compare mono, stereo and surround samples
#if defined DEBUG || defined DEBUGFAST
    PrintObject(PB);
#endif

    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    // initialize "decoder" if the sample is played the first time
    if (PB.NeedsReset)
    {
        // This is 0717_ReadOutPBStuff
        // increment 4fb
        // zelda:
        // perhaps init or "has played before"
        PB.CurBlock = 0x32;
        PB.YN2 = 0x66;     // history1
        PB.YN1 = 0x67;     // history2

        // Length in samples.
        PB.RemLength = PB.Length;
        // Copy ARAM addr from r to rw area.
        PB.CurAddr = PB.StartAddr;
        PB.ReachedEnd = 0;
        PB.CurSampleFrac = 0;

        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;
    }

    // Round upwards how many samples we need to copy, 0759
    // u32 frac = NumberOfSamples & 0xF;
    // NumberOfSamples = (NumberOfSamples + 0xf) >> 4;   // i think the lower 4 are the fraction

    const u8 *source;
    u32 ram_mask = 1024 * 1024 * 16 - 1;
    if (IsDMAVersion()) {
        source = g_dspInitialize.pGetMemoryPointer(m_DMABaseAddr);
        ram_mask = 1024 * 1024 * 64 - 1;
    }
    else
        source = g_dspInitialize.pGetARAMPointer();

    int sampleCount = 0;  // must be above restart.
restart:
    if (PB.ReachedEnd)
    {
reached_end:
        PB.ReachedEnd = 0;
        if (!PB.RepeatMode){
clear_buffer:
            while (sampleCount < _RealSize)
                _Buffer[sampleCount++] = 0;
            PB.KeyOff = 1;
            return;
        }
        else
        {
            //AFC looping
            // The loop start pos is incorrect? (Fixed?), so samples will loop a bit wrong.
            // this fixes the intro music in ZTP.
            PB.RestartPos = PB.LoopStartPos;
            PB.RemLength = PB.Length - PB.RestartPos;
            PB.CurAddr = PB.StartAddr + (PB.LoopStartPos >> 4) * PB.Format;
            // Hmm, this shouldn't be reversed .. or should it? Is it different between versions of the ucode?
            // -> it has to be reversed in ZTP, otherwise intro music is broken...
            PB.YN1 = PB.LoopYN2;
            PB.YN2 = PB.LoopYN1;
        }
    }

Here is a patch of the current work I've done. I've tested and it doesn't appear to break anything, but some widespread testing is needed to confirm. There's still things left to do, I would like to solve the issue with that annoying screeching the first block of code I posted causes.
If any developers spot inconsistencies with the code I've posted, please let me know. Smile


Attached Files
.patch   SMG_Zelda_Looping.patch (Size: 5.65 KB / Downloads: 194)
Find
08-19-2010, 05:29 AM
#45
Jack Frost Offline
aka. BhaaL
**********
Developers (Some Administrators and Super Moderators)
Posts: 510
Threads: 3
Joined: Oct 2009
I don't think thats a good idea, its two different things after all.
Torin and I am working on it anyways, at least when I'm bored enough Smile
Find
08-19-2010, 05:42 AM
#46
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
I haven't really changed the AFC code much, just added some things. The code can be tweaked where appropriate but so far it seems to not broke anything. Do you and Torin know what code is responsible for killing the music and why the music sometimes lasts longer than other times?
Find
08-19-2010, 08:36 AM
#47
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
It seems something in this section of code causes music to break, would anyone know what's wrong with this code by glancing over it?

Code:
restart:
        if (PB.ReachedEnd)
        {
                PB.ReachedEnd = 0;

                if ((PB.RepeatMode == 0) || (!PB.StopOnSilence == 0))
                {
                        PB.KeyOff = 1;
                        PB.RemLength = 0;
                        PB.CurAddr = PB.StartAddr + PB.RestartPos + PB.Length;
                        
                        while (sampleCount < _RealSize)
                                _Buffer[sampleCount++] = 0;
                        return;
                }
                else
                {
                        //AFC looping
                        // The loop start pos is incorrect? (Fixed?), so samples will loop a bit wrong.
                        // this fixes the intro music in ZTP.
                        PB.RestartPos = PB.LoopStartPos;
                        PB.RemLength = PB.Length - PB.RestartPos;
                        // see DSP_UC_Zelda.txt line 2817
                        PB.CurAddr = ((((((PB.LoopStartPos >> 4) & 0xffff0000)*PB.Format)<<16)+
                                (((PB.LoopStartPos >> 4) & 0xffff)*PB.Format))+PB.StartAddr) & 0xffffffff;

                        // Hmm, this shouldn't be reversed .. or should it? Is it different between versions of the ucode?
                        // -> it has to be reversed in ZTP, otherwise intro music is broken...
                        PB.YN1 = PB.LoopYN2;
                        PB.YN2 = PB.LoopYN1;
                }
        }

        short outbuf[16] = {0};
        u16 prev_yn1 = PB.YN1;
        u16 prev_yn2 = PB.YN2;
        u32 prev_addr = PB.CurAddr;

        // Prefill the decode buffer.
    AFCdecodebuffer(m_AFCCoefTable, (char*)(source + (PB.CurAddr & ram_mask)), outbuf, (short*)&PB.YN2, (short*)&PB.YN1, PB.Format);
        PB.CurAddr += PB.Format;  // 9 or 5

        u32 SamplePosition = PB.Length - PB.RemLength;
    while (sampleCount < _RealSize)
    {
                _Buffer[sampleCount] = outbuf[SamplePosition & 15];
                sampleCount++;

                SamplePosition++;
            PB.RemLength--;
                if (PB.RemLength == 0)
                {
                        PB.ReachedEnd = 1;
                        goto restart;
                }
Find
08-20-2010, 02:28 AM
#48
Jack Frost Offline
aka. BhaaL
**********
Developers (Some Administrators and Super Moderators)
Posts: 510
Threads: 3
Joined: Oct 2009
I didn't really intend to look at the code thats there already, I was going to reverse it from scratch. And as far as I know, this wasnt done for AFC, it was more like copied over from PCM and modified a bit.
Find
08-20-2010, 05:46 AM
#49
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
I see, any estimate on how long it will take? I thought it had already been reverse engineered by Lord Mark, nakee and whatever other developers that were working on DSP emulation, it was my understanding that it just hadn't been implemented into the plugin yet. Something also seems amiss with the light Zelda ucode, music does not work in Wario World. I was able to somewhat get the music working by messing with the code for the light Zelda ucode at the bottom of Ucode_Zelda_Voice.cpp.
Find
08-21-2010, 09:29 AM
#50
Xtreme2damax Offline
New & Improved
********
Global Moderators
Posts: 3,135
Threads: 91
Joined: Mar 2009
I know the code for AFC is not the same as it is for PCM16, but I felt this was better than the previous implementation. From what I've tested so far it seems there is no issues with the alterations I made, it may not fix the looping issues but is doesn't seem to cause any problems.

I'm attaching both the patch file and the pre-compiled plugins for x86 and x64, be sure to test thoroughly and report any issues that didn't exist with the previous implementation. Also be sure to report if this fixed anything or not, it's unlikely that it fixed anything though so I'd appreciate any positive news.


.patch   Ucode_Zelda_Voice.patch (Size: 4.45 KB / Downloads: 231)

.7z   Plugin_DSP_HLE_Patched.7z (Size: 1.09 MB / Downloads: 247)
Find
« Next Oldest | Next Newest »
Pages (18): « Previous 1 ... 3 4 5 6 7 ... 18 Next »
Jump to page 


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 1 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode