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"); } }
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; }
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); } } }