|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThe first question to my previous article (C Sharp Ripper) was about how to rip directly to MP3 format. Then I looked for some MP3 compressor done for .NET framework and I couldn't find the exact solution, so I decided to write one. The solution was to use the LAME MP3 encoder, specifically to wrap in C# the functions of lame_enc.dll. See this website for technical and copyright information regarding the LAME project. In this work, there is code from the article: A low level audio player in C# by Ianier Munoz. BackgroundWhile it is true that the LAME encoder is written in C and all source code is available, one could think of compiling these source files in managed C++ to obtain a managed compressor. However, an easier way to achieve that goal is to use the LAME compressor through the functions exposed by the lame_enc.dll. This DLL exports a few functions and it is relatively easy to use. One problem to mention about the use of the DLL is that in the current version, it is not possible to compress two streams at the same time. The compressor I describe in this article ( Using the code
...
using WaveLib;
using Yeti.MMedia;
using Yeti.MMedia.Mp3;
..
WaveStream InStr = new WaveStream("SomeFile.wav");
try
{
Mp3Writer writer = new Mp3Writer(new FileStream("SomeFile.mp3",
FileMode.Create), InStr.Format);
try
{
byte[] buff = new byte[writer.OptimalBufferSize];
int read = 0;
while ( (read = InStr.Read(buff, 0, buff.Length)) > 0 )
{
writer.Write(buff, 0, read);
}
}
finally
{
writer.Close();
}
}
finally
{
InStr.Close();
}
First, a There are two other overloads of the Another example of using the writer could be an improved version of the ripper described in my article C Sharp Ripper to rip directly to MP3 format. In the file Form1.cs, inside the handler of the "Save as.." button, there is the line: m_Writer = new WaveWriter(WaveFile, Format);
which may be changed to: m_Writer = new Mp3Writer(WaveFile, Format);
The rest of the code remains without change and, of course, if you need more control on the compressor parameters then you should add extra code to use ConclusionAs shown here, the use of this compressor is relatively easy. When more control about the compression process is required, then a deeper knowledge about the meaning and use of all fields of each LAME structure is mandatory. It is also important to note that if you use this code in any product, you should observe the LAME product licensing details. Any use of this product does not convey a license under the relevant intellectual property of Thomson and/or Fraunhofer Gesellschaft nor imply any right to use this product in any finished end user or ready-to-use final product. An independent license for such use is required. For details, please visit http://www.mp3licensing.com. You can find a first version of a Widows Media Audio (WMA) compressor in my article, Windows Media Audio Compressor. A better compressor and a translation of the Windows Media Format SDK could be found in my article, C Sharp Windows Media Format SDK translation.
|
||||||||||||||||||||||