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);
|
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 old_pos = BitLength;
|
||||||
int start = old_pos / 8;
|
int start = old_pos / 8;
|
||||||
|
int start1 = pos / 8;
|
||||||
int end = (old_pos + len) / 8;
|
int end = (old_pos + len) / 8;
|
||||||
|
int end1 = (pos + len) / 8;
|
||||||
flush();
|
flush();
|
||||||
byte start_val = old_pos % 8 != 0 ? buffer[start] : (byte)0;
|
byte start_val = old_pos % 8 != 0 ? buffer[start] : (byte)0;
|
||||||
fixed (byte* buf1 = &buffer[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;
|
buffer[start] |= start_val;
|
||||||
buf_ptr = end;
|
buf_ptr = end;
|
||||||
if ((old_pos + len) % 8 != 0)
|
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)
|
public void write(params char [] chars)
|
||||||
|
|||||||
@@ -695,6 +695,12 @@ namespace CUETools.Codecs
|
|||||||
*(res++) = *(smp++);
|
*(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)
|
unsafe public static void MemCpy(short* res, short* smp, int n)
|
||||||
{
|
{
|
||||||
for (int i = n; i > 0; i--)
|
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)
|
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);
|
MemCpy((int*)res, (int*)smp, n >> 2);
|
||||||
int n4 = (n >> 2) << 2;
|
int n4 = (n >> 2) << 2;
|
||||||
n -= n4;
|
n -= n4;
|
||||||
@@ -891,14 +915,21 @@ namespace CUETools.Codecs
|
|||||||
{
|
{
|
||||||
private long _sampleOffset, _sampleCount;
|
private long _sampleOffset, _sampleCount;
|
||||||
private AudioPCMConfig pcm;
|
private AudioPCMConfig pcm;
|
||||||
|
private int _sampleVal;
|
||||||
|
|
||||||
public SilenceGenerator(long sampleCount)
|
public SilenceGenerator(long sampleCount, int sampleVal)
|
||||||
{
|
{
|
||||||
|
_sampleVal = sampleVal;
|
||||||
_sampleOffset = 0;
|
_sampleOffset = 0;
|
||||||
_sampleCount = sampleCount;
|
_sampleCount = sampleCount;
|
||||||
pcm = AudioPCMConfig.RedBook;
|
pcm = AudioPCMConfig.RedBook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SilenceGenerator(long sampleCount)
|
||||||
|
: this(sampleCount, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public long Length
|
public long Length
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -936,7 +967,7 @@ namespace CUETools.Codecs
|
|||||||
int[,] samples = buff.Samples;
|
int[,] samples = buff.Samples;
|
||||||
for (int i = 0; i < buff.Length; i++)
|
for (int i = 0; i < buff.Length; i++)
|
||||||
for (int j = 0; j < PCM.ChannelCount; j++)
|
for (int j = 0; j < PCM.ChannelCount; j++)
|
||||||
samples[i, j] = 0;
|
samples[i, j] = _sampleVal;
|
||||||
|
|
||||||
_sampleOffset += buff.Length;
|
_sampleOffset += buff.Length;
|
||||||
return buff.Length;
|
return buff.Length;
|
||||||
|
|||||||
Reference in New Issue
Block a user