Skip to content

Commit

Permalink
PCM Track Fix
Browse files Browse the repository at this point in the history
Fixed bug where PCM audio tracks could not be replaced. Fix from mobile, may not have valid code syntax.
  • Loading branch information
WesternGamer authored Oct 12, 2023
1 parent 916057b commit 27a2238
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions RDR2AudioTool/ReplaceAudioWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void ReadMp3File(string fileName)

private byte[] EncodeIfNeeded(IWaveProvider reader)
{
if (CodecType == AwcCodecType.ADPCM)
if (CodecType == AwcCodecType.ADPCM || CodecType == AwcCodecType.PCM)
{
WaveFormat format = new WaveFormat(reader.WaveFormat.SampleRate, 16, reader.WaveFormat.Channels);

Expand Down Expand Up @@ -193,56 +193,59 @@ private byte[] EncodeIfNeeded(IWaveProvider reader)
return bytes;
}

if (CodecType == AwcCodecType.VORBIS && reader.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
if (CodecType == AwcCodecType.VORBIS)
{
MemoryStream outputStream = new MemoryStream();

byte[] array = new byte[reader.WaveFormat.AverageBytesPerSecond * 4];
while (true)
if (reader.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
{
int num = reader.Read(array, 0, array.Length);
if (num == 0)
MemoryStream outputStream = new MemoryStream();

byte[] array = new byte[reader.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
break;
}
int num = reader.Read(array, 0, array.Length);
if (num == 0)
{
break;
}

outputStream.Write(array, 0, num);
}
outputStream.Write(array, 0, num);
}

byte[] bytes = outputStream.ToArray();
byte[] bytes = outputStream.ToArray();

outputStream.Dispose();
outputStream.Dispose();

return bytes;
}
else if (CodecType != AwcCodecType.PCM)
{
WaveFormat format = new WaveFormat(reader.WaveFormat.SampleRate, 16, reader.WaveFormat.Channels);
return bytes;
}
else
{
WaveFormat format = new WaveFormat(reader.WaveFormat.SampleRate, 16, reader.WaveFormat.Channels);

MemoryStream outputStream = new MemoryStream();
MemoryStream outputStream = new MemoryStream();

MediaFoundationResampler resampler = new MediaFoundationResampler(reader, format);
MediaFoundationResampler resampler = new MediaFoundationResampler(reader, format);

Wave16ToFloatProvider floatProvider = new Wave16ToFloatProvider(resampler);
Wave16ToFloatProvider floatProvider = new Wave16ToFloatProvider(resampler);

byte[] array = new byte[floatProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int num = floatProvider.Read(array, 0, array.Length);
if (num == 0)
byte[] array = new byte[floatProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
break;
}
int num = floatProvider.Read(array, 0, array.Length);
if (num == 0)
{
break;
}

outputStream.Write(array, 0, num);
}
outputStream.Write(array, 0, num);
}

resampler.Dispose();
resampler.Dispose();

byte[] bytes = outputStream.ToArray();
return bytes;
byte[] bytes = outputStream.ToArray();
return bytes;
}

}

return null;
}
}
Expand Down

0 comments on commit 27a2238

Please sign in to comment.