How to calculate the level/amplitude/db of audio signal in java?

Principally the problem seems to be that you are reading the audio data incorrectly. Specifically I’m not really sure what this excerpt is supposed to mean: if (tempBuffer[j] > tempBuffer[j+1]) … tempBuffer[j] – tempBuffer[j+1]; else … tempBuffer[j + 1] – tempBuffer[j]; But anyhow since you are recording 16-bit data the bytes in the byte array … Read more

Wav file convert to byte array in java

Basically as described by the snippet in the first answer, but instead of the BufferedInputStream use AudioSystem.getAudioInputStream(File) to get the InputStream. Using the audio stream as obtained from AudioSystem will ensure that the headers are stripped, and the input file decode to a byte[] that represents the actual sound frames/samples – which can then be … Read more

How do you play a long AudioClip?

Use BigClip. It is a class I put together to play MP3s of 12-18 minutes (or more1). It requires the mp3plugin.jar on the run-time class-path to actually load MP3 format sound, but that is not the point. The point is: BigClip will load sound files to the maximum memory the JVM will allow before OutOfMemoryError. … Read more

Java Program to create a PNG waveform for an audio file

Below is a java class that will do this very thing. There are certain parameters that I’m hard coding here like width of image, height of image, background color of image, and some more stuff. If you want to pull those out, you could. import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.font.FontRenderContext; import … Read more

Can Java Sound be used to control the system volume?

No, it cannot. Here is source adapted from an answer to Adjusting master volume on coderanch. The source iterates the available lines, checks if they have a control of the right type, and if so, puts them in a GUI attached to a JSlider import java.awt.*; import javax.swing.*; import javax.sound.sampled.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public … Read more

Trouble playing wav in Java

I’m not sure why the second approach you linked to starts another thread; I believe the audio will be played in its own thread anyway. Is the problem that your application finishes before the clip has finished playing? import javax.sound.sampled.*; import java.io.File; import java.io.IOException; import javax.sound.sampled.LineEvent.Type; private static void playClip(File clipFile) throws IOException, UnsupportedAudioFileException, LineUnavailableException, … Read more

Java raw audio output

It is pretty simple to generate a sound in memory. E.G. The important part of generating the tone (and storing it in a Clip) is encompassed in this code: /** Generates a tone, and assigns it to the Clip. */ public void generateTone() throws LineUnavailableException { if ( clip!=null ) { clip.stop(); clip.close(); } else … Read more