Decoding raw sound data??

I’ve been looking at Jlgui (Java MP3 player).

I’ve got access to the raw sound data being sent to the line to play the MP3. I’m trying to find the format of the data so I can decode it and do neat things (equalizier output, or other sound controlled visuals). But so far I haven’t found any reference as to how to interpret the data.

Anyone have any references?

Thanks

I don’t know for sure… the line can be configured in different ways… but the chances are that you have pairs (left/right) of 16 bit samples… the byte order (endian-ness) I think is the most likely thing to vary from one platform to another.

Do you have the code that sets up the line? Then you could be sure of the format.

Well, I just “played” with the data off the data stream. I was able to get a pair of waveform displays by using bytes 2 and 4 of a 4 byte block. Based on your description I’m probably just truncating the upper bytes of info :stuck_out_tongue: Now I imagine this only works for a stereo bitstream, as a mono bitstream wouldn’t have 4 bytes but rather 2 bytes per block.

So it looks like the frequencies are derived from the values in the bitstream and not directly encoded?

Here’s the code that sets up the line. It looks to be based off the loaded sound file.


            AudioFormat sourceFormat = m_audioInputStream.getFormat();
            trace(1, getClass().getName(), "Source format : ", sourceFormat.toString());

            AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sourceFormat.getSampleRate(), 16, sourceFormat.getChannels(), sourceFormat.getChannels() * 2, sourceFormat.getSampleRate(), false);

            trace(1, getClass().getName(), "Target format: " + targetFormat);
            m_audioInputStream = AudioSystem.getAudioInputStream(targetFormat, m_audioInputStream);

            AudioFormat audioFormat = m_audioInputStream.getFormat();
            trace(1, getClass().getName(), "Create Line : ", audioFormat.toString());

            DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, AudioSystem.NOT_SPECIFIED);
            m_line = (SourceDataLine) AudioSystem.getLine(info);

[quote]So it looks like the frequencies are derived from the values in the bitstream and not directly encoded?
[/quote]
Sounds like you are missing a fundamental thing here. The data you pass to the line is TIME DOMAIN data… It’s the amplitude of the audio wave sampled at regular intervals in time (typically every 1/48000 of a second or 1/44100 of a second for high quality audio). MP3 and other compressed formats work in the FREQUENCY domain, do some googling and you will learn much…

Indeed I am missing a fundamental thing. I basically have absolutely no knowledge of the data stream, but managed to “hack” a wave graph out of it anyway :smiley:

What keywords should I google for? I kept looking for info, but couldn’t find any :frowning:

Just look for general intros to Digital Signal Processing.