Hello
I have a program which creates a thread that captures data from the soundcard at 48 KHz and writes it to a buffer for collection. The heart of the thread code is as follows ..
public void run() {
// Run continously
for (;;) {
// get data from the audio device.
getSample();
}
}
// Read in 2 bytes from the audio source combine them together into a single integer
// then write that into the sound buffer
private void getSample () {
int sample,count,total=0,fsample;
byte buffer[]=new byte[2];
try {
while (total<1) {
count=Line.read(buffer,0,2);
total=total+count;
}
} catch (Exception e) {
String err=e.getMessage();
}
sample=(buffer[0]<<8)+buffer[1];
etc etc etc
}
The program works except the process appears to take 100% of the CPU's time. I presume this is because the thread is sat waiting for data to arrive at the Line.Read line. I have tried inserting Thread.yield() at various points in the thread but it seems to make no difference.
Can anyone suggest ways I can reduce the amount of CPU time this thread takes ?
Thanks for your time
Ian