mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Initial checkin, LossyWAV command line utility
This commit is contained in:
101
LossyWAVSharp/LossyWAVSharp.csproj
Normal file
101
LossyWAVSharp/LossyWAVSharp.csproj
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{A574F3B1-E38B-4EE4-9394-49D6E2DF52EA}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>LossyWAVSharp</RootNamespace>
|
||||||
|
<AssemblyName>LossyWAVSharp</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<OutputPath>..\bin\x64\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||||
|
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||||
|
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||||
|
<OutputPath>..\bin\x64\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||||
|
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||||
|
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<OutputPath>..\bin\win32\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||||
|
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||||
|
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<OutputPath>..\bin\win32\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||||
|
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||||
|
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AudioCodecsDotNet\AudioCodecsDotNet.csproj">
|
||||||
|
<Project>{6458A13A-30EF-45A9-9D58-E5031B17BEE2}</Project>
|
||||||
|
<Name>AudioCodecsDotNet</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\LossyWAVDotNet\LossyWAVDotNet.csproj">
|
||||||
|
<Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project>
|
||||||
|
<Name>LossyWAVDotNet</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
||||||
6
LossyWAVSharp/LossyWAVSharp.csproj.user
Normal file
6
LossyWAVSharp/LossyWAVSharp.csproj.user
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||||
|
<StartArguments>-</StartArguments>
|
||||||
|
<StartWorkingDirectory>C:\Work\cuetoolsnet\bin\x64\Release\</StartWorkingDirectory>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
130
LossyWAVSharp/Program.cs
Normal file
130
LossyWAVSharp/Program.cs
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using LossyWAVDotNet;
|
||||||
|
using AudioCodecsDotNet;
|
||||||
|
|
||||||
|
namespace LossyWAVSharp
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Usage()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Usage : LossyWAVSharp.exe <file.wav> <options>");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Quality Options:");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("-I, --insane highest quality output, suitable for transcoding;");
|
||||||
|
Console.WriteLine("-E, --extreme high quality output, also suitable for transcoding;");
|
||||||
|
Console.WriteLine("-S, --standard default quality output, considered to be transparent;");
|
||||||
|
Console.WriteLine("-P, --portable good quality output for DAP use. Not considered to be fully");
|
||||||
|
Console.WriteLine(" transparent, but considered fit for its intended purpose.");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Standard Options:");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("-C, --correction write correction file for processed WAV file; default=off.");
|
||||||
|
Console.WriteLine("-h, --help display help.");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Advanced Options:");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("-q, --quality <n> quality preset (10=highest quality, 0=lowest bitrate;");
|
||||||
|
Console.WriteLine(" default = --standard = 5; --insane = 10; --extreme = 7.5;");
|
||||||
|
Console.WriteLine(" --portable = 2.5)");
|
||||||
|
Console.WriteLine("-N --stdinname <t> pseudo filename to use when input from STDIN.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.SetOut(Console.Error);
|
||||||
|
Console.WriteLine("LossyWAV {0}, Copyright (C) 2007,2008 Nick Currie, Copyleft.", LossyWAVWriter.version_string);
|
||||||
|
Console.WriteLine("C# port Copyright (C) 2008 Gregory S. Chudov.");
|
||||||
|
Console.WriteLine("This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to");
|
||||||
|
Console.WriteLine("the extent permitted by law. <http://www.gnu.org/licenses/> for details.");
|
||||||
|
if (args.Length < 1 || (args[0].StartsWith("-") && args[0] != "-"))
|
||||||
|
{
|
||||||
|
Usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string sourceFile = args[0];
|
||||||
|
string stdinName = null;
|
||||||
|
double quality = 5.0;
|
||||||
|
bool createCorrection = false;
|
||||||
|
for (int arg = 1; arg < args.Length; arg++)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
if (args[arg] == "-I" || args[arg] == "--insane")
|
||||||
|
quality = 10;
|
||||||
|
else if (args[arg] == "-E" || args[arg] == "--extreme")
|
||||||
|
quality = 7.5;
|
||||||
|
else if (args[arg] == "-S" || args[arg] == "--standard")
|
||||||
|
quality = 5.0;
|
||||||
|
else if (args[arg] == "-P" || args[arg] == "--portable")
|
||||||
|
quality = 2.5;
|
||||||
|
else if (args[arg] == "-C" || args[arg] == "--correction")
|
||||||
|
createCorrection = true;
|
||||||
|
else if ((args[arg] == "-N" || args[arg] == "--stdinname") && ++arg < args.Length)
|
||||||
|
stdinName = args[arg];
|
||||||
|
else if ((args[arg] == "-q" || args[arg] == "--quality") && ++arg < args.Length)
|
||||||
|
ok = double.TryParse(args[arg], out quality);
|
||||||
|
else
|
||||||
|
ok = false;
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
Usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Stream stdout = Console.OpenStandardOutput();
|
||||||
|
DateTime start = DateTime.Now;
|
||||||
|
TimeSpan lastPrint = TimeSpan.FromMilliseconds(0);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WAVReader audioSource = new WAVReader(sourceFile, (sourceFile == "-" ? Console.OpenStandardInput() : null));
|
||||||
|
if (sourceFile == "-" && stdinName != null) sourceFile = stdinName;
|
||||||
|
WAVWriter audioDest = new WAVWriter(Path.ChangeExtension(sourceFile, ".lossy.wav"), audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate);
|
||||||
|
WAVWriter lwcdfDest = createCorrection ? new WAVWriter(Path.ChangeExtension(sourceFile, ".lwcdf.wav"), audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate) : null;
|
||||||
|
LossyWAVWriter lossyWAV = new LossyWAVWriter(audioDest, lwcdfDest, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate, quality);
|
||||||
|
int[,] buff = new int[0x1000, audioSource.ChannelCount];
|
||||||
|
|
||||||
|
Console.WriteLine("Filename : {0}", sourceFile);
|
||||||
|
Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.SampleRate, audioSource.ChannelCount, audioSource.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.SampleRate));
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
uint samplesRead = audioSource.Read(buff, Math.Min((uint)buff.GetLength(0), (uint)audioSource.Remaining));
|
||||||
|
if (samplesRead == 0) break;
|
||||||
|
lossyWAV.Write(buff, samplesRead);
|
||||||
|
TimeSpan elapsed = DateTime.Now - start;
|
||||||
|
if ((elapsed - lastPrint).TotalMilliseconds > 60)
|
||||||
|
{
|
||||||
|
Console.Error.Write("\rProgress : {0:00}%; {1:0.0000} bits; {2:0.00}x; {3}/{4}",
|
||||||
|
100.0 * audioSource.Position / audioSource.Length,
|
||||||
|
1.0 * lossyWAV.OverallBitsRemoved / audioSource.ChannelCount / lossyWAV.BlocksProcessed,
|
||||||
|
lossyWAV.SamplesProcessed / elapsed.TotalSeconds / audioSource.SampleRate,
|
||||||
|
elapsed,
|
||||||
|
TimeSpan.FromMilliseconds(elapsed.TotalMilliseconds / lossyWAV.SamplesProcessed * audioSource.Length)
|
||||||
|
);
|
||||||
|
lastPrint = elapsed;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
TimeSpan totalElapsed = DateTime.Now - start;
|
||||||
|
Console.Error.Write("\r \r");
|
||||||
|
Console.WriteLine("Results : {0:0.0000} bits; {1:0.00}x; {2}",
|
||||||
|
(1.0 * lossyWAV.OverallBitsRemoved) / audioSource.ChannelCount / lossyWAV.BlocksProcessed,
|
||||||
|
lossyWAV.SamplesProcessed / totalElapsed.TotalSeconds / audioSource.SampleRate,
|
||||||
|
totalElapsed
|
||||||
|
);
|
||||||
|
audioSource.Close();
|
||||||
|
lossyWAV.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Error: {0}", ex.Message);
|
||||||
|
Console.WriteLine("{0}", ex.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
LossyWAVSharp/Properties/AssemblyInfo.cs
Normal file
33
LossyWAVSharp/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("LossyWAV# command line utility")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Copyleft")]
|
||||||
|
[assembly: AssemblyProduct("LossyWAV#")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright c 2007, 2008 Nick Currie, C# port by Greg Chudov")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("5fdc4393-9a1a-439d-989f-1c055f189b74")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
[assembly: AssemblyVersion("1.1.1.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.1.1.0")]
|
||||||
Reference in New Issue
Block a user