mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Refactoring codecs infrastructure:
AudioWriterSettings passed to IAdioDest constructors now AudioWriterSettings now includes AudioPCMConfig
This commit is contained in:
@@ -15,7 +15,7 @@ namespace CUETools.Codecs.LAME
|
||||
private byte[] m_InBuffer = null;
|
||||
private int m_InBufferPos = 0;
|
||||
private byte[] m_OutBuffer = null;
|
||||
private AudioPCMConfig _pcm;
|
||||
private AudioEncoderSettings m_settings;
|
||||
private string _path;
|
||||
private Stream _IO;
|
||||
private long position = 0, sample_count = -1;
|
||||
@@ -26,12 +26,7 @@ namespace CUETools.Codecs.LAME
|
||||
{
|
||||
get
|
||||
{
|
||||
return new AudioEncoderSettings();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.GetType() != typeof(AudioEncoderSettings))
|
||||
throw new Exception("Unsupported options " + value);
|
||||
return m_settings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +40,6 @@ namespace CUETools.Codecs.LAME
|
||||
set { sample_count = (int)value; }
|
||||
}
|
||||
|
||||
public AudioPCMConfig PCM
|
||||
{
|
||||
get { return _pcm; }
|
||||
}
|
||||
|
||||
public string Path { get { return _path; } }
|
||||
|
||||
public long BytesWritten
|
||||
@@ -57,17 +47,17 @@ namespace CUETools.Codecs.LAME
|
||||
get { return bytesWritten; }
|
||||
}
|
||||
|
||||
public LAMEEncoder(string path, Stream IO, AudioPCMConfig pcm)
|
||||
public LAMEEncoder(string path, Stream IO, AudioEncoderSettings settings)
|
||||
{
|
||||
if (pcm.BitsPerSample != 16)// && pcm.BitsPerSample != 32)
|
||||
if (settings.PCM.BitsPerSample != 16)// && pcm.BitsPerSample != 32)
|
||||
throw new ArgumentOutOfRangeException("format", "Only 16 & 32 bits samples supported");
|
||||
_pcm = pcm;
|
||||
m_settings = settings;
|
||||
_path = path;
|
||||
_IO = IO;
|
||||
}
|
||||
|
||||
public LAMEEncoder(string path, AudioPCMConfig pcm)
|
||||
: this(path, null, pcm)
|
||||
public LAMEEncoder(string path, AudioEncoderSettings settings)
|
||||
: this(path, null, settings)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -146,7 +136,7 @@ namespace CUETools.Codecs.LAME
|
||||
|
||||
protected virtual BE_CONFIG MakeConfig()
|
||||
{
|
||||
return new BE_CONFIG(_pcm);
|
||||
return new BE_CONFIG(Settings.PCM);
|
||||
}
|
||||
|
||||
private void Init()
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace CUETools.Codecs.LAME
|
||||
//[AudioEncoderClass("lame CBR", "mp3", false, 2, typeof(LAMEEncoderCBRSettings))]
|
||||
public class LAMEEncoderCBR : LAMEEncoder
|
||||
{
|
||||
private LAMEEncoderCBRSettings m_settings = new LAMEEncoderCBRSettings();
|
||||
private LAMEEncoderCBRSettings m_settings;
|
||||
|
||||
public override AudioEncoderSettings Settings
|
||||
{
|
||||
@@ -15,25 +15,21 @@ namespace CUETools.Codecs.LAME
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_settings = value.Clone<LAMEEncoderCBRSettings>();
|
||||
}
|
||||
}
|
||||
|
||||
public LAMEEncoderCBR(string path, Stream IO, AudioPCMConfig pcm)
|
||||
: base(path, IO, pcm)
|
||||
public LAMEEncoderCBR(string path, Stream IO, AudioEncoderSettings settings)
|
||||
: base(path, IO, settings)
|
||||
{
|
||||
}
|
||||
|
||||
public LAMEEncoderCBR(string path, AudioPCMConfig pcm)
|
||||
: base(path, null, pcm)
|
||||
public LAMEEncoderCBR(string path, AudioEncoderSettings settings)
|
||||
: base(path, null, settings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override BE_CONFIG MakeConfig()
|
||||
{
|
||||
BE_CONFIG Mp3Config = new BE_CONFIG(PCM, m_settings.CustomBitrate > 0 ? (uint)m_settings.CustomBitrate : LAMEEncoderCBRSettings.bps_table[m_settings.EncoderModeIndex], 5);
|
||||
BE_CONFIG Mp3Config = new BE_CONFIG(Settings.PCM, m_settings.CustomBitrate > 0 ? (uint)m_settings.CustomBitrate : LAMEEncoderCBRSettings.bps_table[m_settings.EncoderModeIndex], 5);
|
||||
Mp3Config.format.lhv1.bWriteVBRHeader = 1;
|
||||
Mp3Config.format.lhv1.nMode = m_settings.StereoMode;
|
||||
//Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; // --cbr
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace CUETools.Codecs.LAME
|
||||
//[AudioEncoderClass("lame VBR", "mp3", false, 2, typeof(LAMEEncoderVBRSettings))]
|
||||
public class LAMEEncoderVBR : LAMEEncoder
|
||||
{
|
||||
private LAMEEncoderVBRSettings m_settings = new LAMEEncoderVBRSettings();
|
||||
private LAMEEncoderVBRSettings m_settings;
|
||||
|
||||
public override AudioEncoderSettings Settings
|
||||
{
|
||||
@@ -15,25 +15,21 @@ namespace CUETools.Codecs.LAME
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_settings = value.Clone<LAMEEncoderVBRSettings>();
|
||||
}
|
||||
}
|
||||
|
||||
public LAMEEncoderVBR(string path, Stream IO, AudioPCMConfig pcm)
|
||||
: base(path, IO, pcm)
|
||||
public LAMEEncoderVBR(string path, Stream IO, AudioEncoderSettings settings)
|
||||
: base(path, IO, settings)
|
||||
{
|
||||
}
|
||||
|
||||
public LAMEEncoderVBR(string path, AudioPCMConfig pcm)
|
||||
: base(path, null, pcm)
|
||||
public LAMEEncoderVBR(string path, AudioEncoderSettings settings)
|
||||
: base(path, null, settings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override BE_CONFIG MakeConfig()
|
||||
{
|
||||
BE_CONFIG Mp3Config = new BE_CONFIG(PCM, 0, (uint)m_settings.Quality);
|
||||
BE_CONFIG Mp3Config = new BE_CONFIG(Settings.PCM, 0, (uint)m_settings.Quality);
|
||||
Mp3Config.format.lhv1.bWriteVBRHeader = 1;
|
||||
Mp3Config.format.lhv1.nMode = MpegMode.JOINT_STEREO;
|
||||
Mp3Config.format.lhv1.bEnableVBR = 1;
|
||||
|
||||
@@ -54,7 +54,6 @@ namespace CUETools.Codecs.LAME
|
||||
|
||||
private bool m_closed = false, m_initialized = false;
|
||||
private IntPtr m_handle;
|
||||
private AudioPCMConfig m_pcm;
|
||||
private uint m_finalSampleCount;
|
||||
private byte[] m_outputBuffer;
|
||||
|
||||
@@ -70,17 +69,12 @@ namespace CUETools.Codecs.LAME
|
||||
}
|
||||
}
|
||||
|
||||
public AudioPCMConfig PCM
|
||||
{
|
||||
get { return this.m_pcm; }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return this.m_outputPath; }
|
||||
}
|
||||
|
||||
private LameWriterSettings m_settings = new LameWriterCBRSettings();
|
||||
private LameWriterSettings m_settings;
|
||||
|
||||
public virtual AudioEncoderSettings Settings
|
||||
{
|
||||
@@ -88,26 +82,19 @@ namespace CUETools.Codecs.LAME
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_settings = value.Clone<LameWriterSettings>();
|
||||
}
|
||||
}
|
||||
|
||||
public LameWriter(string path, Stream output, AudioPCMConfig pcm)
|
||||
public LameWriter(string path, Stream output, LameWriterSettings settings)
|
||||
{
|
||||
this.CheckPCMConfig(pcm);
|
||||
this.m_pcm = pcm;
|
||||
this.CheckPCMConfig(settings.PCM);
|
||||
this.m_settings = settings;
|
||||
this.m_outputPath = path;
|
||||
this.m_outputStream = output != null ? output : File.Create(path);
|
||||
}
|
||||
|
||||
public LameWriter(string path, AudioPCMConfig pcm)
|
||||
public LameWriter(string path, LameWriterSettings settings)
|
||||
: this(path, null, settings)
|
||||
{
|
||||
this.CheckPCMConfig(pcm);
|
||||
this.m_pcm = pcm;
|
||||
this.m_outputPath = path;
|
||||
this.m_outputStream = File.Create(path);
|
||||
}
|
||||
|
||||
private void CheckPCMConfig(AudioPCMConfig pcm)
|
||||
@@ -219,8 +206,8 @@ namespace CUETools.Codecs.LAME
|
||||
lame_set_bWriteVbrTag(m_handle, 1);
|
||||
lame_set_write_id3tag_automatic(m_handle, 0);
|
||||
|
||||
lame_set_num_channels(m_handle, this.m_pcm.ChannelCount);
|
||||
lame_set_in_samplerate(m_handle, this.m_pcm.SampleRate);
|
||||
lame_set_num_channels(m_handle, this.Settings.PCM.ChannelCount);
|
||||
lame_set_in_samplerate(m_handle, this.Settings.PCM.SampleRate);
|
||||
|
||||
if (this.m_finalSampleCount != 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user