Click here to Skip to main content
15,881,139 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.1K   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

 
QuestionSox with AMR Pin
porcelli7-Apr-12 0:00
porcelli7-Apr-12 0:00 
Bugno flac? Pin
get8p11-Mar-12 7:44
get8p11-Mar-12 7:44 
QuestionIn visual studio 2010 how to compile the same code Pin
vikky4u18-Feb-12 9:32
vikky4u18-Feb-12 9:32 
AnswerRuntime library needed (msvcr71.dll) Pin
eferreyra25-Apr-11 7:09
eferreyra25-Apr-11 7:09 
GeneralUsing to extract and downgrade mp3 files first 30 seconds Pin
eferreyra25-Apr-11 3:22
eferreyra25-Apr-11 3:22 
GeneralThanks Pin
iplogger14-Mar-10 7:18
iplogger14-Mar-10 7:18 
GeneralThank you! Pin
lenlynch15-Aug-09 17:59
lenlynch15-Aug-09 17:59 
GeneralCompiling Sox with Lame may not be worth it [modified] Pin
XenoLakitu26-Jul-09 23:20
XenoLakitu26-Jul-09 23:20 
GeneralRe: Compiling Sox with Lame may not be worth it Pin
arinhere9-Aug-09 18:59
arinhere9-Aug-09 18:59 
GeneralError when running on other computer Pin
presto1239-Jul-09 10:53
presto1239-Jul-09 10:53 
GeneralRe: Error when running on other computer Pin
arinhere13-Jul-09 19:01
arinhere13-Jul-09 19:01 
GeneralLimbmad BUild Pin
presto1232-Jul-09 5:34
presto1232-Jul-09 5:34 
GeneralRe: Limbmad BUild Pin
arinhere6-Jul-09 20:52
arinhere6-Jul-09 20:52 
GeneralSOX MP3 binaries Pin
igorbul7-Jun-09 1:00
igorbul7-Jun-09 1:00 
GeneralRe: SOX MP3 binaries Pin
presto12310-Jul-09 4:32
presto12310-Jul-09 4:32 
GeneralRe: SOX MP3 binaries Pin
arinhere13-Jul-09 18:57
arinhere13-Jul-09 18:57 
GeneralRe: SOX MP3 binaries Pin
Alaa El Ghatit24-Jul-09 7:09
Alaa El Ghatit24-Jul-09 7:09 
Question14.0.2 ? Pin
Vuvirt30-Apr-09 2:01
Vuvirt30-Apr-09 2:01 
AnswerRe: 14.0.2 ? Pin
arinhere30-Apr-09 2:32
arinhere30-Apr-09 2:32 
Generalcaution in build Pin
bharat k28-Apr-09 5:24
bharat k28-Apr-09 5:24 
GeneralRe: caution in build Pin
arinhere30-Apr-09 2:27
arinhere30-Apr-09 2:27 
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 

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.