I use AudioRecord to record raw sound for processing. Sound recordings are completely without any interference, but when raw PCM data is played, it plays as if it were significantly accelerated (about twice as much). I view and play PCM data in Audacity. I am using the actual phone (Samsung Galaxy S5670) for testing. Recording is performed at a frequency of 44100 Hz, 16 bits. Any idea what might trigger this?
The following is the recording code:
public class TestApp extends Activity { File file; OutputStream os; BufferedOutputStream bos; AudioRecord recorder; int iAudioBufferSize; boolean bRecording; int iBytesRead; Thread recordThread = new Thread(){ @Override public void run() { byte[] buffer = new byte[iAudioBufferSize]; int iBufferReadResult; iBytesRead = 0; while(!interrupted()) { iBufferReadResult = recorder.read(buffer, 0, iAudioBufferSize);
RESOLVED: I published this after fighting it for 1-2 days. But, ironically, I found a solution shortly after publication. Writing a buffered output stream took too much time in a for loop, so the stream skipped samples. changed it to write lock by deleting the for loop. It works great.
source share