2

I've spent all day on this and its driving me nuts

Does someone know a simple way to decode an mp3 to a simple 16 bit pcm (wave) file? i need something i can ship with my commercial program so i prefer a .lib

I found libmpg123.dll but i can't figure out how to get my program to link with a dll in msvc 2010. i know i need to add a reference but when i click 'add new reference' all i get is a empty dialog with Project Name and Project directory heading and nothing to click. I tried converting .dll to .lib using the lib tool but that keeps complaining the .def file format is bad.

I tried to build madplayer but i can't fine id3tag.h and there is no documentation or examples about using libmad that i can find

Lame looks too huge

Any ideas for a quick solution for a .lib i can link with and be done with it

Thanks, steve

steveh
  • 1,352
  • 2
  • 27
  • 41

2 Answers2

5

mpg123 is fine. I can see you have troubles with getting static library (.lib).

There are 2 ways to get the lib:

  1. Build the source code. It's much more flexible, but it's a bit tricky. If you download the sources, you can find a port to VS2010 by the path: ports\MSVC++\2010. But in this case you will face with issues of installing YASM and playing around with build configurations (seems the configurations are not properly adjusted in the source code package).
  2. Use the lib tool by converting the .def file. You don't need sources as the binary packages already contain the .h and the .def files. I will explain in details:

    1. Download the binaries (win32 or win64) and extract let's say to D:\mpg123 folder.
    2. Run from Start -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010).
    3. Go to your folder cd D:\mpg123, D: and run the line: lib /def:libmpg123-0.dll.def (or however the def file is called).
    4. Now you have the desired .lib file libmpg123-0.dll.lib in your folder.

But notice, that the 'Framework and References' property page is used to set references to .NET Framework assemblies, COM components, or external projects (MSDN), in your case you should specify additional linker dependency in your project [Configuration Properties => Linker => Input => Additional Dependencies].

Olexander Ivanitskyi
  • 2,202
  • 17
  • 32
  • thanks, i'll try. i found the sources at http://fossies.org/linux/misc/mpg123-1.15.1.tar.gz/ and it has a mscv++ 2010 project but it doesn't compile. is it necessary to run some kind of configure tool or something first? thanks – steveh Mar 06 '13 at 00:55
  • I have specified additional info. Try it out. I think the lib tool must work as well. – Olexander Ivanitskyi Mar 06 '13 at 01:02
  • Because building the source might be really painful:) And there is no configure tool. – Olexander Ivanitskyi Mar 06 '13 at 01:12
  • excellent, thanks, i got my app to build following your steps exactly (made the .lib). before when i tried to run lib i did it from the command prompt which didn't work. now it builds but doesn't run, i just need to put the .dll somewhere, i guess system32? is that the right place? – steveh Mar 06 '13 at 01:28
  • i put the dll in windows\system32 and its working now. THANK YOU SO MUCH! this was driving me nuts all day yesterday. when i ship my app, do you think i should install the .dll in windows\system32 or in my install folder? – steveh Mar 06 '13 at 01:35
  • Copy dlls to system32 may end up with something which is called [DLL Hell](http://en.wikipedia.org/wiki/DLL_Hell). I would rather recommend referencing to local folder. [`This`](http://stackoverflow.com/questions/809948/dll-references-in-visual-c) or [`this`](http://stackoverflow.com/questions/428085/how-do-i-set-a-path-in-visual-studio) should help. – Olexander Ivanitskyi Mar 06 '13 at 10:07
1

the answer from Olexander works great, thank you so much

i have one small thing to add, when you download mpg123-1.15.1-x86.zip

you'll see libmpg123-0.dll (the dll) and libmpg123-0.dll.def the thing used to make the .lib as described above. its better to change the name to libmpg123-0.def otherwise it will look for a dll called libmpg123-0.dll.dll which isn't nice

beside that, it works great. i can't believe this info wasn't on the internet years ago. thanks Olexander and thanks stackoverflow

FYI, here's a simple mp3 decoder using mpg123

#include "mpg123/mpg123.h"

#define INBUFF  16384
#define OUTBUFF 32768


void loadMp3File(const char* filename)
{
    mpg123_handle *mh;
    unsigned char *buffer;
    size_t buffer_size;
    size_t done;
    int err;

    int channels, encoding;
    long rate;

    mpg123_init();
    mh = mpg123_new(NULL, &err);
    buffer_size = mpg123_outblock(mh);
    buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));

    /* open the file and get the decoding format */
    mpg123_open(mh, filename);
    mpg123_getformat(mh, &rate, &channels, &encoding);

    /* set the output format and open the output device */
    int m_bits = mpg123_encsize(encoding);
    int m_rate = rate;
    int m_channels = channels;


    /* decode and play */
    for (int totalBtyes = 0 ; mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK ; ) {
        totalBtyes += done;
    }


    /* clean up */
    free(buffer);
    mpg123_close(mh);
    mpg123_delete(mh);
    mpg123_exit();

}
steveh
  • 1,352
  • 2
  • 27
  • 41