reorganizing a bit

This commit is contained in:
chudov
2010-02-06 23:17:07 +00:00
parent 492f5b845a
commit 1f844b44e1
82 changed files with 5239 additions and 3946 deletions

View File

@@ -1,15 +1,10 @@
using System;
using System.IO;
using CUETools.CDImage;
using CUETools.Codecs;
using CUETools.Codecs.ALAC;
using CUETools.Codecs.FLAKE;
using CUETools.Codecs.FlaCuda;
#if !MONO
using CUETools.Codecs.FLAC;
using CUETools.Codecs.WavPack;
using CUETools.Codecs.APE;
using CUETools.Codecs.TTA;
#endif
using CUETools.Codecs.LossyWAV;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -19,35 +14,33 @@ namespace CUETools.Processor
public static class AudioReadWrite {
public static IAudioSource GetAudioSource(string path, Stream IO, string extension, CUEConfig config)
{
if (extension == ".dummy")
{
using (StreamReader sr = (IO == null ? new StreamReader(path) : new StreamReader(IO))) {
string slen = sr.ReadLine();
long len;
if (!long.TryParse(slen, out len))
len = CDImageLayout.TimeFromString(slen) * 588;
return new SilenceGenerator(len);
}
}
if (extension == ".bin")
return new WAVReader(path, IO, AudioPCMConfig.RedBook);
CUEToolsFormat fmt;
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
throw new Exception("Unsupported audio type: " + path);
CUEToolsUDC decoder;
if (fmt.decoder == null || !config.decoders.TryGetValue(fmt.decoder, out decoder))
throw new Exception("Unsupported audio type: " + path);
switch (decoder.className)
{
case "WAVReader":
return new WAVReader(path, IO);
case "ALACReader":
return new ALACReader(path, IO);
case "FlakeReader":
return new FlakeReader(path, IO);
#if !MONO
case "FLACReader":
return new FLACReader(path, IO, config.disableAsm);
case "WavPackReader":
return new WavPackReader(path, IO, null);
case "APEReader":
return new APEReader(path, IO);
case "TTAReader":
return new TTAReader(path, IO);
#endif
default:
if (decoder.path == null)
throw new Exception("Unsupported audio type: " + path);
return new UserDefinedReader(path, IO, decoder.path, decoder.parameters);
}
if (decoder.path != null)
return new UserDefinedReader(path, IO, decoder.path, decoder.parameters);
if (decoder.type == null)
throw new Exception("Unsupported audio type: " + path);
object src = Activator.CreateInstance(decoder.type, path, IO);
if (src == null || !(src is IAudioSource))
throw new Exception("Unsupported audio type: " + path + ": " + decoder.type.FullName);
return src as IAudioSource;
}
public static IAudioSource GetAudioSource(string path, Stream IO, CUEConfig config)
@@ -73,12 +66,12 @@ namespace CUETools.Processor
return new LossyWAVReader(lossySource, lwcdfSource);
}
public static IAudioDest GetAudioDest(AudioEncoderType audioEncoderType, string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, int padding, string extension, CUEConfig config)
public static IAudioDest GetAudioDest(AudioEncoderType audioEncoderType, string path, AudioPCMConfig pcm, long finalSampleCount, int padding, string extension, CUEConfig config)
{
IAudioDest dest;
if (audioEncoderType == AudioEncoderType.NoAudio || extension == ".dummy")
{
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate);
dest = new DummyWriter(path, pcm);
dest.FinalSampleCount = finalSampleCount;
return dest;
}
@@ -90,59 +83,44 @@ namespace CUETools.Processor
null;
if (encoder == null)
throw new Exception("Unsupported audio type: " + path);
switch (encoder.className)
if (encoder.path != null)
dest = new UserDefinedWriter(path, null, pcm, encoder.path, encoder.parameters, encoder.default_mode, padding);
else if (encoder.type != null)
{
case "WAVWriter":
dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate, null);
break;
case "FlakeWriter":
dest = new FlakeWriter(path, bitsPerSample, channelCount, sampleRate, null);
object o = Activator.CreateInstance(encoder.type, path, pcm);
if (o == null || !(o is IAudioDest))
throw new Exception("Unsupported audio type: " + path + ": " + encoder.type.FullName);
dest = o as IAudioDest;
} else
throw new Exception("Unsupported audio type: " + path);
dest.CompressionLevel = encoder.DefaultModeIndex;
dest.FinalSampleCount = finalSampleCount;
switch (encoder.type.FullName)
{
case "CUETools.Codecs.FLAKE.FlakeWriter":
((FlakeWriter)dest).PaddingLength = padding;
((FlakeWriter)dest).CompressionLevel = encoder.DefaultModeIndex;
//dest = new BufferedWriter(dest, 128 * 1024);
break;
case "FlaCudaWriter":
dest = new FlaCudaWriter(path, bitsPerSample, channelCount, sampleRate, null);
case "CUETools.Codecs.FlaCuda.FlaCudaWriter":
((FlaCudaWriter)dest).PaddingLength = padding;
((FlaCudaWriter)dest).CompressionLevel = encoder.DefaultModeIndex;
((FlaCudaWriter)dest).DoVerify = config.flaCudaVerify;
((FlaCudaWriter)dest).GPUOnly = config.flaCudaGPUOnly;
break;
case "ALACWriter":
dest = new ALACWriter(path, bitsPerSample, channelCount, sampleRate, null);
((FlaCudaWriter)dest).CPUThreads = config.FlaCudaThreads ? 1 : 0;
break;
case "CUETools.Codecs.ALAC.ALACWriter":
((ALACWriter)dest).PaddingLength = padding;
((ALACWriter)dest).CompressionLevel = encoder.DefaultModeIndex;
//dest = new BufferedWriter(dest, 128 * 1024);
break;
#if !MONO
case "FLACWriter":
dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate);
((FLACWriter)dest).PaddingLength = padding;
((FLACWriter)dest).CompressionLevel = encoder.DefaultModeIndex;
((FLACWriter)dest).Verify = config.flacVerify;
((FLACWriter)dest).DisableAsm = config.disableAsm;
case "CUETools.Codecs.FLAC.FLACWriter":
dest.Options = string.Format("{0}{1}--padding-length {2}",
config.disableAsm ? "--disable-asm " : "",
config.flacVerify ? "--verify " : "",
padding);
break;
case "WavPackWriter":
dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate);
((WavPackWriter)dest).CompressionMode = encoder.DefaultModeIndex;
((WavPackWriter)dest).ExtraMode = config.wvExtraMode;
((WavPackWriter)dest).MD5Sum = config.wvStoreMD5;
break;
case "APEWriter":
dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate);
((APEWriter)dest).CompressionLevel = encoder.DefaultModeIndex;
break;
case "TTAWriter":
dest = new TTAWriter(path, bitsPerSample, channelCount, sampleRate);
break;
#endif
default:
if (encoder.path == null)
throw new Exception("Unsupported audio type: " + path);
dest = new UserDefinedWriter(path, bitsPerSample, channelCount, sampleRate, null, encoder.path, encoder.parameters, encoder.default_mode, padding);
case "CUETools.Codecs.WavPack.WavPackWriter":
dest.Options = string.Format("{0}--extra-mode {1}",
config.wvStoreMD5 ? "--md5 " : "",
config.wvExtraMode);
break;
}
dest.FinalSampleCount = finalSampleCount;
return dest;
}
@@ -150,14 +128,15 @@ namespace CUETools.Processor
{
string extension = Path.GetExtension(path).ToLower();
string filename = Path.GetFileNameWithoutExtension(path);
AudioPCMConfig pcm = new AudioPCMConfig(bitsPerSample, 2, sampleRate);
if (audioEncoderType == AudioEncoderType.NoAudio || audioEncoderType == AudioEncoderType.Lossless || Path.GetExtension(filename).ToLower() != ".lossy")
return GetAudioDest(audioEncoderType, path, bitsPerSample, 2, sampleRate, finalSampleCount, padding, extension, config);
return GetAudioDest(audioEncoderType, path, pcm, finalSampleCount, padding, extension, config);
string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension);
int lossyBitsPerSample = (config.detectHDCD && config.decodeHDCD && !config.decodeHDCDtoLW16) ? 24 : 16;
IAudioDest lossyDest = GetAudioDest(AudioEncoderType.Lossless, path, lossyBitsPerSample, 2, sampleRate, finalSampleCount, padding, extension, config);
IAudioDest lwcdfDest = audioEncoderType == AudioEncoderType.Hybrid ? GetAudioDest(AudioEncoderType.Lossless, lwcdfPath, bitsPerSample, 2, sampleRate, finalSampleCount, padding, extension, config) : null;
return new LossyWAVWriter(lossyDest, lwcdfDest, bitsPerSample, 2, sampleRate, config.lossyWAVQuality);
AudioPCMConfig lossypcm = new AudioPCMConfig((config.detectHDCD && config.decodeHDCD && !config.decodeHDCDtoLW16) ? 24 : 16, 2, sampleRate);
IAudioDest lossyDest = GetAudioDest(AudioEncoderType.Lossless, path, lossypcm, finalSampleCount, padding, extension, config);
IAudioDest lwcdfDest = audioEncoderType == AudioEncoderType.Hybrid ? GetAudioDest(AudioEncoderType.Lossless, lwcdfPath, lossypcm, finalSampleCount, padding, extension, config) : null;
return new LossyWAVWriter(lossyDest, lwcdfDest, config.lossyWAVQuality, pcm);
}
}
}