mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Adjustments for use of LameWriter in CUETools
This commit is contained in:
@@ -75,9 +75,14 @@
|
|||||||
<Compile Include="LAMEEncoderVBR.cs" />
|
<Compile Include="LAMEEncoderVBR.cs" />
|
||||||
<Compile Include="LAMEEncoderVBRProcessingQuality.cs" />
|
<Compile Include="LAMEEncoderVBRProcessingQuality.cs" />
|
||||||
<Compile Include="LAMEEncoderVBRSettings.cs" />
|
<Compile Include="LAMEEncoderVBRSettings.cs" />
|
||||||
|
<Compile Include="LameException.cs" />
|
||||||
|
<Compile Include="LameWriterConstants.cs" />
|
||||||
<Compile Include="LameWriter.cs" />
|
<Compile Include="LameWriter.cs" />
|
||||||
|
<Compile Include="LameWriterCBR.cs" />
|
||||||
|
<Compile Include="LameWriterCBRSettings.cs" />
|
||||||
<Compile Include="LameWriterSettings.cs" />
|
<Compile Include="LameWriterSettings.cs" />
|
||||||
<Compile Include="LameWriterVBR.cs" />
|
<Compile Include="LameWriterVBR.cs" />
|
||||||
|
<Compile Include="LameWriterVBRSettings.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
14
CUETools.Codecs.LAME/LameException.cs
Normal file
14
CUETools.Codecs.LAME/LameException.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CUETools.Codecs.LAME
|
||||||
|
{
|
||||||
|
public class LameException : Exception
|
||||||
|
{
|
||||||
|
public LameException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace CUETools.Codecs.LAME
|
|||||||
{
|
{
|
||||||
#region Unmanaged Functions
|
#region Unmanaged Functions
|
||||||
|
|
||||||
private const string LameDll = "lame_enc";
|
private const string LameDll = "libmp3lame";
|
||||||
private const CallingConvention LameCallingConvention = CallingConvention.Cdecl;
|
private const CallingConvention LameCallingConvention = CallingConvention.Cdecl;
|
||||||
|
|
||||||
[DllImport(LameDll, CallingConvention = LameCallingConvention)]
|
[DllImport(LameDll, CallingConvention = LameCallingConvention)]
|
||||||
@@ -50,7 +50,6 @@ namespace CUETools.Codecs.LAME
|
|||||||
private string outputPath;
|
private string outputPath;
|
||||||
private Stream outputStream;
|
private Stream outputStream;
|
||||||
|
|
||||||
private LameWriterSettings settings;
|
|
||||||
private bool closed = false, initialized = false;
|
private bool closed = false, initialized = false;
|
||||||
private IntPtr handle;
|
private IntPtr handle;
|
||||||
private AudioPCMConfig pcm;
|
private AudioPCMConfig pcm;
|
||||||
@@ -99,15 +98,19 @@ namespace CUETools.Codecs.LAME
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return this.settings;
|
return null;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!(value is LameWriterSettings))
|
throw new MethodAccessException();
|
||||||
{
|
|
||||||
throw new ArgumentException("Settings must be of type LameWriterSettings");
|
|
||||||
}
|
}
|
||||||
this.settings = (LameWriterSettings)value;
|
}
|
||||||
|
|
||||||
|
protected virtual LameWriterConfig Config
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return LameWriterConfig.CreateCbr(320);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +235,8 @@ namespace CUETools.Codecs.LAME
|
|||||||
{
|
{
|
||||||
if (!this.initialized)
|
if (!this.initialized)
|
||||||
{
|
{
|
||||||
|
var config = this.Config;
|
||||||
|
|
||||||
handle = lame_init();
|
handle = lame_init();
|
||||||
|
|
||||||
lame_set_bWriteVbrTag(handle, 1);
|
lame_set_bWriteVbrTag(handle, 1);
|
||||||
@@ -240,25 +245,25 @@ namespace CUETools.Codecs.LAME
|
|||||||
lame_set_num_channels(handle, this.pcm.ChannelCount);
|
lame_set_num_channels(handle, this.pcm.ChannelCount);
|
||||||
lame_set_in_samplerate(handle, this.pcm.SampleRate);
|
lame_set_in_samplerate(handle, this.pcm.SampleRate);
|
||||||
|
|
||||||
lame_set_quality(handle, (int)this.settings.Quality);
|
lame_set_quality(handle, (int)config.Quality);
|
||||||
|
|
||||||
if (this.finalSampleCount != 0)
|
if (this.finalSampleCount != 0)
|
||||||
{
|
{
|
||||||
lame_set_num_samples(handle, this.finalSampleCount);
|
lame_set_num_samples(handle, this.finalSampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
lame_set_VBR(this.handle, (int)this.settings.VbrMode);
|
lame_set_VBR(this.handle, (int)config.VbrMode);
|
||||||
|
|
||||||
switch (this.settings.VbrMode)
|
switch (config.VbrMode)
|
||||||
{
|
{
|
||||||
case LameVbrMode.Abr:
|
case LameVbrMode.Abr:
|
||||||
lame_set_VBR_mean_bitrate_kbps(handle, this.settings.Bitrate);
|
lame_set_VBR_mean_bitrate_kbps(handle, config.Bitrate);
|
||||||
break;
|
break;
|
||||||
case LameVbrMode.Default:
|
case LameVbrMode.Default:
|
||||||
lame_set_VBR_quality(handle, this.settings.VbrQuality);
|
lame_set_VBR_quality(handle, config.VbrQuality);
|
||||||
break;
|
break;
|
||||||
case LameVbrMode.Off:
|
case LameVbrMode.Off:
|
||||||
lame_set_brate(handle, this.settings.Bitrate);
|
lame_set_brate(handle, config.Bitrate);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("Only ABR, Default and Off VBR modes are supported.");
|
throw new ArgumentException("Only ABR, Default and Off VBR modes are supported.");
|
||||||
|
|||||||
67
CUETools.Codecs.LAME/LameWriterCBR.cs
Normal file
67
CUETools.Codecs.LAME/LameWriterCBR.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace CUETools.Codecs.LAME
|
||||||
|
{
|
||||||
|
[AudioEncoderClass("lame2 CBR", "mp3", false, "96 128 192 256 320", "256", 2, typeof(LameWriterCBRSettings))]
|
||||||
|
public class LameWriterCBR : LameWriter
|
||||||
|
{
|
||||||
|
private static readonly int[] bps_table = new int[] { 96, 128, 192, 256, 320 };
|
||||||
|
private int bps;
|
||||||
|
|
||||||
|
public LameWriterCBR(string path, Stream IO, AudioPCMConfig pcm)
|
||||||
|
: base(IO, pcm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public LameWriterCBR(string path, AudioPCMConfig pcm)
|
||||||
|
: base(path, pcm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int CompressionLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
for (int i = 0; i < bps_table.Length; i++)
|
||||||
|
{
|
||||||
|
if (bps == bps_table[i])
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 0 || value > bps_table.Length)
|
||||||
|
throw new Exception("unsupported compression level");
|
||||||
|
bps = bps_table[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LameWriterCBRSettings _settings = new LameWriterCBRSettings();
|
||||||
|
|
||||||
|
public override object Settings
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _settings;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value as LameWriterCBRSettings == null)
|
||||||
|
throw new Exception("Unsupported options " + value);
|
||||||
|
_settings = value as LameWriterCBRSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override LameWriterConfig Config
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return LameWriterConfig.CreateCbr(this.bps, this._settings.Quality);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
CUETools.Codecs.LAME/LameWriterCBRSettings.cs
Normal file
23
CUETools.Codecs.LAME/LameWriterCBRSettings.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CUETools.Codecs.LAME
|
||||||
|
{
|
||||||
|
public class LameWriterCBRSettings
|
||||||
|
{
|
||||||
|
[DefaultValue(LameQuality.High)]
|
||||||
|
public LameQuality Quality { get; set; }
|
||||||
|
|
||||||
|
public LameWriterCBRSettings()
|
||||||
|
{
|
||||||
|
// Iterate through each property and call ResetValue()
|
||||||
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
||||||
|
{
|
||||||
|
property.ResetValue(this);
|
||||||
|
}
|
||||||
|
this.Quality = LameQuality.High;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
CUETools.Codecs.LAME/LameWriterConstants.cs
Normal file
22
CUETools.Codecs.LAME/LameWriterConstants.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CUETools.Codecs.LAME
|
||||||
|
{
|
||||||
|
public enum LameQuality
|
||||||
|
{
|
||||||
|
High = 2,
|
||||||
|
Normal = 5,
|
||||||
|
Fast = 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LameVbrMode
|
||||||
|
{
|
||||||
|
Off = 0,
|
||||||
|
Mt = 1,
|
||||||
|
Rh = 2,
|
||||||
|
Abr = 3,
|
||||||
|
Default = 4,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,53 +2,33 @@
|
|||||||
|
|
||||||
namespace CUETools.Codecs.LAME
|
namespace CUETools.Codecs.LAME
|
||||||
{
|
{
|
||||||
public class LameException: Exception
|
public class LameWriterConfig
|
||||||
{
|
|
||||||
public LameException(string message)
|
|
||||||
: base(message)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum LameQuality
|
|
||||||
{
|
|
||||||
High,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum LameVbrMode
|
|
||||||
{
|
|
||||||
Off,
|
|
||||||
Default,
|
|
||||||
Abr,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LameWriterSettings
|
|
||||||
{
|
{
|
||||||
public LameQuality Quality { get; set; }
|
public LameQuality Quality { get; set; }
|
||||||
public LameVbrMode VbrMode { get; set; }
|
public LameVbrMode VbrMode { get; set; }
|
||||||
public int VbrQuality { get; set; }
|
public int VbrQuality { get; set; }
|
||||||
public int Bitrate { get; set; }
|
public int Bitrate { get; set; }
|
||||||
|
|
||||||
public LameWriterSettings()
|
public LameWriterConfig()
|
||||||
{
|
{
|
||||||
Quality = LameQuality.High;
|
Quality = LameQuality.High;
|
||||||
VbrMode = LameVbrMode.Default;
|
VbrMode = LameVbrMode.Default;
|
||||||
VbrQuality = 5;
|
VbrQuality = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LameWriterSettings CreateCbr(int bitrate, LameQuality encodeQuality = LameQuality.High)
|
public static LameWriterConfig CreateCbr(int bitrate, LameQuality encodeQuality = LameQuality.High)
|
||||||
{
|
{
|
||||||
return new LameWriterSettings() { VbrMode = LameVbrMode.Off, Bitrate = bitrate, Quality = encodeQuality };
|
return new LameWriterConfig() { VbrMode = LameVbrMode.Off, Bitrate = bitrate, Quality = encodeQuality };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LameWriterSettings CreateAbr(int bitrate, LameQuality encodeQuality = LameQuality.High)
|
public static LameWriterConfig CreateAbr(int bitrate, LameQuality encodeQuality = LameQuality.High)
|
||||||
{
|
{
|
||||||
return new LameWriterSettings() { VbrMode = LameVbrMode.Abr, Bitrate = bitrate, Quality = encodeQuality };
|
return new LameWriterConfig() { VbrMode = LameVbrMode.Abr, Bitrate = bitrate, Quality = encodeQuality };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LameWriterSettings CreateVbr(int vbrQuality, LameQuality encodeQuality = LameQuality.High)
|
public static LameWriterConfig CreateVbr(int vbrQuality, LameQuality encodeQuality = LameQuality.High)
|
||||||
{
|
{
|
||||||
return new LameWriterSettings() { VbrMode = LameVbrMode.Default, VbrQuality = vbrQuality, Quality = encodeQuality };
|
return new LameWriterConfig() { VbrMode = LameVbrMode.Default, VbrQuality = vbrQuality, Quality = encodeQuality };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.IO;
|
|||||||
|
|
||||||
namespace CUETools.Codecs.LAME
|
namespace CUETools.Codecs.LAME
|
||||||
{
|
{
|
||||||
[AudioEncoderClass("lame2 VBR", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", 2, typeof(LAMEEncoderVBRSettings))]
|
[AudioEncoderClass("lame2 VBR", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", 2, typeof(LameWriterVBRSettings))]
|
||||||
public class LameWriterVBR : LameWriter
|
public class LameWriterVBR : LameWriter
|
||||||
{
|
{
|
||||||
private int quality = 0;
|
private int quality = 0;
|
||||||
@@ -32,7 +32,7 @@ namespace CUETools.Codecs.LAME
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMEEncoderVBRSettings _settings = new LAMEEncoderVBRSettings();
|
LameWriterVBRSettings _settings = new LameWriterVBRSettings();
|
||||||
|
|
||||||
public override object Settings
|
public override object Settings
|
||||||
{
|
{
|
||||||
@@ -42,9 +42,17 @@ namespace CUETools.Codecs.LAME
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value as LAMEEncoderVBRSettings == null)
|
if (value as LameWriterVBRSettings == null)
|
||||||
throw new Exception("Unsupported options " + value);
|
throw new Exception("Unsupported options " + value);
|
||||||
_settings = value as LAMEEncoderVBRSettings;
|
_settings = value as LameWriterVBRSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override LameWriterConfig Config
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return LameWriterConfig.CreateVbr(this.quality, this._settings.Quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
CUETools.Codecs.LAME/LameWriterVBRSettings.cs
Normal file
22
CUETools.Codecs.LAME/LameWriterVBRSettings.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CUETools.Codecs.LAME
|
||||||
|
{
|
||||||
|
public class LameWriterVBRSettings
|
||||||
|
{
|
||||||
|
[DefaultValue(LameQuality.High)]
|
||||||
|
public LameQuality Quality { get; set; }
|
||||||
|
|
||||||
|
public LameWriterVBRSettings()
|
||||||
|
{
|
||||||
|
// Iterate through each property and call ResetValue()
|
||||||
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this)) {
|
||||||
|
property.ResetValue(this);
|
||||||
|
}
|
||||||
|
this.Quality = LameQuality.High;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user