Dolphin, the GameCube and Wii emulator - Forums

Full Version: [PATCH] DSP-HLE Plugin: Zelda TP Intro Music [OBSOLETE]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Ok, copy paste of my own issue on UCode_Zelda_voice.cpp:

i guys, posting this here couse in main forum there isn't activity.
So, straight to the point:

At the begining of the file, line 29, it apperas the following code:

u16 *memory = (u16*)g_dspInitialize.pGetMemoryPointer(_Addr);

and so on on line 48. I was searching about trying to fix mario galaxy bgm, but i found on the docs that the game use dma version, wich is exactly teh game uses, i.e, pGetMemoryPointer. after all this, i think there must be some kind of iIFDEF function, to make the case if is dma version or something else, couse i think is making conflict with accelerator on line 145 and so on, on finish-up loop and main render loop on RenderVoice_PCM16. Correct me if i'm wrong plz, to search for another side. greets

Other thing that i found, is that removing PB.NeedsReset = 0; from line 41, of the same cpp file (UCode_Zelda_voice.cpp), inside If on line 21 i think, will do the same like before, i mean, making super mario galaxy play music. Greets
The problem appears to be somewhere in this block of code, anyone who is familiar with coding and/or emulation can take a shot at it. I'm just giving a possible starting point, I may not be correct about this being the problematic code since I'm not a coder.

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

void CUCode_Zelda::RenderVoice_PCM16(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    if (PB.NeedsReset)
    {
        UpdateSampleCounters10(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;  // Doesn't belong here, but dunno where to do it.
    }
    if (PB.ReachedEnd)
    {
        PB.ReachedEnd = 0;
reached_end:
        if (!PB.RepeatMode) {
            // One shot - play zeros the rest of the buffer.
clear_buffer:
            for (u32 i = 0; i < rem_samples; i++)
                *_Buffer++ = 0;
            PB.KeyOff = 1;
            return;
        }
        else
        {
            PB.RestartPos = PB.LoopStartPos;
            UpdateSampleCounters10(PB);
        }
    }
    // SetupAccelerator
    const s16 *read_ptr = (s16*)GetARAMPointer(PB.CurAddr);
    if (PB.RemLength < (u32)rem_samples)
    {
        // finish-up loop
        for (u32 i = 0; i < PB.RemLength; i++)
            *_Buffer++ = Common::swap16(*read_ptr++);
        rem_samples -= PB.RemLength;
        goto reached_end;
    }
    // main render loop
    for (u32 i = 0; i < rem_samples; i++)
        *_Buffer++ = Common::swap16(*read_ptr++);

    PB.RemLength -= rem_samples;
    if (PB.RemLength == 0)
        PB.ReachedEnd = 1;
    PB.CurAddr += rem_samples << 1;
}
xD, we are looking at the same thing, ar u online now?
Why, what code are you looking at? There is no such code as PB.NeedsReset == 0 on line 41 according to the line graph in Visual Studio.
look, at this:
Code:
void CUCode_Zelda::RenderVoice_PCM16(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    if (PB.NeedsReset)
    {
        [color=#FF0000]PB.NeedsReset = 0;    // Necessary for SMG for start playing[/color] BGM, don't know why yet
        UpdateSampleCounters10(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;
    }
    if (PB.ReachedEnd)
    {
reached_end:
        PB.ReachedEnd = 0;
        if (!PB.RepeatMode) {
            // One shot - play zeros the rest of the buffer.
clear_buffer:
            for (u32 i = 0; i < rem_samples; i++)
                *_Buffer++ = 0;
            PB.KeyOff = 1;
            return;
        }
        else
        {
            PB.RestartPos = PB.LoopStartPos;
            UpdateSampleCounters10(PB);
        }
    }
    // SetupAccelerator
    const s16 *read_ptr = (s16*)GetARAMPointer(PB.CurAddr);
    if (PB.RemLength < (u32)rem_samples)
    {
        // finish-up loop
        for (u32 i = 0; i < PB.RemLength; i++)
            *_Buffer++ = Common::swap16(*read_ptr++);
        rem_samples -= PB.RemLength;
        goto reached_end;
    }
    // main render loop
    for (u32 i = 0; i < rem_samples; i++)
        *_Buffer++ = Common::swap16(*read_ptr++);

    PB.RemLength -= rem_samples;
    if (PB.RemLength == 0)
        PB.ReachedEnd = 1;
    PB.CurAddr += rem_samples << 1;
}

The red one part, was before here marked with blue:

Code:
        case 0x0006:
            WARN_LOG(DSPHLE, "Synthesizing 0x0006 (constant sound)");
            RenderSynth_Constant(PB, m_VoiceBuffer, _Size);
            break;
                        
          // These are more "synth" formats - square wave, saw wave etc.
        case 0x0002:
            WARN_LOG(DSPHLE, "PB Format 0x02 used!");
            break;
                    
        case 0x0004: // Example: Big Pikmin onion mothership landing/building a bridge in Pikmin
        case 0x0007: // Example: "success" SFX in Pikmin 1, Pikmin 2 in a cave, not sure what sound it is.
        case 0x000b: // Example: SFX in area selection menu in Pikmin
        case 0x000c: // Example: beam of death/yellow force-field in Temple of the Gods, ZWW
            RenderSynth_WaveTable(PB, m_VoiceBuffer, _Size);
            break;

        default:
            // TODO: Implement general decoder here
            memset(m_VoiceBuffer, 0, _Size * sizeof(s32));
            ERROR_LOG(DSPHLE, "Unknown MixAddVoice format in zelda %04x", PB.Format);
            break;
        }
    }
  
ContinueWithBlock:    
    if (PB.FilterEnable)
    {  // 0x04a8
        for (int i = 0; i < _Size; i++)
        {
            // TODO: Apply filter from ZWW: 0c84_FilterBufferInPlace
        }
    }
[color=#0000CD]PB.NeedsReset = 0;[/color]

ups, the code thing doesn't show colores xD, mmm let me search on original .cpp, couse i have modified mine, wait a sec
there it is, take a look at original code, line 584, that code i moved up
i moved it and placed on line 124
(06-27-2010, 12:48 PM)Xtreme2damax Wrote: [ -> ]Why, what code are you looking at? There is no such code as PB.NeedsReset == 0 on line 41 according to the line graph in Visual Studio.

xD my mistake, error of mine, in this post i've put the right line xD
This investigation issue is for BGM mario galaxy 1 and 2.
I was thinking that the code is not the root of the problem:

Code:
void CUCode_Zelda::RenderVoice_PCM16(ZeldaVoicePB &PB, s16 *_Buffer, int _Size)
{
    int _RealSize = SizeForResampling(PB, _Size, PB.RatioInt);
    u32 rem_samples = _RealSize;
    if (PB.KeyOff)
        goto clear_buffer;
    if (PB.NeedsReset)
    {
        UpdateSampleCounters10(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;  // Doesn't belong here, but dunno where to do it.
    }
    if (PB.ReachedEnd)
    {
        PB.ReachedEnd = 0;
reached_end:
        if (!PB.RepeatMode) {
            // One shot - play zeros the rest of the buffer.
clear_buffer:
            for (u32 i = 0; i < rem_samples; i++)
                *_Buffer++ = 0;
            PB.KeyOff = 1;
            return;
        }
        else
        {
            PB.RestartPos = PB.LoopStartPos;
            UpdateSampleCounters10(PB);
        }
    }
    // SetupAccelerator
    const s16 *read_ptr = (s16*)GetARAMPointer(PB.CurAddr);
    if (PB.RemLength < (u32)rem_samples)
    {
        // finish-up loop
        for (u32 i = 0; i < PB.RemLength; i++)
            *_Buffer++ = Common::swap16(*read_ptr++);
        rem_samples -= PB.RemLength;
        goto reached_end;
    }
    // main render loop
    for (u32 i = 0; i < rem_samples; i++)
        *_Buffer++ = Common::swap16(*read_ptr++);

    PB.RemLength -= rem_samples;
    if (PB.RemLength == 0)
        PB.ReachedEnd = 1;
    PB.CurAddr += rem_samples << 1;
}

Look close at:

Code:
if (PB.NeedsReset)
    {
        UpdateSampleCounters10(PB);
        for (int i = 0; i < 4; i++)
            PB.ResamplerOldData[i] = 0;  // Doesn't belong here, but dunno where to do it.
    }

the If function states PB.NeedsReset == 1, couse in UCode_Zelda.h ; NeedsReset say that if is equal to 1, the counters must be reset, but i think that actually doesn't happen for this reasons:

1- If you put: PB.NeedsReset = 0; inside that IF, actually it will do the same thing taht if is was on line 584. And the commentary says, that if you don't use PB.NeedsReset = 0, the BGM won't sound at all and the result will be a scratchy glitchy sound.

2- On the other hand, if you put the PB.NeedsReset = 0; inside of:

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

It actually will do the same work as if it was on lin 584.

So i think something is wrong before line 108. Sorry for my bad english. Bye
I tested the change you mentioned and it has no effect on the music looping issue. To be quite honest, the developers should be the ones doing this since they actually know how to code and have conducted tests on the actual hardware, but they seem not to care too much about DSP emulation or any of the other important issues such as the famous Hyrule Field slowdown issue as of lately. The project seems less active now and whenever there are commits more issues arise due to poor coding than 1000 - 2000 or so revisions ago. Although I have to commend the developers that are actually doing a good job.
(06-27-2010, 03:53 PM)Xtreme2damax Wrote: [ -> ][...] To be quite honest, the developers should be the ones doing this since they actually know how to code and have conducted tests on the actual hardware, but they seem not to care too much about DSP emulation or any of the other important issues such as the famous Hyrule Field slowdown issue as of lately. The project seems less active now and whenever there are commits more issues arise due to poor coding than 1000 - 2000 or so revisions ago. Although I have to commend the developers that are actually doing a good job.

Please stay on topic... The developers spend their freetime to improve the emulator so they can do whatever they like. In addition, the project was dead before they came. So little improvement is better than no improvement. If you want to state that DirectX11 support and the repairing of major issues with the graphic is only a little improvement.... So no more "bashing" of the coders, please. Smile

OK, back to topic: If you want to improve the code, you could try to match the DSP_UC_Zelda.txt with UCode_Zelda_Voice.cpp
I was not trying to repair the music looping issue, i only showed how does PB.NeedsReset (if you dont use PB.NeedsReset = 0; like i showed on my previous post, then the music wont start at all, taht is the strange thing)affect ONLY for play BGM on mario galaxy, that's why i stated that the problem maybe isn't on the PCM16 render, maybe is before that, when it reads voices
(06-27-2010, 07:38 PM)neXus Wrote: [ -> ]
(06-27-2010, 03:53 PM)Xtreme2damax Wrote: [ -> ][...] To be quite honest, the developers should be the ones doing this since they actually know how to code and have conducted tests on the actual hardware, but they seem not to care too much about DSP emulation or any of the other important issues such as the famous Hyrule Field slowdown issue as of lately. The project seems less active now and whenever there are commits more issues arise due to poor coding than 1000 - 2000 or so revisions ago. Although I have to commend the developers that are actually doing a good job.

Please stay on topic... The developers spend their freetime to improve the emulator so they can do whatever they like. In addition, the project was dead before they came. So little improvement is better than no improvement. If you want to state that DirectX11 support and the repairing of major issues with the graphic is only a little improvement.... So no more "bashing" of the coders, please. Smile

OK, back to topic: If you want to improve the code, you could try to match the DSP_UC_Zelda.txt with UCode_Zelda_Voice.cpp

I am aware of that..

My point is that all we the end users can do is speculate and tinker with the code hoping that it may fix an issue, while the developers are able to actually fix the issues. There doesn't seem to be much interest from them to fix these sound issues that have been around for about a year now, DSP development flourished in the past about 1500 - 2000 revisions or so ago and fizzled out. DSP emulation isn't the only thing receiving little attention considering there are quite a bit of critical/important issues posted on the issue tracker (Hyrule Field Slowdowns), issues that have existed for a while and are receiving very little attention and still remained unfixed to this day.

I'm not sure if they hit a roadblock or ran into other issues when working on DSP emulation and other issues, but some feedback from the developers would be appreciated.

As I mentioned I commend those that are doing a good job or anyone that is contributing to the project and hope I can do the same someday. Smile
Pages: 1 2 3 4 5 6 7 8 9 10 11 12