Any idea why reading bytes from AudioRecord would cause an error while
reading shorts would not?  The sound comes through great with short
but I get only static with bytes.

Working code with short[]:

int minBufferSize = AudioRecord.getMinBufferSize(this.getSampleRate(),
                                                                          
this.getChannelConfiguration(),
                                                                          
this.getAudioEncoding());

AudioRecord recordInstance = new AudioRecord
(MediaRecorder.AudioSource.MIC,
                                                                        
this.getSampleRate(),
                                                                        
this.getChannelConfiguration(),
                                                                        
this.getAudioEncoding(),
                                                                        
minBufferSize );
bufferedStreamInstance = new BufferedOutputStream(new FileOutputStream
(this.pcmFile));
DataOutputStream dataOutputStreamInstance = new DataOutputStream
(bufferedStreamInstance);

short[] tempBuffer = new short[minBufferSize ];
recordInstance.startRecording();
while (totalBytesRead < timeToRecord*sampleRate) {
        bufferRead = recordInstance.read(tempBuffer, 0, minBufferSize );

        for (int idxBuffer = 0; idxBuffer < bufferRead; ++idxBuffer) {
                dataOutputStreamInstance.writeShort(tempBuffer[idxBuffer]);
        }
}

//      Close resources…
recordInstance.stop();
bufferedStreamInstance.close();

If I just change these two lines though, I get static:

1) Change:
short[] tempBuffer = new short[minBufferSize];

To this:
byte[] tempBuffer = new byte[minBufferSize];

2) And this:
for (int idxBuffer = 0; idxBuffer < bufferRead; ++idxBuffer) {
        dataOutputStreamInstance.writeShort(tempBuffer[idxBuffer]);
}

To this:
dataOutputStreamInstance.write(tempBuffer, 0, bufferRead);

Anyone else experience this or have suggestions?


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to