CUETools.Codecs.ALAC: fix a bug that was causing corruption of the last 4 bytes in some files.

This commit is contained in:
Grigory Chudov
2018-02-19 14:04:14 -05:00
parent b6fe9968a1
commit 6312b2a86a
3 changed files with 42 additions and 32 deletions

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins"/>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -36,7 +36,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@@ -88,6 +88,9 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -492,14 +492,16 @@ namespace CUETools.Codecs.ALAC
res[0] = smp[0]; res[0] = smp[0];
for (int i = 1; i < n; i++) for (int i = 1; i < n; i++)
res[i] = smp[i] - smp[i - 1]; res[i] = smp[i] - smp[i - 1];
} res[n] = 1; // Stop byte to help alac_entropy_coder;
}
unsafe static void alac_encode_residual_0(int* res, int* smp, int n) unsafe static void alac_encode_residual_0(int* res, int* smp, int n)
{ {
AudioSamples.MemCpy(res, smp, n); AudioSamples.MemCpy(res, smp, n);
} res[n] = 1; // Stop byte to help alac_entropy_coder;
}
unsafe static void alac_encode_residual(int* res, int* smp, int n, int order, int* coefs, int shift, int bps) unsafe static void alac_encode_residual(int* res, int* smp, int n, int order, int* coefs, int shift, int bps)
{ {
int csum = 0; int csum = 0;
@@ -838,35 +840,32 @@ namespace CUETools.Codecs.ALAC
} }
} }
unsafe void encode_residual(ALACFrame frame, int ch, int pass, int best_windows) unsafe void encode_residual(ALACFrame frame, int ch, int pass, int best_windows)
{ {
int* smp = frame.subframes[ch].samples; int* smp = frame.subframes[ch].samples;
int i, n = frame.blocksize; int i, n = frame.blocksize;
int bps = Settings.PCM.BitsPerSample + Settings.PCM.ChannelCount - 1; int bps = Settings.PCM.BitsPerSample + Settings.PCM.ChannelCount - 1;
// FIXED // FIXED
//if (0 == (2 & frame.subframes[ch].done_fixed) && (pass != 1 || n < eparams.max_prediction_order)) //if (0 == (2 & frame.subframes[ch].done_fixed) && (pass != 1 || n < eparams.max_prediction_order))
//{ //{
// frame.subframes[ch].done_fixed |= 2; // frame.subframes[ch].done_fixed |= 2;
// frame.current.order = 31; // frame.current.order = 31;
// frame.current.window = -1; // frame.current.window = -1;
// alac_encode_residual_31(frame.current.residual, frame.subframes[ch].samples, frame.blocksize); // alac_encode_residual_31(frame.current.residual, frame.subframes[ch].samples, frame.blocksize);
// frame.current.size = (uint)(alac_entropy_coder(frame.current.residual, frame.blocksize, bps, out frame.current.ricemodifier) + 16); // frame.current.size = (uint)(alac_entropy_coder(frame.current.residual, frame.blocksize, bps, out frame.current.ricemodifier) + 16);
// frame.ChooseBestSubframe(ch); // frame.ChooseBestSubframe(ch);
//} //}
//if (0 == (1 & frame.subframes[ch].done_fixed) && (pass != 1 || n < eparams.max_prediction_order)) //if (0 == (1 & frame.subframes[ch].done_fixed) && (pass != 1 || n < eparams.max_prediction_order))
//{ if (0 == (1 & frame.subframes[ch].done_fixed) && n < eparams.max_prediction_order)
// frame.subframes[ch].done_fixed |= 1; {
// frame.current.order = 0; frame.subframes[ch].done_fixed |= 1;
// frame.current.window = -1; frame.current.order = 0;
// alac_encode_residual_0(frame.current.residual, frame.subframes[ch].samples, frame.blocksize); frame.current.window = -1;
// frame.current.size = (uint)(alac_entropy_coder(frame.current.residual, frame.blocksize, bps, out frame.current.ricemodifier) + 16); alac_encode_residual_0(frame.current.residual, frame.subframes[ch].samples, frame.blocksize);
// frame.ChooseBestSubframe(ch); frame.current.size = (uint)(alac_entropy_coder(frame.current.residual, frame.blocksize, bps, out frame.current.ricemodifier) + 16);
//} frame.ChooseBestSubframe(ch);
}
// LPC
if (n < eparams.max_prediction_order)
return;
float* lpcs = stackalloc float[lpc.MAX_LPC_ORDER * lpc.MAX_LPC_ORDER]; float* lpcs = stackalloc float[lpc.MAX_LPC_ORDER * lpc.MAX_LPC_ORDER];
int min_order = eparams.min_prediction_order; int min_order = eparams.min_prediction_order;