Forum > Audio and Video

Help translate this public domain Mpeg Layer 1 decoder to Lazarus

(1/3) > >>

domasz:
I found a public domain Mpeg Layer 1 decoder written in C++ and started porting it to Pascal. But the thing is- I barely know C++.

Could anybody help so Pascal has a native Mpeg Layer 1 decoder?

Source CPP (because it can't be attached):
https://www.jonolick.com/uploads/7/9/2/1/7921194/jo_mp1.cpp

Sample file:
https://samples.ffmpeg.org/A-codecs/mp1-sample.mp1

Usage example:

--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var F: TFileStream;
    Buf1: array of Byte;
    Buf2: array of CShort;
    Len1,Len2: Integer;
    Hz, Channels: Integer;
    res: cbool;
begin
  F := TFileStream.Create('test.mpeg', fmOpenRead or fmShareDenyWrite);
  Len1 := F.Size;
  SetLength(Buf1, Len1);
  F.Read(Buf1[0], Len1);
  F.Free;


  res := jo_read_mp1(@Buf1,
              Len1,
              @Buf2,
              Len2,
              Hz,
              Channels);

  if res then
    showMessage(format('%d %d', [hz, channels]))
  else
    showmessage('bad');
end; 

--- End code ---

winni:
Hi!

Not what you are looking for but:

All ways lead to Rome:

https://github.com/TheLazyTomcat/bnd.mpg123/blob/master/mpg123.pas


Winni

domasz:
Thank you, but that's quite useless as it requires a different DLL every time you want to compile for a different architecture. That's why I want a Pascal native library.

wp:
There's another mp3 decoder which even is for Lazarus: https://github.com/dpethes/mp3dp. I tested it - it is working. For the mp3player_demo you do need external dlls (sdl2.dll and cimgui.dll) - but this is independent of the mp3 decoding process; there is another demo, mp3_decode, which runs on its own, without a dll.

Zvoni:
Just looked at his code:
What in blazes is a "Pointeger"? Should be "Pointer"

EDIT: And there are some other things wrong in his argument-lists
in jo_read_mp1
"OutPut" is a Reference to a pointer to Short (That's an Int16, right?), so at a guess it should be "var OutPut:PInt16" or something

in jo_readBits
first argument should be "const data:PByte"

and nevermind that when porting C/C++-code you should use the CTypes-Unit with its C-types provided

Navigation

[0] Message Index

[#] Next page

Go to full version