aspose file tools*
The moose likes Java in General and the fly likes Audio Level Meter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Audio Level Meter" Watch "Audio Level Meter" New topic
Author

Audio Level Meter

Chris Papadopoulos
Greenhorn

Joined: Nov 14, 2013
Posts: 7
Hello

I'm new to programming and I'm trying to make a java application that will "hear" (not record necessarily) the sound and display how loud is.I'm thinking of converting the sound recordings to numbers,so I can see the difference on the sound levels.I got this code and I added the "getLevel()" method,which returns the amplitude of the current recording,but it's returning -1 everytime.I guess I'm not using it properly. Any ideas how I must call this method?I have to deliver my project in a week,so any help will be much appreciated!

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Since getLevel seems to return a float in the range 0.0f to 1.0f, you cannot get it to print -1. It would appear you are never actually getting to that print instruction. Try printing out what the value from read() is, so you can see whether you get to that if.

I shall move this discussion as too difficult for “beginning”.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Campbell Ritchie wrote:Since getLevel seems to return a float in the range 0.0f to 1.0f, you cannot get it to print -1.

It can also return AudioSystem.NOT_SPECIFIED which is an int (presumably with the value -1). Not sure if this would print as -1 or -1.0 (I would guess the latter).

To find out why it is returning -1 you could take a look at the source code, find what could cause it to return -1 (or AudioSystem.NOT_SPECIFIED) and then work out which of those situations applies to your code.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
I never noticed that. Yes, NOT_SPECIFIED is -1.
Chris Papadopoulos
Greenhorn

Joined: Nov 14, 2013
Posts: 7
Ok,I managed to make it capture audio and print on a xls file the timestamp and the value of the current sample,but there is a problem : even I've put some spaces between the time and the value and it seems that they are in different columns,they are actualy on the same column of the xls,it's just expanded and covers the next column (I can put a print screen if you don't understand).How can I make it print the data of time and amplitude in two different columns?Here's my code of the class which creates the file and saves the data on xls :

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Well done sorting out the first problem How did you do it?

If that file is a csv, why are you using that sort of format? Where are the commas? Put some commas in to separate the columns.
You ought to have one method which writes the file, and close the formatter in a finally (or in Java7+ use try with resources).
Chris Papadopoulos
Greenhorn

Joined: Nov 14, 2013
Posts: 7
Thanks

Well,I didn't manage to use the getLevel method,I just made a new method which reads the buffer and writes (using Formatter) the data on a csv file.I also figured out that it's not necessary to convert the data from byte to integer,as I firstly did.

About the columns,I didn't know about the csv,my professor told me to use it,but I don't know how to use it and I tried to make it print the time and the amplitude in two columns,but I've failed.Isn't there a way to make it work in xls files?I used "\t" and "%t",but it didn't work.I'm trying to avoid rewriting my code,if it's not necessary.
Chris Papadopoulos
Greenhorn

Joined: Nov 14, 2013
Posts: 7
I figured that "\t" wasn't working because the format was csv,I've changed it in xls and now it works
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Audio Level Meter