本文整理汇总了C#中CUETools.Codecs.FLAKE.FlacFrame类的典型用法代码示例。如果您正苦于以下问题:C# FlacFrame类的具体用法?C# FlacFrame怎么用?C# FlacFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FlacFrame类属于CUETools.Codecs.FLAKE命名空间,在下文中一共展示了FlacFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlakeReader
public FlakeReader(string path, Stream IO)
{
_path = path;
_IO = IO != null ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x10000);
crc8 = new Crc8();
crc16 = new Crc16();
_framesBuffer = new byte[0x20000];
decode_metadata();
frame = new FlacFrame(PCM.ChannelCount);
framereader = new BitReader();
//max_frame_size = 16 + ((Flake.MAX_BLOCKSIZE * PCM.BitsPerSample * PCM.ChannelCount + 1) + 7) >> 3);
if (((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3) > _framesBuffer.Length)
{
byte[] temp = _framesBuffer;
_framesBuffer = new byte[((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3)];
if (_framesBufferLength > 0)
Array.Copy(temp, _framesBufferOffset, _framesBuffer, 0, _framesBufferLength);
_framesBufferOffset = 0;
}
_samplesInBuffer = 0;
if ((PCM.BitsPerSample != 16 && PCM.BitsPerSample != 24) || PCM.ChannelCount != 2 || (PCM.SampleRate != 44100 && PCM.SampleRate != 48000))
throw new Exception("invalid flac file");
samplesBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount];
residualBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount];
}
示例2: FlakeReader
public FlakeReader(Stream IO)
{
if (IO == null)
{
throw new ArgumentNullException("IO");
}
_IO = IO;
crc8 = new Crc8();
_framesBuffer = new byte[0x20000];
decode_metadata();
frame = new FlacFrame(PCM.ChannelCount);
framereader = new BitReader();
//max_frame_size = 16 + ((Flake.MAX_BLOCKSIZE * PCM.BitsPerSample * PCM.ChannelCount + 1) + 7) >> 3);
if (((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3) > _framesBuffer.Length)
{
byte[] temp = _framesBuffer;
_framesBuffer = new byte[((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3)];
if (_framesBufferLength > 0)
Array.Copy(temp, _framesBufferOffset, _framesBuffer, 0, _framesBufferLength);
_framesBufferOffset = 0;
}
_samplesInBuffer = 0;
if (PCM.BitsPerSample != 16 && PCM.BitsPerSample != 24)
throw new Exception("invalid flac file");
samplesBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount];
residualBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount];
}
示例3: decode_subframe_fixed
unsafe void decode_subframe_fixed(BitReader bitreader, FlacFrame frame, int ch)
{
// warm-up samples
int obits = frame.subframes[ch].obits;
for (int i = 0; i < frame.subframes[ch].best.order; i++)
frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
// residual
decode_residual(bitreader, frame, ch);
}
示例4: encode_residual_fixed_sub
unsafe void encode_residual_fixed_sub(FlacFrame frame, int order, int ch)
{
if ((frame.subframes[ch].done_fixed & (1U << order)) != 0)
return; // already calculated;
frame.current.order = order;
frame.current.type = SubframeType.Fixed;
encode_residual_fixed(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order);
int pmax = get_max_p_order(eparams.max_partition_order, frame.blocksize, frame.current.order);
int pmin = Math.Min(eparams.min_partition_order, pmax);
frame.current.size = (uint)(frame.current.order * frame.subframes[ch].obits) + 6
+ calc_rice_params(frame.current.rc, pmin, pmax, frame.current.residual, (uint)frame.blocksize, (uint)frame.current.order, PCM.BitsPerSample);
frame.subframes[ch].done_fixed |= (1U << order);
frame.ChooseBestSubframe(ch);
}
示例5: encode_frame
unsafe int encode_frame(out int size)
{
fixed (int* s = samplesBuffer, r = residualBuffer)
fixed (float* window = windowBuffer)
{
frame.InitSize(eparams.block_size, eparams.variable_block_size != 0);
if (frame.blocksize != _windowsize && frame.blocksize > 4)
{
_windowsize = frame.blocksize;
_windowcount = 0;
calculate_window(window, lpc.window_welch, WindowFunction.Welch);
calculate_window(window, lpc.window_tukey, WindowFunction.Tukey);
calculate_window(window, lpc.window_flattop, WindowFunction.Flattop);
calculate_window(window, lpc.window_hann, WindowFunction.Hann);
calculate_window(window, lpc.window_bartlett, WindowFunction.Bartlett);
if (_windowcount == 0)
throw new Exception("invalid windowfunction");
}
if (channels != 2 || frame.blocksize <= 32 || eparams.stereo_method == StereoMethod.Independent)
{
frame.window_buffer = window;
frame.current.residual = r + channels * Flake.MAX_BLOCKSIZE;
frame.ch_mode = channels != 2 ? ChannelMode.NotStereo : ChannelMode.LeftRight;
for (int ch = 0; ch < channels; ch++)
frame.subframes[ch].Init(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE,
_pcm.BitsPerSample, get_wasted_bits(s + ch * Flake.MAX_BLOCKSIZE, frame.blocksize));
for (int ch = 0; ch < channels; ch++)
encode_residual_pass2(frame, ch);
}
else
{
//channel_decorrelation(s, s + Flake.MAX_BLOCKSIZE, s + 2 * Flake.MAX_BLOCKSIZE, s + 3 * Flake.MAX_BLOCKSIZE, frame.blocksize);
frame.window_buffer = window;
frame.current.residual = r + 4 * Flake.MAX_BLOCKSIZE;
for (int ch = 0; ch < 4; ch++)
frame.subframes[ch].Init(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE,
_pcm.BitsPerSample + (ch == 3 ? 1 : 0), get_wasted_bits(s + ch * Flake.MAX_BLOCKSIZE, frame.blocksize));
//for (int ch = 0; ch < 4; ch++)
// for (int iWindow = 0; iWindow < _windowcount; iWindow++)
// frame.subframes[ch].lpc_ctx[iWindow].GetReflection(32, frame.subframes[ch].samples, frame.blocksize, frame.window_buffer + iWindow * Flake.MAX_BLOCKSIZE * 2);
estimate_frame(frame, true);
uint fs = measure_frame_size(frame, true);
if (0 != eparams.variable_block_size)
{
FlacFrame frame2 = new FlacFrame(channels * 2);
FlacFrame frame3 = new FlacFrame(channels * 2);
int tumbler = 1;
while ((frame.blocksize & 1) == 0 && frame.blocksize >= 1024)
{
frame2.InitSize(frame.blocksize / 2, true);
frame2.window_buffer = frame.window_buffer + frame.blocksize;
frame2.current.residual = r + tumbler * 5 * Flake.MAX_BLOCKSIZE;
for (int ch = 0; ch < 4; ch++)
frame2.subframes[ch].Init(frame.subframes[ch].samples, frame2.current.residual + (ch + 1) * frame2.blocksize,
frame.subframes[ch].obits + frame.subframes[ch].wbits, frame.subframes[ch].wbits);
estimate_frame(frame2, true);
uint fs2 = measure_frame_size(frame2, true);
uint fs3 = fs2;
if (eparams.variable_block_size == 2 || eparams.variable_block_size == 4)
{
frame3.InitSize(frame2.blocksize, true);
frame3.window_buffer = frame2.window_buffer;
frame3.current.residual = frame2.current.residual + 5 * frame2.blocksize;
for (int ch = 0; ch < 4; ch++)
frame3.subframes[ch].Init(frame2.subframes[ch].samples + frame2.blocksize, frame3.current.residual + (ch + 1) * frame3.blocksize,
frame.subframes[ch].obits + frame.subframes[ch].wbits, frame.subframes[ch].wbits);
estimate_frame(frame3, true);
fs3 = measure_frame_size(frame3, true);
}
if (fs2 + fs3 > fs)
break;
FlacFrame tmp = frame;
frame = frame2;
frame2 = tmp;
fs = fs2;
if (eparams.variable_block_size <= 2)
break;
tumbler = 1 - tumbler;
}
}
frame.ChooseSubframes();
encode_estimated_frame(frame);
}
BitWriter bitwriter = new BitWriter(frame_buffer, 0, max_frame_size);
output_frame_header(frame, bitwriter);
output_subframes(frame, bitwriter);
output_frame_footer(bitwriter);
if (bitwriter.Length >= max_frame_size)
throw new Exception("buffer overflow");
//.........这里部分代码省略.........
示例6: measure_frame_size
unsafe uint measure_frame_size(FlacFrame frame, bool do_midside)
{
// crude estimation of header/footer size
uint total = (uint)(32 + ((BitReader.log2i(frame_count) + 4) / 5) * 8 + (eparams.variable_block_size != 0 ? 16 : 0) + 16);
if (do_midside)
{
uint bitsBest = AudioSamples.UINT32_MAX;
ChannelMode modeBest = ChannelMode.LeftRight;
if (bitsBest > frame.subframes[2].best.size + frame.subframes[3].best.size)
{
bitsBest = frame.subframes[2].best.size + frame.subframes[3].best.size;
modeBest = ChannelMode.MidSide;
}
if (bitsBest > frame.subframes[3].best.size + frame.subframes[1].best.size)
{
bitsBest = frame.subframes[3].best.size + frame.subframes[1].best.size;
modeBest = ChannelMode.RightSide;
}
if (bitsBest > frame.subframes[3].best.size + frame.subframes[0].best.size)
{
bitsBest = frame.subframes[3].best.size + frame.subframes[0].best.size;
modeBest = ChannelMode.LeftSide;
}
if (bitsBest > frame.subframes[0].best.size + frame.subframes[1].best.size)
{
bitsBest = frame.subframes[0].best.size + frame.subframes[1].best.size;
modeBest = ChannelMode.LeftRight;
}
frame.ch_mode = modeBest;
return total + bitsBest;
}
for (int ch = 0; ch < channels; ch++)
total += frame.subframes[ch].best.size;
return total;
}
示例7: FlakeWriter
public FlakeWriter(string path, Stream IO, AudioPCMConfig pcm)
{
_pcm = pcm;
//if (_pcm.BitsPerSample != 16)
// throw new Exception("Bits per sample must be 16.");
if (_pcm.ChannelCount != 2)
throw new Exception("ChannelCount must be 2.");
channels = pcm.ChannelCount;
// flake_validate_params
_path = path;
_IO = IO;
samplesBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 4 : channels)];
residualBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 10 : channels + 1)];
windowBuffer = new float[Flake.MAX_BLOCKSIZE * 2 * lpc.MAX_LPC_WINDOWS];
windowScale = new double[lpc.MAX_LPC_WINDOWS];
eparams.flake_set_defaults(_compressionLevel);
eparams.padding_size = 8192;
crc8 = new Crc8();
crc16 = new Crc16();
frame = new FlacFrame(channels * 2);
}
示例8: encode_residual_pass2
unsafe void encode_residual_pass2(FlacFrame frame, int ch)
{
encode_residual(frame, ch, eparams.prediction_type, eparams.order_method, 2, estimate_best_window(frame, ch));
}
示例9: output_subframes
unsafe void output_subframes(FlacFrame frame, BitWriter bitwriter)
{
for (int ch = 0; ch < channels; ch++)
{
FlacSubframeInfo sub = frame.subframes[ch];
// subframe header
int type_code = (int) sub.best.type;
if (sub.best.type == SubframeType.Fixed)
type_code |= sub.best.order;
if (sub.best.type == SubframeType.LPC)
type_code |= sub.best.order - 1;
bitwriter.writebits(1, 0);
bitwriter.writebits(6, type_code);
bitwriter.writebits(1, sub.wbits != 0 ? 1 : 0);
if (sub.wbits > 0)
bitwriter.writebits((int)sub.wbits, 1);
// subframe
switch (sub.best.type)
{
case SubframeType.Constant:
output_subframe_constant(frame, bitwriter, sub);
break;
case SubframeType.Verbatim:
output_subframe_verbatim(frame, bitwriter, sub);
break;
case SubframeType.Fixed:
output_subframe_fixed(frame, bitwriter, sub);
break;
case SubframeType.LPC:
output_subframe_lpc(frame, bitwriter, sub);
break;
}
}
}
示例10: restore_samples_lpc
unsafe void restore_samples_lpc(FlacFrame frame, int ch)
{
FlacSubframeInfo sub = frame.subframes[ch];
ulong csum = 0;
fixed (int* coefs = sub.best.coefs)
{
for (int i = sub.best.order; i > 0; i--)
csum += (ulong)Math.Abs(coefs[i - 1]);
if ((csum << sub.obits) >= 1UL << 32)
lpc.decode_residual_long(sub.best.residual, sub.samples, frame.blocksize, sub.best.order, coefs, sub.best.shift);
else
lpc.decode_residual(sub.best.residual, sub.samples, frame.blocksize, sub.best.order, coefs, sub.best.shift);
}
}
示例11: restore_samples_fixed
unsafe void restore_samples_fixed(FlacFrame frame, int ch)
{
FlacSubframeInfo sub = frame.subframes[ch];
AudioSamples.MemCpy(sub.samples, sub.best.residual, sub.best.order);
int* data = sub.samples + sub.best.order;
int* residual = sub.best.residual + sub.best.order;
int data_len = frame.blocksize - sub.best.order;
int s0, s1, s2;
switch (sub.best.order)
{
case 0:
AudioSamples.MemCpy(data, residual, data_len);
break;
case 1:
s1 = data[-1];
for (int i = data_len; i > 0; i--)
{
s1 += *(residual++);
*(data++) = s1;
}
//data[i] = residual[i] + data[i - 1];
break;
case 2:
s2 = data[-2];
s1 = data[-1];
for (int i = data_len; i > 0; i--)
{
s0 = *(residual++) + (s1 << 1) - s2;
*(data++) = s0;
s2 = s1;
s1 = s0;
}
//data[i] = residual[i] + data[i - 1] * 2 - data[i - 2];
break;
case 3:
for (int i = 0; i < data_len; i++)
data[i] = residual[i] + (((data[i - 1] - data[i - 2]) << 1) + (data[i - 1] - data[i - 2])) + data[i - 3];
break;
case 4:
for (int i = 0; i < data_len; i++)
data[i] = residual[i] + ((data[i - 1] + data[i - 3]) << 2) - ((data[i - 2] << 2) + (data[i - 2] << 1)) - data[i - 4];
break;
}
}
示例12: restore_samples
unsafe void restore_samples(FlacFrame frame)
{
for (int ch = 0; ch < PCM.ChannelCount; ch++)
{
switch (frame.subframes[ch].best.type)
{
case SubframeType.Constant:
AudioSamples.MemSet(frame.subframes[ch].samples, frame.subframes[ch].best.residual[0], frame.blocksize);
break;
case SubframeType.Verbatim:
AudioSamples.MemCpy(frame.subframes[ch].samples, frame.subframes[ch].best.residual, frame.blocksize);
break;
case SubframeType.Fixed:
restore_samples_fixed(frame, ch);
break;
case SubframeType.LPC:
restore_samples_lpc(frame, ch);
break;
}
if (frame.subframes[ch].wbits != 0)
{
int* s = frame.subframes[ch].samples;
int x = (int) frame.subframes[ch].wbits;
for (int i = frame.blocksize; i > 0; i--)
*(s++) <<= x;
}
}
if (frame.ch_mode != ChannelMode.NotStereo)
{
int* l = frame.subframes[0].samples;
int* r = frame.subframes[1].samples;
switch (frame.ch_mode)
{
case ChannelMode.LeftRight:
break;
case ChannelMode.MidSide:
for (int i = frame.blocksize; i > 0; i--)
{
int mid = *l;
int side = *r;
mid <<= 1;
mid |= (side & 1); /* i.e. if 'side' is odd... */
*(l++) = (mid + side) >> 1;
*(r++) = (mid - side) >> 1;
}
break;
case ChannelMode.LeftSide:
for (int i = frame.blocksize; i > 0; i--)
{
int _l = *(l++), _r = *r;
*(r++) = _l - _r;
}
break;
case ChannelMode.RightSide:
for (int i = frame.blocksize; i > 0; i--)
*(l++) += *(r++);
break;
}
}
}
示例13: decode_subframe_verbatim
unsafe void decode_subframe_verbatim(BitReader bitreader, FlacFrame frame, int ch)
{
int obits = frame.subframes[ch].obits;
for (int i = 0; i < frame.blocksize; i++)
frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
}
示例14: decode_subframe_lpc
unsafe void decode_subframe_lpc(BitReader bitreader, FlacFrame frame, int ch)
{
// warm-up samples
int obits = frame.subframes[ch].obits;
for (int i = 0; i < frame.subframes[ch].best.order; i++)
frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
// LPC coefficients
frame.subframes[ch].best.cbits = (int)bitreader.readbits(4) + 1; // lpc_precision
frame.subframes[ch].best.shift = bitreader.readbits_signed(5);
if (frame.subframes[ch].best.shift < 0)
throw new Exception("negative shift");
for (int i = 0; i < frame.subframes[ch].best.order; i++)
frame.subframes[ch].best.coefs[i] = bitreader.readbits_signed(frame.subframes[ch].best.cbits);
// residual
decode_residual(bitreader, frame, ch);
}
示例15: output_subframe_fixed
output_subframe_fixed(FlacFrame frame, BitWriter bitwriter, FlacSubframeInfo sub)
{
// warm-up samples
for (int i = 0; i < sub.best.order; i++)
bitwriter.writebits_signed(sub.obits, sub.best.residual[i]);
// residual
output_residual(frame, bitwriter, sub);
}