0
$\begingroup$

First of all sorry if this is a stupid question, but I am an absolute beginner in this field and have been trying for days now. I'm working on a java program that uses fft to analyze audio files. To test the results I'm getting from the fft I drew some spectrograms, which are working perfectly for WAV files. But I get weird effects when using mp3 or mp4 files. I use the Jtransform library from wendykierp.

This is what it should look like. Spectrogram of wav file

And this is what is looks like. Spectrogram of mp3 file

It is also half the width of the wav spectrogram (due to compression?). If yes can this be compensated for?

The samples seem to be correct:

From my program: Program audio mp3

From Audacity:

Audacity mp3

And here are the spectrograms for the Mp3 and Mp4 of a 1khz Sinus wave.

Mp3: Mp3 1khz

Mp4:

Mp4 1khz

EDIT:

The suggestion to test with octave helped quite a bit. I changed the code to just take the first half of the FFT output and added channel separation for the samples of the mp3. Now I get the correct specrogram for mp3 files.

But there are still two problems:

The first is that the mp3 spectrogram has only 1/4th of the width and 1/2 of the height of the wav specrogram because of the sample count. It also seems to be cut of[f] a bit at the top. Can I solve the width problem by just interpolationg new samples or is there a better way?

The second is that mp4 files still look like above, which probably has more to do with the samples or channel layout than the FFT itself (?)

$\endgroup$
  • $\begingroup$ Can you share the parameters by which you call the FFT? Do you take the different sampling frequencies into account? How do you access the MP3 and MP4 formats? $\endgroup$ – A_A Dec 24 '18 at 14:07
  • $\begingroup$ The mp3 and mp4 formats are accessed via the humble-video library (github.com/artclarke/humble-video). The frequencies are for the 1khz example all 44,1khz. But how should they be taken into consideration if they were different? And I noticed that I was not using the right FFT method but the DCT, which confuses me even more, because the data from the DCT at least resembles the WAV spectrogram while the FFT output is just all over the place. The FFT takes an array of complex numbers in form [real, imag, real, ...] of size N * 2. The DCT just takes an array of samples. $\endgroup$ – BpZ Dec 24 '18 at 17:29
  • $\begingroup$ The humble video library returns the audio stream as byte array which is then transformed into an double array. $\endgroup$ – BpZ Dec 24 '18 at 17:40
  • $\begingroup$ The thing is, I don't mind writing up some form of guidance but judging by your comment right here, I think that I would have to start from a very early point. So much so that the answer would be massive and this means that the question is too broad. This is not a comment on your ability. I am not trying to put you on the spot and I am sure that you can understand what is going on but it needs a bit of reading about the basics first. Shall we tackle the spectrogram first? You indeed need the fft function and the complex input is perfectly fine.Does the second image remind you of... $\endgroup$ – A_A Dec 24 '18 at 20:37
  • $\begingroup$ ...anything about the properties of the Discrete Fourier Transform? If it does not, can I please ask you to read a little bit about the DFT (from the wikipedia page) and then come back and amend this question with something more specific? Throughout your reading, I think that it would be quicker if you used an environment that requires less set up than Java for experimentation. Try Octave for that and see if you can load a wav file $\endgroup$ – A_A Dec 24 '18 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.