Recent

Author Topic: Help translate this public domain Mpeg Layer 1 decoder to Lazarus  (Read 2397 times)

domasz

  • Sr. Member
  • ****
  • Posts: 435
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: [Select]
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; 
« Last Edit: March 29, 2022, 11:36:58 pm by domasz »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #1 on: March 28, 2022, 11:39:22 pm »
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

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #2 on: March 28, 2022, 11:58:06 pm »
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

  • Hero Member
  • *****
  • Posts: 11916
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #3 on: March 29, 2022, 01:53:32 pm »
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.
« Last Edit: March 29, 2022, 02:37:04 pm by wp »

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #4 on: March 29, 2022, 03:03:29 pm »
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
« Last Edit: March 29, 2022, 03:12:10 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #5 on: March 29, 2022, 06:54:06 pm »
There's another mp3 decoder which even is for Lazarus: https://github.com/dpethes/mp3dp. I tested it - it is working.
This is based on Delphi MPEG which is GNU/GPL and Delphi MPEG is based on maplay which is also GNU/GPL. So this thing is GNU/GPL.

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #6 on: March 29, 2022, 08:37:41 pm »
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

Thank you very much! Very useful! I updated the file in the first post.

Can you tell me how to translate this?
Code: [Select]
output = (short*)realloc(output, outputMax);

korba812

  • Sr. Member
  • ****
  • Posts: 394
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #7 on: March 29, 2022, 08:51:09 pm »
Can you tell me how to translate this?
Code: [Select]
output = (short*)realloc(output, outputMax);
https://www.freepascal.org/docs-html/rtl/system/reallocmem.html
Code: Pascal  [Select][+][-]
  1. output := ReAllocMem(output, outputMax);

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #8 on: March 29, 2022, 10:06:34 pm »
Can you tell me how to translate this?
Code: [Select]
output = (short*)realloc(output, outputMax);
https://www.freepascal.org/docs-html/rtl/system/reallocmem.html
Code: Pascal  [Select][+][-]
  1. output := ReAllocMem(output, outputMax);
Thank you. It compiles now but doesn't seem to work. Most likely I made an error in translation :(
« Last Edit: April 02, 2022, 02:07:52 pm by domasz »

dpethes

  • Newbie
  • Posts: 4
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #9 on: May 02, 2022, 07:58:18 pm »
You do realize that this is a layer 1 decoder and as such of extremely limited use (I haven't seen a layer 1 file pretty much ever)? I'm pointing this out because you renamed it to jo_mp3 , and this is misleading and far from an actual mp3 decoder, like mp3dp.

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #10 on: May 06, 2022, 08:41:06 pm »
Yes, I thought it was MPEG 1 Layer 3 but it's just Layer 1.

If your mp3dp had a usable license it would be an amazing thing.

serbod

  • Full Member
  • ***
  • Posts: 142
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #11 on: August 17, 2022, 04:23:48 pm »
I can translate, it's not very big and complicated. If it still actual.

Also, I translated public domain MP3 decoder with permissive MIT license:

https://github.com/serbod/acs/blob/master/src/formats/general/mp3.pas

But it has flaws in L3_Subband_Synthesis() procedure, and I can't properly debug it step-by-step because known working algorithm from mp3dp (see comments above) is totally different.

UPD: Flaws was fixed, and usage example added.
« Last Edit: August 27, 2022, 12:45:39 am by serbod »

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Help translate this public domain Mpeg Layer 1 decoder to Lazarus
« Reply #12 on: October 11, 2022, 09:16:07 pm »
I can translate, it's not very big and complicated. If it still actual.

Also, I translated public domain MP3 decoder with permissive MIT license:

You did a great job with the MP3 decoder, Sergey! Much appreciated!
I didn't find any MPEG-1 Layer 1 decoder in Pascal and my attempt at conversion wasn't  successful. So yes- it is actual.

 

TinyPortal © 2005-2018