aspose file tools
The moose likes Java in General and the fly likes MP3 and byte array conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "MP3 and byte array conversion" Watch "MP3 and byte array conversion" New topic
Author

MP3 and byte array conversion

Eddie Shakarchi
Greenhorn

Joined: Apr 06, 2004
Posts: 15
Hi guys,

I have some code which converts 16bit audio from byte data to short arrays (or any type of arrays) for processing. Once all sorts of possible processing is done, it is then converted back to a byte array for playback. I've attached the code which does this initial conversion at the bottom of this email.

I've recently starting using the jlayer, mp3spi, and tritonus_share libraries. So far i'm able to get metadata from the mp3 files easily, however i'm struggling to get the audio converted into a format that's playable by my software. When i use: int bytesread = din.read(bytes, 0, (int) bufSize);

'bytesread' is only 4068 regardless of the mp3 file, or the values of bufSize/the size of the bytes[] array. When using 16bit wavs, bytesread is the same size as bufSize and bytes[]. All the audio which comes out after conversion from a byte array (from the code below) is silent/has a value of 0.

Can anyone let me know why i can't 'access' this raw byte data for conversion?

'din' is the decoded audioInputStream, you can see the 'standard' audio code here:



When i try to use 'int bytesread = audioInputStream.read(bytes, 0, (int) bufSize); - all i get is white noise!

Many thanks,

Eddie

============


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35252
    
    7
No idea what's going on, but I still think you would have an easier time using JMF. Is there a particular reason you want to use MP3SPI?


Android appsImageJ pluginsJava web charts
Eddie Shakarchi
Greenhorn

Joined: Apr 06, 2004
Posts: 15
Hi Ulf,

The mains reasons are, if i'm not mistaken:

1) With MP3SPI, you can simply reuse all the javasound code, which i have already implemented

2) With MP3SPI, i believe i can access the raw byte data, convert it using the code above (i.e. treat it like a wav), and then convert it back to 16bit byte data for play back - all using the same mechanisms as i am familar with - i.e. the javasound API. The software i'm coding for is not a small app that simply requires an mp3 playing in the background, or anything like that.

Please correct me if i'm wrong, or if i can do this with JMF!

Many thanks

Eddie
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: MP3 and byte array conversion
 
Similar Threads
Audio format conversion problems
Play a .wav file
audio visualization graphics
how to create an image through bufferedimage,image and other helper class using byte array
Java Sound API problems