Click here to Skip to main content
15,885,216 members
Articles / Operating Systems / Windows

Compiling SOX with Lame and Libmad for Windows

Rate me:
Please Sign up or sign in to vote.
3.39/5 (11 votes)
13 Jul 2009CPOL4 min read 151.2K   7.4K   22   40
Compiling SOX with Lame and Libmad for windows

Introduction

This article shows how to compile sox with lame and libmad to enable mp3 support for Windows.

Background

Many of us have an idea about the audio tool sox, through which one can edit the audio files in various formats. But it is pretty unfortunate for developers to find out that sox does not have mp3 support.  

Sox is an open source project of SourceForge, which was built on the source code of Lame, another open source. Now it is quite interesting that Lame does have mp3 support but sox does not. But sox has more audio editing features than lame, which makes sox so useful.

Now to enable mp3 support, we have to compile Sox with Lame and Libmad. Linux server has its process to compile, but Windows has its own way. If you Google this, you can find one basic article written by “Jason Smestad”. But when I tried that out I found some problems, some steps didn’t appear as they seemed to be written.

I don’t know why that happens, but I tried out a slightly different way after that and succeeded.

In this article, there is no credit for me, all credit goes to “Jason Smestad”, but I only publish this so that some developers like me may get it right.

Using the Code 

Prequisities

  1. Visual Studio 2005 / 2008
  2. Cmake 2.6
  3. Windows XP, SP-2 [It should work with others, but I haven’t tried]
  4. Sox 14.0.1
  5. Lame 3.97
  6. Libmad 0.15.1b

Step-1 [Compiling Lame]

  • Unzip the LAME source code and open it as a Visual Studio project.
  • Solution Explorer -> Right Click on libmp3lame -> Configuration Properties
    -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD).
  • Solution Explorer -> Right Click on mpglib -> Configuration Properties
    -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD)
  • Build libmp3lame
  • Build mpglib
  • Search libmp3lame.lib within that folder and rename it as mp3lame.lib
  • Create a folder outside and name it as you wish, for now let's consider, lameforsox
  • Create a folder inside it and name it as “lame” and now search “lame.h” within lame source code folder and copy that within this lame folder
  • Copy mp3lame.lib and mpglib.lib within lameforsox

Step-2 [Compiling Libmad]

  • Unzip the Libmad source code and open it as a Visual Studio project
  • Solution Explorer -> Right Click on each file of “source file” folder -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD)
  • Build Libmad
  • Search mad.h within that folder and copy it
  • Create another folder outside the application and name it as you wish. For now, let’s say “madforsox” and create another folder named “mad” within it.
  • Copy mad.h within “mad"
  • Search libmad.lib within Libmad source folder and rename it as mad.lib
  • Copy mad.lib within “madforsox

Step-3 [Compiling Sox with Lame and Mad Library]

  • Open Visual Studio. Tools -> Options -> Projects and Solutions -> VC++ Directories -> Include Directories -> Click on the “…” button -> now browse and add the lame.h and mad.h if these headers are not there.
  • Library Files -> click on “…” button -> add those lib files i.e. mp3lame.lib, mpglib.lib and mad.lib.
  • Visit sox source folder, find CMakeLists.txt
  • Open it and find if (NEED_LIBM)
    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -lm) 

    It should be within line number 62-65. Leave some space after that and add:

    set(CMAKE_REQUIRED_LIBRARIES {CMAKE_REQUIRED_LIBRARIES} mpglib)
    optional(HAVE_LAME_LAME_H lame/lame.h mp3lame lame_init mp3) 

    And edit “lame/lame.h” to “lame.h”, i.e.: the line should look like this.

    optional(HAVE_LAME_LAME_H lame.h mp3lame lame_init mp3) 
  • Run -> Cmd -> change the path into Sox directory
  • Type  cmake.exe ./ -G "Visual Studio 9 2008" if you are using Visual Studio 2005, then  make it cmake.exe ./ -G "Visual Studio 8 2005"
  • If  everything is ok, then the following will appear:
      ... 
    include files HAVE_MAD_H1 – found 
    mad_stream_buffer in madmad_stream_buffer in mad – found 
    include files HAVE_LAME_LAME_H1 – found 
    lame_init in mp3lamelame_init in mp3lame - found 
  • Now open Visual Studio and open the solution file [.sln] for sox
  • Rebuild “All Build”, if “File Modification Detected” appears then “Reload”, otherwise let the rebuild complete
  • Solution Explorer -> Right click on libsox -> "Preprocessor Definitions" (right click on libsox -> Properties -> Configuration Properties -> C/C++ -> Preprocessor) HAVE_STRING_H before the first line.  Set the "Runtime Library" to Multi-threaded DLL (/MD) as described above.
  • Do the same for sox after that Linker -> Input -> Additional Dependencies -> click on “…” button -> after the last line add mpglib.lib
  • Now build libsox
  • Build sox
  • Run -> cmd -> change to sox directory -> type sox –h
  • Now you will find "mp3, mp2" in the usage output in the section "SUPPORTED FILE FORMATS"

Points of Interest

I haven't tried with the latest version of sox. I might provide an update in the near future.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCompiling addition libraries Pin
haden.pereira26-Apr-09 22:12
haden.pereira26-Apr-09 22:12 
GeneralRe: Compiling addition libraries Pin
arinhere27-Apr-09 0:34
arinhere27-Apr-09 0:34 
GeneralWin XP binary please Pin
kilroyjones13-Apr-09 11:21
kilroyjones13-Apr-09 11:21 
GeneralBugs in the guide Pin
Jasmine Pomelo4-Apr-09 0:37
Jasmine Pomelo4-Apr-09 0:37 
GeneralRe: Bugs in the guide Pin
haden.pereira26-Apr-09 22:14
haden.pereira26-Apr-09 22:14 
QuestionThank you! Pin
tylocook10-Mar-09 19:24
tylocook10-Mar-09 19:24 
QuestionRe: Thank you! Pin
tylocook10-Mar-09 19:27
tylocook10-Mar-09 19:27 
AnswerRe: Thank you! Pin
arinhere11-Mar-09 20:15
arinhere11-Mar-09 20:15 
Hi TyloCook,

Though I have lost interest from the article but still thanks for your comment

Did u you command line to convert your file to mp3? If you use command line to convert audio file to mp3 then use the following command line

sox test.wav test.mp3

and if you use sox in your asp.net application then simply use the following

test.wav test.mp3

I hope it will work...at least worked for me

Let me know if you have any queries...I'll help as far as I can

Thanks - Arin

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

QuestionRe: Thank you! Pin
tylocook12-Mar-09 4:03
tylocook12-Mar-09 4:03 
AnswerRe: Thank you! Pin
arinhere12-Mar-09 5:17
arinhere12-Mar-09 5:17 
AnswerRe: Thank you! Pin
tylocook12-Mar-09 11:03
tylocook12-Mar-09 11:03 
GeneralRe: Thank you! Pin
arinhere12-Mar-09 18:44
arinhere12-Mar-09 18:44 
GeneralMy vote of 1 Pin
Ben Ratzlaff9-Mar-09 9:00
professionalBen Ratzlaff9-Mar-09 9:00 
GeneralRe: My vote of 1 Pin
arinhere9-Mar-09 21:08
arinhere9-Mar-09 21:08 
QuestionWhat the final result can be used for? Pin
Tage Lejon9-Mar-09 5:43
Tage Lejon9-Mar-09 5:43 
AnswerRe: What the final result can be used for? Pin
arinhere9-Mar-09 6:54
arinhere9-Mar-09 6:54 
GeneralMy vote of 1 Pin
Jim Crafton9-Mar-09 5:26
Jim Crafton9-Mar-09 5:26 
QuestionASP.NET??? Pin
gstolarov9-Mar-09 5:18
gstolarov9-Mar-09 5:18 
AnswerRe: ASP.NET??? Pin
arinhere9-Mar-09 6:57
arinhere9-Mar-09 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.