1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
class CaptureThreadSignal extends Thread {
public void run(){
try {
byte tempBuffer[]=new byte[line.getBufferSize()/5];
AudioFormat format = getAudioFormat();
line.open(format);
line.start();
dataOutputStream = null;
audioOutputStream = null;
dataOutputStream = AudioSystemShadow.getDataOutputStream(wavFile);
audioOutputStream = AudioSystemShadow.getAudioOutputStream(fileType, format, AudioSystem.NOT_SPECIFIED,dataOutputStream);
StopCaptureSignal = false;
while(!stopCaptureSignal){
int cnt=line.read(tempBuffer,0,tempBuffer.length);
if (cnt>0){
if (startWrite){
int nBytesWritten = audioOutputStream.write(tempBuffer, 0, tempBuffer.length);
}
progressBar.setValue((int)(calculateRMSLevel(tempBuffer)/327.67));
// divided by 32767 (because 16bit data) and mutiplied by 100 to get a 0-100 progressbar value
}//end if
}//end while
line.stop();
line.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
} |
Partager