6 Replies Latest reply: Nov 13, 2010 2:11 PM by sabre150 RSS

    Audio Spectrum Analyzer

    811170
      Hi to all,

      I have to do a small UI that display the spectrum band of an audio source (wav, or mp3). In order to to accomplish this work I used javax.soud library, and a class that computes FFT (made by me), but I don't know of to connect the stream got from the audio source to FFT algorithm. I mean, simply passing audio data (converting byte arrays from souce into integer array) into FFT do I will obtain the spectrum magnitude I'm searching for?
        • 1. Re: Audio Spectrum Analyzer
          sabre150
          808167 wrote:{quote
          I have to do a small UI that display the spectrum band of an audio source (wav, or mp3). In order to to accomplish this work I used javax.soud library, and a class that computes FFT (made by me),
          If the object of your project was to write an FFT then fair enough but you should be aware that there a plenty of free good Java FFT implementations arround.
          but I don't know of to connect the stream got from the audio source to FFT algorithm. I mean, simply passing audio data (converting byte arrays from souce into integer array) into FFT do I will obtain the spectrum magnitude I'm searching for?
          1) You will need to convert the bytes of the stream to sample values suitable for YOUR FFT implementation. This conversion will require you to extract the AudioFormat and write converters for each format you wish to support. You can gains some relief from this task by using some of the inbuilt audio conversion available in the Java Sound API. Assuming that you have just implemented the minimal FFT then you will need to fill the FFT real value buffer with these values and, since audio samples have not imaginary part, fill the imaginary value buffer with zeroes.

          2) You will need to perform (1) for each channel.

          3) You need to understand the relationship between the FFT of the audio samples and the power spectrum of the audio samples. In essence, you need to form the modulus of the (real,imag) pairs of the FFT values and plot these.

          4) You should understand that in principle the power spectrum exists at a given instance but you can only estimate the average power spectrum over a period (the collection period). The resolution one obtains is directly related to the collection period i.e. delta-frequency = 1 / collection-period. This means that for fine resolution one needs a long collection period BUT if one makes the collection period too long one does not see any transient detail (such as single note played for a short period).

          5) You should understand that the DFT (as implemented by the FFT) assumes a periodic signal is being transformed. This means that one needs to apply a 'window' to the data before being transformed so as to minimising the spectrum smearing caused by the discontinuities introduced by the periodic assumption. A side effect of the windowing is to reduce the available spectral resolution.

          To get this understanding you should spend some time studying signal analysis theory.
          • 2. Re: Audio Spectrum Analyzer
            811170
            Thanks for the reply!

            Searching by the web I've found an interesting example of data capture and analysis here: http://jvalentino2.tripod.com/dft/index.html , but as much as I've learned from your post, it doesn't take account of double channel FFT and alias/resolution problems, can this implementation be considered good enough? (maybe substituting the regular DFT with the FFT algorithm)

            Edited by: 808167 on 8-nov-2010 3.46

            Edited by: 808167 on 8-nov-2010 6.24
            • 3. Re: Audio Spectrum Analyzer
              sabre150
              The link is broken.

              The FFT algorithm is just a rapid and accurate way of implementing the DFT. A double channel FFT is nothing special since it is equivalent to perform the FFT/DFT on two channels. These two limitations in your knowledge indicate that you need to do a lot more reading.
              • 4. Re: Audio Spectrum Analyzer
                811170
                Sorry, was broken due the comma. I'm currently reading about, :)
                • 5. Re: Audio Spectrum Analyzer
                  813555
                  can you give the code?
                  • 6. Re: Audio Spectrum Analyzer
                    sabre150
                    810552 wrote:
                    can you give the code?
                    I might - are you a poor student who is trying to do this as a project and is in desperate need of some assistance?