Re: Java silence detection
Andrew Thompson ha scritto:
miraglia.c@gmail.com wrote:
....
I used a simple mathematic average like this:
if((numBytesRead= targetLine.read(data, 0, bufferLengthInBytes)) ==-1)
{break;}
somma=0;
for(int i = 800; i<20000; i+=1 ){
somma += Math.abs ( data [i]);
}
I had been meaning to ask if you had taken the format
of the data line into account. I was surprised to see that
all lines on my PC were stereo 44.1KHz - 16 bit (signed
or something).
When plotting the data, it was apparent I was making
some fundamental mistake in converting the bytes to
numbers, and my traces* 'looked like your description'.
* <http://www.physci.org/test/oscilloscope/screenshots/>
Note particularly the images prefixed with 'sinetone' -
I wanted the simplest of input signals.
Go to the parent directory for the 'audiotraces' Jar file,
the source I of it, and the small 'tone.jar' which I found
handy for testing..
BTW - please remove tab's from source before posting.
2 or four space characters is best.
Andrew T.
No, I hadn't taken in account the format of the data line.
I just read the sound data from the targetDataLine and
converted every single byte (they are 44100) from the line
in a number. I suppose that when this number was near to
0...it was silence. But I discovered that these values are,
in a lot of cases, very far from 0. This is why I introduced
the average.
All lines on my PC are 44.1 KHz 16 bit PCM_SIGNED too (I
found out these infos from your "audiotraces.jar").
I executed your application and I can't understand why
did you write "I was making some fundamental mistake in converting
the bytes to numbers". I think your traces are good. I just
understood that reading from the line produces an array of
byte of 44100 elements. Every one of them is a frequency.
But I am not able to understand nothing about the number of
channels (stereo).
Fortunately for me, I'm not interested in distinguish the
actual signal from noise. I just want to detect silence
to stop recording (acquiring sound data).
I hope my post will be useful for you.
Kar