Solved

Porting MPG123 to Windows

Posted on 2004-08-14
10
1,713 Views
Last Modified: 2013-11-15
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
0
Comment
Question by:RJSoft
  • 6
  • 4
10 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11803000
I know there is a mpg123 for windows. Look at:
http://www.s2.org/~pekangas/
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11803011
This is an interesting LGPL MP3 project:
http://bladeenc.mp3.no
0
 
LVL 3

Author Comment

by:RJSoft
ID: 11803922
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


0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11811468
>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.
0
 
LVL 3

Author Comment

by:RJSoft
ID: 11816002
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
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Author Comment

by:RJSoft
ID: 11816308
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;

}
0
 
LVL 3

Author Comment

by:RJSoft
ID: 11816404
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


0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 11829326
Hi RJSoft,
>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.
If you compile it with visual C++ (creating a proper Win32 console applications), any Linux dependent variable of function will generate an error.

>The author does not expressly say that it is specifically for converting mp3 to wav. But he says it's for decoding.
Wav is a simple audio format where you store audio signal values without any special management, so, it will be easy to use decoded data to generate wav file.

>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.
Yes, that's it.

main function appears to be simple, it is pure and simple C, so, if any problem, it is not there.
Forget the makefile, as I told you, create a Win32 console project in your compiler, add all file to that project. Maybe some data alignment considerations should be taken. I guess it will need 1-byte data alignment, for example.


0
 
LVL 3

Author Comment

by:RJSoft
ID: 11866566
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
0
 
LVL 3

Author Comment

by:RJSoft
ID: 11866570
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
A list of useful business intelligence software.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now