Signal amplitude in Java

I rack my brains to solve a knotty problem (at least for me).

When playing an audio file (using Java), I want the signal amplitude to display over time.

I mean, I would like to implement a small panel showing a kind of oscilloscope (spectrum analyzer). The audio signal should be viewed in the time domain (the vertical axis is the amplitude and the horizontal axis is time).

Does anyone know how to do this? Is there a good tutorial I can rely on? Since I know very little about Java, I hope someone can help me.

Update:

Basically, I want this to be amplitude versus time, not frequency. The audio signal should be viewed in the time domain (the vertical axis is the amplitude and the horizontal axis is time).

+3
source share
4 answers

The main approach is as follows:

  • collect your audio data that you want to display. It can be raw sound samples or it can be the result of processing (for example, averaging over N samples or obtaining each N-th sample) to ensure scaling along the X axis. (Without scaling, you will need 48,000 pixels to display 1 second of audio.)

  • , . JPanel .

.

public void paint(Graphics g)
{
   short[] samples;  // the samples to render - get this from step 1.

   int height = getHeight();
   int middle = height/2;

   for (int i=0; i<samples.length; i++)
   {
      int sample = samples[i];
      int amplitude = sample*middle;
      g.drawLine(i, middle+amplitide, i, middle-amplitude); 
   }  
}

. , , .

, [] () ( Swing, !).

!

+3

. . .

?

+1

This is a pretty cool tutorial that answers most of your questions: Digital signal processing and fast Fourier transform in Java

0
source

Source: https://habr.com/ru/post/1740690/


All Articles