2010-03-31 15:37:42 +00:00
|
|
|
|
using System;
|
2010-05-18 17:18:37 +00:00
|
|
|
|
using System.ComponentModel;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using CUETools.Codecs;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CUETools.Codecs.LAME
|
|
|
|
|
|
{
|
|
|
|
|
|
public class LAMEEncoder : IAudioDest
|
|
|
|
|
|
{
|
|
|
|
|
|
private bool closed = false;
|
|
|
|
|
|
private BE_CONFIG m_Mp3Config = null;
|
|
|
|
|
|
private uint m_hLameStream = 0;
|
|
|
|
|
|
private uint m_InputSamples = 0;
|
|
|
|
|
|
private uint m_OutBufferSize = 0;
|
|
|
|
|
|
private byte[] m_InBuffer = null;
|
|
|
|
|
|
private int m_InBufferPos = 0;
|
|
|
|
|
|
private byte[] m_OutBuffer = null;
|
|
|
|
|
|
private AudioPCMConfig _pcm;
|
|
|
|
|
|
private string _path;
|
|
|
|
|
|
private Stream _IO;
|
|
|
|
|
|
private long position = 0, sample_count = -1;
|
2010-04-16 04:30:51 +00:00
|
|
|
|
private long bytesWritten = 0;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
public LAMEEncoder(string path, Stream IO, AudioPCMConfig pcm)
|
|
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
if (pcm.BitsPerSample != 16)// && pcm.BitsPerSample != 32)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException("format", "Only 16 & 32 bits samples supported");
|
2010-03-31 15:37:42 +00:00
|
|
|
|
_pcm = pcm;
|
|
|
|
|
|
_path = path;
|
|
|
|
|
|
_IO = IO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LAMEEncoder(string path, AudioPCMConfig pcm)
|
|
|
|
|
|
: this(path, null, pcm)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-16 04:30:51 +00:00
|
|
|
|
public void DeInit(bool flush)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (!inited || closed)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
if (flush)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
uint EncodedSize = 0;
|
|
|
|
|
|
if (m_InBufferPos > 0)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
if (Lame_encDll.EncodeChunk(m_hLameStream, m_InBuffer, 0, (uint)m_InBufferPos, m_OutBuffer, ref EncodedSize) == Lame_encDll.BE_ERR_SUCCESSFUL)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
if (EncodedSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_IO.Write(m_OutBuffer, 0, (int)EncodedSize);
|
|
|
|
|
|
bytesWritten += EncodedSize;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2010-04-16 04:30:51 +00:00
|
|
|
|
EncodedSize = 0;
|
|
|
|
|
|
if (Lame_encDll.beDeinitStream(m_hLameStream, m_OutBuffer, ref EncodedSize) == Lame_encDll.BE_ERR_SUCCESSFUL)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
if (EncodedSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_IO.Write(m_OutBuffer, 0, (int)EncodedSize);
|
|
|
|
|
|
bytesWritten += EncodedSize;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Lame_encDll.beCloseStream(m_hLameStream);
|
|
|
|
|
|
_IO.Close();
|
2010-04-16 04:30:51 +00:00
|
|
|
|
closed = true;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool needTag = !closed && _path != null && _path != "";
|
2010-04-16 04:30:51 +00:00
|
|
|
|
DeInit(true);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
if (needTag)
|
|
|
|
|
|
{
|
2011-09-08 18:25:54 +00:00
|
|
|
|
bool utf8Required = Encoding.Default.GetString(Encoding.Default.GetBytes(_path)) != _path;
|
|
|
|
|
|
var tempDir = System.IO.Path.Combine(System.IO.Path.GetPathRoot(_path), "Temp");
|
|
|
|
|
|
var tempName = utf8Required ? System.IO.Path.Combine(tempDir, Guid.NewGuid().ToString()) : _path;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2011-09-08 18:25:54 +00:00
|
|
|
|
if (utf8Required && !Directory.Exists(tempDir)) Directory.CreateDirectory(tempDir);
|
|
|
|
|
|
if (utf8Required) File.Move(_path, tempName);
|
|
|
|
|
|
Lame_encDll.beWriteInfoTag(m_hLameStream, tempName);
|
|
|
|
|
|
if (utf8Required) File.Move(tempName, _path);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2011-09-08 18:25:54 +00:00
|
|
|
|
if (utf8Required) File.Move(tempName, _path);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Delete()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!closed)
|
|
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
DeInit(false);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
if (_path != "")
|
|
|
|
|
|
File.Delete(_path);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual BE_CONFIG MakeConfig()
|
|
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
return new BE_CONFIG(_pcm);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool inited = false;
|
|
|
|
|
|
private void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (inited)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
m_Mp3Config = MakeConfig();
|
|
|
|
|
|
|
|
|
|
|
|
uint LameResult = Lame_encDll.beInitStream(m_Mp3Config, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream);
|
|
|
|
|
|
if (LameResult != Lame_encDll.BE_ERR_SUCCESSFUL)
|
|
|
|
|
|
throw new ApplicationException(string.Format("Lame_encDll.beInitStream failed with the error code {0}", LameResult));
|
|
|
|
|
|
|
|
|
|
|
|
m_InBuffer = new byte[m_InputSamples * 2]; //Input buffer is expected as short[]
|
2011-05-06 20:22:21 +00:00
|
|
|
|
m_OutBuffer = new byte[Math.Max(65536, m_OutBufferSize)];
|
2010-03-31 15:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
if (_IO == null)
|
|
|
|
|
|
_IO = new FileStream(_path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
|
|
|
|
|
|
|
|
|
|
|
inited = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-06 20:22:21 +00:00
|
|
|
|
public unsafe void Write(AudioBuffer buff)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
buff.Prepare(this);
|
|
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = buff.Bytes;
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
int count = buff.ByteLength;
|
|
|
|
|
|
|
|
|
|
|
|
int ToCopy = 0;
|
|
|
|
|
|
uint EncodedSize = 0;
|
|
|
|
|
|
uint LameResult;
|
2011-05-06 20:22:21 +00:00
|
|
|
|
uint outBufferIndex = 0;
|
|
|
|
|
|
fixed (byte* pBuffer = buffer, pOutBuffer = m_OutBuffer)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
while (count > 0)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
if (m_InBufferPos > 0)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
ToCopy = Math.Min(count, m_InBuffer.Length - m_InBufferPos);
|
|
|
|
|
|
Buffer.BlockCopy(buffer, index, m_InBuffer, m_InBufferPos, ToCopy);
|
|
|
|
|
|
m_InBufferPos += ToCopy;
|
|
|
|
|
|
index += ToCopy;
|
|
|
|
|
|
count -= ToCopy;
|
|
|
|
|
|
if (m_InBufferPos >= m_InBuffer.Length)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
m_InBufferPos = 0;
|
|
|
|
|
|
if (outBufferIndex > 0)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
_IO.Write(m_OutBuffer, 0, (int)outBufferIndex);
|
|
|
|
|
|
bytesWritten += outBufferIndex;
|
|
|
|
|
|
outBufferIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((LameResult = Lame_encDll.EncodeChunk(m_hLameStream, m_InBuffer, m_OutBuffer, ref EncodedSize)) == Lame_encDll.BE_ERR_SUCCESSFUL)
|
|
|
|
|
|
{
|
|
|
|
|
|
outBufferIndex += EncodedSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ApplicationException(string.Format("Lame_encDll.EncodeChunk failed with the error code {0}", LameResult));
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-05-06 20:22:21 +00:00
|
|
|
|
else
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
if (count >= m_InBuffer.Length)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
if (outBufferIndex + m_OutBufferSize > m_OutBuffer.Length)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
_IO.Write(m_OutBuffer, 0, (int)outBufferIndex);
|
|
|
|
|
|
bytesWritten += outBufferIndex;
|
|
|
|
|
|
outBufferIndex = 0;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
2011-05-06 20:22:21 +00:00
|
|
|
|
|
|
|
|
|
|
if ((LameResult = Lame_encDll.EncodeChunk(m_hLameStream, pBuffer + index, (uint)m_InBuffer.Length, pOutBuffer + outBufferIndex, ref EncodedSize)) == Lame_encDll.BE_ERR_SUCCESSFUL)
|
|
|
|
|
|
{
|
|
|
|
|
|
outBufferIndex += EncodedSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ApplicationException(string.Format("Lame_encDll.EncodeChunk failed with the error code {0}", LameResult));
|
|
|
|
|
|
}
|
|
|
|
|
|
count -= m_InBuffer.Length;
|
|
|
|
|
|
index += m_InBuffer.Length;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
Buffer.BlockCopy(buffer, index, m_InBuffer, 0, count);
|
|
|
|
|
|
m_InBufferPos = count;
|
|
|
|
|
|
index += count;
|
|
|
|
|
|
count = 0;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-05-06 20:22:21 +00:00
|
|
|
|
|
|
|
|
|
|
if (outBufferIndex > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_IO.Write(m_OutBuffer, 0, (int)outBufferIndex);
|
|
|
|
|
|
bytesWritten += outBufferIndex;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual int CompressionLevel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value != 0)
|
|
|
|
|
|
throw new Exception("unsupported compression level");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-06-11 17:54:37 +00:00
|
|
|
|
public virtual object Settings
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
if (value != null && value.GetType() != typeof(object))
|
|
|
|
|
|
throw new Exception("Unsupported options " + value);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-05-18 17:18:37 +00:00
|
|
|
|
public long Padding
|
|
|
|
|
|
{
|
|
|
|
|
|
set { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-03-31 15:37:42 +00:00
|
|
|
|
public long Position
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long FinalSampleCount
|
|
|
|
|
|
{
|
|
|
|
|
|
set { sample_count = (int)value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long BlockSize
|
|
|
|
|
|
{
|
|
|
|
|
|
set { }
|
|
|
|
|
|
get { return 0; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AudioPCMConfig PCM
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _pcm; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Path { get { return _path; } }
|
2010-04-16 04:30:51 +00:00
|
|
|
|
|
|
|
|
|
|
public long BytesWritten
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return bytesWritten;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-06 20:22:21 +00:00
|
|
|
|
public enum LAMEEncoderVBRProcessingQuality : uint
|
|
|
|
|
|
{
|
|
|
|
|
|
Best = 0,
|
|
|
|
|
|
Normal = 5,
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
|
2010-05-18 17:18:37 +00:00
|
|
|
|
public class LAMEEncoderVBRSettings
|
|
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
public LAMEEncoderVBRSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Iterate through each property and call ResetValue()
|
|
|
|
|
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
|
|
|
|
|
property.ResetValue(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DefaultValue(LAMEEncoderVBRProcessingQuality.Normal)]
|
|
|
|
|
|
public LAMEEncoderVBRProcessingQuality Quality { get; set; }
|
2010-05-18 17:18:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[AudioEncoderClass("lame VBR", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", 2, typeof(LAMEEncoderVBRSettings))]
|
2010-03-31 15:37:42 +00:00
|
|
|
|
public class LAMEEncoderVBR : LAMEEncoder
|
|
|
|
|
|
{
|
|
|
|
|
|
private int quality = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public LAMEEncoderVBR(string path, Stream IO, AudioPCMConfig pcm)
|
|
|
|
|
|
: base(path, IO, pcm)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LAMEEncoderVBR(string path, AudioPCMConfig pcm)
|
|
|
|
|
|
: base(path, null, pcm)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override BE_CONFIG MakeConfig()
|
|
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
BE_CONFIG Mp3Config = new BE_CONFIG(PCM, 0, (uint)_settings.Quality);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
Mp3Config.format.lhv1.bWriteVBRHeader = 1;
|
|
|
|
|
|
Mp3Config.format.lhv1.nMode = MpegMode.JOINT_STEREO;
|
|
|
|
|
|
Mp3Config.format.lhv1.bEnableVBR = 1;
|
|
|
|
|
|
Mp3Config.format.lhv1.nVBRQuality = quality;
|
|
|
|
|
|
Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW; // --vbr-new
|
|
|
|
|
|
return Mp3Config;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int CompressionLevel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return 9 - quality;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value < 0 || value > 9)
|
|
|
|
|
|
throw new Exception("unsupported compression level");
|
|
|
|
|
|
quality = 9 - value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-05-18 17:18:37 +00:00
|
|
|
|
LAMEEncoderVBRSettings _settings = new LAMEEncoderVBRSettings();
|
|
|
|
|
|
|
2010-06-11 17:54:37 +00:00
|
|
|
|
public override object Settings
|
2010-03-31 15:37:42 +00:00
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _settings;
|
|
|
|
|
|
}
|
2010-03-31 15:37:42 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
if (value as LAMEEncoderVBRSettings == null)
|
2010-03-31 15:37:42 +00:00
|
|
|
|
throw new Exception("Unsupported options " + value);
|
2010-05-18 17:18:37 +00:00
|
|
|
|
_settings = value as LAMEEncoderVBRSettings;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-05-18 17:18:37 +00:00
|
|
|
|
public class LAMEEncoderCBRSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
public LAMEEncoderCBRSettings() {
|
|
|
|
|
|
// Iterate through each property and call ResetValue()
|
|
|
|
|
|
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
|
|
|
|
|
|
property.ResetValue(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
|
public int CustomBitrate { get; set; }
|
|
|
|
|
|
[DefaultValue(MpegMode.STEREO)]
|
|
|
|
|
|
public MpegMode StereoMode { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[AudioEncoderClass("lame CBR", "mp3", false, "96 128 192 256 320", "256", 2, typeof(LAMEEncoderCBRSettings))]
|
2010-03-31 15:37:42 +00:00
|
|
|
|
public class LAMEEncoderCBR : LAMEEncoder
|
|
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
private uint bps;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
private static readonly uint[] bps_table = new uint[] {96, 128, 192, 256, 320};
|
|
|
|
|
|
|
|
|
|
|
|
public LAMEEncoderCBR(string path, Stream IO, AudioPCMConfig pcm)
|
|
|
|
|
|
: base(path, IO, pcm)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LAMEEncoderCBR(string path, AudioPCMConfig pcm)
|
|
|
|
|
|
: base(path, null, pcm)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int CompressionLevel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2010-04-16 04:30:51 +00:00
|
|
|
|
for (int i = 0; i < bps_table.Length; i++)
|
|
|
|
|
|
if (bps == bps_table[i])
|
|
|
|
|
|
return i;
|
|
|
|
|
|
return -1;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value < 0 || value > bps_table.Length)
|
|
|
|
|
|
throw new Exception("unsupported compression level");
|
2010-04-16 04:30:51 +00:00
|
|
|
|
bps = bps_table[value];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-05-18 17:18:37 +00:00
|
|
|
|
LAMEEncoderCBRSettings _settings = new LAMEEncoderCBRSettings();
|
|
|
|
|
|
|
2010-06-11 17:54:37 +00:00
|
|
|
|
public override object Settings
|
2010-04-16 04:30:51 +00:00
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _settings;
|
|
|
|
|
|
}
|
2010-04-16 04:30:51 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2010-05-18 17:18:37 +00:00
|
|
|
|
if (value as LAMEEncoderCBRSettings == null)
|
2010-04-16 04:30:51 +00:00
|
|
|
|
throw new Exception("Unsupported options " + value);
|
2010-05-18 17:18:37 +00:00
|
|
|
|
_settings = value as LAMEEncoderCBRSettings;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override BE_CONFIG MakeConfig()
|
|
|
|
|
|
{
|
2011-05-06 20:22:21 +00:00
|
|
|
|
BE_CONFIG Mp3Config = new BE_CONFIG(PCM, _settings.CustomBitrate > 0 ? (uint)_settings.CustomBitrate : bps, 5);
|
2010-03-31 15:37:42 +00:00
|
|
|
|
Mp3Config.format.lhv1.bWriteVBRHeader = 1;
|
2010-05-18 17:18:37 +00:00
|
|
|
|
Mp3Config.format.lhv1.nMode = _settings.StereoMode;
|
2010-03-31 15:37:42 +00:00
|
|
|
|
//Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; // --cbr
|
|
|
|
|
|
//Mp3Config.format.lhv1.nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY;
|
|
|
|
|
|
return Mp3Config;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|