mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
LossyWAV support
This commit is contained in:
@@ -4,15 +4,16 @@ using FLACDotNet;
|
||||
using WavPackDotNet;
|
||||
using APEDotNet;
|
||||
using ALACDotNet;
|
||||
using LossyWAVDotNet;
|
||||
using AudioCodecsDotNet;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace CUEToolsLib {
|
||||
public static class AudioReadWrite {
|
||||
public static IAudioSource GetAudioSource(string path, Stream IO)
|
||||
public static IAudioSource GetAudioSource(string path, Stream IO, string extension)
|
||||
{
|
||||
switch (Path.GetExtension(path).ToLower())
|
||||
switch (extension)
|
||||
{
|
||||
case ".wav":
|
||||
return new WAVReader(path, IO);
|
||||
@@ -31,20 +32,46 @@ namespace CUEToolsLib {
|
||||
}
|
||||
}
|
||||
|
||||
public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount) {
|
||||
public static IAudioSource GetAudioSource(string path, Stream IO)
|
||||
{
|
||||
string extension = Path.GetExtension(path).ToLower();
|
||||
string filename = Path.GetFileNameWithoutExtension(path);
|
||||
string secondExtension = Path.GetExtension(filename).ToLower();
|
||||
if (secondExtension != ".lossy" && secondExtension != ".lwcdf")
|
||||
return GetAudioSource(path, IO, extension);
|
||||
|
||||
string lossyPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lossy" + extension);
|
||||
string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension);
|
||||
IAudioSource lossySource = GetAudioSource(lossyPath, null, extension);
|
||||
IAudioSource lwcdfSource = GetAudioSource(lwcdfPath, null, extension);
|
||||
return new LossyWAVReader(lossySource, lwcdfSource);
|
||||
}
|
||||
|
||||
public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, string extension, CUEConfig config) {
|
||||
IAudioDest dest;
|
||||
switch (Path.GetExtension(path).ToLower()) {
|
||||
switch (extension) {
|
||||
case ".wav":
|
||||
dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
||||
dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
break;
|
||||
#if !MONO
|
||||
case ".flac":
|
||||
dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
||||
dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((FLACWriter)dest).CompressionLevel = (int)config.flacCompressionLevel;
|
||||
((FLACWriter)dest).Verify = config.flacVerify;
|
||||
break;
|
||||
case ".wv":
|
||||
dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
||||
dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((WavPackWriter)dest).CompressionMode = config.wvCompressionMode;
|
||||
((WavPackWriter)dest).ExtraMode = config.wvExtraMode;
|
||||
((WavPackWriter)dest).MD5Sum = config.wvStoreMD5;
|
||||
break;
|
||||
case ".ape":
|
||||
dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
||||
dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((APEWriter)dest).CompressionLevel = (int)config.apeCompressionLevel;
|
||||
break;
|
||||
case ".dummy":
|
||||
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
||||
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
throw new Exception("Unsupported audio type.");
|
||||
@@ -52,5 +79,18 @@ namespace CUEToolsLib {
|
||||
dest.FinalSampleCount = finalSampleCount;
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, CUEConfig config)
|
||||
{
|
||||
string extension = Path.GetExtension(path).ToLower();
|
||||
string filename = Path.GetFileNameWithoutExtension(path);
|
||||
if (Path.GetExtension(filename).ToLower() != ".lossy")
|
||||
return GetAudioDest(path, bitsPerSample, channelCount, sampleRate, finalSampleCount, extension, config);
|
||||
|
||||
string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension);
|
||||
IAudioDest lossyDest = GetAudioDest(path, bitsPerSample, channelCount, sampleRate, finalSampleCount, extension, config);
|
||||
IAudioDest lwcdfDest = GetAudioDest(lwcdfPath, bitsPerSample, channelCount, sampleRate, finalSampleCount, extension, config);
|
||||
return new LossyWAVWriter(lossyDest, lwcdfDest, bitsPerSample, channelCount, sampleRate, config.lossyWAVQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,10 @@
|
||||
<Project>{32338A04-5B6B-4C63-8EE7-C6400F73B5D7}</Project>
|
||||
<Name>HDCDDotNet</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LossyWAVDotNet\LossyWAVDotNet.csproj">
|
||||
<Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project>
|
||||
<Name>LossyWAVDotNet</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\UnRarDotNet\UnRarDotNet.csproj">
|
||||
<Project>{8427CAA5-80B8-4952-9A68-5F3DFCFBDF40}</Project>
|
||||
<Name>UnRarDotNet</Name>
|
||||
|
||||
@@ -31,6 +31,7 @@ using System.Threading;
|
||||
using System.Xml;
|
||||
using AudioCodecsDotNet;
|
||||
using HDCDDotNet;
|
||||
using LossyWAVDotNet;
|
||||
#if !MONO
|
||||
using UnRarDotNet;
|
||||
using FLACDotNet;
|
||||
@@ -241,6 +242,7 @@ namespace CUEToolsLib
|
||||
public bool createTOC;
|
||||
public bool createCUEFileWhenEmbedded;
|
||||
public bool truncate4608ExtraSamples;
|
||||
public int lossyWAVQuality;
|
||||
|
||||
public CUEConfig()
|
||||
{
|
||||
@@ -281,6 +283,7 @@ namespace CUEToolsLib
|
||||
createTOC = false;
|
||||
createCUEFileWhenEmbedded = false;
|
||||
truncate4608ExtraSamples = true;
|
||||
lossyWAVQuality = 5;
|
||||
}
|
||||
|
||||
public void Save (SettingsWriter sw)
|
||||
@@ -322,6 +325,7 @@ namespace CUEToolsLib
|
||||
sw.Save("CreateTOC", createTOC);
|
||||
sw.Save("CreateCUEFileWhenEmbedded", createCUEFileWhenEmbedded);
|
||||
sw.Save("Truncate4608ExtraSamples", truncate4608ExtraSamples);
|
||||
sw.Save("LossyWAVQuality", lossyWAVQuality);
|
||||
}
|
||||
|
||||
public void Load(SettingsReader sr)
|
||||
@@ -363,6 +367,7 @@ namespace CUEToolsLib
|
||||
createTOC = sr.LoadBoolean("CreateTOC") ?? false;
|
||||
createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? false;
|
||||
truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true;
|
||||
lossyWAVQuality = sr.LoadInt32("LossyWAVQuality", 0, 10) ?? 5;
|
||||
}
|
||||
|
||||
public string CleanseString (string s)
|
||||
@@ -982,7 +987,7 @@ namespace CUEToolsLib
|
||||
return null;
|
||||
}
|
||||
|
||||
public void GenerateFilenames (OutputAudioFormat format, string outputPath)
|
||||
public void GenerateFilenames (OutputAudioFormat format, string outputPath, bool lossyWAV)
|
||||
{
|
||||
_cuePath = outputPath;
|
||||
|
||||
@@ -1008,6 +1013,8 @@ namespace CUEToolsLib
|
||||
replace.Add(null);
|
||||
replace.Add(Path.GetFileNameWithoutExtension(outputPath));
|
||||
|
||||
if (lossyWAV)
|
||||
extension = ".lossy" + extension;
|
||||
if (_config.detectHDCD && hdcdDecoder != null && _config.decodeHDCD)
|
||||
extension = ".24bit" + extension;
|
||||
|
||||
@@ -2534,28 +2541,7 @@ namespace CUEToolsLib
|
||||
if (noOutput)
|
||||
return new DummyWriter(path, bitsPerSample, 2, 44100);
|
||||
|
||||
IAudioDest dest = AudioReadWrite.GetAudioDest(path, bitsPerSample, 2, 44100, finalSampleCount);
|
||||
|
||||
#if !MONO
|
||||
if (dest is FLACWriter) {
|
||||
FLACWriter w = (FLACWriter)dest;
|
||||
w.CompressionLevel = (int) _config.flacCompressionLevel;
|
||||
w.Verify = _config.flacVerify;
|
||||
}
|
||||
if (dest is WavPackWriter) {
|
||||
WavPackWriter w = (WavPackWriter)dest;
|
||||
w.CompressionMode = _config.wvCompressionMode;
|
||||
w.ExtraMode = _config.wvExtraMode;
|
||||
w.MD5Sum = _config.wvStoreMD5;
|
||||
}
|
||||
if (dest is APEWriter)
|
||||
{
|
||||
APEWriter w = (APEWriter)dest;
|
||||
w.CompressionLevel = (int) _config.apeCompressionLevel;
|
||||
}
|
||||
#endif
|
||||
|
||||
return dest;
|
||||
return AudioReadWrite.GetAudioDest(path, bitsPerSample, 2, 44100, finalSampleCount, _config);
|
||||
}
|
||||
|
||||
private IAudioSource GetAudioSource(int sourceIndex) {
|
||||
|
||||
Reference in New Issue
Block a user