Link to home
Start Free TrialLog in
Avatar of RJSoft
RJSoft

asked on

Porting MPG123 to Windows

Hello all;

I would like to port MPG123 to Windows environment so that I could convert mp3 to wav.

I was going to use the libmad but they are licensed under the GNU/GPL. MPG123 is licensed under the LPGL so that makes it much nicer.

However, I am not sure about all the steps required. Also there could be the possibility that this has already been done. I searched Google for a ported version but did not find anything. But that does not mean it does not exist.

All comments and suggestions/criticisms are apreciated.

RJ
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

I know there is a mpg123 for windows. Look at:
http://www.s2.org/~pekangas/
This is an interesting LGPL MP3 project:
http://bladeenc.mp3.no
Avatar of RJSoft
RJSoft

ASKER

Hello jaime;

The MP3 blade project is strictly for converting WAV to mp3. Unless I missed something.

The link to mpg123 (http://www.s2.org/~pekangas/) has 2 versions of mpg123.exe.

One of those mpg123.exe is supposed to do MP3 to WAV but it does not work. It crashes on my system.

The source code is in a gz file. Which when extracted is a tar file. So since I am on windows I dont believe I will be able to extract the tar source. Unless I can find a utility to do so.

I know how to construct a WAV file. I can construct the WAV header and then output the raw PCM data afterwards. I just don't know how to get the values from the MP3 file (via mpg123 or blade) to construct the header. I believe that I can output the MP3 as raw PCM data with MPG123.

RJ


>The source code is in a gz file. Which when extracted is a tar file. So since I am on windows I dont believe I will be
> able to extract the tar source. Unless I can find a utility to do so.

WinRAR will extract the tar format.
Notice that a audio conversion software is not system-dependent (at least in theory), but audio/playing recording functionality is.
Avatar of RJSoft

ASKER

Thanks jaime!

The WinRAR worked to untar the file. But did some strange things to my registry. Upon next startup my pc informed me that the Registry was being restored by using the old copy.

Well my pc works so I could care less. As long as it runs. Im ok.

Now that I have the source code I guess the next step would be to scour the web for example code that uses mpg123.

This time arround I would like to more than just compile the code into an exe and then ShellExecute and use Named pipes to get the stdout.

I would like to create a Windows dll out of it. I think that if I can get some example code at leasts I can back track through the code to see how I could export some functions.

I guess the first thing I can do is just compile the source to see what kind of errors I get.
I assume I should just try to add them all to a project and compile.

Since it appears to be all c code. I dont see why I should have problems. I am not sure if there is much of any dependancy upon Linux/Unix variables etc... But I do not know.

Any pointers would be apreciated.
RJ
Avatar of RJSoft

ASKER

Jaime;

I just found out that there is a sub folder in the main source that was strictly the mpg123 dll library build. It is a stripped down version of the mpg123 library. The author does not expressly say that it is specifically for converting mp3 to wav. But he says it's for decoding.

So I take this to mean that this is for decoding and playback. I have not checked the decode function to see if there is any output being directed to a multi media player (like mciSendString or or some playSound, waveOut function).


Also it contains an example file. main.c which might show me how to convert an mp3 to wav file. I am posting the main.c at bottom of this post.

The main.c is expressed as buffers. So I believe this would only be raw PCM buffer values. I am hoping the only thing left is to calculate what the wav header file should be. So I could write the header information to file before I write the raw PCM data.

In his main code he has the -w option to create a wave output file. But as I stated previous that part of the program bombs. (the main code being the non stripped down version which creates the mpg123.exe)

I think I could use the code from that file (wave.c) as a guide to a routine that would build my own wav file output.

But I was thinking maybe I should experiment with fixing whatever bug makes the code bomb "File creation error" before I work on building the dll.

What would be nice if you could unzip the file and follow me as I go through this? I would apreciate a helpful comment every now and then.

Also you could tell me if your getting the same errors as me, that way I would know if it was something wrong with my pc verses just something wrong with the code. For example if you ran mpg123.exe with the wave output flag and got no error.

There may also be issues with licensing too. Even though the author was kind enough to place it under LPGL he states some issue with another company. I would like your opinion on this too.

If you need more points I am good for it. Also I can award you points by placing a question directed for you only. I could also advance you points. Or any other way you could figure...

Thanks in advance
RJ

here is the main.c

#include "mpg123.h"
#include "mpglib.h"

char buf[16384];
struct mpstr mp;

int main(int argc,char **argv)
{
      int size;
      char out[8192];
      int len,ret;
      

      InitMP3(&mp);

      while(1) {
            len = read(0,buf,16384);
            if(len <= 0)
                  break;
            ret = decodeMP3(&mp,buf,len,out,8192,&size);
            while(ret == MP3_OK) {
                  write(1,out,size);
                  ret = decodeMP3(&mp,NULL,0,out,8192,&size);
            }
      }

  return 0;

}
Avatar of RJSoft

ASKER

Also I dont know how to compile it yet because it uses a makefile.

There is no dsw or prj etc...

here is the make file


CC=gcc
CFLAGS=-Wall -g -DLAYER1 -DLAYER2 -DLAYER3

all: mpglib


*.o: mpg123.h mpglib.h

mpglib: layer1.o layer2.o common.o dct64_i386.o decode_i386.o layer3.o tabinit.o interface.o main.o
      $(CC) -o mpglib \
            common.o dct64_i386.o decode_i386.o layer3.o \
            tabinit.o interface.o main.o layer2.o layer1.o -lm

clean:
      rm *.o mpglib


ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RJSoft

ASKER

When you say allignment you mean I have to pad the buffer so the size of the buffer will have to be divisible evenly by 8?

Probably will not have to worry about that because the buffer is pointed to by char. (In the example code.)

When I was working on my wave editor I had some confusion over the addressing of the buffer.

What I did not realize was that all I had to do was to have a char * pointer to address the buffer in 8 bit units. Then to address in 16 bit units use unsigned int* pointer.

But since I am only concearned with making a wav header that will represent the raw pcm output, I find I now need a library or some code to extract reliable mp3 header information and then use that to produce the wav header.

I found one class that had this functionality but allot of mp3 terminology so I am not sure what I am doing.

All I need are the hertz, bits(8 or 16), stereo or not. Then I believe I can calculate the Average bytes per sec and other Wav header info.

Any ideals about a good mp3 info extraction class? One that does not take a rocket scientist to figure out?

RJ
Avatar of RJSoft

ASKER

But hey, since I am compiling the mpglib anyway, to make a dll, maybe I should create another export function to give me the info.

RJ