mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Code cleanup; Reader classes renamed to Decoders, Writers to Encoders, every Decoder must have a corresponding Settings class now just like Encoders. UserDefinedEncoders renamed to CommandLineEncoders, etc.
This commit is contained in:
@@ -13,37 +13,23 @@ namespace CUETools.Codecs
|
||||
/// <example>
|
||||
/// <code lang="C#">using CUETools.Codecs;
|
||||
///
|
||||
///[AudioDecoderClass("libFLAC", "flac")]
|
||||
///[AudioDecoderClass(typeof(MyDecoderSettings))]
|
||||
///public class MyDecoder : IAudioSource {
|
||||
/// ...
|
||||
///}</code>
|
||||
/// </example>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
public sealed class AudioDecoderClass : Attribute
|
||||
public sealed class AudioDecoderClassAttribute : Attribute
|
||||
{
|
||||
public string DecoderName
|
||||
public Type Settings
|
||||
{
|
||||
get;
|
||||
set;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Extension
|
||||
public AudioDecoderClassAttribute(Type settings)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public int Priority
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public AudioDecoderClass(string decoderName, string extension, int priority)
|
||||
{
|
||||
DecoderName = decoderName;
|
||||
Extension = extension;
|
||||
Priority = priority;
|
||||
Settings = settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,41 @@ using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class AudioDecoderSettings
|
||||
public interface IAudioDecoderSettings
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
string Extension { get; }
|
||||
|
||||
Type DecoderType { get; }
|
||||
|
||||
bool Lossless { get; }
|
||||
|
||||
int Priority { get; }
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioDecoderSettings: IAudioDecoderSettings
|
||||
{
|
||||
[Browsable(false)]
|
||||
public virtual string Name => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual string Extension => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual Type DecoderType => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual bool Lossless => true;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual int Priority => 0;
|
||||
|
||||
public AudioDecoderSettings()
|
||||
{
|
||||
// Iterate through each property and call ResetValue()
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace CUETools.Codecs
|
||||
/// <example>
|
||||
/// <code lang="C#">using CUETools.Codecs;
|
||||
///
|
||||
///[AudioEncoderClass("libFLAC", "flac", true, "0 1 2 3 4 5 6 7 8", "5", 1)]
|
||||
///[AudioEncoderClass(typeof(MyEncoderSettings))]
|
||||
///public class MyEncoder : IAudioDest {
|
||||
/// ...
|
||||
///}</code>
|
||||
@@ -21,43 +21,15 @@ namespace CUETools.Codecs
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public sealed class AudioEncoderClassAttribute : Attribute
|
||||
{
|
||||
private string _encoderName, _extension;
|
||||
private bool _lossless;
|
||||
private int _priority;
|
||||
private Type _settings;
|
||||
|
||||
public string EncoderName
|
||||
{
|
||||
get { return _encoderName; }
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get { return _extension; }
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get { return _lossless; }
|
||||
}
|
||||
|
||||
public int Priority
|
||||
{
|
||||
get { return _priority; }
|
||||
}
|
||||
|
||||
public Type Settings
|
||||
{
|
||||
get { return _settings; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public AudioEncoderClassAttribute(string encoderName, string extension, bool lossless, int priority, Type settings)
|
||||
public AudioEncoderClassAttribute(Type settings)
|
||||
{
|
||||
_encoderName = encoderName;
|
||||
_extension = extension;
|
||||
_lossless = lossless;
|
||||
_priority = priority;
|
||||
_settings = settings;
|
||||
Settings = settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public interface IAudioEncoderSettings
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
string Extension { get; }
|
||||
|
||||
Type EncoderType { get; }
|
||||
|
||||
bool Lossless { get; }
|
||||
|
||||
int Priority { get; }
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioEncoderSettings
|
||||
{
|
||||
[Browsable(false)]
|
||||
public virtual string Name => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual string Extension => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual Type EncoderType => null;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual bool Lossless => false;
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual int Priority => 0;
|
||||
|
||||
public AudioEncoderSettings()
|
||||
: this("", "")
|
||||
{
|
||||
@@ -99,7 +128,6 @@ namespace CUETools.Codecs
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[XmlIgnore]
|
||||
public AudioPCMConfig PCM
|
||||
{
|
||||
get;
|
||||
@@ -116,7 +144,6 @@ namespace CUETools.Codecs
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[XmlIgnore]
|
||||
[DefaultValue(4096)]
|
||||
public int Padding
|
||||
{
|
||||
@@ -126,13 +153,13 @@ namespace CUETools.Codecs
|
||||
|
||||
[Browsable(false)]
|
||||
[DefaultValue("")]
|
||||
[JsonProperty]
|
||||
public string EncoderMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
[Browsable(false)]
|
||||
public int EncoderModeIndex
|
||||
{
|
||||
|
||||
@@ -16,4 +16,8 @@
|
||||
<Company />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -12,15 +12,15 @@ namespace CUETools.Codecs
|
||||
public class CUEToolsCodecsConfig
|
||||
{
|
||||
public Dictionary<string, CUEToolsFormat> formats;
|
||||
public CUEToolsUDCList encoders;
|
||||
public CUEToolsUDCList decoders;
|
||||
public CUEToolsUDCEncoderList encoders;
|
||||
public CUEToolsUDCDecoderList decoders;
|
||||
|
||||
public CUEToolsCodecsConfig(CUEToolsCodecsConfig src)
|
||||
{
|
||||
encoders = new CUEToolsUDCList(true);
|
||||
encoders = new CUEToolsUDCEncoderList();
|
||||
foreach (var enc in src.encoders)
|
||||
encoders.Add(enc.Clone());
|
||||
decoders = new CUEToolsUDCList(false);
|
||||
decoders = new CUEToolsUDCDecoderList();
|
||||
foreach (var dec in src.decoders)
|
||||
decoders.Add(dec.Clone());
|
||||
formats = new Dictionary<string, CUEToolsFormat>();
|
||||
@@ -30,38 +30,44 @@ namespace CUETools.Codecs
|
||||
|
||||
public CUEToolsCodecsConfig(List<Type> encs, List<Type> decs)
|
||||
{
|
||||
encoders = new CUEToolsUDCList(true);
|
||||
encoders = new CUEToolsUDCEncoderList();
|
||||
foreach (Type type in encs)
|
||||
foreach (AudioEncoderClassAttribute enc in Attribute.GetCustomAttributes(type, typeof(AudioEncoderClassAttribute)))
|
||||
{
|
||||
try
|
||||
{
|
||||
encoders.Add(new CUEToolsUDC(enc, type));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel(enc));
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
decoders = new CUEToolsUDCList(false);
|
||||
|
||||
decoders = new CUEToolsUDCDecoderList();
|
||||
foreach (Type type in decs)
|
||||
foreach (AudioDecoderClass dec in Attribute.GetCustomAttributes(type, typeof(AudioDecoderClass)))
|
||||
decoders.Add(new CUEToolsUDC(dec, type));
|
||||
foreach (AudioDecoderClassAttribute dec in Attribute.GetCustomAttributes(type, typeof(AudioDecoderClassAttribute)))
|
||||
try
|
||||
{
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(Activator.CreateInstance(dec.Settings) as AudioDecoderSettings));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
if (Type.GetType("Mono.Runtime", false) == null)
|
||||
{
|
||||
encoders.Add(new CUEToolsUDC("flake", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11 12", "8", "flake.exe", "-%M - -o %O -p %P"));
|
||||
encoders.Add(new CUEToolsUDC("takc", "tak", true, "0 1 2 2e 2m 3 3e 3m 4 4e 4m", "2", "takc.exe", "-e -p%M -overwrite - %O"));
|
||||
encoders.Add(new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "-i - -f ipod -acodec alac -y %O"));
|
||||
encoders.Add(new CUEToolsUDC("VBR (lame.exe)", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", "lame.exe", "--vbr-new -%M - %O"));
|
||||
encoders.Add(new CUEToolsUDC("CBR (lame.exe)", "mp3", false, "96 128 192 256 320", "256", "lame.exe", "-m s -q 0 -b %M --noreplaygain - %O"));
|
||||
encoders.Add(new CUEToolsUDC("oggenc", "ogg", false, "-1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8", "3", "oggenc.exe", "-q %M - -o %O"));
|
||||
encoders.Add(new CUEToolsUDC("opusenc", "opus", false, "6 16 32 48 64 96 128 192 256", "128", "opusenc.exe", "--bitrate %M - %O"));
|
||||
encoders.Add(new CUEToolsUDC("nero aac", "m4a", false, "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9", "0.4", "neroAacEnc.exe", "-q %M -if - -of %O"));
|
||||
encoders.Add(new CUEToolsUDC("qaac tvbr", "m4a", false, "10 20 30 40 50 60 70 80 90 100 110 127", "80", "qaac.exe", "-s -V %M -q 2 - -o %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("flake", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11 12", "8", "flake.exe", "-%M - -o %O -p %P"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("takc", "tak", true, "0 1 2 2e 2m 3 3e 3m 4 4e 4m", "2", "takc.exe", "-e -p%M -overwrite - %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "-i - -f ipod -acodec alac -y %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("VBR (lame.exe)", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", "lame.exe", "--vbr-new -%M - %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("CBR (lame.exe)", "mp3", false, "96 128 192 256 320", "256", "lame.exe", "-m s -q 0 -b %M --noreplaygain - %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("oggenc", "ogg", false, "-1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8", "3", "oggenc.exe", "-q %M - -o %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("opusenc", "opus", false, "6 16 32 48 64 96 128 192 256", "128", "opusenc.exe", "--bitrate %M - %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("nero aac", "m4a", false, "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9", "0.4", "neroAacEnc.exe", "-q %M -if - -of %O"));
|
||||
encoders.Add(new AudioEncoderSettingsViewModel("qaac tvbr", "m4a", false, "10 20 30 40 50 60 70 80 90 100 110 127", "80", "qaac.exe", "-s -V %M -q 2 - -o %O"));
|
||||
|
||||
decoders.Add(new CUEToolsUDC("takc", "tak", "takc.exe", "-d %I -"));
|
||||
decoders.Add(new CUEToolsUDC("ffmpeg alac", "m4a", "ffmpeg.exe", "-v 0 -i %I -f wav -"));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("takc", "tak", "takc.exe", "-d %I -")));
|
||||
decoders.Add(new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("ffmpeg alac", "m4a", "ffmpeg.exe", "-v 0 -i %I -f wav -")));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
bool _allowLossy,
|
||||
bool _allowEmbed,
|
||||
bool _builtin,
|
||||
CUEToolsUDC _encoderLossless,
|
||||
CUEToolsUDC _encoderLossy,
|
||||
CUEToolsUDC _decoder)
|
||||
AudioEncoderSettingsViewModel _encoderLossless,
|
||||
AudioEncoderSettingsViewModel _encoderLossy,
|
||||
AudioDecoderSettingsViewModel _decoder)
|
||||
{
|
||||
extension = _extension;
|
||||
tagger = _tagger;
|
||||
@@ -34,9 +34,9 @@
|
||||
public CUEToolsFormat Clone(CUEToolsCodecsConfig cfg)
|
||||
{
|
||||
var res = this.MemberwiseClone() as CUEToolsFormat;
|
||||
if (decoder != null) cfg.decoders.TryGetValue(decoder.extension, decoder.lossless, decoder.name, out res.decoder);
|
||||
if (encoderLossy != null) cfg.encoders.TryGetValue(encoderLossy.extension, encoderLossy.lossless, encoderLossy.name, out res.encoderLossy);
|
||||
if (encoderLossless != null) cfg.encoders.TryGetValue(encoderLossless.extension, encoderLossless.lossless, encoderLossless.name, out res.encoderLossless);
|
||||
if (decoder != null) cfg.decoders.TryGetValue(decoder.decoderSettings.Extension, decoder.Lossless, decoder.decoderSettings.Name, out res.decoder);
|
||||
if (encoderLossy != null) cfg.encoders.TryGetValue(encoderLossy.settings.Extension, encoderLossy.Lossless, encoderLossy.settings.Name, out res.encoderLossy);
|
||||
if (encoderLossless != null) cfg.encoders.TryGetValue(encoderLossless.settings.Extension, encoderLossless.Lossless, encoderLossless.settings.Name, out res.encoderLossless);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
}
|
||||
|
||||
public string extension;
|
||||
public CUEToolsUDC encoderLossless;
|
||||
public CUEToolsUDC encoderLossy;
|
||||
public CUEToolsUDC decoder;
|
||||
public AudioEncoderSettingsViewModel encoderLossless;
|
||||
public AudioEncoderSettingsViewModel encoderLossy;
|
||||
public AudioDecoderSettingsViewModel decoder;
|
||||
public CUEToolsTagger tagger;
|
||||
public bool allowLossless, allowLossy, allowEmbed, builtin;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsUDC : INotifyPropertyChanged
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public string name = "";
|
||||
public string extension = "wav";
|
||||
public string path = "";
|
||||
public string parameters = "";
|
||||
public Type type = null;
|
||||
[JsonProperty]
|
||||
public AudioEncoderSettings settings = null;
|
||||
public XmlSerializer settingsSerializer = null;
|
||||
public bool lossless = false;
|
||||
public int priority = 0;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public CUEToolsUDC(
|
||||
[JsonConstructor]
|
||||
private AudioEncoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(
|
||||
string _name,
|
||||
string _extension,
|
||||
bool _lossless,
|
||||
@@ -28,134 +27,103 @@ namespace CUETools.Codecs
|
||||
string _parameters
|
||||
)
|
||||
{
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
lossless = _lossless;
|
||||
priority = 0;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = typeof(UserDefinedWriter);
|
||||
settingsSerializer = new XmlSerializer(typeof(UserDefinedEncoderSettings));
|
||||
settings = new UserDefinedEncoderSettings() { SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters };
|
||||
settings = new CommandLineEncoderSettings() { name = _name, extension = _extension, SupportedModes = _supported_modes, EncoderMode = _default_mode, Path = _path, Parameters = _parameters, lossless = _lossless };
|
||||
}
|
||||
|
||||
public CUEToolsUDC(AudioEncoderClassAttribute enc, Type enctype)
|
||||
public AudioEncoderSettingsViewModel(AudioEncoderClassAttribute enc)
|
||||
{
|
||||
name = enc.EncoderName;
|
||||
extension = enc.Extension;
|
||||
lossless = enc.Lossless;
|
||||
priority = enc.Priority;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = enctype;
|
||||
settingsSerializer = new XmlSerializer(enc.Settings);
|
||||
settings = Activator.CreateInstance(enc.Settings) as AudioEncoderSettings;
|
||||
if (settings == null)
|
||||
throw new InvalidOperationException("invalid codec");
|
||||
}
|
||||
|
||||
public CUEToolsUDC(
|
||||
string _name,
|
||||
string _extension,
|
||||
string _path,
|
||||
string _parameters
|
||||
)
|
||||
public AudioEncoderSettingsViewModel Clone()
|
||||
{
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
lossless = true;
|
||||
priority = 0;
|
||||
path = _path;
|
||||
parameters = _parameters;
|
||||
type = null;
|
||||
}
|
||||
|
||||
public CUEToolsUDC(AudioDecoderClass dec, Type dectype)
|
||||
{
|
||||
name = dec.DecoderName;
|
||||
extension = dec.Extension;
|
||||
lossless = true;
|
||||
priority = dec.Priority;
|
||||
path = null;
|
||||
parameters = null;
|
||||
type = dectype;
|
||||
}
|
||||
|
||||
public CUEToolsUDC Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as CUEToolsUDC;
|
||||
var res = this.MemberwiseClone() as AudioEncoderSettingsViewModel;
|
||||
if (settings != null) res.settings = settings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { if (name == value) return; name = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name")); }
|
||||
}
|
||||
public string FullName
|
||||
{
|
||||
get { return name + " [" + extension + "]"; }
|
||||
//set { name = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name")); }
|
||||
}
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
return settings == null ? path : settings.Path;
|
||||
if (settings is CommandLineEncoderSettings)
|
||||
return (settings as CommandLineEncoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) path = value;
|
||||
else settings.Path = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Path"));
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Path = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
return settings == null ? parameters : settings.Parameters;
|
||||
if (settings is CommandLineEncoderSettings)
|
||||
return (settings as CommandLineEncoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
if (settings == null) parameters = value;
|
||||
else settings.Parameters = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Parameters"));
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Parameters = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get { return lossless; }
|
||||
set { lossless = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Lossless")); }
|
||||
get => settings.Lossless;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.lossless = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Lossless"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => settings.Name;
|
||||
set
|
||||
{
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.name = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get { return extension; }
|
||||
get => settings.Extension;
|
||||
set
|
||||
{
|
||||
if (extension == value) return;
|
||||
if (type != null && type != typeof(UserDefinedWriter)) throw new InvalidOperationException();
|
||||
extension = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Extension"));
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.extension = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension
|
||||
{
|
||||
get { return "." + extension; }
|
||||
}
|
||||
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public string SupportedModesStr
|
||||
{
|
||||
get
|
||||
@@ -165,20 +133,14 @@ namespace CUETools.Codecs
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.settings as UserDefinedEncoderSettings;
|
||||
var settings = this.settings as CommandLineEncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModesStr"));
|
||||
}
|
||||
}
|
||||
|
||||
public string[] SupportedModes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.SupportedModesStr.Split(' ');
|
||||
}
|
||||
}
|
||||
public string[] SupportedModes => this.SupportedModesStr.Split(' ');
|
||||
|
||||
public int EncoderModeIndex
|
||||
{
|
||||
@@ -194,12 +156,116 @@ namespace CUETools.Codecs
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeDeleted
|
||||
public bool CanBeDeleted => settings is CommandLineEncoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(settings != null)
|
||||
&& (settings is CommandLineEncoderSettings ? (settings as CommandLineEncoderSettings).Path != "" : true);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioDecoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public AudioDecoderSettings decoderSettings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioDecoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel(AudioDecoderSettings settings)
|
||||
{
|
||||
decoderSettings = settings;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel Clone()
|
||||
{
|
||||
var res = this.MemberwiseClone() as AudioDecoderSettingsViewModel;
|
||||
if (decoderSettings != null) res.decoderSettings = decoderSettings.Clone();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return type == null || type == typeof(UserDefinedWriter);
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
return (decoderSettings as CommandLineDecoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).Path = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
return (decoderSettings as CommandLineDecoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).Parameters = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => true;
|
||||
set {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => decoderSettings.Name;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).name = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => decoderSettings.Extension;
|
||||
set
|
||||
{
|
||||
if (decoderSettings is CommandLineDecoderSettings)
|
||||
(decoderSettings as CommandLineDecoderSettings).extension = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public bool CanBeDeleted => decoderSettings is CommandLineDecoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(decoderSettings != null)
|
||||
&& (decoderSettings is CommandLineDecoderSettings ? (decoderSettings as CommandLineDecoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,29 +3,25 @@ using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class CUEToolsUDCList : BindingList<CUEToolsUDC>
|
||||
public class CUEToolsUDCEncoderList : BindingList<AudioEncoderSettingsViewModel>
|
||||
{
|
||||
bool m_encoder;
|
||||
|
||||
public CUEToolsUDCList(bool encoder)
|
||||
public CUEToolsUDCEncoderList()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
m_encoder = encoder;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = m_encoder ?
|
||||
new CUEToolsUDC("new", "wav", true, "", "", "", "") :
|
||||
new CUEToolsUDC("new", "wav", "", "");
|
||||
e.NewObject = new AudioEncoderSettingsViewModel("new", "wav", true, "", "", "", "");
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out CUEToolsUDC result)
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioEncoderSettingsViewModel result)
|
||||
{
|
||||
foreach (CUEToolsUDC udc in this)
|
||||
//result = this.Where(udc => udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name).First();
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.extension == extension && udc.lossless == lossless && udc.name == name)
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
@@ -35,12 +31,53 @@ namespace CUETools.Codecs
|
||||
return false;
|
||||
}
|
||||
|
||||
public CUEToolsUDC GetDefault(string extension, bool lossless)
|
||||
public AudioEncoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
CUEToolsUDC result = null;
|
||||
foreach (CUEToolsUDC udc in this)
|
||||
AudioEncoderSettingsViewModel result = null;
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.extension == extension && udc.lossless == lossless && (result == null || result.priority < udc.priority))
|
||||
if (udc.settings.Extension == extension && udc.settings.Lossless == lossless && (result == null || result.settings.Priority < udc.settings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class CUEToolsUDCDecoderList : BindingList<AudioDecoderSettingsViewModel>
|
||||
{
|
||||
public CUEToolsUDCDecoderList()
|
||||
: base()
|
||||
{
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
e.NewObject = new AudioDecoderSettingsViewModel(new CommandLineDecoderSettings("new", "wav", "", ""));
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioDecoderSettingsViewModel result)
|
||||
{
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && udc.decoderSettings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioDecoderSettingsViewModel result = null;
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.decoderSettings.Extension == extension && udc.decoderSettings.Lossless == lossless && (result == null || result.decoderSettings.Priority < udc.decoderSettings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
|
||||
56
CUETools.Codecs/UserDefinedDecoderSettings.cs
Normal file
56
CUETools.Codecs/UserDefinedDecoderSettings.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CommandLineDecoderSettings : AudioDecoderSettings
|
||||
{
|
||||
public override string Name => name;
|
||||
|
||||
public override string Extension => extension;
|
||||
|
||||
public CommandLineDecoderSettings()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CommandLineDecoderSettings(
|
||||
string _name,
|
||||
string _extension,
|
||||
string _path,
|
||||
string _parameters)
|
||||
: base()
|
||||
{
|
||||
name = _name;
|
||||
extension = _extension;
|
||||
Path = _path;
|
||||
Parameters = _parameters;
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public string name;
|
||||
|
||||
[JsonProperty]
|
||||
public string extension;
|
||||
|
||||
[DefaultValue(null)]
|
||||
[JsonProperty]
|
||||
public string Path
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
[JsonProperty]
|
||||
public string Parameters
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class UserDefinedEncoderSettings : AudioEncoderSettings
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CommandLineEncoderSettings : AudioEncoderSettings
|
||||
{
|
||||
public UserDefinedEncoderSettings()
|
||||
public override string Name => name;
|
||||
|
||||
public override string Extension => extension;
|
||||
|
||||
public override Type EncoderType => typeof(CommandLineEncoder);
|
||||
|
||||
public override bool Lossless => lossless;
|
||||
|
||||
public CommandLineEncoderSettings()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public string name;
|
||||
|
||||
[JsonProperty]
|
||||
public string extension;
|
||||
|
||||
[JsonProperty]
|
||||
public bool lossless;
|
||||
|
||||
[DefaultValue(null)]
|
||||
[JsonProperty]
|
||||
public string Path
|
||||
{
|
||||
get;
|
||||
@@ -20,12 +40,14 @@ namespace CUETools.Codecs
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
[JsonProperty]
|
||||
public string Parameters
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public string SupportedModes
|
||||
{
|
||||
get
|
||||
|
||||
@@ -4,13 +4,14 @@ using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class UserDefinedReader : IAudioSource
|
||||
public class CommandLineDecoder : IAudioSource
|
||||
{
|
||||
string _path, _decoder, _decoderParams;
|
||||
string _path;
|
||||
Process _decoderProcess;
|
||||
WAVReader rdr;
|
||||
WAV.AudioDecoder rdr;
|
||||
|
||||
public AudioDecoderSettings Settings { get { return null; } }
|
||||
private CommandLineDecoderSettings m_settings;
|
||||
public AudioDecoderSettings Settings => m_settings;
|
||||
|
||||
public long Position
|
||||
{
|
||||
@@ -55,11 +56,10 @@ namespace CUETools.Codecs
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public UserDefinedReader(string path, Stream IO, string decoder, string decoderParams)
|
||||
public CommandLineDecoder(CommandLineDecoderSettings settings, string path, Stream IO)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_decoder = decoder;
|
||||
_decoderParams = decoderParams;
|
||||
_decoderProcess = null;
|
||||
rdr = null;
|
||||
}
|
||||
@@ -69,8 +69,8 @@ namespace CUETools.Codecs
|
||||
if (_decoderProcess != null)
|
||||
return;
|
||||
_decoderProcess = new Process();
|
||||
_decoderProcess.StartInfo.FileName = _decoder;
|
||||
_decoderProcess.StartInfo.Arguments = _decoderParams.Replace("%I", "\"" + _path + "\"");
|
||||
_decoderProcess.StartInfo.FileName = m_settings.Path;
|
||||
_decoderProcess.StartInfo.Arguments = m_settings.Parameters.Replace("%I", "\"" + _path + "\"");
|
||||
_decoderProcess.StartInfo.CreateNoWindow = true;
|
||||
_decoderProcess.StartInfo.RedirectStandardOutput = true;
|
||||
_decoderProcess.StartInfo.UseShellExecute = false;
|
||||
@@ -89,9 +89,9 @@ namespace CUETools.Codecs
|
||||
if (!started)
|
||||
{
|
||||
_decoderProcess = null;
|
||||
throw new Exception(_decoder + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
throw new Exception(m_settings.Path + ": " + (ex == null ? "please check the path" : ex.Message));
|
||||
}
|
||||
rdr = new WAVReader(_path, _decoderProcess.StandardOutput.BaseStream);
|
||||
rdr = new WAV.AudioDecoder(new WAV.DecoderSettings(), _path, _decoderProcess.StandardOutput.BaseStream);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
||||
@@ -4,17 +4,16 @@ using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class UserDefinedWriter : IAudioDest
|
||||
public class CommandLineEncoder : IAudioDest
|
||||
{
|
||||
string _path;
|
||||
Process _encoderProcess;
|
||||
WAVWriter wrt;
|
||||
WAV.AudioEncoder wrt;
|
||||
CyclicBuffer outputBuffer = null;
|
||||
bool useTempFile = false;
|
||||
string tempFile = null;
|
||||
long _finalSampleCount = -1;
|
||||
bool closed = false;
|
||||
private UserDefinedEncoderSettings m_settings;
|
||||
|
||||
public long Position
|
||||
{
|
||||
@@ -30,22 +29,12 @@ namespace CUETools.Codecs
|
||||
}
|
||||
|
||||
// !!!! Must not start the process in constructor, so that we can set CompressionLevel via Settings!
|
||||
public AudioEncoderSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
}
|
||||
private CommandLineEncoderSettings m_settings;
|
||||
public AudioEncoderSettings Settings => m_settings;
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public UserDefinedWriter(string path, UserDefinedEncoderSettings settings)
|
||||
: this(path, null, settings)
|
||||
{
|
||||
}
|
||||
|
||||
public UserDefinedWriter(string path, Stream IO, UserDefinedEncoderSettings settings)
|
||||
public CommandLineEncoder(CommandLineEncoderSettings settings, string path, Stream IO = null)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
@@ -63,7 +52,7 @@ namespace CUETools.Codecs
|
||||
_encoderProcess.StartInfo.RedirectStandardOutput = true;
|
||||
if (useTempFile)
|
||||
{
|
||||
wrt = new WAVWriter(tempFile, null, new WAVWriterSettings(settings.PCM));
|
||||
wrt = new WAV.AudioEncoder(new WAV.EncoderSettings(settings.PCM), tempFile);
|
||||
return;
|
||||
}
|
||||
bool started = false;
|
||||
@@ -86,7 +75,7 @@ namespace CUETools.Codecs
|
||||
outputBuffer = new CyclicBuffer(2 * 1024 * 1024, _encoderProcess.StandardOutput.BaseStream, outputStream);
|
||||
}
|
||||
Stream inputStream = new CyclicBufferOutputStream(_encoderProcess.StandardInput.BaseStream, 128 * 1024);
|
||||
wrt = new WAVWriter(path, inputStream, new WAVWriterSettings(settings.PCM));
|
||||
wrt = new WAV.AudioEncoder(new WAV.EncoderSettings(settings.PCM), path, inputStream);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.WAV
|
||||
{
|
||||
[AudioDecoderClass("cuetools", "wav", 2)]
|
||||
public class WAVReader : IAudioSource
|
||||
public class DecoderSettings : AudioDecoderSettings
|
||||
{
|
||||
public override string Name => "cuetools";
|
||||
|
||||
public override string Extension => "wav";
|
||||
|
||||
public override Type DecoderType => typeof(AudioDecoder);
|
||||
|
||||
public override int Priority => 2;
|
||||
|
||||
public DecoderSettings() : base() {}
|
||||
|
||||
public bool IgnoreChunkSizes;
|
||||
}
|
||||
|
||||
[AudioDecoderClass(typeof(DecoderSettings))]
|
||||
public class AudioDecoder : IAudioSource
|
||||
{
|
||||
Stream _IO;
|
||||
BinaryReader _br;
|
||||
@@ -14,7 +29,8 @@ namespace CUETools.Codecs
|
||||
bool _largeFile;
|
||||
string _path;
|
||||
|
||||
public AudioDecoderSettings Settings { get { return null; } }
|
||||
private DecoderSettings m_settings;
|
||||
public AudioDecoderSettings Settings => m_settings;
|
||||
|
||||
public long Position
|
||||
{
|
||||
@@ -75,27 +91,24 @@ namespace CUETools.Codecs
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public WAVReader(string path, Stream IO)
|
||||
: this(path, IO, false)
|
||||
{
|
||||
}
|
||||
|
||||
public WAVReader(string path, Stream IO, bool ignore_chunk_sizes)
|
||||
public AudioDecoder(DecoderSettings settings, string path, Stream IO = null)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_IO = IO != null ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x10000, FileOptions.SequentialScan);
|
||||
_IO = IO ?? new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x10000, FileOptions.SequentialScan);
|
||||
_br = new BinaryReader(_IO);
|
||||
|
||||
ParseHeaders();
|
||||
|
||||
if (_dataLen < 0 || ignore_chunk_sizes)
|
||||
if (_dataLen < 0 || m_settings.IgnoreChunkSizes)
|
||||
_sampleLen = -1;
|
||||
else
|
||||
_sampleLen = _dataLen / pcm.BlockAlign;
|
||||
}
|
||||
|
||||
public WAVReader(string path, Stream IO, AudioPCMConfig _pcm)
|
||||
public AudioDecoder(DecoderSettings settings, string path, Stream IO, AudioPCMConfig _pcm)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_IO = IO != null ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x10000, FileOptions.SequentialScan);
|
||||
_br = new BinaryReader(_IO);
|
||||
@@ -115,9 +128,9 @@ namespace CUETools.Codecs
|
||||
}
|
||||
}
|
||||
|
||||
public static AudioBuffer ReadAllSamples(string path, Stream IO)
|
||||
public static AudioBuffer ReadAllSamples(DecoderSettings settings, string path, Stream IO = null)
|
||||
{
|
||||
WAVReader reader = new WAVReader(path, IO);
|
||||
AudioDecoder reader = new AudioDecoder(settings, path, IO);
|
||||
AudioBuffer buff = new AudioBuffer(reader, (int)reader.Length);
|
||||
reader.Read(buff, -1);
|
||||
if (reader.Remaining != 0)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.WAV
|
||||
{
|
||||
[AudioEncoderClass("cuetools", "wav", true, 10, typeof(WAVWriterSettings))]
|
||||
public class WAVWriter : IAudioDest
|
||||
[AudioEncoderClass(typeof(EncoderSettings))]
|
||||
public class AudioEncoder : IAudioDest
|
||||
{
|
||||
private Stream _IO;
|
||||
private BinaryWriter _bw;
|
||||
@@ -16,7 +16,6 @@ namespace CUETools.Codecs
|
||||
private long _finalSampleCount = -1;
|
||||
private List<byte[]> _chunks = null;
|
||||
private List<uint> _chunkFCCs = null;
|
||||
private WAVWriterSettings m_settings;
|
||||
|
||||
public long Position
|
||||
{
|
||||
@@ -31,29 +30,19 @@ namespace CUETools.Codecs
|
||||
set { _finalSampleCount = value; }
|
||||
}
|
||||
|
||||
public AudioEncoderSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
}
|
||||
private EncoderSettings m_settings;
|
||||
public AudioEncoderSettings Settings => m_settings;
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public WAVWriter(string path, Stream IO, WAVWriterSettings settings)
|
||||
public AudioEncoder(EncoderSettings settings, string path, Stream IO = null)
|
||||
{
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_IO = IO != null ? IO : new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
_IO = IO ?? new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
_bw = new BinaryWriter(_IO);
|
||||
}
|
||||
|
||||
public WAVWriter(string path, WAVWriterSettings settings)
|
||||
: this(path, null, settings)
|
||||
{
|
||||
}
|
||||
|
||||
public void WriteChunk(uint fcc, byte[] data)
|
||||
{
|
||||
if (_sampleLen > 0)
|
||||
|
||||
@@ -2,16 +2,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
namespace CUETools.Codecs.WAV
|
||||
{
|
||||
public class WAVWriterSettings : AudioEncoderSettings
|
||||
public class EncoderSettings : AudioEncoderSettings
|
||||
{
|
||||
public WAVWriterSettings()
|
||||
public override string Extension => "wav";
|
||||
|
||||
public override string Name => "cuetools";
|
||||
|
||||
public override Type EncoderType => typeof(WAV.AudioEncoder);
|
||||
|
||||
public override int Priority => 10;
|
||||
|
||||
public override bool Lossless => true;
|
||||
|
||||
public EncoderSettings()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public WAVWriterSettings(AudioPCMConfig pcm)
|
||||
public EncoderSettings(AudioPCMConfig pcm)
|
||||
: base(pcm)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user