Esempio n. 1
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))) + 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;
        }
        public void Decode(VGM_Stream vgmStream, VGM_Channel vgmChannel, ref short[] vgmOutput, int vgmChannelSpacing,
                           int vgmFirstSample, int vgmSamplesToDo, int vgmChannelNumber)
        {
            for (int i = vgmFirstSample, vgmSampleCount = 0; i < vgmFirstSample + vgmSamplesToDo; i++, vgmSampleCount += vgmChannelSpacing)
            {
                int offset = vgmStream.vgmSamplesBlockOffset + vgmSampleCount + vgmChannelNumber;

                vgmOutput[offset] = (short)(vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)(i * 2)) * 0x100);
            }
        }
Esempio n. 3
0
        public void Decode(VGM_Stream vgmStream, VGM_Channel vgmChannel, ref short[] vgmOutput, int vgmChannelSpacing,
                           int vgmFirstSample, int vgmSamplesToDo, int vgmChannelNumber)
        {
            int i;

            double vgmSample;
            int    vgmSampleCount;

            double vgmSampleHistory1 = vgmChannel.adpcm_history_dbl_1;
            double vgmSampleHistory2 = vgmChannel.adpcm_history_dbl_2;

            Int16 vgmScale;

            // Get the offset of the correct frame
            Int32 vgmFrameNum = vgmFirstSample / 28;

            Int16 vgmPredictor   = (Int16)(vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)(vgmFrameNum * 16)) >> 4);
            Int16 vgmShiftFactor = (Int16)(vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)(vgmFrameNum * 16)) & 0x0F);
            byte  vgmFlag        = vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)((vgmFrameNum * 16) + 1));

            vgmFirstSample = vgmFirstSample % 28;

            for (i = vgmFirstSample, vgmSampleCount = 0; i < vgmFirstSample + vgmSamplesToDo; i++, vgmSampleCount += vgmChannelSpacing)
            {
                vgmSample = 0;

                if (vgmFlag < 0x07)
                {
                    Int16 sample_byte = vgmChannel.fReader.Read_8Bits(vgmChannel.currentOffset + (UInt64)((vgmFrameNum * 16) + 2 + i / 2));

                    vgmScale = (Int16)(((((i & 1) == 1) ? sample_byte >> 4 : (sample_byte & 0x0f)) << 12));

                    if (vgmPredictor < 5)
                    {
                        vgmSample = (((vgmScale >> vgmShiftFactor) + vgmSampleHistory1 * VAG_f[vgmPredictor, 0] + vgmSampleHistory2 * VAG_f[vgmPredictor, 1]));
                    }
                    else
                    {
                        vgmSample = 0;
                    }
                }
                vgmOutput[vgmStream.vgmSamplesBlockOffset + vgmSampleCount + vgmChannelNumber] = VGM_Utils.clamp16(vgmSample);
                vgmSampleHistory2 = vgmSampleHistory1;
                vgmSampleHistory1 = vgmSample;
            }

            vgmChannel.adpcm_history_dbl_1 = vgmSampleHistory1;
            vgmChannel.adpcm_history_dbl_2 = vgmSampleHistory2;
        }
Esempio n. 4
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");
            }
        }
Esempio n. 5
0
        public void Decode(VGM_Stream vgmStream, VGM_Channel vgmChannel, ref short[] vgmOutput, int vgmChannelSpacing,
                           int vgmFirstSample, int vgmSamplesToDo, int vgmChannelNumber)
        {
            for (int i = vgmFirstSample, vgmSampleCount = 0; i < vgmFirstSample + vgmSamplesToDo; i++, vgmSampleCount += vgmChannelSpacing)
            {
                int offset = vgmStream.vgmSamplesBlockOffset + vgmSampleCount + vgmChannelNumber;

                if (vgmStream.vgmDecoderType == VGM_Decoder_Type.PCM16BITS)
                {
                    vgmOutput[offset] = (short)vgmChannel.fReader.Read_16bits(vgmChannel.currentOffset + (UInt64)(i * 2));
                }
                else
                {
                    vgmOutput[offset] = (short)vgmChannel.fReader.Read_16bitsBE(vgmChannel.currentOffset + (UInt64)(i * 2));
                }
            }
        }
Esempio n. 6
0
 public static void adx_next_key(ref VGM_Channel vgmChannel)
 {
     vgmChannel.adx_xor = (UInt16)((vgmChannel.adx_xor * vgmChannel.adx_mult + vgmChannel.adx_add) & 0x7fff);
 }