minimp3 source code

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#41 Post by technosaurus »

I reworked Krister Lagerstrom's public domain code a bit... my modifications are also public domain... work is still in progress adding the optimizations in as compile time options, but the big ones are there, (however if you want to add more optimizations, see https://github.com/technosaurus/PDMP3)

You can use this in any project, commercial or otherwise without attribution (I'm still working on making this part easy though - patches welcome)
Attachments
pdmp3.zip
Its not letting me add tar.gz files now
(27.76 KiB) Downloaded 173 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#42 Post by musher0 »

Hello, technosaurus.

Surprising little piece of software! :) Oooh, good work, there.

Compiled just fine with "make".

Generally plays ok the mp3's I tried on it.

Except a Japanese recording (see screen cap below) of J. S. Bach's
Goldberg Variations. Something about "Layer 3". Probably you know this
already, but I'm reporting it just in case you don't.

Also -- and this is entirely subjective, please don't go chasing wild geese
on my account -- is it possible that the beat may be off on some songs,
and a male voice could sound "bass-enriched" ? Nah, it's probably this
particular singer! ;)

Anyway, thanks for this. BFN.

musher0
Attachments
Only_layer_3_2015-05-15.jpg
(48.25 KiB) Downloaded 257 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#43 Post by technosaurus »

If you have a link to a mp3 that won't play, post it ... I'm really sick of /usr/share/audio/ivy.mp3 anyhow. I'm still planning to add id3 tag support (you can try using the id tag stripper from a few posts back ... which is where I will ultimately get the code from)

... you may be right about the sound; while reviewing the code I noticed some things that were "iffy"

the original author of minimp3 on this thread also wrote a mp2 player ... parts of which were released to the public domain... I'm not sure about layer 1 though... not sure if I have ever seen it.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#44 Post by Ibidem »

technosaurus wrote:If you have a link to a mp3 that won't play, post it ... I'm really sick of /usr/share/audio/ivy.mp3 anyhow. I'm still planning to add id3 tag support (you can try using the id tag stripper from a few posts back ... which is where I will ultimately get the code from)

... you may be right about the sound; while reviewing the code I noticed some things that were "iffy"

the original author of minimp3 on this thread also wrote a mp2 player ... parts of which were released to the public domain... I'm not sure about layer 1 though... not sure if I have ever seen it.
The first mp3 musher0 refers to is the first mp3 of the Open Goldberg Variations (http://www.opengoldbergvariations.org/), which is CC0.
file reports it to be:

Code: Select all

Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
So it may be the lack of id3 support.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#45 Post by musher0 »

@Ibidem: yep, that's the one.

@technosaurus: The "Aria" track that I mentioned above is here.
It's a "pass-the-hat", "pay-what-you-can" kind of download.

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#46 Post by Ibidem »

Having downloaded those recordings a while ago, I tried it out.
Results:
-Same errors when played without modification
-id3 and id3tool don't recognize the id3 tags, but id3v2 can remove them.
-mp3dec_opt plays the result nicely, at ~25% CPU on my 1.6GHz Atom N270.
-mp3dec plays the result, but runs ~66% CPU.
I'll try out the id3 tag stripper referred to.

UPDATE:
Yup, the id3 tag stripper works (meaning it removes enough); <unistd.h> should be added, though.
It does point out an issue with the PDMP3 code:
the API and code almost seem like they were designed to prevent use with pipes.
- rather than passing a file handle / descriptor, you copy a name to the global

Code: Select all

char filename[256]
(256 is the max length for a file name...without a path!).
- it apparently checks if it has hit the end of the file, via ftell(), rather than whether reading has failed; if ftell() fails, it is treated as an EOF.
- the overuse of globals results in the relevant code being rather well hidden.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#47 Post by technosaurus »

Ibidem wrote:Having downloaded those recordings a while ago, I tried it out.
Results:
-Same errors when played without modification
-id3 and id3tool don't recognize the id3 tags, but id3v2 can remove them.
-mp3dec_opt plays the result nicely, at ~25% CPU on my 1.6GHz Atom N270.
-mp3dec plays the result, but runs ~66% CPU.
I'll try out the id3 tag stripper referred to.

UPDATE:
Yup, the id3 tag stripper works (meaning it removes enough); <unistd.h> should be added, though.
It does point out an issue with the PDMP3 code:
the API and code almost seem like they were designed to prevent use with pipes.
- rather than passing a file handle / descriptor, you copy a name to the global

Code: Select all

char filename[256]
(256 is the max length for a file name...without a path!).
- it apparently checks if it has hit the end of the file, via ftell(), rather than whether reading has failed; if ftell() fails, it is treated as an EOF.
- the overuse of globals results in the relevant code being rather well hidden.
I am working on those ... as to resource usage, I added lookup tables for the IMDCT cos function which can be enabled with the CFLAG -DIMDCT_NTABLES ... that reduces CPU usage to ~15% after initialization.
Also need to set up a separate initialization function.

Edit:
I have updated https://github.com/technosaurus/PDMP3 with my current code and added a todo list in the readme.md ... For further issues, please add an issue via github.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#48 Post by Ibidem »

technosaurus wrote: I am working on those ... as to resource usage, I added lookup tables for the IMDCT cos function which can be enabled with the CFLAG -DIMDCT_NTABLES ... that reduces CPU usage to ~15% after initialization.
Also need to set up a separate initialization function.

Edit:
I have updated https://github.com/technosaurus/PDMP3 with my current code and added a todo list in the readme.md ... For further issues, please add an issue via github.
Thanks for the IDMCT bit!
You have a new pull request on github. ;-)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#49 Post by technosaurus »

Ibidem wrote:Thanks for the IDMCT bit!
You have a new pull request on github. ;-)
Merged. Thanks!
Anytime you see a function that requires #include <math.h>, its a good hint that it could use a lookup table pow*(), sin*(), cos*(), tan*(), etc...
Keep in mind that each chunk of data corresponds to ~20ms, so it needs to be processed very quickly (most programs take longer than 20ms just to load)
I got a bit better cpu load (slightly larger binary) by doing -fprofile-generate (running it) and then -fprofile-use

Edit::Here are the gperf results, Looks like L3_Subband_Synthesis and L3_Reorder alon with reading the data are the hot spots.

Code: Select all

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
 56.82      0.25     0.25                             L3_Subband_Synthesis
 27.27      0.37     0.12                             L3_Reorder
  6.82      0.40     0.03   437169     0.07     0.07  __do_global_dtors_aux
  4.55      0.42     0.02   181361     0.11     0.11  Read_Header
  2.27      0.43     0.01    78785     0.13     0.13  Get_Bytes
  2.27      0.44     0.01                             Get_Side_Bits
  0.00      0.44     0.00   167430     0.00     0.00  Get_Main_Pos
  0.00      0.44     0.00     9734     0.00     0.00  frame_dummy
  0.00      0.44     0.00     2629     0.00     0.00  Requantize_Pow_43
  0.00      0.44     0.00     1859     0.00     2.29  Read_Audio_L3
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#50 Post by musher0 »

technosaurus wrote:I reworked Krister Lagerstrom's public domain code a bit... my modifications are also public domain... work is still in progress adding the optimizations in as compile time options, but the big ones are there, (however if you want to add more optimizations, see https://github.com/technosaurus/PDMP3)

You can use this in any project, commercial or otherwise without attribution (I'm still working on making this part easy though - patches welcome)
Thanks again for this, tehcnosaurus!
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply