diff --git a/CUETools.ALACEnc/Program.cs b/CUETools.ALACEnc/Program.cs index 8a173c8..2f4498c 100644 --- a/CUETools.ALACEnc/Program.cs +++ b/CUETools.ALACEnc/Program.cs @@ -54,13 +54,14 @@ namespace CUETools.ALACEnc string input_file = null; string output_file = null; int min_lpc_order = -1, max_lpc_order = -1, - blocksize = -1, estimation_depth = -1, + estimation_depth = -1, min_modifier = -1, max_modifier = -1; - int level = -1, padding = -1; + int intarg = -1; int initial_history = -1, history_mult = -1; int adaptive_passes = -1; - bool do_seektable = true, do_verify = false; + bool do_seektable = true; bool buffered = false; + var settings = new ALACWriterSettings(); for (int arg = 0; arg < args.Length; arg++) { @@ -72,7 +73,7 @@ namespace CUETools.ALACEnc else if ((args[arg] == "-q" || args[arg] == "--quiet")) quiet = true; else if (args[arg] == "--verify") - do_verify = true; + settings.DoVerify = true; else if (args[arg] == "--no-seektable") do_seektable = false; else if (args[arg] == "--buffered") @@ -109,16 +110,25 @@ namespace CUETools.ALACEnc ok = int.TryParse(args[arg], out history_mult); else if ((args[arg] == "-e" || args[arg] == "--estimation-depth") && ++arg < args.Length) ok = int.TryParse(args[arg], out estimation_depth); - else if ((args[arg] == "-b" || args[arg] == "--blocksize") && ++arg < args.Length) - ok = int.TryParse(args[arg], out blocksize); - else if ((args[arg] == "-p" || args[arg] == "--padding") && ++arg < args.Length) - ok = int.TryParse(args[arg], out padding); - else if (args[arg] != "-" && args[arg][0] == '-' && int.TryParse(args[arg].Substring(1), out level)) - ok = level >= 0 && level <= 11; - else if ((args[arg][0] != '-' || args[arg] == "-") && input_file == null) - input_file = args[arg]; - else - ok = false; + else if ((args[arg] == "-b" || args[arg] == "--blocksize") && ++arg < args.Length) + { + ok = int.TryParse(args[arg], out intarg); + settings.BlockSize = intarg; + } + else if ((args[arg] == "-p" || args[arg] == "--padding") && ++arg < args.Length) + { + ok = int.TryParse(args[arg], out intarg); + settings.Padding = intarg; + } + else if (args[arg] != "-" && args[arg][0] == '-' && int.TryParse(args[arg].Substring(1), out intarg)) + { + ok = intarg >= 0 && intarg <= 11; + settings.EncoderModeIndex = intarg; + } + else if ((args[arg][0] != '-' || args[arg] == "-") && input_file == null) + input_file = args[arg]; + else + ok = false; if (!ok) { Usage(); @@ -176,10 +186,6 @@ namespace CUETools.ALACEnc try { - var settings = new ALACWriterSettings(); - settings.DoVerify = do_verify; - if (level >= 0) - settings.EncoderModeIndex = level; alac.Settings = settings; if (stereo_method != null) alac.StereoMethod = Alac.LookupStereoMethod(stereo_method); @@ -201,16 +207,11 @@ namespace CUETools.ALACEnc alac.HistoryMult = history_mult; if (initial_history >= 0) alac.InitialHistory = initial_history; - if (blocksize >= 0) - alac.BlockSize = blocksize; if (estimation_depth >= 0) alac.EstimationDepth = estimation_depth; - if (padding >= 0) - alac.Padding = padding; if (adaptive_passes >= 0) alac.AdaptivePasses = adaptive_passes; alac.DoSeekTable = do_seektable; - (alac.Settings as ALACWriterSettings).DoVerify = do_verify; } catch (Exception ex) { @@ -285,7 +286,7 @@ namespace CUETools.ALACEnc alac.MaxLPCOrder, alac.MinHistoryModifier, alac.MaxHistoryModifier, - alac.BlockSize + alac.Settings.BlockSize ); } //File.SetAttributes(output_file, FileAttributes.ReadOnly); diff --git a/CUETools.AccurateRip/AccurateRip.cs b/CUETools.AccurateRip/AccurateRip.cs index 670d35b..9658a19 100644 --- a/CUETools.AccurateRip/AccurateRip.cs +++ b/CUETools.AccurateRip/AccurateRip.cs @@ -944,11 +944,6 @@ namespace CUETools.AccurateRip } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return AudioPCMConfig.RedBook; } @@ -972,11 +967,6 @@ namespace CUETools.AccurateRip } } - public long BlockSize - { - set { throw new Exception("unsupported"); } - } - public string Path { get { throw new Exception("unsupported"); } diff --git a/CUETools.AccurateRip/CDRepair.cs b/CUETools.AccurateRip/CDRepair.cs index 09558e6..2c0efbc 100644 --- a/CUETools.AccurateRip/CDRepair.cs +++ b/CUETools.AccurateRip/CDRepair.cs @@ -426,21 +426,11 @@ namespace CUETools.AccurateRip } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return AudioPCMConfig.RedBook; } } - public long BlockSize - { - set { throw new Exception("unsupported"); } - } - public string Path { get { throw new Exception("unsupported"); } diff --git a/CUETools.Codecs.ALAC/ALACWriter.cs b/CUETools.Codecs.ALAC/ALACWriter.cs index 5d20e69..042810f 100644 --- a/CUETools.Codecs.ALAC/ALACWriter.cs +++ b/CUETools.Codecs.ALAC/ALACWriter.cs @@ -41,6 +41,12 @@ namespace CUETools.Codecs.ALAC DoVerify = false; } + public override bool IsValid() + { + return EncoderModeIndex >= 0 && Padding >= 0 && + (BlockSize == 0 || BlockSize >= 256 && BlockSize < Int32.MaxValue); + } + [DefaultValue(false)] [DisplayName("Verify")] [Description("Decode each frame and compare with original")] @@ -86,7 +92,7 @@ namespace CUETools.Codecs.ALAC float[] windowBuffer; int samplesInBuffer = 0; - int _blocksize = 0; + int m_blockSize = 0; int _totalSize = 0; int _windowsize = 0, _windowcount = 0; @@ -119,7 +125,6 @@ namespace CUETools.Codecs.ALAC windowBuffer = new float[Alac.MAX_BLOCKSIZE * 2 * Alac.MAX_LPC_WINDOWS]; eparams.set_defaults(5); - eparams.padding_size = 4096; frame = new ALACFrame(_pcm.ChannelCount == 2 ? 5 : _pcm.ChannelCount); chunk_pos = new List(); @@ -138,38 +143,22 @@ namespace CUETools.Codecs.ALAC } } - ALACWriterSettings _settings = new ALACWriterSettings(); + ALACWriterSettings m_settings = new ALACWriterSettings(); public AudioEncoderSettings Settings { get { - return _settings; + return m_settings; } - set - { - if (value as ALACWriterSettings == null) - throw new Exception("Unsupported options " + value); - _settings = value as ALACWriterSettings; - var _compressionLevel = _settings.EncoderModeIndex; - if (_compressionLevel < 0 || _compressionLevel > 10) - throw new Exception("unsupported compression level"); + set + { + m_settings = value.Clone(); + var _compressionLevel = m_settings.EncoderModeIndex; eparams.set_defaults(_compressionLevel); } } - public long Padding - { - get - { - return eparams.padding_size; - } - set - { - eparams.padding_size = (int)value; - } - } - #if INTEROP [DllImport("kernel32.dll")] static extern bool GetThreadTimes(IntPtr hThread, out long lpCreationTime, out long lpExitTime, out long lpKernelTime, out long lpUserTime); @@ -209,7 +198,7 @@ namespace CUETools.Codecs.ALAC { sample_count = (int)_position; header_len = max_header_len - + eparams.padding_size + + m_settings.Padding + frame_count * 4 // stsz + frame_count * 4 / eparams.chunk_size; // stco //if (header_len % 0x400 != 0) @@ -295,12 +284,6 @@ namespace CUETools.Codecs.ALAC set { sample_count = (int)value; } } - public long BlockSize - { - set { _blocksize = (int)value; } - get { return _blocksize == 0 ? eparams.block_size : _blocksize; } - } - public OrderMethod OrderMethod { get { return eparams.order_method; } @@ -915,10 +898,10 @@ namespace CUETools.Codecs.ALAC { bitwriter.writebits(3, _pcm.ChannelCount - 1); bitwriter.writebits(16, 0); - bitwriter.writebits(1, frame.blocksize != eparams.block_size ? 1 : 0); // sample count is in the header + bitwriter.writebits(1, frame.blocksize != m_blockSize ? 1 : 0); // sample count is in the header bitwriter.writebits(2, 0); // wasted bytes bitwriter.writebits(1, frame.type == FrameType.Verbatim ? 1 : 0); // is verbatim - if (frame.blocksize != eparams.block_size) + if (frame.blocksize != m_blockSize) bitwriter.writebits(32, frame.blocksize); if (frame.type != FrameType.Verbatim) { @@ -1195,10 +1178,10 @@ namespace CUETools.Codecs.ALAC { fixed (int* s = verifyBuffer, r = samplesBuffer) for (int ch = 0; ch < _pcm.ChannelCount; ch++) - AudioSamples.MemCpy(s + ch * Alac.MAX_BLOCKSIZE, r + ch * Alac.MAX_BLOCKSIZE, eparams.block_size); + AudioSamples.MemCpy(s + ch * Alac.MAX_BLOCKSIZE, r + ch * Alac.MAX_BLOCKSIZE, blocksize); } - //if (0 != eparams.variable_block_size && 0 == (eparams.block_size & 7) && eparams.block_size >= 128) + //if (0 != eparams.variable_block_size && 0 == (m_blockSize & 7) && m_blockSize >= 128) // fs = encode_frame_vbs(); //else int bs = blocksize; @@ -1229,7 +1212,7 @@ namespace CUETools.Codecs.ALAC { fixed (int* s = samplesBuffer) for (int ch = 0; ch < _pcm.ChannelCount; ch++) - AudioSamples.MemCpy(s + ch * Alac.MAX_BLOCKSIZE, s + bs + ch * Alac.MAX_BLOCKSIZE, eparams.block_size - bs); + AudioSamples.MemCpy(s + ch * Alac.MAX_BLOCKSIZE, s + bs + ch * Alac.MAX_BLOCKSIZE, blocksize - bs); } samplesInBuffer -= bs; @@ -1247,7 +1230,9 @@ namespace CUETools.Codecs.ALAC _IO = new FileStream(_path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); if (_IO != null && !_IO.CanSeek) throw new NotSupportedException("stream doesn't support seeking"); - encode_init(); + if (!m_settings.IsValid()) + throw new Exception("unsupported encoder settings"); + encode_init(); inited = true; } @@ -1257,15 +1242,15 @@ namespace CUETools.Codecs.ALAC int len = buff.Length; while (len > 0) { - int block = Math.Min(len, eparams.block_size - samplesInBuffer); + int block = Math.Min(len, m_blockSize - samplesInBuffer); copy_samples(buff.Samples, pos, block); len -= block; pos += block; - while (samplesInBuffer >= eparams.block_size) - output_frame(eparams.block_size); + while (samplesInBuffer >= m_blockSize) + output_frame(m_blockSize); } } @@ -1402,7 +1387,7 @@ namespace CUETools.Codecs.ALAC } bitwriter.write('a', 'l', 'a', 'c'); bitwriter.writebits(32, 0); // reserved - bitwriter.writebits(32, eparams.block_size); // max frame size + bitwriter.writebits(32, m_blockSize); // max frame size bitwriter.writebits(8, 0); // reserved bitwriter.writebits(8, _pcm.BitsPerSample); bitwriter.writebits(8, history_mult); @@ -1423,19 +1408,19 @@ namespace CUETools.Codecs.ALAC { bitwriter.write('s', 't', 't', 's'); bitwriter.writebits(32, 0); // version & flags - if (sample_count % eparams.block_size == 0) + if (sample_count % m_blockSize == 0) { bitwriter.writebits(32, 1); // entries - bitwriter.writebits(32, sample_count / eparams.block_size); - bitwriter.writebits(32, eparams.block_size); + bitwriter.writebits(32, sample_count / m_blockSize); + bitwriter.writebits(32, m_blockSize); } else { bitwriter.writebits(32, 2); // entries - bitwriter.writebits(32, sample_count / eparams.block_size); - bitwriter.writebits(32, eparams.block_size); + bitwriter.writebits(32, sample_count / m_blockSize); + bitwriter.writebits(32, m_blockSize); bitwriter.writebits(32, 1); - bitwriter.writebits(32, sample_count % eparams.block_size); + bitwriter.writebits(32, sample_count % m_blockSize); } } chunk_end(bitwriter); @@ -1606,7 +1591,7 @@ namespace CUETools.Codecs.ALAC chunk_start(bitwriter); // padding { bitwriter.write('f', 'r', 'e', 'e'); - bitwriter.writebytes(eparams.padding_size, 0); + bitwriter.writebytes(m_settings.Padding, 0); } chunk_end(bitwriter); } @@ -1660,8 +1645,6 @@ namespace CUETools.Codecs.ALAC void encode_init() { - //if(flake_validate_params(s) < 0) - // FIXME: For now, only 44100 samplerate is supported if (_pcm.SampleRate != 44100) throw new Exception("non-standard samplerate"); @@ -1670,35 +1653,30 @@ namespace CUETools.Codecs.ALAC if (_pcm.BitsPerSample != 16) throw new Exception("non-standard bps"); - if (_blocksize == 0) - { - if (eparams.block_size == 0) - eparams.block_size = select_blocksize(_pcm.SampleRate, eparams.block_time_ms); - _blocksize = eparams.block_size; - } - else - eparams.block_size = _blocksize; + m_blockSize = + m_settings.BlockSize != 0 ? m_settings.BlockSize : + select_blocksize(_pcm.SampleRate, eparams.block_time_ms); // set maximum encoded frame size (if larger, re-encodes in verbatim mode) if (_pcm.ChannelCount == 2) - max_frame_size = 16 + ((eparams.block_size * (_pcm.BitsPerSample + _pcm.BitsPerSample + 1) + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * (_pcm.BitsPerSample + _pcm.BitsPerSample + 1) + 7) >> 3); else - max_frame_size = 16 + ((eparams.block_size * _pcm.ChannelCount * _pcm.BitsPerSample + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * _pcm.ChannelCount * _pcm.BitsPerSample + 7) >> 3); frame_buffer = new byte[max_frame_size]; - _sample_byte_size = new uint[Math.Max(0x100, sample_count / eparams.block_size + 1)]; + _sample_byte_size = new uint[Math.Max(0x100, sample_count / m_blockSize + 1)]; - if (_settings.DoVerify) + if (m_settings.DoVerify) { - verify = new ALACReader(_pcm, history_mult, initial_history, k_modifier, eparams.block_size); + verify = new ALACReader(_pcm, history_mult, initial_history, k_modifier, m_blockSize); verifyBuffer = new int[Alac.MAX_BLOCKSIZE * _pcm.ChannelCount]; } if (sample_count < 0) throw new InvalidOperationException("FinalSampleCount unknown"); - int frames = sample_count / eparams.block_size; + int frames = sample_count / m_blockSize; int header_len = max_header_len - + eparams.padding_size + + m_settings.Padding + frames * 4 // stsz + frames * 4 / eparams.chunk_size; // stco //if (header_len % 0x400 != 0) @@ -1743,12 +1721,6 @@ namespace CUETools.Codecs.ALAC public WindowMethod window_method; - // block size in samples - // set by the user prior to calling encode_init - // if set to 0, a block size is chosen based on block_time_ms - // can also be changed by user before encoding a frame - public int block_size; - public int chunk_size; // block time in milliseconds @@ -1757,11 +1729,6 @@ namespace CUETools.Codecs.ALAC // can also be changed by user before encoding a frame public int block_time_ms; - // padding size in bytes - // set by the user prior to calling encode_init - // if set to less than 0, defaults to 4096 - public int padding_size; - // minimum LPC order // set by user prior to calling encode_init // if set to less than 0, it is chosen based on compression. @@ -1802,7 +1769,6 @@ namespace CUETools.Codecs.ALAC order_method = OrderMethod.Estimate; stereo_method = StereoMethod.Evaluate; window_method = WindowMethod.Evaluate; - block_size = 0; block_time_ms = 105; min_modifier = 4; max_modifier = 4; diff --git a/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp b/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp index 1423b05..e572a10 100644 --- a/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp +++ b/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp @@ -252,7 +252,7 @@ namespace CUETools { namespace Codecs { namespace APE { } }; - public ref class APEWriterSettings : AudioEncoderSettings + public ref class APEWriterSettings : public AudioEncoderSettings { public: APEWriterSettings() @@ -342,13 +342,6 @@ namespace CUETools { namespace Codecs { namespace APE { } } - virtual property Int64 BlockSize - { - void set(Int64 value) - { - } - } - virtual property AudioPCMConfig^ PCM { AudioPCMConfig^ get() @@ -375,12 +368,6 @@ namespace CUETools { namespace Codecs { namespace APE { } } - virtual property __int64 Padding - { - void set(__int64 value) { - } - } - virtual property AudioEncoderSettings^ Settings { AudioEncoderSettings^ get() @@ -390,9 +377,7 @@ namespace CUETools { namespace Codecs { namespace APE { void set(AudioEncoderSettings^ value) { - if (value != nullptr && value->GetType() != APEWriterSettings::typeid) - throw gcnew Exception(String::Format("Unsupported options: {0}", value)); - _settings = (APEWriterSettings^)value; + _settings = value->Clone(); } } diff --git a/CUETools.Codecs.CoreAudio/WasapiOut.cs b/CUETools.Codecs.CoreAudio/WasapiOut.cs index d318b0c..887052b 100644 --- a/CUETools.Codecs.CoreAudio/WasapiOut.cs +++ b/CUETools.Codecs.CoreAudio/WasapiOut.cs @@ -484,11 +484,6 @@ namespace CUETools.Codecs.CoreAudio } } - public long BlockSize - { - set { } - } - public long FinalSampleCount { set { ; } @@ -507,11 +502,6 @@ namespace CUETools.Codecs.CoreAudio } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return pcm; } diff --git a/CUETools.Codecs.FLAC/CUETools.Codecs.FLAC.cpp b/CUETools.Codecs.FLAC/CUETools.Codecs.FLAC.cpp index 7065a45..64ed654 100644 --- a/CUETools.Codecs.FLAC/CUETools.Codecs.FLAC.cpp +++ b/CUETools.Codecs.FLAC/CUETools.Codecs.FLAC.cpp @@ -516,8 +516,6 @@ namespace CUETools { namespace Codecs { namespace FLAC { _path = path; _finalSampleCount = 0; _samplesWritten = 0; - _paddingLength = 8192; - _blockSize = 0; _encoder = FLAC__stream_encoder_new(); @@ -561,14 +559,6 @@ namespace CUETools { namespace Codecs { namespace FLAC { } } - virtual property Int64 BlockSize - { - void set(Int64 value) - { - _blockSize = value; - } - } - virtual property AudioPCMConfig^ PCM { AudioPCMConfig^ get() { return _pcm; @@ -617,20 +607,7 @@ namespace CUETools { namespace Codecs { namespace FLAC { void set(AudioEncoderSettings^ value) { - if (value == nullptr || value->GetType() != FLACWriterSettings::typeid) - throw gcnew Exception(String::Format("Unsupported options: {0}", value)); - _settings = (FLACWriterSettings^)value; - } - } - - virtual property __int64 Padding { - __int64 get() { - return _paddingLength; - } - void set(__int64 value) { - if (value < 0) - throw gcnew Exception("invalid padding length"); - _paddingLength = value; + _settings = value->Clone(); } } @@ -639,9 +616,8 @@ namespace CUETools { namespace Codecs { namespace FLAC { FLAC__StreamEncoder *_encoder; bool _initialized; String^ _path; - Int64 _finalSampleCount, _samplesWritten, _blockSize; + Int64 _finalSampleCount, _samplesWritten; AudioPCMConfig^ _pcm; - __int64 _paddingLength; FLAC__StreamMetadata **_metadataList; int _metadataCount; @@ -696,9 +672,9 @@ namespace CUETools { namespace Codecs { namespace FLAC { //} _metadataList[_metadataCount++] = vorbiscomment; - if (_paddingLength != 0) { + if (_settings->Padding != 0) { padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - padding->length = (int)_paddingLength; + padding->length = _settings->Padding; _metadataList[_metadataCount++] = padding; } @@ -716,8 +692,8 @@ namespace CUETools { namespace Codecs { namespace FLAC { FLAC__stream_encoder_set_compression_level(_encoder, _settings->EncoderModeIndex); - if (_blockSize > 0) - FLAC__stream_encoder_set_blocksize(_encoder, (unsigned)_blockSize); + if (_settings->BlockSize > 0) + FLAC__stream_encoder_set_blocksize(_encoder, (unsigned)_settings->BlockSize); pathChars = Marshal::StringToHGlobalUni(_path); errno_t err = _wfopen_s(&hFile, (const wchar_t*)pathChars.ToPointer(), L"w+b"); diff --git a/CUETools.Codecs.FLACCL/FLACCLWriter.cs b/CUETools.Codecs.FLACCL/FLACCLWriter.cs index be4c1cc..953ec9e 100644 --- a/CUETools.Codecs.FLACCL/FLACCLWriter.cs +++ b/CUETools.Codecs.FLACCL/FLACCLWriter.cs @@ -52,6 +52,13 @@ namespace CUETools.Codecs.FLACCL return this.AllowNonSubset ? "0 1 2 3 4 5 6 7 8 9 10 11" : "0 1 2 3 4 5 6 7 8"; } + public override bool IsValid() + { + return EncoderModeIndex >= 0 && Padding >= 0 && + (BlockSize == 0 || (BlockSize >= 256 && BlockSize <= Flake.MAX_BLOCKSIZE)) && + (AllowNonSubset || EncoderModeIndex <= 8); + } + [DefaultValue(false)] [DisplayName("Verify")] [SRDescription(typeof(Properties.Resources), "DoVerifyDescription")] @@ -212,7 +219,7 @@ namespace CUETools.Codecs.FLACCL int samplesInBuffer = 0; - int _blocksize = 0; + internal int m_blockSize = 0; int _totalSize = 0; Crc8 crc8; @@ -257,7 +264,6 @@ namespace CUETools.Codecs.FLACCL _IO = IO; eparams.flake_set_defaults(7); - eparams.padding_size = _settings.Padding; crc8 = new Crc8(); } @@ -275,36 +281,19 @@ namespace CUETools.Codecs.FLACCL } } - public long Padding - { - get - { - return eparams.padding_size; - } - set - { - eparams.padding_size = value; - } - } - - internal FLACCLWriterSettings _settings = new FLACCLWriterSettings(); + internal FLACCLWriterSettings m_settings = new FLACCLWriterSettings(); public AudioEncoderSettings Settings { get { - return _settings; + return m_settings; } set { - if (value as FLACCLWriterSettings == null) - throw new Exception("Unsupported options " + value); - _settings = value as FLACCLWriterSettings; - var _compressionLevel = _settings.EncoderModeIndex; - if (_compressionLevel < 0 || _compressionLevel > 11) - throw new Exception("unsupported compression level"); + m_settings = value.Clone(); + var _compressionLevel = m_settings.EncoderModeIndex; eparams.flake_set_defaults(_compressionLevel); - eparams.padding_size = _settings.Padding; } } @@ -317,12 +306,12 @@ namespace CUETools.Codecs.FLACCL { if (inited) { - int nFrames = samplesInBuffer / eparams.block_size; + int nFrames = samplesInBuffer / m_blockSize; if (nFrames > 0) do_output_frames(nFrames); if (samplesInBuffer > 0) { - eparams.block_size = samplesInBuffer; + m_blockSize = samplesInBuffer; do_output_frames(1); } if (task2.frameCount > 0) @@ -424,16 +413,6 @@ namespace CUETools.Codecs.FLACCL set { sample_count = (int)value; } } - public long BlockSize - { - set { - if (value < 256 || value > MAX_BLOCKSIZE ) - throw new Exception("unsupported BlockSize value"); - _blocksize = (int)value; - } - get { return _blocksize == 0 ? eparams.block_size : _blocksize; } - } - public StereoMethod StereoMethod { get { return eparams.do_midside ? StereoMethod.Search : StereoMethod.Independent; } @@ -1723,8 +1702,10 @@ namespace CUETools.Codecs.FLACCL { if (OpenCL.NumberOfPlatforms < 1) throw new Exception("no opencl platforms found"); + if (!m_settings.IsValid()) + throw new Exception("unsupported encoder settings"); - int groupSize = _settings.DeviceType == OpenCLDeviceType.CPU ? 1 : _settings.GroupSize; + int groupSize = m_settings.DeviceType == OpenCLDeviceType.CPU ? 1 : m_settings.GroupSize; OCLMan = new OpenCLManager(); // Attempt to save binaries after compilation, as well as load precompiled binaries // to avoid compilation. Usually you'll want this to be true. @@ -1747,7 +1728,7 @@ namespace CUETools.Codecs.FLACCL OCLMan.SourcePath = System.IO.Path.GetDirectoryName(GetType().Assembly.Location); OCLMan.BinaryPath = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CUE Tools"), "OpenCL"); int platformId = 0; - if (_settings.Platform != null) + if (m_settings.Platform != null) { platformId = -1; string platforms = ""; @@ -1755,32 +1736,26 @@ namespace CUETools.Codecs.FLACCL { var platform = OpenCL.GetPlatform(i); platforms += " \"" + platform.Name + "\""; - if (platform.Name.Equals(_settings.Platform, StringComparison.InvariantCultureIgnoreCase)) + if (platform.Name.Equals(m_settings.Platform, StringComparison.InvariantCultureIgnoreCase)) { platformId = i; break; } } if (platformId < 0) - throw new Exception("unknown platform \"" + _settings.Platform + "\". Platforms available:" + platforms); + throw new Exception("unknown platform \"" + m_settings.Platform + "\". Platforms available:" + platforms); } - OCLMan.CreateDefaultContext(platformId, (DeviceType)_settings.DeviceType); + OCLMan.CreateDefaultContext(platformId, (DeviceType)m_settings.DeviceType); - this.framesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * Math.Max(1, _settings.TaskSize / channels); + this.framesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * Math.Max(1, m_settings.TaskSize / channels); - bool UseGPUOnly = _settings.GPUOnly && OCLMan.Context.Devices[0].Extensions.Contains("cl_khr_local_int32_extended_atomics"); - bool UseGPURice = UseGPUOnly && _settings.DoRice; + bool UseGPUOnly = m_settings.GPUOnly && OCLMan.Context.Devices[0].Extensions.Contains("cl_khr_local_int32_extended_atomics"); + bool UseGPURice = UseGPUOnly && m_settings.DoRice; - if (_blocksize == 0) - { - if (eparams.block_size == 0) - eparams.block_size = select_blocksize(sample_rate, eparams.block_time_ms); - _blocksize = eparams.block_size; - } - else - eparams.block_size = _blocksize; + m_blockSize = m_settings.BlockSize != 0 ? m_settings.BlockSize : + select_blocksize(sample_rate, eparams.block_time_ms); - int maxBS = 1 << (BitReader.log2i(eparams.block_size - 1) + 1); + int maxBS = 1 << (BitReader.log2i(m_blockSize - 1) + 1); // The Defines string gets prepended to any and all sources that are compiled // and serve as a convenient way to pass configuration information to the compilation process @@ -1796,8 +1771,8 @@ namespace CUETools.Codecs.FLACCL #if DEBUG "#define DEBUG\n" + #endif - (_settings.DeviceType == OpenCLDeviceType.CPU ? "#define FLACCL_CPU\n" : "") + - _settings.Defines + "\n"; + (m_settings.DeviceType == OpenCLDeviceType.CPU ? "#define FLACCL_CPU\n" : "") + + m_settings.Defines + "\n"; var exts = new string[] { "cl_khr_local_int32_base_atomics", "cl_khr_local_int32_extended_atomics", "cl_khr_fp64", "cl_amd_fp64" }; foreach (string extension in exts) @@ -1848,7 +1823,7 @@ namespace CUETools.Codecs.FLACCL if (_IO == null) _IO = new FileStream(_path, FileMode.Create, FileAccess.Write, FileShare.Read); - int header_size = flake_encode_init(); + int header_size = flake_encode_init(); _IO.Write(header, 0, header_size); _totalSize += header_size; if (_IO.CanSeek) @@ -1856,9 +1831,9 @@ namespace CUETools.Codecs.FLACCL task1 = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice); task2 = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice); - if (_settings.CPUThreads > 0) + if (m_settings.CPUThreads > 0) { - cpu_tasks = new FLACCLTask[_settings.CPUThreads]; + cpu_tasks = new FLACCLTask[m_settings.CPUThreads]; for (int i = 0; i < cpu_tasks.Length; i++) cpu_tasks[i] = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice); } @@ -1873,7 +1848,7 @@ namespace CUETools.Codecs.FLACCL int pos = 0; while (pos < buff.Length) { - int block = Math.Min(buff.Length - pos, eparams.block_size * framesPerTask - samplesInBuffer); + int block = Math.Min(buff.Length - pos, m_blockSize * framesPerTask - samplesInBuffer); fixed (byte* buf = buff.Bytes) AudioSamples.MemCpy(((byte*)task1.clSamplesBytesPtr) + samplesInBuffer * _pcm.BlockAlign, buf + pos * _pcm.BlockAlign, block * _pcm.BlockAlign); @@ -1881,7 +1856,7 @@ namespace CUETools.Codecs.FLACCL samplesInBuffer += block; pos += block; - int nFrames = samplesInBuffer / eparams.block_size; + int nFrames = samplesInBuffer / m_blockSize; if (nFrames >= framesPerTask) do_output_frames(nFrames); } @@ -1959,7 +1934,7 @@ namespace CUETools.Codecs.FLACCL public unsafe void do_output_frames(int nFrames) { - send_to_GPU(task1, nFrames, eparams.block_size); + send_to_GPU(task1, nFrames, m_blockSize); run_GPU_task(task1); if (task2.frameCount > 0) task2.openCLCQ.Finish(); @@ -1986,7 +1961,7 @@ namespace CUETools.Codecs.FLACCL write_result(task2); } } - int bs = eparams.block_size * nFrames; + int bs = m_blockSize * nFrames; samplesInBuffer -= bs; if (samplesInBuffer > 0) AudioSamples.MemCpy( @@ -2037,9 +2012,9 @@ namespace CUETools.Codecs.FLACCL if (eparams.variable_block_size > 0) bitwriter.writebits(16, 0); else - bitwriter.writebits(16, eparams.block_size); + bitwriter.writebits(16, m_blockSize); - bitwriter.writebits(16, eparams.block_size); + bitwriter.writebits(16, m_blockSize); bitwriter.writebits(24, 0); bitwriter.writebits(24, max_frame_size); bitwriter.writebits(20, sample_rate); @@ -2144,14 +2119,14 @@ namespace CUETools.Codecs.FLACCL header_size += write_seekpoints(header, header_size, last); // vorbis comment - if (eparams.padding_size == 0) last = 1; + if (m_settings.Padding == 0) last = 1; header_size += write_vorbis_comment(header, header_size, last); // padding - if (eparams.padding_size > 0) + if (m_settings.Padding > 0) { last = 1; - header_size += write_padding(header, header_size, last, eparams.padding_size); + header_size += write_padding(header, header_size, last, m_settings.Padding); } return header_size; @@ -2192,9 +2167,9 @@ namespace CUETools.Codecs.FLACCL // set maximum encoded frame size (if larger, re-encodes in verbatim mode) if (channels == 2) - max_frame_size = 16 + ((eparams.block_size * (int)(bits_per_sample + bits_per_sample + 1) + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * (int)(bits_per_sample + bits_per_sample + 1) + 7) >> 3); else - max_frame_size = 16 + ((eparams.block_size * channels * (int)bits_per_sample + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * channels * (int)bits_per_sample + 7) >> 3); if (_IO.CanSeek && eparams.do_seektable && sample_count > 0) { @@ -2212,11 +2187,11 @@ namespace CUETools.Codecs.FLACCL } // output header bytes - header = new byte[eparams.padding_size + 1024 + (seek_table == null ? 0 : seek_table.Length * 18)]; + header = new byte[m_settings.Padding + 1024 + (seek_table == null ? 0 : seek_table.Length * 18)]; header_len = write_headers(); // initialize CRC & MD5 - if (_IO.CanSeek && _settings.DoMD5) + if (_IO.CanSeek && m_settings.DoMD5) md5 = new MD5CryptoServiceProvider(); return header_len; @@ -2242,23 +2217,12 @@ namespace CUETools.Codecs.FLACCL // 1 = mid-side encoding public bool do_midside; - // block size in samples - // set by the user prior to calling flake_encode_init - // if set to 0, a block size is chosen based on block_time_ms - // can also be changed by user before encoding a frame - public int block_size; - // block time in milliseconds // set by the user prior to calling flake_encode_init // used to calculate block_size based on sample rate // can also be changed by user before encoding a frame public int block_time_ms; - // padding size in bytes - // set by the user prior to calling flake_encode_init - // if set to less than 0, defaults to 4096 - public long padding_size; - // minimum LPC order // set by user prior to calling flake_encode_init // if set to less than 0, it is chosen based on compression. @@ -2334,7 +2298,6 @@ namespace CUETools.Codecs.FLACCL // default to level 5 params window_function = WindowFunction.Flattop | WindowFunction.Tukey; do_midside = true; - block_size = 0; block_time_ms = 100; min_fixed_order = 0; max_fixed_order = 4; @@ -2565,7 +2528,7 @@ namespace CUETools.Codecs.FLACCL { this.UseGPUOnly = gpuOnly; this.UseGPURice = gpuOnly && gpuRice; - this.UseMappedMemory = writer._settings.MappedMemory || writer._settings.DeviceType == OpenCLDeviceType.CPU; + this.UseMappedMemory = writer.m_settings.MappedMemory || writer.m_settings.DeviceType == OpenCLDeviceType.CPU; this.groupSize = groupSize; this.channels = channels; this.channelsCount = channelsCount; @@ -2580,7 +2543,7 @@ namespace CUETools.Codecs.FLACCL int MAX_ORDER = this.writer.eparams.max_prediction_order; int MAX_FRAMES = this.writer.framesPerTask; - int MAX_CHANNELSIZE = MAX_FRAMES * ((writer.eparams.block_size + 3) & ~3); + int MAX_CHANNELSIZE = MAX_FRAMES * ((writer.m_blockSize + 3) & ~3); residualTasksLen = sizeof(FLACCLSubframeTask) * 32 * channelsCount * MAX_FRAMES; bestResidualTasksLen = sizeof(FLACCLSubframeTask) * channels * MAX_FRAMES; int samplesBufferLen = writer.PCM.BlockAlign * MAX_CHANNELSIZE * channelsCount; @@ -2699,7 +2662,7 @@ namespace CUETools.Codecs.FLACCL frame = new FlacFrame(channelsCount); frame.writer = new BitWriter(outputBuffer, 0, outputBuffer.Length); - if (writer._settings.DoVerify) + if (writer.m_settings.DoVerify) verify = new FlakeReader(new AudioPCMConfig((int)bits_per_sample, channels, 44100)); } diff --git a/CUETools.Codecs.FLAKE/FlakeWriter.cs b/CUETools.Codecs.FLAKE/FlakeWriter.cs index 8753e62..0aee750 100644 --- a/CUETools.Codecs.FLAKE/FlakeWriter.cs +++ b/CUETools.Codecs.FLAKE/FlakeWriter.cs @@ -49,6 +49,13 @@ namespace CUETools.Codecs.FLAKE return this.AllowNonSubset ? "0 1 2 3 4 5 6 7 8 9 10 11" : "0 1 2 3 4 5 6 7 8"; } + public override bool IsValid() + { + return EncoderModeIndex >= 0 && Padding >= 0 && + (BlockSize == 0 || (BlockSize >= 256 && BlockSize <= Flake.MAX_BLOCKSIZE)) && + (AllowNonSubset || EncoderModeIndex <= 8); + } + [DefaultValue(false)] [DisplayName("Verify")] [SRDescription(typeof(Properties.Resources), "DoVerifyDescription")] @@ -120,7 +127,7 @@ namespace CUETools.Codecs.FLAKE double[] windowScale; int samplesInBuffer = 0; - int _blocksize = 0; + int m_blockSize = 0; int _totalSize = 0; int _windowsize = 0, _windowcount = 0; @@ -158,7 +165,6 @@ namespace CUETools.Codecs.FLAKE windowScale = new double[lpc.MAX_LPC_WINDOWS]; eparams.flake_set_defaults(7); - eparams.padding_size = 8192; crc8 = new Crc8(); frame = new FlacFrame(channels * 2); @@ -177,38 +183,22 @@ namespace CUETools.Codecs.FLAKE } } - FlakeWriterSettings _settings = new FlakeWriterSettings(); + FlakeWriterSettings m_settings = new FlakeWriterSettings(); public AudioEncoderSettings Settings { get { - return _settings; + return m_settings; } set { - if (value as FlakeWriterSettings == null) - throw new Exception("Unsupported options " + value); - _settings = value as FlakeWriterSettings; - var _compressionLevel = _settings.EncoderModeIndex; - if (_compressionLevel < 0 || _compressionLevel > 11) - throw new Exception("unsupported compression level"); + m_settings = value.Clone(); + var _compressionLevel = m_settings.EncoderModeIndex; eparams.flake_set_defaults(_compressionLevel); } } - public long Padding - { - get - { - return eparams.padding_size; - } - set - { - eparams.padding_size = (int)value; - } - } - #if INTEROP [DllImport("kernel32.dll")] static extern bool GetThreadTimes(IntPtr hThread, out long lpCreationTime, out long lpExitTime, out long lpKernelTime, out long lpUserTime); @@ -222,7 +212,7 @@ namespace CUETools.Codecs.FLAKE { while (samplesInBuffer > 0) { - eparams.block_size = samplesInBuffer; + m_blockSize = samplesInBuffer; output_frame(); } @@ -294,12 +284,6 @@ namespace CUETools.Codecs.FLAKE set { sample_count = (int)value; } } - public long BlockSize - { - set { _blocksize = (int)value; } - get { return _blocksize == 0 ? eparams.block_size : _blocksize; } - } - public OrderMethod OrderMethod { get { return eparams.order_method; } @@ -1632,7 +1616,7 @@ new int[] { // 30 fixed (int* s = samplesBuffer, r = residualBuffer) fixed (float* window = windowBuffer) { - frame.InitSize(eparams.block_size, eparams.variable_block_size != 0); + frame.InitSize(m_blockSize, eparams.variable_block_size != 0); if (frame.blocksize != _windowsize && frame.blocksize > 4) { @@ -1745,11 +1729,11 @@ new int[] { // 30 { fixed (int* s = verifyBuffer, r = samplesBuffer) for (int ch = 0; ch < channels; ch++) - AudioSamples.MemCpy(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE, eparams.block_size); + AudioSamples.MemCpy(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE, m_blockSize); } int fs, bs; - //if (0 != eparams.variable_block_size && 0 == (eparams.block_size & 7) && eparams.block_size >= 128) + //if (0 != eparams.variable_block_size && 0 == (m_blockSize & 7) && m_blockSize >= 128) // fs = encode_frame_vbs(); //else fs = encode_frame(out bs); @@ -1788,13 +1772,13 @@ new int[] { // 30 } } - if (bs < eparams.block_size) + if (bs < m_blockSize) { for (int ch = 0; ch < (channels == 2 ? 4 : channels); ch++) - Buffer.BlockCopy(samplesBuffer, (bs + ch * Flake.MAX_BLOCKSIZE) * sizeof(int), samplesBuffer, ch * Flake.MAX_BLOCKSIZE * sizeof(int), (eparams.block_size - bs) * sizeof(int)); + Buffer.BlockCopy(samplesBuffer, (bs + ch * Flake.MAX_BLOCKSIZE) * sizeof(int), samplesBuffer, ch * Flake.MAX_BLOCKSIZE * sizeof(int), (m_blockSize - bs) * sizeof(int)); //fixed (int* s = samplesBuffer) // for (int ch = 0; ch < channels; ch++) - // AudioSamples.MemCpy(s + ch * Flake.MAX_BLOCKSIZE, s + bs + ch * Flake.MAX_BLOCKSIZE, eparams.block_size - bs); + // AudioSamples.MemCpy(s + ch * Flake.MAX_BLOCKSIZE, s + bs + ch * Flake.MAX_BLOCKSIZE, m_blockSize - bs); } samplesInBuffer -= bs; @@ -1808,6 +1792,8 @@ new int[] { // 30 { if (_IO == null) _IO = new FileStream(_path, FileMode.Create, FileAccess.Write, FileShare.Read); + if (!m_settings.IsValid()) + throw new Exception("unsupported encoder settings"); inited = true; int header_size = flake_encode_init(); _IO.Write(header, 0, header_size); @@ -1820,13 +1806,13 @@ new int[] { // 30 int pos = 0; while (pos < buff.Length) { - int block = Math.Min(buff.Length - pos, eparams.block_size - samplesInBuffer); + int block = Math.Min(buff.Length - pos, m_blockSize - samplesInBuffer); copy_samples(buff.Samples, pos, block); pos += block; - while (samplesInBuffer >= eparams.block_size) + while (samplesInBuffer >= m_blockSize) output_frame(); } @@ -1871,9 +1857,9 @@ new int[] { // 30 if (eparams.variable_block_size > 0) bitwriter.writebits(16, 0); else - bitwriter.writebits(16, eparams.block_size); + bitwriter.writebits(16, m_blockSize); - bitwriter.writebits(16, eparams.block_size); + bitwriter.writebits(16, m_blockSize); bitwriter.writebits(24, 0); bitwriter.writebits(24, max_frame_size); bitwriter.writebits(20, _pcm.SampleRate); @@ -1979,14 +1965,14 @@ new int[] { // 30 header_size += write_seekpoints(header, header_size, last); // vorbis comment - if (eparams.padding_size == 0) last = 1; + if (m_settings.Padding == 0) last = 1; header_size += write_vorbis_comment(header, header_size, last); // padding - if (eparams.padding_size > 0) + if (m_settings.Padding > 0) { last = 1; - header_size += write_padding(header, header_size, last, eparams.padding_size); + header_size += write_padding(header, header_size, last, m_settings.Padding); } return header_size; @@ -2025,20 +2011,14 @@ new int[] { // 30 if (i == 8) throw new Exception("non-standard bps"); - if (_blocksize == 0) - { - if (eparams.block_size == 0) - eparams.block_size = select_blocksize(_pcm.SampleRate, eparams.block_time_ms); - _blocksize = eparams.block_size; - } - else - eparams.block_size = _blocksize; + m_blockSize = m_settings.BlockSize != 0 ? m_settings.BlockSize : + select_blocksize(_pcm.SampleRate, eparams.block_time_ms); // set maximum encoded frame size (if larger, re-encodes in verbatim mode) if (channels == 2) - max_frame_size = 16 + ((eparams.block_size * (_pcm.BitsPerSample + _pcm.BitsPerSample + 1) + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * (_pcm.BitsPerSample + _pcm.BitsPerSample + 1) + 7) >> 3); else - max_frame_size = 16 + ((eparams.block_size * channels * _pcm.BitsPerSample + 7) >> 3); + max_frame_size = 16 + ((m_blockSize * channels * _pcm.BitsPerSample + 7) >> 3); if (_IO.CanSeek && eparams.do_seektable && sample_count > 0) { @@ -2056,14 +2036,14 @@ new int[] { // 30 } // output header bytes - header = new byte[eparams.padding_size + 1024 + (seek_table == null ? 0 : seek_table.Length * 18)]; + header = new byte[m_settings.Padding + 1024 + (seek_table == null ? 0 : seek_table.Length * 18)]; header_len = write_headers(); // initialize CRC & MD5 - if (_IO.CanSeek && _settings.DoMD5) + if (_IO.CanSeek && m_settings.DoMD5) md5 = new MD5CryptoServiceProvider(); - if (_settings.DoVerify) + if (m_settings.DoVerify) { verify = new FlakeReader(_pcm); verifyBuffer = new int[Flake.MAX_BLOCKSIZE * channels]; @@ -2110,23 +2090,12 @@ new int[] { // 30 public WindowMethod window_method; - // block size in samples - // set by the user prior to calling flake_encode_init - // if set to 0, a block size is chosen based on block_time_ms - // can also be changed by user before encoding a frame - public int block_size; - // block time in milliseconds // set by the user prior to calling flake_encode_init // used to calculate block_size based on sample rate // can also be changed by user before encoding a frame public int block_time_ms; - // padding size in bytes - // set by the user prior to calling flake_encode_init - // if set to less than 0, defaults to 4096 - public int padding_size; - // minimum LPC order // set by user prior to calling flake_encode_init // if set to less than 0, it is chosen based on compression. @@ -2206,7 +2175,6 @@ new int[] { // 30 order_method = OrderMethod.Akaike; stereo_method = StereoMethod.Evaluate; window_method = WindowMethod.Evaluate; - block_size = 0; block_time_ms = 105; prediction_type = PredictionType.Search; min_prediction_order = 1; diff --git a/CUETools.Codecs.HDCD/HDCDDotNet.cs b/CUETools.Codecs.HDCD/HDCDDotNet.cs index 86bf72d..aa266fc 100644 --- a/CUETools.Codecs.HDCD/HDCDDotNet.cs +++ b/CUETools.Codecs.HDCD/HDCDDotNet.cs @@ -89,21 +89,11 @@ namespace HDCDDotNet set { throw new Exception("unsupported"); } } - public long BlockSize - { - set { throw new Exception("unsupported"); } - } - public string Path { get { throw new Exception("unsupported"); } } - public long Padding - { - set { throw new Exception("unsupported"); } - } - public AudioEncoderSettings Settings { get { throw new Exception("unsupported"); } diff --git a/CUETools.Codecs.Icecast/IcecastWriter.cs b/CUETools.Codecs.Icecast/IcecastWriter.cs index d01ce9e..4423a20 100644 --- a/CUETools.Codecs.Icecast/IcecastWriter.cs +++ b/CUETools.Codecs.Icecast/IcecastWriter.cs @@ -200,11 +200,6 @@ namespace CUETools.Codecs.Icecast } } - public long BlockSize - { - set { } - } - public long FinalSampleCount { set { ; } @@ -223,11 +218,6 @@ namespace CUETools.Codecs.Icecast } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return pcm; } diff --git a/CUETools.Codecs.LAME/LAMEEncoder.cs b/CUETools.Codecs.LAME/LAMEEncoder.cs index e63e1e0..680f856 100644 --- a/CUETools.Codecs.LAME/LAMEEncoder.cs +++ b/CUETools.Codecs.LAME/LAMEEncoder.cs @@ -35,11 +35,6 @@ namespace CUETools.Codecs.LAME } } - public long Padding - { - set { } - } - public long Position { get { return position; } @@ -50,12 +45,6 @@ namespace CUETools.Codecs.LAME set { sample_count = (int)value; } } - public long BlockSize - { - set { } - get { return 0; } - } - public AudioPCMConfig PCM { get { return _pcm; } diff --git a/CUETools.Codecs.LAME/LAMEEncoderCBR.cs b/CUETools.Codecs.LAME/LAMEEncoderCBR.cs index d047ca8..2303403 100644 --- a/CUETools.Codecs.LAME/LAMEEncoderCBR.cs +++ b/CUETools.Codecs.LAME/LAMEEncoderCBR.cs @@ -7,19 +7,17 @@ namespace CUETools.Codecs.LAME //[AudioEncoderClass("lame CBR", "mp3", false, 2, typeof(LAMEEncoderCBRSettings))] public class LAMEEncoderCBR : LAMEEncoder { - private LAMEEncoderCBRSettings _settings = new LAMEEncoderCBRSettings(); + private LAMEEncoderCBRSettings m_settings = new LAMEEncoderCBRSettings(); public override AudioEncoderSettings Settings { get { - return _settings; + return m_settings; } set { - if (value as LAMEEncoderCBRSettings == null) - throw new Exception("Unsupported options " + value); - _settings = value as LAMEEncoderCBRSettings; + m_settings = value.Clone(); } } @@ -35,9 +33,9 @@ namespace CUETools.Codecs.LAME protected override BE_CONFIG MakeConfig() { - BE_CONFIG Mp3Config = new BE_CONFIG(PCM, _settings.CustomBitrate > 0 ? (uint)_settings.CustomBitrate : LAMEEncoderCBRSettings.bps_table[_settings.EncoderModeIndex], 5); + BE_CONFIG Mp3Config = new BE_CONFIG(PCM, m_settings.CustomBitrate > 0 ? (uint)m_settings.CustomBitrate : LAMEEncoderCBRSettings.bps_table[m_settings.EncoderModeIndex], 5); Mp3Config.format.lhv1.bWriteVBRHeader = 1; - Mp3Config.format.lhv1.nMode = _settings.StereoMode; + Mp3Config.format.lhv1.nMode = m_settings.StereoMode; //Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; // --cbr //Mp3Config.format.lhv1.nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY; return Mp3Config; diff --git a/CUETools.Codecs.LAME/LAMEEncoderVBR.cs b/CUETools.Codecs.LAME/LAMEEncoderVBR.cs index 731848b..726879a 100644 --- a/CUETools.Codecs.LAME/LAMEEncoderVBR.cs +++ b/CUETools.Codecs.LAME/LAMEEncoderVBR.cs @@ -7,19 +7,17 @@ namespace CUETools.Codecs.LAME //[AudioEncoderClass("lame VBR", "mp3", false, 2, typeof(LAMEEncoderVBRSettings))] public class LAMEEncoderVBR : LAMEEncoder { - private LAMEEncoderVBRSettings _settings = new LAMEEncoderVBRSettings(); + private LAMEEncoderVBRSettings m_settings = new LAMEEncoderVBRSettings(); public override AudioEncoderSettings Settings { get { - return _settings; + return m_settings; } set { - if (value as LAMEEncoderVBRSettings == null) - throw new Exception("Unsupported options " + value); - _settings = value as LAMEEncoderVBRSettings; + m_settings = value.Clone(); } } @@ -35,11 +33,11 @@ namespace CUETools.Codecs.LAME protected override BE_CONFIG MakeConfig() { - BE_CONFIG Mp3Config = new BE_CONFIG(PCM, 0, (uint)_settings.Quality); + BE_CONFIG Mp3Config = new BE_CONFIG(PCM, 0, (uint)m_settings.Quality); Mp3Config.format.lhv1.bWriteVBRHeader = 1; Mp3Config.format.lhv1.nMode = MpegMode.JOINT_STEREO; Mp3Config.format.lhv1.bEnableVBR = 1; - Mp3Config.format.lhv1.nVBRQuality = 9 - _settings.EncoderModeIndex; + Mp3Config.format.lhv1.nVBRQuality = 9 - m_settings.EncoderModeIndex; Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW; // --vbr-new return Mp3Config; } diff --git a/CUETools.Codecs.LAME/LameWriter.cs b/CUETools.Codecs.LAME/LameWriter.cs index b10875d..31f8995 100644 --- a/CUETools.Codecs.LAME/LameWriter.cs +++ b/CUETools.Codecs.LAME/LameWriter.cs @@ -58,11 +58,6 @@ namespace CUETools.Codecs.LAME private uint m_finalSampleCount; private byte[] m_outputBuffer; - public long BlockSize - { - set { } - } - public long FinalSampleCount { set @@ -80,11 +75,6 @@ namespace CUETools.Codecs.LAME get { return this.m_pcm; } } - public long Padding - { - set { } - } - public string Path { get { return this.m_outputPath; } @@ -100,9 +90,7 @@ namespace CUETools.Codecs.LAME } set { - if (value as LameWriterSettings == null) - throw new InvalidOperationException("Unsupported options " + value); - m_settings = value as LameWriterSettings; + m_settings = value.Clone(); } } diff --git a/CUETools.Codecs.LossyWAV/LossyWAVWriter.cs b/CUETools.Codecs.LossyWAV/LossyWAVWriter.cs index e4a23b8..4fa91ca 100644 --- a/CUETools.Codecs.LossyWAV/LossyWAVWriter.cs +++ b/CUETools.Codecs.LossyWAV/LossyWAVWriter.cs @@ -71,11 +71,6 @@ namespace CUETools.Codecs.LossyWAV } } - public long BlockSize - { - set { } - } - public AudioEncoderSettings Settings { get @@ -89,11 +84,6 @@ namespace CUETools.Codecs.LossyWAV } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return _pcm; } @@ -488,8 +478,8 @@ namespace CUETools.Codecs.LossyWAV string factString = "lossyWAV " + version_string + " @ " + datestamp + ", " + parameter_string + "\r\n\0"; if (_audioDest != null && _audioDest is WAVWriter) ((WAVWriter)_audioDest).WriteChunk(fccFact, new ASCIIEncoding().GetBytes(factString)); if (_lwcdfDest != null && _lwcdfDest is WAVWriter) ((WAVWriter)_lwcdfDest).WriteChunk(fccFact, new ASCIIEncoding().GetBytes(factString)); - if (_audioDest != null) _audioDest.BlockSize = codec_block_size; - if (_lwcdfDest != null) _lwcdfDest.BlockSize = codec_block_size * 2; + if (_audioDest != null) _audioDest.Settings.BlockSize = codec_block_size; + if (_lwcdfDest != null) _lwcdfDest.Settings.BlockSize = codec_block_size * 2; } double fill_fft_input(int actual_analysis_block_start, int this_fft_length, int channel) diff --git a/CUETools.Codecs.TTA/CUETools.Codecs.TTA.cpp b/CUETools.Codecs.TTA/CUETools.Codecs.TTA.cpp index 61929b6..5159e59 100644 --- a/CUETools.Codecs.TTA/CUETools.Codecs.TTA.cpp +++ b/CUETools.Codecs.TTA/CUETools.Codecs.TTA.cpp @@ -211,6 +211,7 @@ namespace TTA { public: TTAWriter(String^ path, AudioPCMConfig^ pcm) { + _settings = gcnew AudioEncoderSettings(); _pcm = pcm; if (_pcm->BitsPerSample < 16 || _pcm->BitsPerSample > 24) @@ -221,7 +222,6 @@ namespace TTA { _path = path; _finalSampleCount = 0; _samplesWritten = 0; - _blockSize = 0; } virtual void Close() { @@ -271,14 +271,6 @@ namespace TTA { } } - virtual property Int64 BlockSize - { - void set(Int64 value) - { - _blockSize = value; - } - } - virtual property AudioPCMConfig^ PCM { AudioPCMConfig^ get() { return _pcm; } @@ -315,23 +307,16 @@ namespace TTA { _samplesWritten += sampleBuffer->Length; } - virtual property __int64 Padding - { - void set(__int64 value) { - } - } - virtual property AudioEncoderSettings^ Settings { AudioEncoderSettings^ get() { - return gcnew AudioEncoderSettings(); + return _settings; } void set(AudioEncoderSettings^ value) { - if (value != nullptr && value->GetType() != AudioEncoderSettings::typeid) - throw gcnew Exception(String::Format("Unsupported options: {0}", value)); + _settings = value->Clone(); } } @@ -341,8 +326,9 @@ namespace TTA { array^ _sampleBuffer; bool _initialized; String^ _path; - Int64 _finalSampleCount, _samplesWritten, _blockSize; + Int64 _finalSampleCount, _samplesWritten; AudioPCMConfig^ _pcm; + AudioEncoderSettings^ _settings; void Initialize() { diff --git a/CUETools.Codecs.WMA/WMAWriter.cs b/CUETools.Codecs.WMA/WMAWriter.cs index 1cd495b..2fbcb03 100644 --- a/CUETools.Codecs.WMA/WMAWriter.cs +++ b/CUETools.Codecs.WMA/WMAWriter.cs @@ -26,11 +26,6 @@ namespace CUETools.Codecs.WMA private AudioPCMConfig pcm; private long sampleCount, finalSampleCount; - public long BlockSize - { - set { } - } - public long FinalSampleCount { set @@ -44,11 +39,6 @@ namespace CUETools.Codecs.WMA get { return this.pcm; } } - public long Padding - { - set { } - } - public string Path { get { return this.outputPath; } @@ -64,9 +54,7 @@ namespace CUETools.Codecs.WMA } set { - if (value != null && value.GetType() != typeof(AudioEncoderSettings)) - throw new Exception("Unsupported options " + value); - m_settings = value; + m_settings = value.Clone(); } } diff --git a/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp index 06a6c51..fd454cf 100644 --- a/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp +++ b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp @@ -351,8 +351,6 @@ namespace CUETools { namespace Codecs { namespace WavPack { _path = path; - _blockSize = 0; - IntPtr pathChars = Marshal::StringToHGlobalUni(path); _hFile = _wfopen((const wchar_t*)pathChars.ToPointer(), L"w+b"); Marshal::FreeHGlobal(pathChars); @@ -400,14 +398,6 @@ namespace CUETools { namespace Codecs { namespace WavPack { } } - virtual property Int64 BlockSize - { - void set(Int64 value) - { - _blockSize = value; - } - } - virtual property AudioPCMConfig^ PCM { AudioPCMConfig^ get() { return _pcm; } @@ -452,12 +442,6 @@ namespace CUETools { namespace Codecs { namespace WavPack { } } - virtual property __int64 Padding - { - void set(__int64 value) { - } - } - virtual property AudioEncoderSettings^ Settings { AudioEncoderSettings^ get() @@ -467,9 +451,7 @@ namespace CUETools { namespace Codecs { namespace WavPack { void set(AudioEncoderSettings^ value) { - if (value == nullptr || value->GetType() != WavPackWriterSettings::typeid) - throw gcnew Exception(String::Format("Unsupported options: {0}", value)); - _settings = (WavPackWriterSettings^)value; + _settings = value->Clone(); } } @@ -487,7 +469,6 @@ namespace CUETools { namespace Codecs { namespace WavPack { bool _initialized; WavpackContext *_wpc; Int32 _finalSampleCount, _samplesWritten; - Int32 _blockSize; String^ _path; MD5^ _md5hasher; array^ _shiftedSampleBuffer; @@ -522,8 +503,8 @@ namespace CUETools { namespace Codecs { namespace WavPack { _md5hasher = gcnew MD5CryptoServiceProvider (); config.flags |= CONFIG_MD5_CHECKSUM; } - config.block_samples = (int)_blockSize; - if (_blockSize > 0 && _blockSize < 2048) + config.block_samples = (int)_settings->BlockSize; + if (_settings->BlockSize > 0 && _settings->BlockSize < 2048) config.flags |= CONFIG_MERGE_BLOCKS; if (!WavpackSetConfiguration(_wpc, &config, (_finalSampleCount == 0) ? -1 : _finalSampleCount)) { diff --git a/CUETools.Codecs/AudioEncoderSettings.cs b/CUETools.Codecs/AudioEncoderSettings.cs index 57fc3b4..3ac6589 100644 --- a/CUETools.Codecs/AudioEncoderSettings.cs +++ b/CUETools.Codecs/AudioEncoderSettings.cs @@ -13,24 +13,54 @@ namespace CUETools.Codecs // Iterate through each property and call ResetValue() foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this)) property.ResetValue(this); - this.supported_modes = ""; + this.m_supported_modes = ""; this.EncoderMode = ""; } - public AudioEncoderSettings(string _supported_modes, string _default_mode) + public AudioEncoderSettings(string supported_modes, string default_mode) { // Iterate through each property and call ResetValue() foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this)) property.ResetValue(this); - this.supported_modes = _supported_modes; - this.EncoderMode = _default_mode; + this.m_supported_modes = supported_modes; + this.EncoderMode = default_mode; } - private string supported_modes; + private string m_supported_modes; public virtual string GetSupportedModes() { - return this.supported_modes; + return this.m_supported_modes; + } + + public virtual bool IsValid() + { + return BlockSize == 0 && Padding >= 0; + } + + public T Clone() where T : AudioEncoderSettings + { + if (this as T == null) + throw new Exception("Unsupported options " + this); + var result = this.MemberwiseClone() as T; + if (!result.IsValid()) + throw new Exception("unsupported encoder settings"); + return result; + } + + [Browsable(false)] + [DefaultValue(0)] + public int BlockSize + { + get; set; + } + + [Browsable(false)] + [DefaultValue(4096)] + public int Padding + { + get; + set; } [Browsable(false)] diff --git a/CUETools.Codecs/DummyWriter.cs b/CUETools.Codecs/DummyWriter.cs index 5bcefd6..b024368 100644 --- a/CUETools.Codecs/DummyWriter.cs +++ b/CUETools.Codecs/DummyWriter.cs @@ -37,16 +37,6 @@ namespace CUETools.Codecs } } - public long Padding - { - set { } - } - - public long BlockSize - { - set { } - } - public AudioPCMConfig PCM { get { return _pcm; } diff --git a/CUETools.Codecs/IAudioDest.cs b/CUETools.Codecs/IAudioDest.cs index 14fa109..130e609 100644 --- a/CUETools.Codecs/IAudioDest.cs +++ b/CUETools.Codecs/IAudioDest.cs @@ -7,8 +7,6 @@ AudioEncoderSettings Settings { get; set; } long FinalSampleCount { set; } - long BlockSize { set; } - long Padding { set; } void Write(AudioBuffer buffer); void Close(); diff --git a/CUETools.Codecs/UserDefinedWriter.cs b/CUETools.Codecs/UserDefinedWriter.cs index edd7483..d84f01b 100644 --- a/CUETools.Codecs/UserDefinedWriter.cs +++ b/CUETools.Codecs/UserDefinedWriter.cs @@ -28,30 +28,21 @@ namespace CUETools.Codecs set { _finalSampleCount = wrt.FinalSampleCount = value; } } - public long BlockSize - { - set { } - } - // !!!! Must not start the process in constructor, so that we can set CompressionLevel via Settings! + private AudioEncoderSettings m_settings = new AudioEncoderSettings(); + public AudioEncoderSettings Settings { get { - return new AudioEncoderSettings(); + return m_settings; } set { - if (value != null && value.GetType() != typeof(AudioEncoderSettings)) - throw new Exception("Unsupported options " + value); + m_settings = value.Clone(); } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return wrt.PCM; } diff --git a/CUETools.Codecs/WAVWriter.cs b/CUETools.Codecs/WAVWriter.cs index 43151e3..9524ca7 100644 --- a/CUETools.Codecs/WAVWriter.cs +++ b/CUETools.Codecs/WAVWriter.cs @@ -31,11 +31,6 @@ namespace CUETools.Codecs set { _finalSampleCount = value; } } - public long BlockSize - { - set { } - } - public AudioEncoderSettings Settings { get @@ -49,11 +44,6 @@ namespace CUETools.Codecs } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return _pcm; } diff --git a/CUETools.DSP.Mixer/MixingWriter.cs b/CUETools.DSP.Mixer/MixingWriter.cs index 2cda5bf..5cd5c45 100644 --- a/CUETools.DSP.Mixer/MixingWriter.cs +++ b/CUETools.DSP.Mixer/MixingWriter.cs @@ -22,11 +22,6 @@ namespace CUETools.DSP.Mixer set { throw new NotSupportedException(); } } - public long BlockSize - { - set { throw new NotSupportedException(); } - } - public AudioEncoderSettings Settings { get @@ -40,11 +35,6 @@ namespace CUETools.DSP.Mixer } } - public long Padding - { - set { } - } - public AudioPCMConfig PCM { get { return mixer.PCM; } diff --git a/CUETools.FLACCL.cmd/Program.cs b/CUETools.FLACCL.cmd/Program.cs index a3af729..f3d6dc9 100644 --- a/CUETools.FLACCL.cmd/Program.cs +++ b/CUETools.FLACCL.cmd/Program.cs @@ -81,14 +81,13 @@ namespace CUETools.FLACCL.cmd string input_file = null; string output_file = null; string device_type = null; - int min_partition_order = -1, max_partition_order = -1, - min_lpc_order = -1, max_lpc_order = -1, - min_fixed_order = -1, max_fixed_order = -1, - min_precision = -1, max_precision = -1, - orders_per_window = -1, orders_per_channel = -1, - blocksize = -1; + int min_partition_order = -1, max_partition_order = -1, + min_lpc_order = -1, max_lpc_order = -1, + min_fixed_order = -1, max_fixed_order = -1, + min_precision = -1, max_precision = -1, + orders_per_window = -1, orders_per_channel = -1; int input_len = 4096, input_val = 0, input_bps = 16, input_ch = 2, input_rate = 44100; - int level = -1, padding = -1, vbr_mode = -1; + int level = -1, vbr_mode = -1; bool do_seektable = true; bool estimate_window = false; bool buffered = false; @@ -184,9 +183,9 @@ namespace CUETools.FLACCL.cmd else if (args[arg] == "--estimate-window") estimate_window = true; else if ((args[arg] == "-b" || args[arg] == "--blocksize") && ++arg < args.Length && int.TryParse(args[arg], out intarg)) - blocksize = intarg; + settings.BlockSize = intarg; else if ((args[arg] == "-p" || args[arg] == "--padding") && ++arg < args.Length && int.TryParse(args[arg], out intarg)) - padding = intarg; + settings.Padding = intarg; else if (args[arg] != "-" && args[arg][0] == '-' && int.TryParse(args[arg].Substring(1), out level)) { ok = level >= 0 && level <= 11; @@ -260,7 +259,7 @@ namespace CUETools.FLACCL.cmd { if (device_type != null) settings.DeviceType = (OpenCLDeviceType)(Enum.Parse(typeof(OpenCLDeviceType), device_type, true)); - encoder.Settings = settings; + encoder.Settings = settings; if (stereo_method != null) encoder.StereoMethod = Flake.LookupStereoMethod(stereo_method); if (window_function != null) @@ -281,10 +280,6 @@ namespace CUETools.FLACCL.cmd encoder.MaxPrecisionSearch = max_precision; if (min_precision >= 0) encoder.MinPrecisionSearch = min_precision; - if (blocksize >= 0) - encoder.BlockSize = blocksize; - if (padding >= 0) - encoder.Padding = padding; if (vbr_mode >= 0) encoder.VBRMode = vbr_mode; if (orders_per_window >= 0) @@ -386,7 +381,7 @@ namespace CUETools.FLACCL.cmd encoder.MaxLPCOrder, encoder.MinPrecisionSearch, encoder.MaxPrecisionSearch, - encoder.BlockSize, + encoder.Settings.BlockSize, encoder.VBRMode, encoder.MaxFixedOrder - encoder.MinFixedOrder + 1, encoder.DoConstant ? "c" : "" diff --git a/CUETools.Flake/Program.cs b/CUETools.Flake/Program.cs index 950592d..2eeb645 100644 --- a/CUETools.Flake/Program.cs +++ b/CUETools.Flake/Program.cs @@ -141,12 +141,13 @@ namespace CUETools.FlakeExe min_lpc_order = -1, max_lpc_order = -1, min_fixed_order = -1, max_fixed_order = -1, min_precision = -1, max_precision = -1, - blocksize = -1, estimation_depth = -1; + estimation_depth = -1; int skip_a = 0, skip_b = 0; - int level = -1, padding = -1, vbr_mode = -1, magic = -1; - bool do_md5 = true, do_seektable = true, do_verify = false; + int intarg = -1, vbr_mode = -1, magic = -1; + bool do_seektable = true; bool buffered = false; string coeffs = null; + var settings = new FlakeWriterSettings(); #if FINETUNE int finetune_depth = -1; #endif @@ -161,11 +162,11 @@ namespace CUETools.FlakeExe else if ((args[arg] == "-q" || args[arg] == "--quiet")) quiet = true; else if (args[arg] == "--verify") - do_verify = true; + settings.DoVerify = true; else if (args[arg] == "--no-seektable") do_seektable = false; else if (args[arg] == "--no-md5") - do_md5 = false; + settings.DoMD5 = false; else if (args[arg] == "--buffered") buffered = true; else if ((args[arg] == "-o" || args[arg] == "--output") && ++arg < args.Length) @@ -219,10 +220,10 @@ namespace CUETools.FlakeExe } else if ((args[arg] == "-v" || args[arg] == "--vbr")) ok = (++arg < args.Length) && int.TryParse(args[arg], out vbr_mode); - else if ((args[arg] == "-b" || args[arg] == "--blocksize") && ++arg < args.Length) - ok = int.TryParse(args[arg], out blocksize); - else if ((args[arg] == "-p" || args[arg] == "--padding") && ++arg < args.Length) - ok = int.TryParse(args[arg], out padding); + else if ((args[arg] == "-b" || args[arg] == "--blocksize") && ++arg < args.Length && int.TryParse(args[arg], out intarg)) + settings.BlockSize = intarg; + else if ((args[arg] == "-p" || args[arg] == "--padding") && ++arg < args.Length && int.TryParse(args[arg], out intarg)) + settings.Padding = intarg; else if (args[arg] == "--magic" && ++arg < args.Length) ok = int.TryParse(args[arg], out magic); #if FINETUNE @@ -231,8 +232,11 @@ namespace CUETools.FlakeExe #endif else if (args[arg] == "--coefs" && ++arg < args.Length) coeffs = args[arg]; - else if (args[arg] != "-" && args[arg][0] == '-' && int.TryParse(args[arg].Substring(1), out level)) - ok = level >= 0 && level <= 11; + else if (args[arg] != "-" && args[arg][0] == '-' && int.TryParse(args[arg].Substring(1), out intarg)) + { + ok = intarg >= 0 && intarg <= 11; + settings.EncoderModeIndex = intarg; + } else if ((args[arg][0] != '-' || args[arg] == "-") && input_file == null) input_file = args[arg]; else @@ -326,15 +330,9 @@ namespace CUETools.FlakeExe flake.FinalSampleCount = audioSource.Length - skip_a - skip_b; IAudioDest audioDest = flake; AudioBuffer buff = new AudioBuffer(audioSource, 0x10000); - var settings = new FlakeWriterSettings(); try { - if (level >= 0) - settings.EncoderModeIndex = level; - settings.DoVerify = do_verify; - settings.DoMD5 = do_md5; - flake.Settings = settings; if (prediction_type != null) flake.PredictionType = Flake.LookupPredictionType(prediction_type); @@ -362,12 +360,8 @@ namespace CUETools.FlakeExe flake.MinPrecisionSearch = min_precision; if (max_precision >= 0) flake.MaxPrecisionSearch = max_precision; - if (blocksize >= 0) - flake.BlockSize = blocksize; if (estimation_depth >= 0) flake.EstimationDepth = estimation_depth; - if (padding >= 0) - flake.Padding = padding; if (vbr_mode >= 0) flake.VBRMode = vbr_mode; if (magic >= 0) @@ -475,7 +469,7 @@ namespace CUETools.FlakeExe flake.MaxFixedOrder, flake.MinPrecisionSearch, flake.MaxPrecisionSearch, - flake.BlockSize, + flake.Settings.BlockSize, flake.VBRMode, coeffs ?? "" ); diff --git a/CUETools.Processor/AudioReadWrite.cs b/CUETools.Processor/AudioReadWrite.cs index 63820d8..26ea0ad 100644 --- a/CUETools.Processor/AudioReadWrite.cs +++ b/CUETools.Processor/AudioReadWrite.cs @@ -98,8 +98,8 @@ namespace CUETools.Processor else throw new Exception("Unsupported audio type: " + path); dest.Settings = encoder.settings; - dest.FinalSampleCount = finalSampleCount; - dest.Padding = padding; + dest.Settings.Padding = padding; + dest.FinalSampleCount = finalSampleCount; return dest; } diff --git a/CUETools/CUETools.TestCodecs/ALACWriterTest.cs b/CUETools/CUETools.TestCodecs/ALACWriterTest.cs index 4797c2b..ccd4f2c 100644 --- a/CUETools/CUETools.TestCodecs/ALACWriterTest.cs +++ b/CUETools/CUETools.TestCodecs/ALACWriterTest.cs @@ -80,7 +80,7 @@ namespace CUETools.TestCodecs ALACWriter target; target = new ALACWriter("alacwriter1.m4a", null, buff.PCM); - target.Padding = 1; + target.Settings.Padding = 1; target.Vendor = "CUETools"; target.CreationTime = DateTime.Parse("15 Aug 1976"); target.FinalSampleCount = buff.Length; @@ -89,7 +89,7 @@ namespace CUETools.TestCodecs CollectionAssert.AreEqual(File.ReadAllBytes("alac.m4a"), File.ReadAllBytes("alacwriter1.m4a"), "alacwriter1.m4a doesn't match."); target = new ALACWriter("alacwriter0.m4a", null, buff.PCM); - target.Padding = 1; + target.Settings.Padding = 1; target.Vendor = "CUETools"; target.CreationTime = DateTime.Parse("15 Aug 1976"); target.Write(buff); diff --git a/CUETools/CUETools.TestCodecs/FlacWriterTest.cs b/CUETools/CUETools.TestCodecs/FlacWriterTest.cs index 6f074a1..6bf00bf 100644 --- a/CUETools/CUETools.TestCodecs/FlacWriterTest.cs +++ b/CUETools/CUETools.TestCodecs/FlacWriterTest.cs @@ -39,8 +39,8 @@ namespace CUETools.TestCodecs FLACWriter target; target = new FLACWriter("flacwriter2.flac", buff.PCM); - target.Padding = 1; - target.BlockSize = 32; + target.Settings.Padding = 1; + target.Settings.BlockSize = 32; //target.Vendor = "CUETools"; //target.CreationTime = DateTime.Parse("15 Aug 1976"); target.FinalSampleCount = buff.Length; diff --git a/CUETools/CUETools.TestCodecs/FlakeWriterTest.cs b/CUETools/CUETools.TestCodecs/FlakeWriterTest.cs index eb005dc..7774c9a 100644 --- a/CUETools/CUETools.TestCodecs/FlakeWriterTest.cs +++ b/CUETools/CUETools.TestCodecs/FlakeWriterTest.cs @@ -80,7 +80,7 @@ namespace CUETools.TestCodecs FlakeWriter target; target = new FlakeWriter("flakewriter0.flac", null, buff.PCM); - target.Padding = 1; + target.Settings.Padding = 1; target.DoSeekTable = false; //target.Vendor = "CUETools"; //target.CreationTime = DateTime.Parse("15 Aug 1976"); @@ -90,7 +90,7 @@ namespace CUETools.TestCodecs CollectionAssert.AreEqual(File.ReadAllBytes("flake.flac"), File.ReadAllBytes("flakewriter0.flac"), "flakewriter0.flac doesn't match."); target = new FlakeWriter("flakewriter1.flac", null, buff.PCM); - target.Padding = 1; + target.Settings.Padding = 1; target.DoSeekTable = false; //target.Vendor = "CUETools"; //target.CreationTime = DateTime.Parse("15 Aug 1976");