mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
optimizations
This commit is contained in:
@@ -56,19 +56,21 @@ namespace CUETools.Codecs
|
||||
writebits(8, c);
|
||||
}
|
||||
|
||||
public unsafe void writeints(int len, byte* buf)
|
||||
public unsafe void writeints(int len, int pos, byte* buf)
|
||||
{
|
||||
int old_pos = BitLength;
|
||||
int start = old_pos / 8;
|
||||
int start1 = pos / 8;
|
||||
int end = (old_pos + len) / 8;
|
||||
int end1 = (pos + len) / 8;
|
||||
flush();
|
||||
byte start_val = old_pos % 8 != 0 ? buffer[start] : (byte)0;
|
||||
fixed (byte* buf1 = &buffer[0])
|
||||
AudioSamples.MemCpy(buf1 + start, buf + start, end - start);
|
||||
AudioSamples.MemCpy(buf1 + start, buf + start1, end - start);
|
||||
buffer[start] |= start_val;
|
||||
buf_ptr = end;
|
||||
if ((old_pos + len) % 8 != 0)
|
||||
writebits((old_pos + len) % 8, buf[end] >> (8 - ((old_pos + len) % 8)));
|
||||
writebits((old_pos + len) % 8, buf[end1] >> (8 - ((old_pos + len) % 8)));
|
||||
}
|
||||
|
||||
public void write(params char [] chars)
|
||||
|
||||
@@ -695,6 +695,12 @@ namespace CUETools.Codecs
|
||||
*(res++) = *(smp++);
|
||||
}
|
||||
|
||||
unsafe public static void MemCpy(long* res, long* smp, int n)
|
||||
{
|
||||
for (int i = n; i > 0; i--)
|
||||
*(res++) = *(smp++);
|
||||
}
|
||||
|
||||
unsafe public static void MemCpy(short* res, short* smp, int n)
|
||||
{
|
||||
for (int i = n; i > 0; i--)
|
||||
@@ -703,8 +709,26 @@ namespace CUETools.Codecs
|
||||
|
||||
unsafe public static void MemCpy(byte* res, byte* smp, int n)
|
||||
{
|
||||
if ((((IntPtr)smp).ToInt64() & 3) == 0 && (((IntPtr)res).ToInt64() & 3) == 0 && n > 4)
|
||||
if ((((IntPtr)smp).ToInt64() & 7) == (((IntPtr)res).ToInt64() & 7) && n > 32)
|
||||
{
|
||||
int delta = (int)((8 - (((IntPtr)smp).ToInt64() & 7)) & 7);
|
||||
for (int i = delta; i > 0; i--)
|
||||
*(res++) = *(smp++);
|
||||
n -= delta;
|
||||
|
||||
MemCpy((long*)res, (long*)smp, n >> 3);
|
||||
int n8 = (n >> 3) << 3;
|
||||
n -= n8;
|
||||
smp += n8;
|
||||
res += n8;
|
||||
}
|
||||
if ((((IntPtr)smp).ToInt64() & 3) == (((IntPtr)res).ToInt64() & 3) && n > 16)
|
||||
{
|
||||
int delta = (int)((4 - (((IntPtr)smp).ToInt64() & 3)) & 3);
|
||||
for (int i = delta; i > 0; i--)
|
||||
*(res++) = *(smp++);
|
||||
n -= delta;
|
||||
|
||||
MemCpy((int*)res, (int*)smp, n >> 2);
|
||||
int n4 = (n >> 2) << 2;
|
||||
n -= n4;
|
||||
@@ -891,14 +915,21 @@ namespace CUETools.Codecs
|
||||
{
|
||||
private long _sampleOffset, _sampleCount;
|
||||
private AudioPCMConfig pcm;
|
||||
private int _sampleVal;
|
||||
|
||||
public SilenceGenerator(long sampleCount)
|
||||
public SilenceGenerator(long sampleCount, int sampleVal)
|
||||
{
|
||||
_sampleVal = sampleVal;
|
||||
_sampleOffset = 0;
|
||||
_sampleCount = sampleCount;
|
||||
pcm = AudioPCMConfig.RedBook;
|
||||
}
|
||||
|
||||
public SilenceGenerator(long sampleCount)
|
||||
: this(sampleCount, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public long Length
|
||||
{
|
||||
get
|
||||
@@ -936,7 +967,7 @@ namespace CUETools.Codecs
|
||||
int[,] samples = buff.Samples;
|
||||
for (int i = 0; i < buff.Length; i++)
|
||||
for (int j = 0; j < PCM.ChannelCount; j++)
|
||||
samples[i, j] = 0;
|
||||
samples[i, j] = _sampleVal;
|
||||
|
||||
_sampleOffset += buff.Length;
|
||||
return buff.Length;
|
||||
|
||||
Reference in New Issue
Block a user