Code covered by the BSD License  

Highlights from
mp3read and mp3write

4.42857

4.4 | 23 ratings Rate this file 176 Downloads (last 30 days) File Size: 2.13 MB File ID: #13852
image thumbnail

mp3read and mp3write

by

 

04 Feb 2007 (Updated )

Improved reading and writing of mp3 files

| Watch this File

File Information
Description

These versions of mp3read and mp3write are direct drop-in replacements for wavread and wavwrite to access MPEG audio mp3 files. Features include:
 - aims to duplicate complete syntax of wavread and wavwrite
 - also supports on-the-fly downsampling and channel merging of mpg123
 - optimized for very long mp3 files - only decodes the needed portion
 - uses popen for encoding to avoid a large temporary file (when available - see my popenw mex)
 - attempts to preserve time alignment of files through read/write loop by removing "warm up" samples
 - package includes helper binaries for Linux, Windows, Mac-PPC, Mac-Intel, and Mac-Intel-64bit

Acknowledgements

Mp3 Write And Mp3 Read inspired this file.

This file inspired M4awrite Write M4a Format Audio File, Mi Rtoolbox, Mp3 Player (Gui), and Audioread Unified Audio File Input Function.

MATLAB release MATLAB 7.10 (R2010a)
Other requirements Relies on external binaries mpg123, mp3info, and lame. Package includes binaries that should work, but YMMV. Documentation includes links to the sources of these programs.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (38)
16 Sep 2014 akin

thankss

05 Sep 2013 Athanasios Lykartsis

Hi,

i get the same problem as Onno reported with mac 10.6.8 and Version R2011a, although permissions are correct.

I am thinking: Maybe there is an issue with the options of the system command which are passed with the cmd argument at line 371 of the mp3read.m, because they are not permitted to be run from other than internal programs?

If anybody has an idea, please share! I am gonna try it under windows us well to see if the same comes up...

Best regards,

Thanassis

05 Sep 2013 Athanasios Lykartsis

...continuation:

...at line 371 of the mp3read.m and the command "cmd" delivers all the options) cause the problem, because they are not permitted to be run from other than internal programs?

If anybody has an idea, please share! I am gonna try it under windows us well to see if the same comes up...

Greets,

Thanassis

30 Jun 2013 Onno

I am using Mac and Matlab 2012b. The code seems to work however I get the error message:

unable to execute (..) /mp3readwrite/mp3info.maci64" -r m -p "%Q %u %b %r
%v * %C %e %E %L %O %o %p" "sound.mp3" (/bin/bash: (...)/mp3readwrite/mp3info.maci64: Permission denied)

If i look at the permissions for this (mp3info.maci64) file then I see that I can read and write. Anyone any idea how to solve this?

01 Apr 2013 reza

its good

29 Oct 2012 Manuel  
09 Sep 2012 vyshakh

good

10 Jun 2012 KVGCE  
10 Jun 2012 KVGCE

Really useful... i've used it in my project... Thanks to u and of course to "Luigi Rosa" < http://labrosa.ee.columbia.edu/matlab/mp3read.html >

24 May 2012 nick

Thank you, I very much need this

26 Mar 2012 Oliver

Regarding the error with mysystem(cmd):
The cmd variable defines how the mp3info/mpg123 is called on your machine. I got the mp3read working by changing the corresponding lines (somewhere around line 180 and 312 in the code) to:

cmd = ['mp3info -r m -p "%Q %u %b %r %v * %C %e %E %L %O %o %p" "', FILE,'"'];
and
cmd=['mpg123', downsampstr, chansstr, skipstr, lenstr,' -q -w "', tmpfile,'" "',FILE,'"'];

This should work if you installed the mp3info/mpg123 normally and I expect the mp3write can be fixed in a similar manner.

(Sidenote: Sorry for the low ratings, apparently I'm really bad at clicking textboxes on a trackpad.)

26 Mar 2012 Oliver  
19 Mar 2012 Shreyes  
11 Mar 2012 Ajay

I am getting a similar to the error described above I m using 64 bit Ubuntu and trying to execute mp3read but it gives me this error :-

mp3read('test.mp3')
??? Error using ==> mp3read>mysystem at 373
unable to execute "/home/ajayram/Documents/MusicWork/Codes/mp3info.glnxa64" -r
m -p "%Q %u %b %r %v * %C %e %E %L %O %o %p" "test.mp3"
(/bin/bash: /home/ajayram/Documents/MusicWork/Codes/mp3info.glnxa64: No such
file or directory
)

Error in ==> mp3read at 188
w = mysystem(cmd);

--------------------------------

I have no clue as to how to get around this issue.

21 Feb 2012 Mamoon

I'm using this on a 65-bit Ubuntu (10.04.4 LTS) and I keep on getting the following error when I run the demo file:
??? Error using ==> mp3write>mysystem at 168
unable to execute
"/MATLAB/mp3readwrite/lame.glnxa64"
--quiet -h "/tmp/tmp632.wav" "piano.mp3"
(/bin/bash:
/MATLAB/mp3readwrite/lame.glnxa64:
No such file or directory
)

Error in ==> mp3write at 156
mysystem(cmd);

Error in ==> demo_mp3readwrite at 45
mp3write(d,sr,'piano.mp3');

I'm certain that this is because I'm missing the lame.glnxa64 file for 64 bit version.

PLEASE HELP ME!! It is much appreciated.

20 Feb 2012 sunil chhipa

great work............

20 Feb 2012 sunil chhipa  
28 Nov 2011 bei liu

It's good,bur I dont know hwo to use it.

22 Nov 2011 Han

Thank you

11 Oct 2011 Jesse van Muijden

works fine with Matlab 7.10.0 (R2010a) on Windows XP Pro SP3. Thank you!

19 Sep 2011 Mr Smart  
08 Aug 2011 Ilaria Milesi  
01 Aug 2010 Manikandan

I got 'Out of Memory' error. Please advice me. Thanks.

20 Jul 2010 David

and I got this error with mp3read

>> mp3read([mp3_list(i).name])
??? Error using ==> mp3read>mysystem at 373
unable to execute "C:\Documents and Settings\mfiles\mp3readwrite\mpg123.exe" -q -w "\tmp\tmp127.wav"
"DJ.mp3" ()

Error in ==> mp3read at 330
mysystem(cmd);

06 May 2010 brigitte audrey

very good stuff. thanks for sharing

31 Mar 2010 Gökhan Vural

It works very nice overally. However, it gives ".mp3 is corrupt or is not a standard MP3 file." error for some songs. Indeed, files're not corrupt.
Does anybody know the reason of it ?

30 Mar 2010 T myself

Great tool! Works nice. Thank you.

01 Dec 2008 Jorge Moragues

As Mahocan said, the corresponding 'SIZ' command does not work properly and it returns a wrong number of samples of the file.

Has anybody solved this problem?

Thanks

01 Aug 2008 JG NT

I can recommend this program! IT worked very good. Thanks

16 Apr 2008 loch zeng

This is a good tools

14 Apr 2008 Aaron Clarke

I tried it and it worked great right away. Nice program!

21 Feb 2008 suraj prakash

its cool.

15 Jan 2008 Jose Uy

It doesn't seem to work with mp3's downloaded from itunes. Does the AAC encoding have anything to do with this?

18 Aug 2007 hrushikesh kulkarni

great i am very thankful to you

31 Jul 2007 Mahocan Ganemur

Good job!

23 Jul 2007 Mahocan Ganemur

Hi,

Thanks for building such a useful tool. I just tried the command "SIZ = MP3READ(FILE,'size')" on MATLAB. The resulting "total number of audio samples" value given by the command is not correct. For example in the file that I test, there are 237 931 198 total audio samples, while the command has given the result as 193 625 280. I tried on another mp3 file that is relatiely small. The correct size of this file is 41 133 311, while the command has given as 40 912 128. I cannot get the correct value of the total number of audio samples in the mp3 file with this command. Any suggestions on this issue? Thanks in advance.

19 Feb 2007 Daryush Mehta

Forgot to mention that in my setup (WinXP SP2, Matlab 2006b), the default bit rate for mp3write turns out to be 64 kbps, not 128 kbps that's mentioned in the help file.

19 Feb 2007 Daryush Mehta

Works great! Commenting in the code helps the reader well. I am running Windows XP SP2 and Matlab 7.3.0 (R2006b).

As Dan Ellis notes on his website <http://labrosa.ee.columbia.edu/matlab/popenrw.html>, two functions are available to prevent Lame from having to access a large temporary file; instead, a "pipeline" is open to the lame codec. I was able to compile Dan Ellis' popenw.c and popenr.c files ('mex popenw.c' and 'mex popenr.c' at Matlab command prompt) to give platform-specific mex files. But, when I ran the mp3write code, no error was given and no mp3 file was created. If anyone can get this functionality working, please share it!

Also, definitely read the mp3write help file to note that you can specify the bit rate by changing the last integer in
mp3write(x,fs,'filename','--quiet -h -b 128');'

Should prove to be very useful. Thanks for writing them.

Updates
27 Jul 2007

- fix to writing stereo files on Windows
 - mp3read(...,'size') now more accurate (but not perfect owing to limitations in mp3info)
 - various cleanups to reduce mlint errors

15 Mar 2009

This version enables the ability of mpg123 to read mp3 files from URLs.

09 Apr 2010

Updated to use and include more recent versions of mpg123 and lame. I've done my best to fix inconsistencies with the 'size' return, but for some MP3s this relies on header info I can't probe.

21 Apr 2010

 - updated binaries for maci64 (static link) and windows (http works)
 - expands '~' in file names
 - returns correct SR when reading over http:

Contact us