示例#1
0
        public void Decode(VGM_Stream vgmStream, VGM_Channel vgmChannel, ref short[] vgmOutput, int vgmChannelSpacing,
                           int vgmFirstSample, int vgmSamplesToDo, int vgmChannelNumber)
        {
            int framesin = vgmFirstSample / 14;

            vgmFirstSample = vgmFirstSample % 14;

            byte header     = vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)(framesin * 8));
            int  scale      = 1 << (header & 0xf);
            int  coef_index = (header >> 4) & 0xf;

            int vgmSampleHistory1 = vgmChannel.adpcm_history_32bits_1;
            int vgmSampleHistory2 = vgmChannel.adpcm_history_32bits_2;

            try
            {
                int coef1 = vgmChannel.adpcm_coef[coef_index * 2];
                int coef2 = vgmChannel.adpcm_coef[coef_index * 2 + 1];

                int vgmSampleCount, i;
                int vgmSample;

                for (i = vgmFirstSample, vgmSampleCount = 0; i < vgmFirstSample + vgmSamplesToDo; i++, vgmSampleCount += vgmChannelSpacing)
                {
                    int sample_byte = vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)(framesin * 8 + 1 + i / 2));

                    vgmSample = (((i & 1) == 1) ? VGM_Utils.LOWNIBBLE_SIGNED(sample_byte)
                                                : VGM_Utils.HINIBBLE_SIGNED(sample_byte));

                    vgmSample = ((vgmSample * scale) << 11) + 1024;
                    vgmSample = vgmSample + (coef1 * vgmSampleHistory1 + coef2 * vgmSampleHistory2);
                    vgmSample = vgmSample >> 11;

                    vgmOutput[vgmStream.vgmSamplesBlockOffset + vgmSampleCount + vgmChannelNumber] = VGM_Utils.clamp16(vgmSample);

                    vgmSampleHistory2 = vgmSampleHistory1;
                    vgmSampleHistory1 = vgmSample;
                }

                vgmChannel.adpcm_history_32bits_1 = vgmSampleHistory1;
                vgmChannel.adpcm_history_32bits_2 = vgmSampleHistory2;
            }
            catch (Exception e)
            {
                Console.Write(e.Message + " in DSP_Decoder");
            }
        }
示例#2
0
        public void Decode(VGM_Stream vgmStream, VGM_Channel vgmChannel, ref short[] vgmOutput, int vgmChannelSpacing,
                           int vgmFirstSample, int vgmSamplesToDo, int vgmChannelNumber)
        {
            int vgmSampleCount, i;

            int framesin = vgmFirstSample / 32;

            int scale             = vgmChannel.fReader.Read_16bitsBE(vgmChannel.currentOffset + (UInt64)((framesin * 18) ^ vgmChannel.adx_xor)) + 1;
            int vgmSampleHistory1 = vgmChannel.adpcm_history_32bits_1;
            int vgmSampleHistory2 = vgmChannel.adpcm_history_32bits_2;
            int coef1             = vgmChannel.adpcm_coef[0];
            int coef2             = vgmChannel.adpcm_coef[1];
            int vgmSample;

            vgmFirstSample = vgmFirstSample % 32;

            for (i = vgmFirstSample, vgmSampleCount = 0; i < vgmFirstSample + vgmSamplesToDo; i++, vgmSampleCount += vgmChannelSpacing)
            {
                int sample_byte = vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)((framesin * 18) + 2 + i / 2));

                sample_byte = (((i & 1) == 1) ? VGM_Utils.LOWNIBBLE_SIGNED(sample_byte) : VGM_Utils.HINIBBLE_SIGNED(sample_byte));
                vgmSample   = (sample_byte * scale);
                vgmSample  += (((coef1 * vgmSampleHistory1) + (coef2 * vgmSampleHistory2)) >> 12);
                vgmOutput[vgmStream.vgmSamplesBlockOffset + vgmSampleCount + vgmChannelNumber] = VGM_Utils.clamp16(vgmSample);

                vgmSampleHistory2 = vgmSampleHistory1;
                vgmSampleHistory1 = vgmSample;
            }

            vgmChannel.adpcm_history_32bits_1 = vgmSampleHistory1;
            vgmChannel.adpcm_history_32bits_2 = vgmSampleHistory2;

            if ((i % 32) == 0)
            {
                for (i = 0; i < vgmChannel.adx_channels; i++)
                {
                    VGM_Utils.adx_next_key(ref vgmChannel);
                }
            }
        }