Click here to Skip to main content
Click here to Skip to main content

Compiling SOX with Lame and Libmad for Windows

, 13 Jul 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

arinhere
Web Developer
India India
No Biography provided

Comments and Discussions

 
QuestionSox with AMR Pinmemberporcelli7-Apr-12 1:00 
Bugno flac? Pinmemberget8p11-Mar-12 8:44 
QuestionIn visual studio 2010 how to compile the same code Pinmembervikky4u18-Feb-12 10:32 
AnswerRuntime library needed (msvcr71.dll) Pinmembereferreyra25-Apr-11 8:09 
GeneralUsing to extract and downgrade mp3 files first 30 seconds Pinmembereferreyra25-Apr-11 4:22 
GeneralThanks Pinmemberiplogger14-Mar-10 8:18 
GeneralThank you! Pinmemberlenlynch15-Aug-09 18:59 
GeneralCompiling Sox with Lame may not be worth it [modified] PinmemberXenoLakitu27-Jul-09 0:20 
GeneralRe: Compiling Sox with Lame may not be worth it Pinmemberarinhere9-Aug-09 19:59 
GeneralError when running on other computer Pinmemberpresto1239-Jul-09 11:53 
GeneralRe: Error when running on other computer Pinmemberarinhere13-Jul-09 20:01 
GeneralLimbmad BUild Pinmemberpresto1232-Jul-09 6:34 
GeneralRe: Limbmad BUild Pinmemberarinhere6-Jul-09 21:52 
GeneralSOX MP3 binaries Pinmemberigorbul7-Jun-09 2:00 
GeneralRe: SOX MP3 binaries Pinmemberpresto12310-Jul-09 5:32 
GeneralRe: SOX MP3 binaries Pinmemberarinhere13-Jul-09 19:57 
GeneralRe: SOX MP3 binaries PinmemberAlaa El Ghatit24-Jul-09 8:09 
Question14.0.2 ? PinmemberX3m30-Apr-09 3:01 
AnswerRe: 14.0.2 ? Pinmemberarinhere30-Apr-09 3:32 
Generalcaution in build Pinmemberbharat k28-Apr-09 6:24 
GeneralRe: caution in build Pinmemberarinhere30-Apr-09 3:27 
GeneralCompiling addition libraries Pinmemberhaden.pereira26-Apr-09 23:12 
GeneralRe: Compiling addition libraries Pinmemberarinhere27-Apr-09 1:34 
GeneralWin XP binary please Pinmemberkilroyjones13-Apr-09 12:21 
GeneralBugs in the guide PinmemberMember 60381964-Apr-09 1:37 
GeneralRe: Bugs in the guide Pinmemberhaden.pereira26-Apr-09 23:14 
QuestionThank you! Pinmembertylocook10-Mar-09 20:24 
QuestionRe: Thank you! Pinmembertylocook10-Mar-09 20:27 
AnswerRe: Thank you! Pinmemberarinhere11-Mar-09 21:15 
QuestionRe: Thank you! Pinmembertylocook12-Mar-09 5:03 
AnswerRe: Thank you! Pinmemberarinhere12-Mar-09 6:17 
AnswerRe: Thank you! Pinmembertylocook12-Mar-09 12:03 
GeneralRe: Thank you! Pinmemberarinhere12-Mar-09 19:44 
GeneralMy vote of 1 PinmemberBen Ratzlaff9-Mar-09 10:00 
GeneralRe: My vote of 1 Pinmemberarinhere9-Mar-09 22:08 
QuestionWhat the final result can be used for? PinmemberTage Lejon9-Mar-09 6:43 
AnswerRe: What the final result can be used for? Pinmemberarinhere9-Mar-09 7:54 
GeneralMy vote of 1 PinmemberJim Crafton9-Mar-09 6:26 
QuestionASP.NET??? Pinmembergstolarov9-Mar-09 6:18 
AnswerRe: ASP.NET??? Pinmemberarinhere9-Mar-09 7:57 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 14 Jul 2009
Article Copyright 2009 by arinhere
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid