
#if 0
void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _Size)
{
    u16* pTest = (u16*)&_rPB;

	// Checks at 0293
    if (pTest[0x00] == 0) 
        return;

    if (pTest[0x01] != 0)
        return;
  

    if (pTest[0x06] != 0x00)
    {
        // probably pTest[0x06] == 0 -> AFC (and variants)
		// See 02a4
    }
    else
    {
        switch (_rPB.type)  // or Bytes per Sample
        {
        case 0x05:
        case 0x09:
            {
                // initialize "decoder" if the sample is played the first time
                if (pTest[0x04] != 0)
                {
					// This is 0717_ReadOutPBStuff

					// increment 4fb

                    // zelda: 
                    // perhaps init or "has played before"
                    pTest[0x32] = 0x00;
					pTest[0x66] = 0x00;     // history1 
                    pTest[0x67] = 0x00;     // history2 

                    // samplerate? length? num of samples? i dunno...
					// Likely length...
                    pTest[0x3a] = pTest[0x8a];
                    pTest[0x3b] = pTest[0x8b];

                    // Copy ARAM addr from r to rw area.
                    pTest[0x38] = pTest[0x8c];
                    pTest[0x39] = pTest[0x8d];
                }

                if (pTest[0x01] != 0)  // 0747 early out... i dunno if this can happen because we filter it above
                    return;

                u32 ARAMAddr        = (pTest[0x38] << 16) | pTest[0x39];
                u32 NumberOfSamples = (pTest[0x3a] << 16) | pTest[0x3b];

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

                u8 inBuffer[9];
                short outbuf[16];
                u32 sampleCount = 0;

				// It must be something like this:

				// The PB contains a small sample buffer of 0x4D decoded samples.
				// If it's empty or "used", decode to it.
				// Then, resample from this buffer to the output as you go. When it needs
				// wrapping, decode more.
				
#define USE_RESAMPLE
#if !defined(USE_RESAMPLE)
                for (int s = 0; s < _Size/16; s++)
                {
                    for (int i = 0; i < 9; i++)    
                    {
                        inBuffer[i] = DSP::ReadARAM(ARAMAddr);
                        ARAMAddr++;
                    }
                                        
                    AFCdecodebuffer((char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67]);

                    for (int i = 0; i < 16; i++)
                    {
                        templbuffer[sampleCount] += outbuf[i];
                        temprbuffer[sampleCount] += outbuf[i];
                        sampleCount++;
                    }

                    NumberOfSamples--;

                    if (NumberOfSamples<=0)
                        break;
                }
#else
                while (NumberOfSamples > 0)
                {
                    for (int i = 0; i < 9; i++)    
                    {
                        inBuffer[i] =  DSP::ReadARAM(ARAMAddr);
                        ARAMAddr++;
                    }

                    AFCdecodebuffer(m_AFCCoefTable, (char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67], 9);
                    CResampler Sampler(outbuf, 16, 48000);

                    while (Sampler.m_queueSize > 0) 
                    {
                        int sample = Sampler.sample_queue.front();
                        Sampler.sample_queue.pop();
                        Sampler.m_queueSize -= 1;

                        templbuffer[sampleCount] += sample;
                        temprbuffer[sampleCount] += sample;
                        sampleCount++;

                        if (sampleCount > _Size)
                            break;
                    }

                    if (sampleCount > _Size)
                        break;

                    NumberOfSamples--;
                }
#endif
                if (NumberOfSamples == 0)
                {
                    pTest[0x01] = 1; // we are done ??
                }

                // write back
                NumberOfSamples = (NumberOfSamples << 4);    // missing fraction

                pTest[0x38] = ARAMAddr >> 16;
                pTest[0x39] = ARAMAddr & 0xFFFF;
                pTest[0x3a] = NumberOfSamples >> 16;
                pTest[0x3b] = NumberOfSamples & 0xFFFF;
                

#if 0
                NumberOfSamples = (NumberOfSamples + 0xf) >> 4;
                
                static u8 Buffer[500000];
                for (int i =0; i<NumberOfSamples*9; i++)
                {
                    Buffer[i] = DSP::ReadARAM(ARAMAddr+i);
                }

                // yes, the dumps are really zelda sound ;)
                DumpAFC(Buffer, NumberOfSamples*9, 0x3d00);

                DumpPB(_rPB);

             //   exit(1);
#endif

                // i think  pTest[0x3a] and pTest[0x3b] got an update after you have decoded some samples...
                // just decrement them with the number of samples you have played
                // and incrrease the ARAM Offset in pTest[0x38], pTest[0x39]


                // end of block (Zelda 03b2)
                if (pTest[0x06] == 0)
                {
					// 02a4
					//

                    pTest[0x04] = 0;
                }
            }
            break;

        default:
			ERROR_LOG(DSPHLE, "Zelda Ucode: Unknown PB type %i", _rPB.type);
			break;
        }
    }
}
#endif
