Hi!

Just signed up and can't help to notice what a good forum you got going here!! congratulations!

I am working on a project of educational software concerning sound editing and audio-video synchronization. I am researching the Java Sound API and it's been working pretty well but now I got stuck in a lower level detail.

I want to extract audio data from an audio file through a AudioInputStream and then work with it to create some sound visualizations.

The problem is that my function to extract the data is only comes out with all the values set to 1.

here is how I am trying to extrat it:

public int [] getSoundData()
	{
		int [] data = new int [soundSize];
		int temp, count = 0;
		try
		{
			
			AudioInputStream tempAudioStream;
			tempAudioStream = AudioSystem.getAudioInputStream(new File(filename));
			
			while((temp = tempAudioStream.read()) != -1)
			{
				data[count] = temp;
				count++;
			}
		}catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
		return data;
	}

I wouldn't mind having a byte [] in the end if you know a better way, I just used int [] because AudioInputStream.read() returns an int.

The file is valid, the sound plays perfect in the application but data comes out with all 1's.
Any idea of what might be the problem?

Thanks in advance!!

David Jonas

Recommended Answers

All 2 Replies

Hi!!

Thank you so much! it worked perfect! I still don't understand why i got only 1's with the AudioInputStream.read() but with the byte array it worked like a charm!!!

Cheers!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.