This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Audio Level Meter

 
Chris Papadopoulos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never noticed that. Yes, NOT_SPECIFIED is -1.
 
Chris Papadopoulos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured that "\t" wasn't working because the format was csv,I've changed it in xls and now it works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic